Пример #1
0
def get_all_topic_rights():
    """Returns the rights object of all topics present in the datastore.

    Returns:
        dict. The dict of rights objects of all topics present in the datastore
        keyed by topic id.
    """
    topic_rights_models = topic_models.TopicRightsModel.get_all()
    topic_rights = {}
    for model in topic_rights_models:
        rights = topic_fetchers.get_topic_rights_from_model(model)
        topic_rights[rights.id] = rights
    return topic_rights
Пример #2
0
def get_topic_rights_with_user(user_id):
    """Retrieves the rights object for all topics assigned to given user.

    Args:
        user_id: str. ID of the user.

    Returns:
        list(TopicRights). The rights objects associated with the topics
        assigned to given user.
    """
    topic_rights_models = topic_models.TopicRightsModel.get_by_user(user_id)
    return [
        topic_fetchers.get_topic_rights_from_model(model)
        for model in topic_rights_models if model is not None
    ]
Пример #3
0
def get_multi_topic_rights(topic_ids):
    """Returns the rights of all topics whose topic ids are passed in.

    Args:
        topic_ids: list(str). The IDs of topics for which rights are to be
            returned.

    Returns:
        list(TopicRights). The list of rights of all given topics present in
        the datastore.
    """
    topic_rights_models = topic_models.TopicRightsModel.get_multi(topic_ids)
    topic_rights = [
        topic_fetchers.get_topic_rights_from_model(rights) if rights else None
        for rights in topic_rights_models]
    return topic_rights
Пример #4
0
def filter_published_topic_ids(topic_ids):
    """Given list of topic IDs, returns the IDs of all topics that are published
    in that list.

    Args:
        topic_ids: list(str). The list of topic ids.

    Returns:
        list(str). The topic IDs in the passed in list corresponding to
        published topics.
    """
    topic_rights_models = topic_models.TopicRightsModel.get_multi(topic_ids)
    published_topic_ids = []
    for ind, model in enumerate(topic_rights_models):
        if model is None:
            continue
        rights = topic_fetchers.get_topic_rights_from_model(model)
        if rights.topic_is_published:
            published_topic_ids.append(topic_ids[ind])
    return published_topic_ids