Beispiel #1
0
 def _get_external_id_relationships(cls, item):
     snapshot_model_ids = [
         '%s-%d' % (item.id, version)
         for version in python_utils.RANGE(1, item.version + 1)]
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'collection_ids',
             collection_models.CollectionModel, [item.id]),
         base_model_validators.UserSettingsModelFetcherDetails(
             'owner_user_ids', item.owner_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'editor_user_ids', item.editor_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'viewer_user_ids', item.viewer_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'snapshot_metadata_ids',
             collection_models.CollectionRightsSnapshotMetadataModel,
             snapshot_model_ids),
         base_model_validators.ExternalModelFetcherDetails(
             'snapshot_content_ids',
             collection_models.CollectionRightsSnapshotContentModel,
             snapshot_model_ids)]
    def _get_external_id_relationships(cls, item):
        field_name_to_external_model_references = [
            base_model_validators.ExternalModelFetcherDetails(
                'feedback_thread_ids',
                feedback_models.GeneralFeedbackThreadModel, [item.id])
        ]
        if user_services.is_user_id_valid(item.author_id):
            field_name_to_external_model_references.append(
                base_model_validators.UserSettingsModelFetcherDetails(
                    'author_ids', [item.author_id],
                    may_contain_system_ids=True,
                    may_contain_pseudonymous_ids=True
                )
            )
        if item.target_type in TARGET_TYPE_TO_TARGET_MODEL:
            field_name_to_external_model_references.append(
                base_model_validators.ExternalModelFetcherDetails(
                    '%s_ids' % item.target_type,
                    TARGET_TYPE_TO_TARGET_MODEL[item.target_type],
                    [item.target_id]))
        if item.final_reviewer_id and user_services.is_user_id_valid(
                item.final_reviewer_id):

            # Bot rejects suggestions when the suggestion's targeted entity gets
            # removed from the topic. The bot doesn't have a UserSettingsModel
            # for their user_id. Exclude external model validation for bot.
            if item.final_reviewer_id != feconf.SUGGESTION_BOT_USER_ID:
                field_name_to_external_model_references.append(
                    base_model_validators.UserSettingsModelFetcherDetails(
                        'reviewer_ids', [item.final_reviewer_id],
                        may_contain_system_ids=True,
                        may_contain_pseudonymous_ids=True
                    ))
        return field_name_to_external_model_references
Beispiel #3
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'exploration_ids', exp_models.ExplorationModel, [item.id]),
         base_model_validators.ExternalModelFetcherDetails(
             'exploration_rights_ids', exp_models.ExplorationRightsModel,
             [item.id]),
         base_model_validators.UserSettingsModelFetcherDetails(
             'owner_user_ids',
             item.owner_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'editor_user_ids',
             item.editor_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'viewer_user_ids',
             item.viewer_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'contributor_user_ids',
             item.contributor_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False)
     ]
 def _get_external_id_relationships(cls, item):
     field_name_to_external_model_references = [
         base_model_validators.ExternalModelFetcherDetails(
             'message_ids',
             feedback_models.GeneralFeedbackMessageModel,
             ['%s.%s' % (item.id, i) for i in python_utils.RANGE(
                 item.message_count)])
     ]
     if item.original_author_id:
         field_name_to_external_model_references.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'author_ids', [item.original_author_id],
                 may_contain_system_ids=False,
                 may_contain_pseudonymous_ids=True
             ))
     if item.has_suggestion:
         field_name_to_external_model_references.append(
             base_model_validators.ExternalModelFetcherDetails(
                 'suggestion_ids', suggestion_models.GeneralSuggestionModel,
                 [item.id]))
     if item.entity_type in prod_validators.TARGET_TYPE_TO_TARGET_MODEL:
         field_name_to_external_model_references.append(
             base_model_validators.ExternalModelFetcherDetails(
                 '%s_ids' % item.entity_type,
                 prod_validators.TARGET_TYPE_TO_TARGET_MODEL[
                     item.entity_type], [item.entity_id]))
     if item.last_nonempty_message_author_id:
         field_name_to_external_model_references.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'last_nonempty_message_author_ids',
                 [item.last_nonempty_message_author_id],
                 may_contain_system_ids=True,
                 may_contain_pseudonymous_ids=True
             ))
     return field_name_to_external_model_references
