def test_collection_rights_handler(self):
        collection_id = 'collection_id'
        collection = collection_domain.Collection.create_default_collection(
            collection_id, title='A title',
            category='A Category', objective='An Objective')
        collection_services.save_new_collection(self.owner_id, collection)

        # Check that collection is published correctly.
        rights_manager.assign_role_for_collection(
            self.owner, collection_id, self.editor_id,
            rights_domain.ROLE_EDITOR)
        rights_manager.publish_collection(self.owner, collection_id)

        # Check that collection cannot be unpublished by non admin.
        with self.assertRaisesRegexp(
            Exception, 'This collection cannot be unpublished.'):
            rights_manager.unpublish_collection(self.owner, collection_id)
        collection_rights = rights_manager.get_collection_rights(collection_id)
        self.assertEqual(
            collection_rights.status,
            rights_domain.ACTIVITY_STATUS_PUBLIC)

        # Check that collection can be unpublished by admin.
        rights_manager.unpublish_collection(self.admin, collection_id)
        collection_rights = rights_manager.get_collection_rights(collection_id)
        self.assertEqual(
            collection_rights.status,
            rights_domain.ACTIVITY_STATUS_PRIVATE)
Example #2
0
    def put(self, collection_id):
        """Unpublishes the given collection."""
        collection = collection_services.get_collection_by_id(collection_id)
        version = self.payload.get('version')
        _require_valid_version(version, collection.version)

        rights_manager.unpublish_collection(self.user, collection_id)
        search_services.delete_collections_from_search_index([collection_id])

        collection_rights = rights_manager.get_collection_rights(collection_id,
                                                                 strict=False)

        self.values.update({
            'can_edit':
            True,
            'can_unpublish':
            rights_manager.check_can_unpublish_activity(
                self.user, collection_rights),
            'collection_id':
            collection.id,
            'is_private':
            rights_manager.is_collection_private(collection_id),
            'owner_names':
            rights_manager.get_collection_owner_names(collection_id)
        })
        self.render_json(self.values)
Example #3
0
    def test_unpublished_activity_is_removed_from_featured_list(self):
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_1)
        rights_manager.publish_collection(self.owner_id, self.COL_ID_2)
        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_collection_reference(self.COL_ID_2)])

        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Unpublishing an unfeatured activity does not affect the featured
        # list.
        rights_manager.unpublish_exploration(self.moderator_id, self.EXP_ID_1)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Unpublishing a featured activity removes it from the featured list.
        rights_manager.unpublish_collection(self.moderator_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0)])

        rights_manager.unpublish_exploration(self.moderator_id, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #4
0
    def test_collection_rights_handler(self):
        collection_id = 'collection_id'
        collection = collection_domain.Collection.create_default_collection(
            collection_id, 'A title', 'A Category', 'An Objective')
        collection_services.save_new_collection(self.owner_id, collection)

        # Check that collection is published correctly.
        rights_manager.assign_role_for_collection(
            self.owner_id, collection_id, self.editor_id,
            rights_manager.ROLE_EDITOR)
        rights_manager.publish_collection(self.owner_id, collection_id)

        # Check that collection cannot be unpublished by non admin.
        with self.assertRaisesRegexp(
            Exception, 'This collection cannot be unpublished.'):
            rights_manager.unpublish_collection(self.owner_id, collection_id)
        collection_rights = rights_manager.get_collection_rights(collection_id)
        self.assertEqual(collection_rights.status,
                         rights_manager.ACTIVITY_STATUS_PUBLIC)

        # Check that collection can be unpublished by admin.
        rights_manager.unpublish_collection(self.admin_id, collection_id)
        collection_rights = rights_manager.get_collection_rights(collection_id)
        self.assertEqual(collection_rights.status,
                         rights_manager.ACTIVITY_STATUS_PRIVATE)
Example #5
0
    def test_can_only_delete_unpublished_collections(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.check_can_delete_activity(self.user_a,
                                                     collection_rights))

        rights_manager.publish_collection(self.user_a, self.COLLECTION_ID)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertFalse(
            rights_manager.check_can_delete_activity(self.user_a,
                                                     collection_rights))

        rights_manager.unpublish_collection(self.user_admin,
                                            self.COLLECTION_ID)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.check_can_delete_activity(self.user_a,
                                                     collection_rights))
