def get(self, collection_id): """Handles GET requests.""" try: collection = collection_services.get_collection_by_id( collection_id) except Exception as e: raise self.PageNotFoundException(e) whitelisted_usernames = ( config_domain.WHITELISTED_COLLECTION_EDITOR_USERNAMES.value) self.values.update({ 'nav_mode': feconf.NAV_MODE_COLLECTION, 'can_edit': ( bool(self.username) and self.username in whitelisted_usernames and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_COLLECTION, collection_id) ), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'collection_skills': collection.skills, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('collection_player/collection_player.html')
def update_collection( committer_id, collection_id, change_list, commit_message): """Update an collection. Commits changes. Args: - committer_id: str. The id of the user who is performing the update action. - collection_id: str. The collection id. - change_list: list of dicts, each representing a CollectionChange object. These changes are applied in sequence to produce the resulting collection. - commit_message: str or None. A description of changes made to the collection. For published collections, this must be present; for unpublished collections, it may be equal to None. """ is_public = rights_manager.is_collection_public(collection_id) if is_public and not commit_message: raise ValueError( 'Collection is public so expected a commit message but ' 'received none.') collection = apply_change_list(collection_id, change_list) _save_collection(committer_id, collection, commit_message, change_list) update_collection_summary(collection.id, committer_id) if not rights_manager.is_collection_private(collection.id): user_services.update_first_contribution_msec_if_not_set( committer_id, utils.get_current_time_in_millisecs())
def update_collection(committer_id, collection_id, change_list, commit_message): """Updates a collection. Commits changes. Args: committer_id: str. The id of the user who is performing the update action. collection_id: str. The collection id. change_list: list(dict). Each entry represents a CollectionChange object. These changes are applied in sequence to produce the resulting collection. commit_message: str or None. A description of changes made to the collection. For published collections, this must be present; for unpublished collections, it may be equal to None. """ is_public = rights_manager.is_collection_public(collection_id) if is_public and not commit_message: raise ValueError( 'Collection is public so expected a commit message but ' 'received none.') collection = apply_change_list(collection_id, change_list) _save_collection(committer_id, collection, commit_message, change_list) update_collection_summary(collection.id, committer_id) if (not rights_manager.is_collection_private(collection.id) and committer_id != feconf.MIGRATION_BOT_USER_ID): user_services.update_first_contribution_msec_if_not_set( committer_id, utils.get_current_time_in_millisecs())
def get(self, collection_id): """Handles GET requests.""" collection = collection_services.get_collection_by_id( collection_id, strict=False) if (collection is None or not rights_manager.Actor(self.user_id).can_view( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)): self.redirect('/') return can_edit = ( bool(self.user_id) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)) self.values.update({ 'is_private': rights_manager.is_collection_private(collection_id), 'can_edit': can_edit, 'collection_id': collection.id, 'title': collection.title, 'can_unpublish': rights_manager.Actor( self.user_id).can_unpublish( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id) }) self.render_template('collection_editor/collection_editor.html')
def get(self, collection_id): """Handles GET requests.""" try: collection = collection_services.get_collection_by_id( collection_id) except Exception as e: raise self.PageNotFoundException(e) whitelisted_usernames = ( config_domain.WHITELISTED_COLLECTION_EDITOR_USERNAMES.value) self.values.update({ 'can_edit': (bool(self.username) and self.username in whitelisted_usernames and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'collection_skills': collection.skills, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('collection_player/collection_player.html')
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)
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)
def get(self, collection_id): """Gets the editing rights for the given collection. Args: collection_id: str. ID for the collection. """ (collection, collection_rights) = ( collection_services.get_collection_and_collection_rights_by_id( collection_id)) 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)
def get(self, collection_id): """Handles GET requests.""" collection = collection_services.get_collection_by_id(collection_id, strict=False) 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), 'nav_mode': feconf.NAV_MODE_CREATE, 'title': collection.title, 'SHOW_COLLECTION_NAVIGATION_TAB_HISTORY': (feconf.SHOW_COLLECTION_NAVIGATION_TAB_HISTORY), 'SHOW_COLLECTION_NAVIGATION_TAB_STATS': (feconf.SHOW_COLLECTION_NAVIGATION_TAB_STATS), 'TAG_REGEX': feconf.TAG_REGEX, }) self.render_template('pages/collection_editor/collection_editor.html')
def _get_domain_object_validation_type(cls, item): collection_rights = rights_manager.get_collection_rights(item.id, strict=False) if collection_rights is None: return base_model_validators.VALIDATION_MODE_NEUTRAL if rights_manager.is_collection_private(item.id): return base_model_validators.VALIDATION_MODE_NON_STRICT return base_model_validators.VALIDATION_MODE_STRICT
def _validate_collections_are_public( cls, item, field_name_to_external_model_references): """Validates that collections for model are public. Args: item: ndb.Model. BaseUserModel to validate. field_name_to_external_model_references: dict(str, (list(ExternalModelReference))). A dict keyed by field name. The field name represents a unique identifier provided by the storage model to which the external model is associated. Each value contains a list of ExternalModelReference objects corresponding to the field_name. For examples, all the external Exploration Models corresponding to a storage model can be associated with the field name 'exp_ids'. This dict is used for validation of External Model properties linked to the storage model. """ if 'collection_ids' not in field_name_to_external_model_references: return col_ids = [] collection_model_references = ( field_name_to_external_model_references['collection_ids']) for collection_model_reference in collection_model_references: collection_model = collection_model_reference.model_instance if collection_model is None or collection_model.deleted: model_class = collection_model_reference.model_class model_id = collection_model_reference.model_id cls._add_error( 'collection_ids %s' % ERROR_CATEGORY_FIELD_CHECK, 'Entity id %s: based on field collection_ids having' ' value %s, expected model %s with id %s but it doesn\'t' ' exist' % (item.id, model_id, model_class.__name__, model_id)) continue col_ids.append(collection_model.id) private_col_ids = [ col_id for col_id in col_ids if (rights_manager.is_collection_private(col_id)) ] if private_col_ids: cls._add_error( 'public collection check', 'Entity id %s: Collections with ids %s are private' % (item.id, private_col_ids))
def get(self, collection_id): """Gets the editing rights for the given collection.""" collection = collection_services.get_collection_by_id(collection_id) 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) }) self.render_json(self.values)
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) })
def get(self, collection_id): """Gets the editing rights for the given collection.""" collection = collection_services.get_collection_by_id(collection_id) 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) }) self.render_json(self.values)
def get(self, collection_id): """Handles GET requests.""" collection = collection_services.get_collection_by_id(collection_id, strict=False) if (collection is None or not rights_manager.Actor(self.user_id).can_view( feconf.ACTIVITY_TYPE_COLLECTION, collection_id)): self.redirect('/') return can_edit = (bool(self.user_id) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_COLLECTION, collection_id)) self.values.update({ 'can_edit': can_edit, '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), 'nav_mode': feconf.NAV_MODE_CREATE, 'title': collection.title, 'SHOW_COLLECTION_NAVIGATION_TAB_HISTORY': (feconf.SHOW_COLLECTION_NAVIGATION_TAB_HISTORY), 'SHOW_COLLECTION_NAVIGATION_TAB_FEEDBACK': (feconf.SHOW_COLLECTION_NAVIGATION_TAB_FEEDBACK), 'SHOW_COLLECTION_NAVIGATION_TAB_STATS': (feconf.SHOW_COLLECTION_NAVIGATION_TAB_STATS), 'TAG_REGEX': feconf.TAG_REGEX, }) self.render_template('collection_editor/collection_editor.html')
def get(self, collection_id): """Handles GET requests.""" (collection, collection_rights) = ( collection_services.get_collection_and_collection_rights_by_id( collection_id)) if collection is None: raise self.PageNotFoundException self.values.update({ 'can_edit': rights_manager.check_can_edit_activity( self.user, collection_rights), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('pages/collection_player/collection_player.html')
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) })
def get(self, collection_id): """Handles GET requests.""" collection = collection_services.get_collection_by_id( collection_id, strict=False) 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), 'nav_mode': feconf.NAV_MODE_CREATE, 'title': collection.title, 'SHOW_COLLECTION_NAVIGATION_TAB_HISTORY': ( feconf.SHOW_COLLECTION_NAVIGATION_TAB_HISTORY), 'SHOW_COLLECTION_NAVIGATION_TAB_STATS': ( feconf.SHOW_COLLECTION_NAVIGATION_TAB_STATS), 'TAG_REGEX': feconf.TAG_REGEX, }) self.render_template('pages/collection_editor/collection_editor.html')
def get(self, collection_id): """Handles GET requests.""" collection = collection_services.get_collection_by_id( collection_id, strict=False) if (collection is None or not rights_manager.Actor(self.user_id).can_view( feconf.ACTIVITY_TYPE_COLLECTION, collection_id)): self.redirect('/') return can_edit = ( bool(self.user_id) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_COLLECTION, collection_id)) self.values.update({ 'can_edit': can_edit, '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), 'nav_mode': feconf.NAV_MODE_CREATE, 'title': collection.title, 'SHOW_COLLECTION_NAVIGATION_TAB_HISTORY': ( feconf.SHOW_COLLECTION_NAVIGATION_TAB_HISTORY), 'SHOW_COLLECTION_NAVIGATION_TAB_FEEDBACK': ( feconf.SHOW_COLLECTION_NAVIGATION_TAB_FEEDBACK), 'SHOW_COLLECTION_NAVIGATION_TAB_STATS': ( feconf.SHOW_COLLECTION_NAVIGATION_TAB_STATS), 'TAG_REGEX': feconf.TAG_REGEX, }) self.render_template('collection_editor/collection_editor.html')