Exemplo n.º 1
0
    def test_demo_collection(self):
        collection_services.load_demo('0')
        rights_manager.release_ownership_of_collection(
            feconf.SYSTEM_COMMITTER_ID, '0')

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))

        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
Exemplo n.º 2
0
    def test_contribution_msec_updates_on_published_collections(self):
        self.save_new_valid_collection(
            self.COL_ID, self.admin_id, title=self.COLLECTION_TITLE,
            category=self.COLLECTION_CATEGORY,
            objective=self.COLLECTION_OBJECTIVE,
            exploration_id=self.EXP_ID)

        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)
        exp_services.publish_exploration_and_update_user_profiles(
            self.admin_id, self.EXP_ID)

        # Test all owners and editors of collection after publication have
        # updated first contribution times.
        self.assertIsNotNone(user_services.get_user_settings(
            self.admin_id).first_contribution_msec)

        # Test editor of published collection has updated
        # first contribution time.
        rights_manager.release_ownership_of_collection(
            self.admin_id, self.COL_ID)

        collection_services.update_collection(
            self.editor_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'title',
                'new_value': 'Some new title'
            }], 'Changed the title')

        self.assertIsNotNone(user_services.get_user_settings(
            self.editor_id).first_contribution_msec)
Exemplo n.º 3
0
    def test_demo_collection(self):
        collection_services.load_demo('0')
        rights_manager.release_ownership_of_collection(
            self.system_user, '0')
        collection_rights = rights_manager.get_collection_rights('0')

        self.assertTrue(rights_manager.check_can_access_activity(
            self.user_a, collection_rights))
        self.assertTrue(rights_manager.check_can_edit_activity(
            self.user_a, collection_rights))
        self.assertFalse(rights_manager.check_can_delete_activity(
            self.user_a, collection_rights))

        self.assertTrue(rights_manager.check_can_access_activity(
            self.user_admin, collection_rights))
        self.assertTrue(rights_manager.check_can_edit_activity(
            self.user_admin, collection_rights))
        self.assertTrue(rights_manager.check_can_delete_activity(
            self.user_admin, collection_rights))

        self.assertTrue(rights_manager.check_can_access_activity(
            self.user_moderator, collection_rights))
        self.assertTrue(rights_manager.check_can_edit_activity(
            self.user_moderator, collection_rights))
        self.assertTrue(rights_manager.check_can_delete_activity(
            self.user_moderator, collection_rights))
    def setUp(self):
        super(CollectionEditorTests, self).setUp()
        system_user = user_services.get_system_user()

        collection_services.load_demo(self.COLLECTION_ID)
        rights_manager.release_ownership_of_collection(
            system_user, self.COLLECTION_ID)
Exemplo n.º 5
0
    def test_demo_collection(self):
        collection_services.load_demo('0')
        rights_manager.release_ownership_of_collection(
            feconf.SYSTEM_COMMITTER_ID, '0')

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))

        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
        self.assertTrue(
            rights_manager.Actor(self.user_id_admin).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, '0'))
Exemplo n.º 6
0
    def test_contribution_msec_updates_on_published_collections(self):
        self.save_new_valid_collection(self.COL_ID,
                                       self.admin_id,
                                       title=self.COLLECTION_TITLE,
                                       category=self.COLLECTION_CATEGORY,
                                       objective=self.COLLECTION_OBJECTIVE,
                                       exploration_id=self.EXP_ID)

        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)
        exp_services.publish_exploration_and_update_user_profiles(
            self.admin_id, self.EXP_ID)

        # Test all owners and editors of collection after publication have
        # updated first contribution times.
        self.assertIsNotNone(
            user_services.get_user_settings(
                self.admin_id).first_contribution_msec)

        # Test editor of published collection has updated
        # first contribution time.
        rights_manager.release_ownership_of_collection(self.admin_id,
                                                       self.COL_ID)

        collection_services.update_collection(
            self.editor_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'title',
                'new_value': 'Some new title'
            }], 'Changed the title')

        self.assertIsNotNone(
            user_services.get_user_settings(
                self.editor_id).first_contribution_msec)