Beispiel #5
0
 def _get_external_id_relationships(cls, item):
     external_id_relationships = [
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_settings_ids', [item.id],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
     ]
     if item.parent_user_id is None:
         # Full users (users without a parent) should have a valid auth ID.
         if item.gae_id is not None:
             external_id_relationships.append(
                 base_model_validators.ExternalModelFetcherDetails(
                     'auth_ids', auth_models.UserIdentifiersModel,
                     [item.gae_id]))
         if item.firebase_auth_id is not None:
             external_id_relationships.append(
                 base_model_validators.ExternalModelFetcherDetails(
                     'auth_ids', auth_models.UserIdByFirebaseAuthIdModel,
                     [item.firebase_auth_id]))
     else:
         # Profile users (users with a parent) should have a valid parent ID.
         external_id_relationships.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'parent_user_settings_ids', [item.parent_user_id],
                 may_contain_system_ids=False,
                 may_contain_pseudonymous_ids=False))
     return external_id_relationships
 def _get_external_id_relationships(cls, item):
     field_name_to_external_model_references = []
     if user_services.is_user_id_valid(item.author_id):
         field_name_to_external_model_references.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'author_ids', [item.author_id],
                 may_contain_system_ids=False,
                 may_contain_pseudonymous_ids=True
             )
         )
     if item.target_type in TARGET_TYPE_TO_TARGET_MODEL:
         field_name_to_external_model_references.append(
             base_model_validators.ExternalModelFetcherDetails(
                 '%s_ids' % item.target_type,
                 TARGET_TYPE_TO_TARGET_MODEL[item.target_type],
                 [item.target_id]))
     if (
             item.final_reviewer_id and
             user_services.is_user_id_valid(item.final_reviewer_id)
     ):
         field_name_to_external_model_references.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'final_reviewer_ids', [item.final_reviewer_id],
                 may_contain_system_ids=False,
                 may_contain_pseudonymous_ids=True
             ))
     return field_name_to_external_model_references
Beispiel #7
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'recipient_id', [item.recipient_id],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'sender_id', [item.sender_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=False)]
Beispiel #8
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [item.committer_id],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False)
     ]
Beispiel #9
0
    def test_may_contain_pseudonymous_users_filters_pseudonymous_users(self):
        user_settings_model = (
            base_model_validators.UserSettingsModelFetcherDetails(
                'committer_ids', [self.USER_ID, self.PSEUDONYMOUS_ID],
                may_contain_system_ids=False,
                may_contain_pseudonymous_ids=True))

        self.assertItemsEqual(user_settings_model.model_ids, [self.USER_ID])
 def test_error_raised_if_model_ids_contain_system_ids(self):
     with self.assertRaisesRegexp(
             utils.ValidationError,
             'The field \'committer_ids\' should not contain system IDs'):
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [feconf.MIGRATION_BOT_USER_ID, 'User-1'],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False)
    def test_may_contain_system_users_filters_system_ids(self):
        user_settings_model = (
            base_model_validators.UserSettingsModelFetcherDetails(
                'committer_ids', [feconf.MIGRATION_BOT_USER_ID, 'User-1'],
                may_contain_system_ids=True,
                may_contain_pseudonymous_ids=False))

        self.assertItemsEqual(user_settings_model.model_ids, ['User-1'])
Beispiel #12
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'story_ids', story_models.StoryModel, [item.story_id]),
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_id', [item.user_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=True)
     ]
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'resolver_ids',
             [item.resolver_id] if item.resolver_id is not None else [],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'entity_ids', exp_models.ExplorationModel, [item.entity_id])]
Beispiel #14
0
 def test_user_setting_model_fetcher_with_system_id(self):
     user_settings_model = (
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [feconf.MIGRATION_BOT_USER_ID, self.USER_ID],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False))
     self.assertItemsEqual(user_settings_model.model_ids, [self.USER_ID])
     self.assertItemsEqual(
         user_settings_model.model_id_errors,
         ['The field \'committer_ids\' should not contain system IDs'])
