Esempio n. 1
0
def delete_skill(committer_id, skill_id, force_deletion=False):
    """Deletes the skill with the given skill_id.

    Args:
        committer_id: str. ID of the committer.
        skill_id: str. ID of the skill to be deleted.
        force_deletion: bool. If true, the skill and its history are fully
            deleted and are unrecoverable. Otherwise, the skill and all
            its history are marked as deleted, but the corresponding models are
            still retained in the datastore. This last option is the preferred
            one.
    """
    skill_model = skill_models.SkillModel.get(skill_id)
    skill_model.delete(committer_id,
                       feconf.COMMIT_MESSAGE_SKILL_DELETED,
                       force_deletion=force_deletion)

    # This must come after the skill is retrieved. Otherwise the memcache
    # key will be reinstated.
    skill_memcache_key = skill_fetchers.get_skill_memcache_key(skill_id)
    memcache_services.delete(skill_memcache_key)

    # Delete the summary of the skill (regardless of whether
    # force_deletion is True or not).
    delete_skill_summary(skill_id)
    opportunity_services.delete_skill_opportunity(skill_id)
    suggestion_services.reject_question_suggestions_with_skill_target_id(
        skill_id)
Esempio n. 2
0
 def delete_skill_model_and_memcache(self, user_id, skill_id):
     """Deletes skill model and memcache corresponding to the given skill
     id.
     """
     skill_model = skill_models.SkillModel.get(skill_id)
     skill_model.delete(user_id, 'Delete skill model.')
     skill_memcache_key = skill_fetchers.get_skill_memcache_key(skill_id)  # pylint: disable=protected-access
     memcache_services.delete(skill_memcache_key)
Esempio n. 3
0
def _save_skill(committer_id, skill, commit_message, change_list):
    """Validates a skill and commits it to persistent storage. If
    successful, increments the version number of the incoming skill domain
    object by 1.

    Args:
        committer_id: str. ID of the given committer.
        skill: Skill. The skill domain object to be saved.
        commit_message: str. The commit message.
        change_list: list(SkillChange). List of changes applied to a skill.

    Raises:
        Exception: The skill model and the incoming skill domain object have
            different version numbers.
        Exception: Received invalid change list.
    """
    if not change_list:
        raise Exception(
            'Unexpected error: received an invalid change list when trying to '
            'save skill %s: %s' % (skill.id, change_list))
    skill.validate()

    # Skill model cannot be None as skill is passed as parameter here and that
    # is only possible if a skill model with that skill id exists.
    skill_model = skill_models.SkillModel.get(skill.id, strict=False)

    if skill.version > skill_model.version:
        raise Exception(
            'Unexpected error: trying to update version %s of skill '
            'from version %s. Please reload the page and try again.' %
            (skill_model.version, skill.version))
    elif skill.version < skill_model.version:
        raise Exception(
            'Trying to update version %s of skill from version %s, '
            'which is too old. Please reload the page and try again.' %
            (skill_model.version, skill.version))

    skill_model.description = skill.description
    skill_model.language_code = skill.language_code
    skill_model.superseding_skill_id = skill.superseding_skill_id
    skill_model.all_questions_merged = skill.all_questions_merged
    skill_model.prerequisite_skill_ids = skill.prerequisite_skill_ids
    skill_model.misconceptions_schema_version = (
        skill.misconceptions_schema_version)
    skill_model.rubric_schema_version = (skill.rubric_schema_version)
    skill_model.skill_contents_schema_version = (
        skill.skill_contents_schema_version)
    skill_model.skill_contents = skill.skill_contents.to_dict()
    skill_model.misconceptions = [
        misconception.to_dict() for misconception in skill.misconceptions
    ]
    skill_model.rubrics = [rubric.to_dict() for rubric in skill.rubrics]
    skill_model.next_misconception_id = skill.next_misconception_id
    change_dicts = [change.to_dict() for change in change_list]
    skill_model.commit(committer_id, commit_message, change_dicts)
    memcache_services.delete(skill_fetchers.get_skill_memcache_key(skill.id))
    skill.version += 1