Making WordPress.org

Changeset 10358


Ignore:
Timestamp:
10/11/2020 04:01:43 PM (6 years ago)
Author:
ocean90
Message:

Translate: Introduce the concept of read-only translation sets.

See #5471.

File:
1 edited

Legend:

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

    r6138 r10358  
    3737         */
    3838        const LOCALE_MANAGER_ROLE = 'locale_manager';
     39
     40        /**
     41         * Paths of translation sets the user cannot edit.
     42         */
     43        const READ_ONLY_TRANSLATION_SETS = [ 'sr/latin' ];
    3944
    4045        /**
    … …  
    114119                }
    115120
    116                 // Allow logged in users to submit translations.
    117                 if ( 'edit' == $args['action'] && 'translation-set' === $args['object_type'] ) {
    118                         return is_user_logged_in();
    119                 }
    120 
    121121                // Get locale and current project ID.
    122122                $locale_and_project_id = (object) $this->get_locale_and_project_id( $args['object_type'], $args['object_id'], $args );
    123123                if ( ! $locale_and_project_id ) {
    124124                        return false;
     125                }
     126
     127                $set_path = $locale_and_project_id->locale . '/' . $locale_and_project_id->set_slug;
     128                if ( \in_array( $set_path, self::READ_ONLY_TRANSLATION_SETS, true ) ) {
     129                        return false;
     130                }
     131
     132                // Allow logged in users to submit translations.
     133                if ( 'edit' == $args['action'] && 'translation-set' === $args['object_type'] ) {
     134                        return true;
    125135                }
    126136
    … …  
    512522                                }
    513523
    514                                 return array( 'locale' => $set->locale, 'project_id' => (int) $set->project_id );
     524                                return array( 'locale' => $set->locale, 'set_slug' => $set->slug, 'project_id' => (int) $set->project_id );
    515525
    516526                        case 'translation-set' :
    … …  
    522532                                }
    523533
    524                                 return array( 'locale' => $set->locale, 'project_id' => (int) $set->project_id );
     534                                return array( 'locale' => $set->locale, 'set_slug' => $set->slug, 'project_id' => (int) $set->project_id );
    525535
    526536                        case 'project|locale|set-slug' :
    527                                 list( $project_id, $locale ) = explode( '|', $object_id );
    528                                 return array( 'locale' => $locale, 'project_id' => (int) $project_id );
     537                                list( $project_id, $locale, $set_slug ) = explode( '|', $object_id );
     538                                return array( 'locale' => $locale, 'set_slug' => $set_slug, 'project_id' => (int) $project_id );
    529539                }
    530540
Note: See TracChangeset for help on using the changeset viewer.