Beispiel #15
0
 def test_user_setting_model_fetcher_with_invalid_id(self):
     user_settings_model = (
         base_model_validators.UserSettingsModelFetcherDetails(
             'mock_field', ['User-1', self.USER_ID],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False))
     self.assertItemsEqual(user_settings_model.model_ids, [self.USER_ID])
     self.assertItemsEqual(
         user_settings_model.model_id_errors,
         ['The user id User-1 in the field \'mock_field\' is invalid'])
Beispiel #16
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'subtopic_page_ids', subtopic_models.SubtopicPageModel,
             [item.id[:item.id.rfind(base_models.VERSION_DELIMITER)]]),
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [item.committer_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=True)
     ]
Beispiel #17
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_settings_ids', [item.user_id],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'user_auth_details_ids', auth_models.UserAuthDetailsModel,
             [item.user_id]),
     ]
Beispiel #18
0
 def test_error_raised_if_model_ids_contain_pseudonymous_ids(self):
     user_settings_model = (
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [self.PSEUDONYMOUS_ID, self.USER_ID],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False))
     self.assertItemsEqual(user_settings_model.model_ids, [self.USER_ID])
     self.assertItemsEqual(user_settings_model.model_id_errors, [
         'The field \'committer_ids\' should not contain pseudonymous IDs'
     ])
Beispiel #19
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'item.id.user_id', [
                 item.id[:item.id.find('.')]],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'item.id.thread_id',
             feedback_models.GeneralFeedbackThreadModel, [
                 item.id[item.id.find('.') + 1:]])]
Beispiel #20
0
 def _get_external_id_relationships(cls, item):
     cloned_from_exploration_id = []
     if item.cloned_from:
         cloned_from_exploration_id.append(item.cloned_from)
     snapshot_model_ids = [
         '%s-%d' % (item.id, version)
         for version in python_utils.RANGE(1, item.version + 1)
     ]
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'exploration_ids', exp_models.ExplorationModel, [item.id]),
         # TODO (#10828): Remove validation for cloned_from
         # exp ids after the field is entirely removed from
         # all models.
         base_model_validators.ExternalModelFetcherDetails(
             'cloned_from_exploration_ids', exp_models.ExplorationModel,
             cloned_from_exploration_id),
         base_model_validators.UserSettingsModelFetcherDetails(
             'owner_user_ids',
             item.owner_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'editor_user_ids',
             item.editor_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.UserSettingsModelFetcherDetails(
             'viewer_user_ids',
             item.viewer_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'snapshot_metadata_ids',
             exp_models.ExplorationRightsSnapshotMetadataModel,
             snapshot_model_ids),
         base_model_validators.ExternalModelFetcherDetails(
             'snapshot_content_ids',
             exp_models.ExplorationRightsSnapshotContentModel,
             snapshot_model_ids)
     ]
Beispiel #21
0
 def _get_external_id_relationships(cls, item):
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'platform_parameter_ids',
             config_models.PlatformParameterModel,
             [item.id[:item.id.find('-')]]
         ),
         base_model_validators.UserSettingsModelFetcherDetails(
             'committer_ids', [item.committer_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=True
         )
     ]
Beispiel #22
0
 def _get_external_id_relationships(cls, item):
     field_name_to_external_model_references = [
         base_model_validators.ExternalModelFetcherDetails(
             'feedback_thread_ids',
             feedback_models.GeneralFeedbackThreadModel, [item.thread_id])
     ]
     if item.author_id:
         field_name_to_external_model_references.append(
             base_model_validators.UserSettingsModelFetcherDetails(
                 'author_ids', [item.author_id],
                 may_contain_system_ids=True,
                 may_contain_pseudonymous_ids=True))
     return field_name_to_external_model_references
