Beispiel #1
0
def unpublish_story(topic_id, story_id, committer_id):
    """Marks the given story as unpublished.

    Args:
        topic_id: str. The id of the topic.
        story_id: str. The id of the given story.
        committer_id: str. ID of the committer.

    Raises:
        Exception. The given story does not exist.
        Exception. The story is already unpublished.
        Exception. The user does not have enough rights to unpublish the story.
    """
    user = user_services.get_user_actions_info(committer_id)
    if role_services.ACTION_CHANGE_STORY_STATUS not in user.actions:
        raise Exception(
            'The user does not have enough rights to unpublish the story.')
    topic = topic_fetchers.get_topic_by_id(topic_id, strict=None)
    if topic is None:
        raise Exception('A topic with the given ID doesn\'t exist')
    story = story_fetchers.get_story_by_id(story_id, strict=False)
    if story is None:
        raise Exception('A story with the given ID doesn\'t exist')
    topic.unpublish_story(story_id)
    change_list = [topic_domain.TopicChange({
        'cmd': topic_domain.CMD_UNPUBLISH_STORY,
        'story_id': story_id
    })]
    _save_topic(
        committer_id, topic, 'Unpublished story with id %s' % story_id,
        change_list)
    generate_topic_summary(topic.id)

    # Delete corresponding exploration opportunities and reject associated
    # translation suggestions.
    exp_ids = story.story_contents.get_all_linked_exp_ids()
    opportunity_services.delete_exploration_opportunities(exp_ids)
    suggestion_services.auto_reject_translation_suggestions_for_exp_ids(exp_ids)
Beispiel #2
0
def unpublish_topic(topic_id, committer_id):
    """Marks the given topic as unpublished.

    Args:
        topic_id: str. The id of the given topic.
        committer_id: str. ID of the committer.

    Raises:
        Exception. The given topic does not exist.
        Exception. The topic is already unpublished.
        Exception. The user does not have enough rights to unpublish the topic.
    """
    topic_rights = topic_fetchers.get_topic_rights(topic_id, strict=False)
    if topic_rights is None:
        raise Exception('The given topic does not exist')
    user = user_services.UserActionsInfo(committer_id)
    if role_services.ACTION_CHANGE_TOPIC_STATUS not in user.actions:
        raise Exception(
            'The user does not have enough rights to unpublish the topic.')

    if not topic_rights.topic_is_published:
        raise Exception('The topic is already unpublished.')
    topic_rights.topic_is_published = False
    commit_cmds = [
        topic_domain.TopicRightsChange(
            {'cmd': topic_domain.CMD_UNPUBLISH_TOPIC})
    ]
    save_topic_rights(topic_rights, committer_id, 'Unpublished the topic',
                      commit_cmds)

    # Delete the exploration opportunities associated with the topic and reject
    # the corresponding translation suggestions.
    exp_ids = (
        opportunity_services.
        get_exploration_opportunity_ids_corresponding_to_topic(topic_id))
    opportunity_services.delete_exploration_opportunities(exp_ids)
    suggestion_services.auto_reject_translation_suggestions_for_exp_ids(
        exp_ids)
Beispiel #3
0
def update_story(
        committer_id, story_id, change_list, commit_message):
    """Updates a story. Commits changes.

    # NOTE: This function should not be called on its own. Access it
    # through `topic_services.update_story_and_topic_summary`.

    Args:
        committer_id: str. The id of the user who is performing the update
            action.
        story_id: str. The story id.
        change_list: list(StoryChange). These changes are applied in sequence to
            produce the resulting story.
        commit_message: str or None. A description of changes made to the
            story.

    Raises:
        ValidationError. Exploration is already linked to a different story.
    """
    if not commit_message:
        raise ValueError('Expected a commit message but received none.')

    old_story = story_fetchers.get_story_by_id(story_id)
    new_story, exp_ids_removed_from_story, exp_ids_added_to_story = (
        apply_change_list(story_id, change_list))
    story_is_published = _is_story_published_and_present_in_topic(new_story)
    exploration_context_models_to_be_deleted = (
        exp_models.ExplorationContextModel.get_multi(
            exp_ids_removed_from_story))
    exploration_context_models_to_be_deleted = [
        model for model in exploration_context_models_to_be_deleted
        if model is not None]
    exploration_context_models_collisions_list = (
        exp_models.ExplorationContextModel.get_multi(
            exp_ids_added_to_story))
    for context_model in exploration_context_models_collisions_list:
        if context_model is not None and context_model.story_id != story_id:
            raise utils.ValidationError(
                'The exploration with ID %s is already linked to story '
                'with ID %s' % (context_model.id, context_model.story_id))

    if (
            old_story.url_fragment != new_story.url_fragment and
            does_story_exist_with_url_fragment(new_story.url_fragment)):
        raise utils.ValidationError(
            'Story Url Fragment is not unique across the site.')
    _save_story(
        committer_id, new_story, commit_message, change_list,
        story_is_published)
    create_story_summary(new_story.id)
    if story_is_published and _is_topic_published(new_story):
        opportunity_services.update_exploration_opportunities(
            old_story, new_story)
    suggestion_services.auto_reject_translation_suggestions_for_exp_ids(
        exp_ids_removed_from_story)

    exp_models.ExplorationContextModel.delete_multi(
        exploration_context_models_to_be_deleted)

    new_exploration_context_models = [exp_models.ExplorationContextModel(
        id=exp_id,
        story_id=story_id
    ) for exp_id in exp_ids_added_to_story]
    exp_models.ExplorationContextModel.update_timestamps_multi(
        new_exploration_context_models)
    exp_models.ExplorationContextModel.put_multi(new_exploration_context_models)