Пример #1
0
def assign_role_for_collection(committer, collection_id, assignee_id,
                               new_role):
    """Assign the given user to the given role and subscribes the assignee
    to future collection updates.

    The caller should ensure that assignee_id corresponds to a valid user in
    the system.

    Args:
        committer: UserActionsInfo. UserActionsInfo object for the committer.
        collection_id: str. ID of the collection.
        assignee_id: str. ID of the user whose role is being changed.
        new_role: str. The name of the new role: One of
            ROLE_OWNER,
            ROLE_EDITOR.

    Raises:
        Exception. This could potentially throw an exception from
            _assign_role.
    """
    _assign_role(committer, assignee_id, new_role, collection_id,
                 constants.ACTIVITY_TYPE_COLLECTION)
    if new_role in [rights_domain.ROLE_OWNER, rights_domain.ROLE_EDITOR]:
        subscription_services.subscribe_to_collection(assignee_id,
                                                      collection_id)
Пример #2
0
def create_new_collection_rights(collection_id, committer_id):
    """Creates a new collection rights object and saves it to the datastore.
    Subscribes the committer to the new collection.

    Args:
        collection_id: str. ID of the collection.
        committer_id: str. ID of the committer.
    """
    collection_rights = rights_domain.ActivityRights(collection_id,
                                                     [committer_id], [], [],
                                                     [])
    commit_cmds = [{'cmd': rights_domain.CMD_CREATE_NEW}]

    collection_models.CollectionRightsModel(
        id=collection_rights.id,
        owner_ids=collection_rights.owner_ids,
        editor_ids=collection_rights.editor_ids,
        voice_artist_ids=collection_rights.voice_artist_ids,
        viewer_ids=collection_rights.viewer_ids,
        community_owned=collection_rights.community_owned,
        status=collection_rights.status,
        viewable_if_private=collection_rights.viewable_if_private,
        first_published_msec=collection_rights.first_published_msec).commit(
            committer_id, 'Created new collection', commit_cmds)

    subscription_services.subscribe_to_collection(committer_id, collection_id)
Пример #3
0
 def reduce(key, stringified_values):
     values = [ast.literal_eval(v) for v in stringified_values]
     for item in values:
         if item['type'] == 'feedback':
             subscription_services.subscribe_to_thread(key, item['id'])
         elif item['type'] == 'exploration':
             subscription_services.subscribe_to_exploration(key, item['id'])
         elif item['type'] == 'collection':
             subscription_services.subscribe_to_collection(key, item['id'])
Пример #4
0
 def reduce(key, stringified_values):
     values = [ast.literal_eval(v) for v in stringified_values]
     for item in values:
         if item["type"] == "feedback":
             subscription_services.subscribe_to_thread(key, item["id"])
         elif item["type"] == "exploration":
             subscription_services.subscribe_to_exploration(key, item["id"])
         elif item["type"] == "collection":
             subscription_services.subscribe_to_collection(key, item["id"])
Пример #5
0
 def reduce(key, stringified_values):
     values = [ast.literal_eval(v) for v in stringified_values]
     for item in values:
         if item['type'] == 'feedback':
             subscription_services.subscribe_to_thread(key, item['id'])
         elif item['type'] == 'exploration':
             subscription_services.subscribe_to_exploration(key, item['id'])
         elif item['type'] == 'collection':
             subscription_services.subscribe_to_collection(key, item['id'])
Пример #6
0
    def test_get_collection_ids_subscribed_to(self):
        self.assertEqual(subscription_services.get_collection_ids_subscribed_to(USER_ID), [])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(subscription_services.get_collection_ids_subscribed_to(USER_ID), [COLLECTION_ID])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID_2)
        self.assertEqual(
            subscription_services.get_collection_ids_subscribed_to(USER_ID), [COLLECTION_ID, COLLECTION_ID_2]
        )
    def test_subscribed_collection_cannot_be_added_to_playlist(self):
        # Subscribe to collection.
        subscription_services.subscribe_to_collection(self.user_id,
                                                      self.COL_ID_0)
        self.assertEqual(
            self._get_all_learner_playlist_collection_ids(self.user_id), [])

        # Now if we try to add the same collection, it shouldn't be added.
        learner_progress_services.add_collection_to_learner_playlist(
            self.user_id, self.COL_ID_0)
        self.assertEqual(
            self._get_all_learner_playlist_collection_ids(self.user_id), [])
Пример #8
0
    def test_get_collection_ids_subscribed_to(self):
        self.assertEqual(
            subscription_services.get_collection_ids_subscribed_to(
                USER_ID), [])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(
            subscription_services.get_collection_ids_subscribed_to(USER_ID),
            [COLLECTION_ID])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID_2)
        self.assertEqual(
            subscription_services.get_collection_ids_subscribed_to(USER_ID),
            [COLLECTION_ID, COLLECTION_ID_2])