Beispiel #23
0
 def _get_external_id_relationships(cls, item):
     field_name_to_external_model_references = [
         base_model_validators.ExternalModelFetcherDetails(
             'blog_post_rights_model_ids', blog_models.BlogPostRightsModel,
             [item.id]),
         base_model_validators.ExternalModelFetcherDetails(
             'blog_post_model_ids', blog_models.BlogPostModel, [item.id])
     ]
     field_name_to_external_model_references.append(
         base_model_validators.UserSettingsModelFetcherDetails(
             'author_ids', [item.author_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=True))
     return field_name_to_external_model_references
Beispiel #24
0
    def _get_external_id_relationships(cls, item):
        field_name_to_external_model_references = [
            base_model_validators.ExternalModelFetcherDetails(
                'feedback_thread_ids',
                feedback_models.GeneralFeedbackThreadModel, [item.id]),
            base_model_validators.UserSettingsModelFetcherDetails(
                'author_ids', [item.author_id],
                may_contain_system_ids=True,
                may_contain_pseudonymous_ids=True)
        ]

        if item.target_type in TARGET_TYPE_TO_TARGET_MODEL:
            field_name_to_external_model_references.append(
                base_model_validators.ExternalModelFetcherDetails(
                    '%s_ids' % item.target_type,
                    TARGET_TYPE_TO_TARGET_MODEL[item.target_type],
                    [item.target_id]))
        if item.final_reviewer_id:
            field_name_to_external_model_references.append(
                base_model_validators.UserSettingsModelFetcherDetails(
                    'reviewer_ids', [item.final_reviewer_id],
                    may_contain_system_ids=True,
                    may_contain_pseudonymous_ids=True))
        return field_name_to_external_model_references
Beispiel #25
0
 def _get_external_id_relationships(cls, item):
     external_id_relationships = [
         base_model_validators.ExternalModelFetcherDetails(
             'topic_ids', topic_models.TopicModel, [item.topic_id]),
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_id', [item.user_id],
             may_contain_system_ids=True,
             may_contain_pseudonymous_ids=True)
     ]
     if item.id.startswith('rights'):
         external_id_relationships.append(
             base_model_validators.ExternalModelFetcherDetails(
                 'topic_rights_ids', topic_models.TopicRightsModel,
                 [item.topic_id]))
     return external_id_relationships
Beispiel #26
0
 def _get_external_id_relationships(cls, item):
     message_ids = []
     user_ids = []
     if '.' in item.id:
         index = item.id.find('.')
         user_ids = [item.id[:index]]
         message_ids = ['%s.%s' % (
             item.id[index + 1:], message_id) for message_id in (
                 item.message_ids_read_by_user)]
     return [
         base_model_validators.ExternalModelFetcherDetails(
             'message_ids',
             feedback_models.GeneralFeedbackMessageModel, message_ids),
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_ids', user_ids,
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False)]
Beispiel #27
0
    def _get_external_id_relationships(cls, item):
        """Returns a mapping of external id to model class.

        Args:
            item: auth_models.UserIdentifiersModel. Entity to validate.

        Returns:
            list(ExternalModelFetcherDetails). A list whose values are
            ExternalModelFetcherDetails instances each representing
            the class and ids for a single type of external model to fetch.
        """
        return [
            base_model_validators.UserSettingsModelFetcherDetails(
                'user_settings_ids', [item.user_id],
                may_contain_system_ids=False,
                may_contain_pseudonymous_ids=False),
            base_model_validators.ExternalModelFetcherDetails(
                'user_auth_details_ids', auth_models.UserAuthDetailsModel,
                [item.user_id]),
        ]
Beispiel #28
0
 def _get_external_id_relationships(cls, item):
     message_ids = []
     for reference in item.feedback_message_references:
         try:
             message_ids.append('%s.%s' % (
                 reference['thread_id'], reference['message_id']))
         except Exception:
             cls._add_error(
                 'feedback message %s' % (
                     base_model_validators.ERROR_CATEGORY_REFERENCE_CHECK),
                 'Entity id %s: Invalid feedback reference: %s' % (
                     item.id, reference))
     return [
         base_model_validators.UserSettingsModelFetcherDetails(
             'user_ids', [item.id],
             may_contain_system_ids=False,
             may_contain_pseudonymous_ids=False),
         base_model_validators.ExternalModelFetcherDetails(
             'message_ids', feedback_models.GeneralFeedbackMessageModel,
             message_ids)]