Exemplo n.º 7
0
 def _reload_collection(self, collection_id):
     if constants.DEV_MODE:
         logging.info('[ADMIN] %s reloaded collection %s' %
                      (self.user_id, collection_id))
         collection_services.load_demo(unicode(collection_id))
         rights_manager.release_ownership_of_collection(
             user_services.get_system_user(), unicode(collection_id))
     else:
         raise Exception('Cannot reload a collection in production.')
Exemplo n.º 8
0
 def _reload_collection(self, collection_id):
     if feconf.DEV_MODE:
         logging.info('[ADMIN] %s reloaded collection %s' %
                      (self.user_id, collection_id))
         collection_services.load_demo(unicode(collection_id))
         rights_manager.release_ownership_of_collection(
             feconf.SYSTEM_COMMITTER_ID, unicode(collection_id))
     else:
         raise Exception('Cannot reload a collection in production.')
Exemplo n.º 9
0
 def _reload_collection(self, collection_id):
     if feconf.DEV_MODE:
         logging.info(
             '[ADMIN] %s reloaded collection %s' %
             (self.user_id, collection_id))
         collection_services.load_demo(unicode(collection_id))
         rights_manager.release_ownership_of_collection(
             feconf.SYSTEM_COMMITTER_ID, unicode(collection_id))
     else:
         raise Exception('Cannot reload a collection in production.')
Exemplo n.º 10
0
    def _reload_collection(self, collection_id):
        """Reloads the collection in dev_mode corresponding to the given
        collection id.

        Args:
            collection_id: str. The collection id.

        Raises:
            Exception: Cannot reload a collection in production.
        """
        if constants.DEV_MODE:
            logging.info('[ADMIN] %s reloaded collection %s' %
                         (self.user_id, collection_id))
            collection_services.load_demo(unicode(collection_id))
            rights_manager.release_ownership_of_collection(
                user_services.get_system_user(), unicode(collection_id))
        else:
            raise Exception('Cannot reload a collection in production.')
Exemplo n.º 11
0
def remove_user_from_activities_with_associated_rights_models(user_id):
    """Remove the user from exploration, collection, and topic models.

    Args:
        user_id: str. The ID of the user for which to remove the user from
            explorations, collections, and topics.
    """
    subscribed_exploration_summaries = (
        exp_fetchers.get_exploration_summaries_where_user_has_role(user_id))

    explorations_to_be_deleted_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries if
        exp_summary.is_private() and
        exp_summary.is_solely_owned_by_user(user_id)
    ]
    exp_services.delete_explorations(
        user_id, explorations_to_be_deleted_ids, force_deletion=True)

    # Release ownership of explorations that are public and are solely owned
    # by the to-be-deleted user.
    explorations_to_release_ownership_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries if
        not exp_summary.is_private() and
        exp_summary.is_solely_owned_by_user(user_id) and
        not exp_summary.community_owned
    ]
    for exp_id in explorations_to_release_ownership_ids:
        rights_manager.release_ownership_of_exploration(
            user_services.get_system_user(), exp_id)

    explorations_to_remove_user_from_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries if
        not exp_summary.is_solely_owned_by_user(user_id) and
        exp_summary.does_user_have_any_role(user_id)
    ]
    for exp_id in explorations_to_remove_user_from_ids:
        rights_manager.deassign_role_for_exploration(
            user_services.get_system_user(), exp_id, user_id)

    # To hard-delete explorations marked as deleted we are using the rights
    # model to retrieve the exploration as the summary model gets hard-deleted
    # while marking the exploration as deleted.
    explorations_rights = (
        rights_manager.get_exploration_rights_where_user_is_owner(user_id))
    explorations_to_be_deleted_ids = [
        exploration_rights.id for exploration_rights
        in explorations_rights if
        exploration_rights.is_private() and
        exploration_rights.is_solely_owned_by_user(user_id)
    ]
    exp_services.delete_explorations(
        user_id, explorations_to_be_deleted_ids, force_deletion=True)

    subscribed_collection_summaries = (
        collection_services.get_collection_summaries_where_user_has_role(
            user_id))

    collections_to_be_deleted_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries if
        col_summary.is_private() and
        col_summary.is_solely_owned_by_user(user_id)
    ]
    collection_services.delete_collections(
        user_id, collections_to_be_deleted_ids, force_deletion=True)

    # Release ownership of collections that are public and are solely owned
    # by the to-be-deleted user.
    collections_to_release_ownership_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries if
        not col_summary.is_private() and
        col_summary.is_solely_owned_by_user(user_id) and
        not col_summary.community_owned
    ]
    for col_id in collections_to_release_ownership_ids:
        rights_manager.release_ownership_of_collection(
            user_services.get_system_user(), col_id)

    collections_to_remove_user_from_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries if
        not col_summary.is_solely_owned_by_user(user_id) and
        col_summary.does_user_have_any_role(user_id)
    ]
    for col_id in collections_to_remove_user_from_ids:
        rights_manager.deassign_role_for_collection(
            user_services.get_system_user(), col_id, user_id)

    # To hard-delete collections marked as deleted we are using the rights
    # model to retrieve the collection as the summary model gets hard-deleted
    # while marking the collection as deleted.
    collection_rights = (
        rights_manager.get_collection_rights_where_user_is_owner(user_id))
    collections_to_be_deleted_ids = [
        collection_rights.id for collection_rights in collection_rights if
        collection_rights.is_private() and
        collection_rights.is_solely_owned_by_user(user_id)
    ]
    collection_services.delete_collections(
        user_id, collections_to_be_deleted_ids, force_deletion=True)

    topic_services.deassign_user_from_all_topics(
        user_services.get_system_user(), user_id)
