Ticket #116: project-admin-add.patch
| File project-admin-add.patch, 5.9 KB (added by Nightgunner5, 22 months ago) |
|---|
-
gp-includes/routes/project.php
155 155 foreach( array_merge( (array)$permissions, (array)$parent_permissions ) as $permission ) { 156 156 $permission->user = GP::$user->get( $permission->user_id ); 157 157 } 158 159 $is_admin = $this->can( 'admin', null, null ); 160 $admins = GP::$permission->find_many( array( 'action' => 'write', 'object_type' => 'project', 'object_id' => $project->id ) ); 161 $parent_admins = array(); 162 foreach( $path_to_root as $parent_project ) { 163 $this_parent_admins = GP::$permission->find_many( array( 'action' => 'write', 'object_type' => 'project', 'object_id' => $parent_project->id ) ); 164 foreach( $this_parent_admins as $admin ) { 165 $admin->project = $parent_project; 166 } 167 $parent_admins = array_merge( $parent_admins, (array)$this_parent_admins ); 168 } 169 // we can't join on users table 170 foreach( array_merge( (array)$admins, (array)$parent_admins ) as $admin ) { 171 $admin->user = GP::$user->get( $admin->user_id ); 172 } 173 158 174 $this->tmpl( 'project-permissions', get_defined_vars() ); 159 175 } 160 176 … … 180 196 $permission? 181 197 $this->notices[] = __('Validator was added.') : $this->errors[] = __('Error in adding validator.'); 182 198 } 199 if ( 'add-admin' == gp_post( 'action' ) ) { 200 $this->can_or_redirect( 'admin', null, null ); 201 $user = GP::$user->by_login( gp_post( 'user_login' ) ); 202 if ( !$user ) { 203 $this->redirect_with_error( __('User wasn’t found!'), gp_url_current() ); 204 return; 205 } 206 $new_permission = new GP_Permission( array( 207 'user_id' => $user->id, 208 'action' => 'write', 209 'object_id' => $project->id, 210 'object_type' => 'project' 211 ) ); 212 $this->validate_or_redirect( $new_permission, gp_url_current() ); 213 $permission = GP::$permission->create( $new_permission ); 214 $permission? 215 $this->notices[] = __('Administrator was added.') : $this->errors[] = __('Error in adding administrator.'); 216 } 183 217 $this->redirect( gp_url_current() ); 184 218 } 185 219 -
gp-templates/project-permissions-admin.php
1 <h3 id="admins"> 2 <?php _e('Administrators'); ?> 3 <?php if ( count( $admins ) + count( $parent_admins ) > 10 ): ?> 4 <a href="#add" onclick="jQuery('#user_login_admin').focus(); return false;" class="secondary">Add →</a> 5 <?php endif; ?> 6 </h3> 7 <?php if ( $admins ): ?> 8 <?php if ( $parent_admins ): ?> 9 <h4 id="project-admins"><?php _e('Administrators for this project'); ?></h4> 10 <?php endif; ?> 11 <ul class="permissions"> 12 <?php foreach( $admins as $admin ): ?> 13 <li> 14 <span class="user"><?php echo esc_html( $admin->user->user_login ); ?></span> 15 <span class="permission-action"><?php printf( __( 'has full %s access' ), esc_html( $admin->action ) ); ?></span> 16 <?php if ( $is_admin ): ?> 17 <a href="<?php echo gp_url_join( gp_url_current(), '-delete/'.$admin->id ); ?>" class="action delete"><?php _e('Remove'); ?></a> 18 <?php endif; ?> 19 </li> 20 <?php endforeach; ?> 21 </ul> 22 <?php endif; ?> 23 <?php if ( $parent_admins ): ?> 24 <h4 id="parent-admins"><?php _e('Administrators for parent projects'); ?></h4> 25 <ul class="permissions"> 26 <?php foreach( $parent_admins as $admin ): ?> 27 <li> 28 <span class="user"><?php echo esc_html( $admin->user->user_login ); ?></span> 29 <span class="permission-action"><?php printf( __( 'has full %s access' ), esc_html( $admin->action ) ); ?></span> 30 <span class="permission-action"><?php _e( 'in the project' ); ?></span> 31 <span class="user"><?php gp_link_project( $admin->project, esc_html( $admin->project->name ) ); ?></span> 32 </li> 33 <?php endforeach; ?> 34 </ul> 35 <?php endif; ?> 36 <?php if ( !$admins && !$parent_admins ): ?> 37 <strong><?php _e('No administrators defined for this project.'); ?></strong> 38 <?php endif; ?> 39 <?php if ( $is_admin ): ?> 40 <form action="" method="post" class="secondary"> 41 <h3 id="add-admin"><?php _e('Add an administrator for this project'); ?></h3> 42 <dl> 43 <dt><label for="user_login_admin"><?php _e('Username:'); ?></label></dt> 44 <dd><input type="text" name="user_login" value="" id="user_login_admin" /></dd> 45 46 <dt> 47 <input type="submit" name="submit" value="<?php echo esc_attr(__('Add →')); ?>" id="submit_admin" /> 48 <input type="hidden" name="action" value="add-admin" /> 49 </dt> 50 </dl> 51 </form> 52 <?php endif; ?> -
gp-templates/project-permissions.php
Property changes on: gp-templates\project-permissions-admin.php ___________________________________________________________________ Added: svn:eol-style + native
7 7 gp_tmpl_header(); 8 8 ?> 9 9 <h2><?php _e('Permissions'); ?></h2> 10 <?php gp_tmpl_load( 'project-permissions-admin', get_defined_vars() ); ?> 10 11 <h3 id="validators"> 11 12 <?php _e('Validators'); ?> 12 13 <?php if ( count( $permissions ) + count( $parent_permissions ) > 10 ): ?> … … 28 29 <span class="user"><?php echo esc_html( $permission->set_slug ); ?></span> 29 30 <a href="<?php echo gp_url_join( gp_url_current(), '-delete/'.$permission->id ); ?>" class="action delete"><?php _e('Remove'); ?></a> 30 31 </li> 31 <? endforeach; ?>32 <?php endforeach; ?> 32 33 </ul> 33 34 <?php endif; ?> 34 35 <?php if ( $parent_permissions ): ?> … … 45 46 <span class="permission-action">in the project </span> 46 47 <span class="user"><?php gp_link_project( $permission->project, esc_html( $permission->project->name ) ); ?></span> 47 48 </li> 48 <? endforeach; ?>49 <?php endforeach; ?> 49 50 </ul> 50 51 <?php endif; ?> 51 52 <?php if ( !$permissions && !$parent_permissions ): ?>
