示例#1
0
    def put(self, collection_id):
        """Publishes the given collection."""
        collection = collection_services.get_collection_by_id(collection_id)
        version = self.payload.get('version')
        _require_valid_version(version, collection.version)

        collection.validate(strict=True)
        collection_services.validate_exps_in_collection_are_public(collection)

        collection_services.publish_collection_and_update_user_profiles(
            self.user, collection_id)
        collection_services.index_collections_given_ids([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)
示例#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)
示例#3
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)
示例#4
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 not self.is_admin:
                raise self.InvalidInputException(
                    'Cannot unpublish a collection.')

        self.render_json({
            'rights': rights_manager.get_collection_rights(
                collection_id).to_dict()
        })
示例#5
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 not self.is_admin:
                raise self.InvalidInputException(
                    'Cannot unpublish a collection.')

        self.render_json({
            'rights':
            rights_manager.get_collection_rights(collection_id).to_dict()
        })
示例#6
0
    def test_contribution_msec_does_not_change_if_no_contribution_to_collection(
            self):
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)

        collection = 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)
        rights_manager.assign_role_for_collection(self.admin_id, self.COL_ID,
                                                  self.editor_id, 'editor')
        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)

        # Test that contribution time is not given to an editor that has not
        # contributed.
        self.assertIsNotNone(
            user_services.get_user_settings(
                self.admin_id).first_contribution_msec)
        self.assertIsNone(
            user_services.get_user_settings(
                self.editor_id).first_contribution_msec)
示例#7
0
    def test_contribution_msec_does_not_update_until_collection_is_published(
            self):
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)

        collection = 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)

        # Test that saving a collection does not update first contribution
        # time.
        self.assertIsNone(
            user_services.get_user_settings(
                self.admin_id).first_contribution_msec)

        # Test that commit to unpublished collection does not update
        # contribution time.
        collection_services.update_collection(
            self.admin_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'title',
                'new_value': 'Some new title'
            }], '')
        self.assertIsNone(
            user_services.get_user_settings(
                self.admin_id).first_contribution_msec)

        # Test that another user who commits to unpublished collection does not
        # have updated first contribution time.
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        rights_manager.assign_role_for_collection(self.admin_id, self.COL_ID,
                                                  self.editor_id, 'editor')
        collection_services.update_collection(
            self.editor_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'category',
                'new_value': 'Some new category'
            }], '')
        self.assertIsNone(
            user_services.get_user_settings(
                self.editor_id).first_contribution_msec)

        # Test that after an collection is published, all contributors have
        # updated first contribution times.
        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)
        self.assertIsNotNone(
            user_services.get_user_settings(
                self.admin_id).first_contribution_msec)
        self.assertIsNotNone(
            user_services.get_user_settings(
                self.editor_id).first_contribution_msec)
示例#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)
示例#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)
示例#10
0
    def test_contribution_msec_does_not_update_until_collection_is_published(self):
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)

        collection = 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)

        # Test that saving a collection does not update first contribution
        # time.
        self.assertIsNone(user_services.get_user_settings(
            self.admin_id).first_contribution_msec)

        # Test that commit to unpublished collection does not update
        # contribution time.
        collection_services.update_collection(
            self.admin_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'title',
                'new_value': 'Some new title'
            }], '')
        self.assertIsNone(user_services.get_user_settings(
            self.admin_id).first_contribution_msec)

        # Test that another user who commits to unpublished collection does not
        # have updated first contribution time.
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        rights_manager.assign_role_for_collection(
            self.admin_id, self.COL_ID, self.editor_id, 'editor')
        collection_services.update_collection(
                self.editor_id, self.COL_ID, [{
                'cmd': 'edit_collection_property',
                'property_name': 'category',
                'new_value': 'Some new category'
            }], '')
        self.assertIsNone(user_services.get_user_settings(
            self.editor_id).first_contribution_msec)

        # Test that after an collection is published, all contributors have
        # updated first contribution times.
        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)
        self.assertIsNotNone(user_services.get_user_settings(
            self.admin_id).first_contribution_msec)
        self.assertIsNotNone(user_services.get_user_settings(
            self.editor_id).first_contribution_msec)
示例#11
0
    def test_contribution_msec_does_not_change_if_no_contribution_to_collection(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)
        rights_manager.assign_role_for_collection(
            self.admin_id, self.COL_ID, self.editor_id, 'editor')
        collection_services.publish_collection_and_update_user_profiles(
            self.admin_id, self.COL_ID)

        # Test that contribution time is not given to an editor that has not
        # contributed.
        self.assertIsNotNone(user_services.get_user_settings(
            self.admin_id).first_contribution_msec)
        self.assertIsNone(user_services.get_user_settings(
            self.editor_id).first_contribution_msec)
示例#12
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.values.update({
            'can_edit':
            True,
            'can_unpublish':
            rights_manager.Actor(self.user_id).can_unpublish(
                feconf.ACTIVITY_TYPE_COLLECTION, collection_id),
            'collection_id':
            collection.id,
            'is_private':
            rights_manager.is_collection_private(collection_id),
            'owner_names':
            rights_manager.get_collection_owner_names(collection_id)
        })
示例#13
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.values.update({
            'can_edit': True,
            'can_unpublish': rights_manager.Actor(
                self.user_id).can_unpublish(
                    feconf.ACTIVITY_TYPE_COLLECTION, collection_id),
            'collection_id': collection.id,
            'is_private': rights_manager.is_collection_private(collection_id),
            'owner_names': rights_manager.get_collection_owner_names(
                collection_id)
        })