Exemplo n.º 12
0
def pre_delete_user(user_id):
    """Prepare user for the full deletion.
        1. Mark all the activities that are private and solely owned by the user
           being deleted as deleted.
        2. Disable all the email preferences.
        3. Mark the user as to be deleted.
        4. Create PendingDeletionRequestModel for the user.

    Args:
        user_id: str. The id of the user to be deleted. If the user_id
            corresponds to a profile user then only that profile is deleted.
            For a full user, all of its associated profile users are deleted
            too.
    """
    pending_deletion_requests = []
    user_settings = user_services.get_user_settings(user_id, strict=True)

    linked_profile_user_ids = [
        user.user_id for user in
        user_services.get_all_profiles_auth_details_by_parent_user_id(user_id)
    ]
    profile_users_settings_list = user_services.get_users_settings(
        linked_profile_user_ids)
    for profile_user_settings in profile_users_settings_list:
        profile_id = profile_user_settings.user_id
        user_services.mark_user_for_deletion(profile_id)
        pending_deletion_requests.append(
            wipeout_domain.PendingDeletionRequest.create_default(
                profile_id, profile_user_settings.email,
                profile_user_settings.role, [], []))
    explorations_to_be_deleted_ids = []
    collections_to_be_deleted_ids = []
    if user_settings.role != feconf.ROLE_ID_LEARNER:
        subscribed_exploration_summaries = (
            exp_fetchers.get_exploration_summaries_subscribed_to(user_id))

        explorations_to_be_deleted_ids = [
            exp_summary.id for exp_summary in subscribed_exploration_summaries
            if exp_summary.is_private()
            and exp_summary.is_solely_owned_by_user(user_id)
        ]
        exp_services.delete_explorations(user_id,
                                         explorations_to_be_deleted_ids)

        # Release ownership of explorations that are public and are solely owned
        # by the to-be-deleted user.
        explorations_to_release_ownership_ids = [
            exp_summary.id for exp_summary in subscribed_exploration_summaries
            if not exp_summary.is_private()
            and exp_summary.is_solely_owned_by_user(user_id)
        ]
        for exp_id in explorations_to_release_ownership_ids:
            rights_manager.release_ownership_of_exploration(
                user_services.get_system_user(), exp_id)

        explorations_to_remove_user_from_ids = [
            exp_summary.id for exp_summary in subscribed_exploration_summaries
            if not exp_summary.is_solely_owned_by_user(user_id)
        ]
        for exp_id in explorations_to_remove_user_from_ids:
            rights_manager.deassign_role_for_exploration(
                user_services.get_system_user(), exp_id, user_id)

        subscribed_collection_summaries = (
            collection_services.get_collection_summaries_subscribed_to(user_id)
        )
        collections_to_be_deleted_ids = [
            col_summary.id for col_summary in subscribed_collection_summaries
            if col_summary.is_private()
            and col_summary.is_solely_owned_by_user(user_id)
        ]
        collection_services.delete_collections(user_id,
                                               collections_to_be_deleted_ids)

        # Release ownership of collections that are public and are solely owned
        # by the to-be-deleted user.
        collections_to_release_ownership_ids = [
            col_summary.id for col_summary in subscribed_collection_summaries
            if not col_summary.is_private()
            and col_summary.is_solely_owned_by_user(user_id)
        ]
        for col_id in collections_to_release_ownership_ids:
            rights_manager.release_ownership_of_collection(
                user_services.get_system_user(), col_id)

        collections_to_remove_user_from_ids = [
            col_summary.id for col_summary in subscribed_collection_summaries
            if not col_summary.is_solely_owned_by_user(user_id)
        ]
        for col_id in collections_to_remove_user_from_ids:
            rights_manager.deassign_role_for_collection(
                user_services.get_system_user(), col_id, user_id)

        topic_services.deassign_user_from_all_topics(
            user_services.get_system_user(), user_id)

        # Set all the user's email preferences to False in order to disable all
        # ordinary emails that could be sent to the users.
        user_services.update_email_preferences(user_id, False, False, False,
                                               False)

    user_services.mark_user_for_deletion(user_id)
    pending_deletion_requests.append(
        wipeout_domain.PendingDeletionRequest.create_default(
            user_id, user_settings.email, user_settings.role,
            explorations_to_be_deleted_ids, collections_to_be_deleted_ids))

    save_pending_deletion_requests(pending_deletion_requests)