Пример #9
0
def create_new_collection_rights(collection_id, committer_id):
    collection_rights = ActivityRights(collection_id, [committer_id], [], [])
    commit_cmds = [{'cmd': CMD_CREATE_NEW}]

    collection_models.CollectionRightsModel(
        id=collection_rights.id,
        owner_ids=collection_rights.owner_ids,
        editor_ids=collection_rights.editor_ids,
        viewer_ids=collection_rights.viewer_ids,
        community_owned=collection_rights.community_owned,
        status=collection_rights.status,
        viewable_if_private=collection_rights.viewable_if_private,
    ).commit(committer_id, 'Created new collection', commit_cmds)

    subscription_services.subscribe_to_collection(committer_id, collection_id)
Пример #10
0
    def setUp(self):
        super(UserSubscriptionsModelValidatorTests, self).setUp()

        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.signup(USER_EMAIL, USER_NAME)

        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        self.user_id = self.get_user_id_from_email(USER_EMAIL)
        self.owner = user_services.UserActionsInfo(self.owner_id)

        explorations = [exp_domain.Exploration.create_default_exploration(
            '%s' % i,
            title='title %d' % i,
            category='category%d' % i
        ) for i in xrange(3)]

        for exp in explorations:
            exp_services.save_new_exploration(self.owner_id, exp)
            rights_manager.publish_exploration(self.owner, exp.id)

        collections = [collection_domain.Collection.create_default_collection(
            '%s' % i,
            title='title %d' % i,
            category='category%d' % i
        ) for i in xrange(3, 6)]

        for collection in collections:
            collection_services.save_new_collection(self.owner_id, collection)
            rights_manager.publish_collection(self.owner, collection.id)

        thread_id = feedback_services.create_thread(
            'exploration', 'exp_id', None, 'a subject', 'some text')

        subscription_services.subscribe_to_thread(
            self.user_id, thread_id)
        subscription_services.subscribe_to_creator(self.user_id, self.owner_id)
        for exp in explorations:
            subscription_services.subscribe_to_exploration(
                self.user_id, exp.id)
        for collection in collections:
            subscription_services.subscribe_to_collection(
                self.user_id, collection.id)
        self.process_and_flush_pending_tasks()

        prod_validation_jobs_one_off.MODEL_TO_VALIDATOR_MAPPING = {
            user_models.UserSubscriptionsModel:
                prod_validation_jobs_one_off.UserSubscriptionsModelValidator,
        }
Пример #11
0
def assign_role_for_collection(committer_id, collection_id, assignee_id, new_role):
    """Assign `assignee_id` to the given role and subscribes the assignee
    to future collection updates.

    The caller should ensure that assignee_id corresponds to a valid user in
    the system.

    Args:
    - committer_id: str. The user_id of the user who is performing the action.
    - collection_id: str. The collection id.
    - assignee_id: str. The user_id of the user whose role is being changed.
    - new_role: str. The name of the new role: either 'owner', 'editor' or
        'viewer'.
    """
    _assign_role(committer_id, assignee_id, new_role, collection_id, feconf.ACTIVITY_TYPE_COLLECTION)
    if new_role in [ROLE_OWNER, ROLE_EDITOR]:
        subscription_services.subscribe_to_collection(assignee_id, collection_id)
Пример #12
0
def assign_role_for_collection(committer_id, collection_id, assignee_id,
                               new_role):
    """Assign `assignee_id` to the given role and subscribes the assignee
    to future collection updates.

    The caller should ensure that assignee_id corresponds to a valid user in
    the system.

    Args:
    - committer_id: str. The user_id of the user who is performing the action.
    - collection_id: str. The collection id.
    - assignee_id: str. The user_id of the user whose role is being changed.
    - new_role: str. The name of the new role: either 'owner', 'editor' or
        'viewer'.
    """
    _assign_role(committer_id, assignee_id, new_role, collection_id,
                 ACTIVITY_TYPE_COLLECTION)
    if new_role in [ROLE_OWNER, ROLE_EDITOR]:
        subscription_services.subscribe_to_collection(assignee_id,
                                                      collection_id)
Пример #13
0
    def test_subscribe_to_collection(self):
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID), [])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID), [COLLECTION_ID])

        # Repeated subscriptions to the same collection have no effect.
        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID), [COLLECTION_ID])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID_2)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID), [COLLECTION_ID, COLLECTION_ID_2])
Пример #14
0
    def test_subscribe_to_collection(self):
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID), [])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID),
                         [COLLECTION_ID])

        # Repeated subscriptions to the same collection have no effect.
        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID),
                         [COLLECTION_ID])

        subscription_services.subscribe_to_collection(USER_ID, COLLECTION_ID_2)
        self.assertEqual(self._get_collection_ids_subscribed_to(USER_ID),
                         [COLLECTION_ID, COLLECTION_ID_2])