Changeset 4183 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php
- Timestamp:
- 10/03/2016 02:05:43 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php
r4083 r4183 84 84 */ 85 85 public function pre_can_user( $verdict, $args ) { 86 // Logged out users have no permissions. 87 if ( ! is_user_logged_in() ) { 88 return false; 89 } 90 91 // No user is allowed to delete something. 86 92 if ( 'delete' === $args['action'] ) { 87 93 return false; … … 93 99 } 94 100 95 if ( 'approve' !== $args['action'] || ! in_array( $args['object_type'], array( 'project|locale|set-slug', 'translation-set' ) ) ) { 101 // No permissions for unknown object types. 102 if ( ! in_array( $args['object_type'], array( 'project|locale|set-slug', 'translation-set' ) ) ) { 96 103 return false; 97 104 } … … 103 110 } 104 111 105 $locale_slug = $locale_and_project_id->locale; 106 $current_project_id = $locale_and_project_id->project_id; 112 // Grant permissions to import plugin/theme translations with status 'waiting'. 113 if ( 'import-waiting' === $args['action'] ) { 114 return $this->is_plugin_or_theme_project( $locale_and_project_id->project_id ); 115 } 116 117 // The next checks are only for the 'approve' action, no permissions for other actions. 118 if ( 'approve' !== $args['action'] ) { 119 return false; 120 } 107 121 108 122 // Simple check to see if they're an approver or not. 109 $role = $this->is_approver_for_locale( $args['user_id'], $locale_ slug);123 $role = $this->is_approver_for_locale( $args['user_id'], $locale_and_project_id->locale ); 110 124 if ( ! $role ) { 111 125 return false; … … 118 132 119 133 // Grab the list of Projects (or 'all') that the user can approve. 120 $project_access_list = $this->get_project_id_access_list( $args['user_id'], $locale_ slug);134 $project_access_list = $this->get_project_id_access_list( $args['user_id'], $locale_and_project_id->locale ); 121 135 if ( ! $project_access_list ) { 122 136 return false; … … 129 143 130 144 // If current project is a parent ID. 131 if ( in_array( $ current_project_id, $project_access_list ) ) {145 if ( in_array( $locale_and_project_id->project_id, $project_access_list ) ) { 132 146 return true; 133 147 } 134 148 135 149 // A user is allowed to approve sub projects as well. 136 $project_access_list = $this->get_project_id_access_list( $args['user_id'], $locale_ slug, /* $include_children = */ true );137 if ( in_array( $ current_project_id, $project_access_list ) ) {150 $project_access_list = $this->get_project_id_access_list( $args['user_id'], $locale_and_project_id->locale, /* $include_children = */ true ); 151 if ( in_array( $locale_and_project_id->project_id, $project_access_list ) ) { 138 152 return true; 139 153 } 140 154 141 155 return false; 156 } 157 158 /** 159 * Determines if the project is for a plugin or theme. 160 * 161 * @param int $project_id Project ID. 162 * @return bool True, if project is a plugin/theme, false if not. 163 */ 164 public function is_plugin_or_theme_project( $project_id ) { 165 $project = GP::$project->get( $project_id ); 166 if ( ! $project ) { 167 return false; 168 } 169 170 return ( 0 === strpos( $project->path, 'wp-plugins/' ) || 0 === strpos( $project->path, 'wp-themes/' ) ); 142 171 } 143 172
Note: See TracChangeset
for help on using the changeset viewer.