Exemplo n.º 13
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('exploration_id')
                logging.info(
                    '[ADMIN] %s reloaded exploration %s' %
                    (self.user_id, exploration_id))
                exp_services.load_demo(unicode(exploration_id))
                rights_manager.release_ownership_of_exploration(
                    feconf.SYSTEM_COMMITTER_ID, unicode(exploration_id))
            elif self.payload.get('action') == 'reload_collection':
                collection_id = self.payload.get('collection_id')
                logging.info(
                    '[ADMIN] %s reloaded collection %s' %
                    (self.user_id, collection_id))
                collection_services.load_demo(unicode(collection_id))
                rights_manager.release_ownership_of_collection(
                    feconf.SYSTEM_COMMITTER_ID, unicode(collection_id))
            elif self.payload.get('action') == 'clear_search_index':
                exp_services.clear_search_index()
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(
                    self.user_id, config_property_id)
            elif self.payload.get('action') == 'start_new_job':
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == self.payload.get('job_type'):
                        klass.enqueue(klass.create_new())
                        break
            elif self.payload.get('action') == 'cancel_job':
                job_id = self.payload.get('job_id')
                job_type = self.payload.get('job_type')
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == job_type:
                        klass.cancel(job_id, self.user_id)
                        break
            elif self.payload.get('action') == 'start_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.start_computation()
                        break
            elif self.payload.get('action') == 'stop_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.stop_computation(self.user_id)
                        break
            elif self.payload.get('action') == 'upload_topic_similarities':
                data = self.payload.get('data')
                recommendations_services.update_topic_similarities(data)

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 14
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('exploration_id')
                logging.info(
                    '[ADMIN] %s reloaded exploration %s' %
                    (self.user_id, exploration_id))
                exp_services.load_demo(unicode(exploration_id))
                rights_manager.release_ownership_of_exploration(
                    feconf.SYSTEM_COMMITTER_ID, unicode(exploration_id))
            elif self.payload.get('action') == 'reload_collection':
                collection_id = self.payload.get('collection_id')
                logging.info(
                    '[ADMIN] %s reloaded collection %s' %
                    (self.user_id, collection_id))
                collection_services.load_demo(unicode(collection_id))
                rights_manager.release_ownership_of_collection(
                    feconf.SYSTEM_COMMITTER_ID, unicode(collection_id))
            elif self.payload.get('action') == 'clear_search_index':
                exp_services.clear_search_index()
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(
                    self.user_id, config_property_id)
            elif self.payload.get('action') == 'refresh_computed_property':
                computed_property_name = self.payload.get(
                    'computed_property_name')
                config_domain.Registry.get_config_property(
                    computed_property_name).refresh_default_value()
            elif self.payload.get('action') == 'start_new_job':
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == self.payload.get('job_type'):
                        klass.enqueue(klass.create_new())
                        break
            elif self.payload.get('action') == 'cancel_job':
                job_id = self.payload.get('job_id')
                job_type = self.payload.get('job_type')
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == job_type:
                        klass.cancel(job_id, self.user_id)
                        break
            elif self.payload.get('action') == 'start_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.start_computation()
                        break
            elif self.payload.get('action') == 'stop_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.stop_computation(self.user_id)
                        break
            elif self.payload.get('action') == 'upload_topic_similarities':
                data = self.payload.get('data')
                recommendations_services.update_topic_similarities(data)

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 15
0
def _remove_user_from_activities_with_associated_rights_models(
        user_id, use_user_subscriptions_ids):
    """Remove the user from exploration, collection, and topic models.

    Args:
        user_id: str. The ID of the user for which to remove the user from
            explorations, collections, and topics.
        use_user_subscriptions_ids: bool. Whether to use the IDs from user's
            UserSubscriptionsModel. When False the IDs are gathered via
            datastore queries.
    """
    if use_user_subscriptions_ids:
        subscribed_exploration_summaries = (
            exp_fetchers.get_exploration_summaries_subscribed_to(user_id))
    else:
        subscribed_exploration_summaries = (
            exp_fetchers.get_exploration_summaries_where_user_has_role(user_id)
        )

    explorations_to_be_deleted_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries
        if exp_summary.is_private()
        and exp_summary.is_solely_owned_by_user(user_id)
    ]
    exp_services.delete_explorations(user_id,
                                     explorations_to_be_deleted_ids,
                                     force_deletion=True)

    # Release ownership of explorations that are public and are solely owned
    # by the to-be-deleted user.
    explorations_to_release_ownership_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries
        if not exp_summary.is_private() and exp_summary.
        is_solely_owned_by_user(user_id) and not exp_summary.community_owned
    ]
    for exp_id in explorations_to_release_ownership_ids:
        rights_manager.release_ownership_of_exploration(
            user_services.get_system_user(), exp_id)

    explorations_to_remove_user_from_ids = [
        exp_summary.id for exp_summary in subscribed_exploration_summaries
        if not exp_summary.is_solely_owned_by_user(user_id)
        and exp_summary.does_user_have_any_role(user_id)
    ]
    for exp_id in explorations_to_remove_user_from_ids:
        rights_manager.deassign_role_for_exploration(
            user_services.get_system_user(), exp_id, user_id)

    if use_user_subscriptions_ids:
        subscribed_collection_summaries = (
            collection_services.get_collection_summaries_subscribed_to(user_id)
        )
    else:
        subscribed_collection_summaries = (
            collection_services.get_collection_summaries_where_user_has_role(
                user_id))

    collections_to_be_deleted_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries
        if col_summary.is_private()
        and col_summary.is_solely_owned_by_user(user_id)
    ]
    collection_services.delete_collections(user_id,
                                           collections_to_be_deleted_ids,
                                           force_deletion=True)

    # Release ownership of collections that are public and are solely owned
    # by the to-be-deleted user.
    collections_to_release_ownership_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries
        if not col_summary.is_private() and col_summary.
        is_solely_owned_by_user(user_id) and not col_summary.community_owned
    ]
    for col_id in collections_to_release_ownership_ids:
        rights_manager.release_ownership_of_collection(
            user_services.get_system_user(), col_id)

    collections_to_remove_user_from_ids = [
        col_summary.id for col_summary in subscribed_collection_summaries
        if not col_summary.is_solely_owned_by_user(user_id)
        and col_summary.does_user_have_any_role(user_id)
    ]
    for col_id in collections_to_remove_user_from_ids:
        rights_manager.deassign_role_for_collection(
            user_services.get_system_user(), col_id, user_id)

    topic_services.deassign_user_from_all_topics(
        user_services.get_system_user(), user_id)
Exemplo n.º 16
0
    def setUp(self):
        super(CollectionEditorTest, self).setUp()

        collection_services.load_demo(self.COLLECTION_ID)
        rights_manager.release_ownership_of_collection(
            feconf.SYSTEM_COMMITTER_ID, self.COLLECTION_ID)
Exemplo n.º 17
0
    def setUp(self):
        super(CollectionEditorTest, self).setUp()

        collection_services.load_demo(self.COLLECTION_ID)
        rights_manager.release_ownership_of_collection(
            feconf.SYSTEM_COMMITTER_ID, self.COLLECTION_ID)