Making WordPress.org

Changeset 4083


Ignore:
Timestamp:
09/16/2016 08:56:17 PM (10 years ago)
Author:
ocean90
Message:

Translate, Rosetta Roles: Add support for the new locale manager role.

See #1398.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php

    r3954 r4083  
    2929         */
    3030        const GENERAL_TRANSLATION_EDITOR_ROLE = 'general_translation_editor';
     31
     32        /**
     33         * Role of a locale manager.
     34         */
     35        const LOCALE_MANAGER_ROLE = 'locale_manager';
    3136
    3237        /**
     
    102107
    103108                // Simple check to see if they're an approver or not.
    104                 if ( ! $this->is_approver_for_locale( $args['user_id'], $locale_slug ) ) {
    105                         return false;
     109                $role = $this->is_approver_for_locale( $args['user_id'], $locale_slug );
     110                if ( ! $role ) {
     111                        return false;
     112                }
     113
     114                // Locale managers are allowed to approve all projects.
     115                if ( self::LOCALE_MANAGER_ROLE === $role ) {
     116                        return true;
    106117                }
    107118
     
    170181         * @param int    $user_id     User ID.
    171182         * @param string $locale_slug The Locale for which we are checking.
    172          * @return bool True, if user is an approver, false if not.
     183         * @return false|string Role, if user is an approver, false if not.
    173184         */
    174185        public function is_approver_for_locale( $user_id, $locale_slug ) {
     
    202213
    203214                $capabilities = $user->{$cap_key};
    204                 $is_approver = ! empty( $capabilities[ self::TRANSLATION_EDITOR_ROLE ] ) || ! empty( $capabilities[ self::GENERAL_TRANSLATION_EDITOR_ROLE ] );
    205                 $cache[ $user_id ][ $locale_slug ] = $is_approver;
    206 
    207                 return $is_approver;
     215
     216                if ( ! empty( $capabilities[ self::LOCALE_MANAGER_ROLE ] ) ) {
     217                        $cache[ $user_id ][ $locale_slug ] = self::LOCALE_MANAGER_ROLE;
     218                        return self::LOCALE_MANAGER_ROLE;
     219                } elseif ( ! empty( $capabilities[ self::GENERAL_TRANSLATION_EDITOR_ROLE ] ) ) {
     220                        $cache[ $user_id ][ $locale_slug ] = self::GENERAL_TRANSLATION_EDITOR_ROLE;
     221                        return self::GENERAL_TRANSLATION_EDITOR_ROLE;
     222                } elseif ( ! empty( $capabilities[ self::TRANSLATION_EDITOR_ROLE ] ) ) {
     223                        $cache[ $user_id ][ $locale_slug ] = self::TRANSLATION_EDITOR_ROLE;
     224                        return self::TRANSLATION_EDITOR_ROLE;
     225                } else {
     226                        $cache[ $user_id ][ $locale_slug ] = false;
     227                        return false;
     228                }
    208229        }
    209230
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php

    r3952 r4083  
    594594                        // Check to see if they have any special approval permissions
    595595                        $allowed_projects = array();
    596                         if ( ! $can_approve_for_all && $this->roles_adapter->is_approver_for_locale( $user_id, $locale ) ) {
     596                        if ( ! $can_approve_for_all && $role = $this->roles_adapter->is_approver_for_locale( $user_id, $locale ) ) {
    597597                                $allowed_projects = $this->roles_adapter->get_project_id_access_list( $user_id, $locale, true );
    598598
    599599                                // Check to see if they can approve for all projects in this locale.
    600                                 if ( in_array( 'all', $allowed_projects ) ) {
     600                                if ( Rosetta_Roles::LOCALE_MANAGER_ROLE === $role || in_array( 'all', $allowed_projects ) ) {
    601601                                        $can_approve_for_all = true;
    602602                                        $allowed_projects = array();
Note: See TracChangeset for help on using the changeset viewer.