Example #6
0
    def test_publishing_and_unpublishing_collection(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertFalse(rights_manager.check_can_access_activity(
            self.user_b, collection_rights))

        rights_manager.publish_collection(self.user_a, self.COLLECTION_ID)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertTrue(rights_manager.check_can_access_activity(
            self.user_b, collection_rights))
        self.assertFalse(rights_manager.check_can_unpublish_activity(
            self.user_a, collection_rights))

        rights_manager.unpublish_collection(
            self.user_admin, self.COLLECTION_ID)
        collection_rights = rights_manager.get_collection_rights(
            self.COLLECTION_ID)

        self.assertTrue(rights_manager.check_can_access_activity(
            self.user_a, collection_rights))
        self.assertFalse(rights_manager.check_can_access_activity(
            self.user_b, collection_rights))
Example #7
0
    def put(self, collection_id):
        """Updates the editing rights for the given collection."""
        collection = collection_services.get_collection_by_id(collection_id)
        version = self.payload.get('version')
        _require_valid_version(version, collection.version)

        # TODO(bhenning): Implement other rights changes here.
        is_public = self.payload.get('is_public')

        if is_public is not None:
            if is_public:
                try:
                    collection.validate(strict=True)
                    collection_services.validate_exps_in_collection_are_public(
                        collection)
                except utils.ValidationError as e:
                    raise self.InvalidInputException(e)

                collection_services.publish_collection_and_update_user_profiles(
                    self.user_id, collection_id)
                collection_services.index_collections_given_ids([
                    collection_id])
            elif rights_manager.Actor(self.user_id).can_unpublish(
                    feconf.ACTIVITY_TYPE_COLLECTION, collection_id):
                rights_manager.unpublish_collection(self.user_id, collection_id)
                collection_services.delete_documents_from_search_index([
                    collection_id])
            else:
                raise self.InvalidInputException(
                    'Cannot unpublish a collection.')

        self.render_json({
            'rights': rights_manager.get_collection_rights(
                collection_id).to_dict()
        })
Example #8
0
    def test_contribution_msec_does_not_change_if_collection_unpublished(self):
        self.save_new_valid_collection(
            self.COL_ID, self.owner_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.owner_id, self.COL_ID)
        rights_manager.unpublish_collection(self.admin_id, self.COL_ID)

        # Test that first contribution msec is not eliminated if collection is
        # unpublished.
        self.assertIsNotNone(user_services.get_user_settings(
            self.owner_id).first_contribution_msec)
Example #9
0
    def test_contribution_msec_does_not_change_if_collection_unpublished(self):
        self.save_new_valid_collection(
            self.COL_ID, self.owner_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.owner_id, self.COL_ID)
        rights_manager.unpublish_collection(self.admin_id, self.COL_ID)

        # Test that first contribution msec is not eliminated if collection is
        # unpublished.
        self.assertIsNotNone(user_services.get_user_settings(
            self.owner_id).first_contribution_msec)
Example #10
0
    def test_can_only_delete_unpublished_collections(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )

        rights_manager.publish_collection(self.user_id_a, self.COLLECTION_ID)

        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )

        rights_manager.unpublish_collection(self.user_id_admin, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
Example #11
0
    def test_can_only_delete_unpublished_collections(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))

        rights_manager.publish_collection(self.user_id_a, self.COLLECTION_ID)

        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))

        rights_manager.unpublish_collection(
            self.user_id_admin, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
Example #12
0
    def test_publishing_and_unpublishing_collection(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)

        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )

        rights_manager.publish_collection(self.user_id_a, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_play(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_view(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_unpublish(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID
            )
        )

        rights_manager.unpublish_collection(self.user_id_admin, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_play(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID)
        )
Example #13
0
    def test_publishing_and_unpublishing_collection(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.user_id_a)

        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))

        rights_manager.publish_collection(self.user_id_a, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_unpublish(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))

        rights_manager.unpublish_collection(
            self.user_id_admin, self.COLLECTION_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_COLLECTION, self.COLLECTION_ID))