Ejemplo n.º 1
0
def _compute_summary_of_collection(collection):
    """Create a CollectionSummary domain object for a given Collection domain
    object and return it.

    Args:
        collection: Collection. The domain object.

    Returns:
        CollectionSummary. The computed summary for the given collection.
    """
    collection_rights = collection_models.CollectionRightsModel.get_by_id(
        collection.id)
    collection_summary_model = (
        collection_models.CollectionSummaryModel.get_by_id(collection.id))

    contributors_summary = (collection_summary_model.contributors_summary
                            if collection_summary_model else {})
    contributor_ids = list(contributors_summary.keys())

    collection_model_last_updated = collection.last_updated
    collection_model_created_on = collection.created_on
    collection_model_node_count = len(collection.nodes)

    collection_summary = collection_domain.CollectionSummary(
        collection.id, collection.title, collection.category,
        collection.objective, collection.language_code, collection.tags,
        collection_rights.status, collection_rights.community_owned,
        collection_rights.owner_ids, collection_rights.editor_ids,
        collection_rights.viewer_ids, contributor_ids, contributors_summary,
        collection.version, collection_model_node_count,
        collection_model_created_on, collection_model_last_updated)

    return collection_summary
Ejemplo n.º 2
0
    def setUp(self):
        super(CollectionSummaryTests, self).setUp()
        current_time = datetime.datetime.utcnow()
        self.collection_summary_dict = {
            'category': 'category',
            'status': constants.ACTIVITY_STATUS_PRIVATE,
            'community_owned': True,
            'viewer_ids': ['viewer_id'],
            'version': 1,
            'editor_ids': ['editor_id'],
            'title': 'title',
            'collection_model_created_on': current_time,
            'tags': [],
            'collection_model_last_updated': current_time,
            'contributor_ids': ['contributor_id'],
            'language_code': 'en',
            'objective': 'objective',
            'contributors_summary': {},
            'id': 'col_id',
            'owner_ids': ['owner_id']
        }

        self.collection_summary = collection_domain.CollectionSummary(
            'col_id', 'title', 'category', 'objective', 'en', [],
            constants.ACTIVITY_STATUS_PRIVATE, True, ['owner_id'],
            ['editor_id'], ['viewer_id'], ['contributor_id'], {}, 1, 1,
            current_time, current_time)
Ejemplo n.º 3
0
def get_collection_summary_from_model(collection_summary_model):
    """Returns a domain object for an Oppia collection summary given a
    collection summary model.

    Args:
        collection_summary_model: CollectionSummaryModel. The model object
            to extract domain object for oppia collection summary.

    Returns:
        CollectionSummary. The collection summary domain object extracted
        from collection summary model.
    """
    return collection_domain.CollectionSummary(
        collection_summary_model.id, collection_summary_model.title,
        collection_summary_model.category, collection_summary_model.objective,
        collection_summary_model.language_code, collection_summary_model.tags,
        collection_summary_model.status,
        collection_summary_model.community_owned,
        collection_summary_model.owner_ids,
        collection_summary_model.editor_ids,
        collection_summary_model.viewer_ids,
        collection_summary_model.contributor_ids,
        collection_summary_model.contributors_summary,
        collection_summary_model.version, collection_summary_model.node_count,
        collection_summary_model.collection_model_created_on,
        collection_summary_model.collection_model_last_updated)
Ejemplo n.º 4
0
def get_summary_of_collection(collection, contributor_id_to_add):
    """Create a CollectionSummary domain object for a given Collection domain
    object and return it.
    """
    collection_rights = collection_models.CollectionRightsModel.get_by_id(
        collection.id)
    collection_summary_model = (
        collection_models.CollectionSummaryModel.get_by_id(collection.id))

    # Update the contributor id list if necessary (contributors
    # defined as humans who have made a positive (i.e. not just
    # a revert) change to an collection's content).
    if collection_summary_model:
        contributor_ids = collection_summary_model.contributor_ids
    else:
        contributor_ids = []
    if (contributor_id_to_add is not None
            and contributor_id_to_add not in feconf.SYSTEM_USER_IDS):
        if contributor_id_to_add not in contributor_ids:
            contributor_ids.append(contributor_id_to_add)

    collection_model_last_updated = collection.last_updated
    collection_model_created_on = collection.created_on

    collection_summary = collection_domain.CollectionSummary(
        collection.id, collection.title, collection.category,
        collection.objective, collection_rights.status,
        collection_rights.community_owned, collection_rights.owner_ids,
        collection_rights.editor_ids, collection_rights.viewer_ids,
        contributor_ids, collection.version, collection_model_created_on,
        collection_model_last_updated)

    return collection_summary
Ejemplo n.º 5
0
    def test_collection_summary_gets_created(self):

        collection_summary_dict = {
            'category': 'category',
            'status': 'status',
            'community_owned': 'True',
            'viewer_ids': ['viewer_id'],
            'version': 1,
            'editor_ids': ['editor_id'],
            'title': 'title',
            'collection_model_created_on': {},
            'tags': [],
            'collection_model_last_updated': {},
            'contributor_ids': ['contributor_id'],
            'language_code': 'en',
            'objective': 'objective',
            'contributors_summary': {},
            'id': 'col_id',
            'owner_ids': ['owner_id']
        }

        collection_summary = collection_domain.CollectionSummary(
            'col_id', 'title', 'category', 'objective', 'en', [], 'status',
            'True', ['owner_id'], ['editor_id'], ['viewer_id'],
            ['contributor_id'], {}, 1, 1, {}, {})

        self.assertEqual(collection_summary.to_dict(), collection_summary_dict)
Ejemplo n.º 6
0
def compute_summary_of_collection(collection, contributor_id_to_add):
    """Create a CollectionSummary domain object for a given Collection domain
    object and return it.

    Args:
        collection_id: str. ID of the collection.
        contributor_id_to_add: str. ID of the contributor to be added to the
            collection summary.

    Returns:
        CollectionSummary. The computed summary for the given collection.
    """
    collection_rights = collection_models.CollectionRightsModel.get_by_id(
        collection.id)
    collection_summary_model = (
        collection_models.CollectionSummaryModel.get_by_id(collection.id))

    # Update the contributor id list if necessary (contributors
    # defined as humans who have made a positive (i.e. not just
    # a revert) change to an collection's content).
    if collection_summary_model:
        contributor_ids = collection_summary_model.contributor_ids
        contributors_summary = collection_summary_model.contributors_summary
    else:
        contributor_ids = []
        contributors_summary = {}

    if (contributor_id_to_add is not None and
            contributor_id_to_add not in feconf.SYSTEM_USER_IDS and
            contributor_id_to_add not in contributor_ids):
        contributor_ids.append(contributor_id_to_add)

    if contributor_id_to_add not in feconf.SYSTEM_USER_IDS:
        if contributor_id_to_add is None:
            # Revert commit or other non-positive commit.
            contributors_summary = compute_collection_contributors_summary(
                collection.id)
        else:
            if contributor_id_to_add in contributors_summary:
                contributors_summary[contributor_id_to_add] += 1
            else:
                contributors_summary[contributor_id_to_add] = 1

    collection_model_last_updated = collection.last_updated
    collection_model_created_on = collection.created_on
    collection_model_node_count = len(collection.nodes)

    collection_summary = collection_domain.CollectionSummary(
        collection.id, collection.title, collection.category,
        collection.objective, collection.language_code, collection.tags,
        collection_rights.status, collection_rights.community_owned,
        collection_rights.owner_ids, collection_rights.editor_ids,
        collection_rights.viewer_ids, contributor_ids, contributors_summary,
        collection.version, collection_model_node_count,
        collection_model_created_on,
        collection_model_last_updated
    )

    return collection_summary
Ejemplo n.º 7
0
 def test_is_private(self):
     self.assertTrue(self.collection_summary.is_private())
     self.collection_summary = collection_domain.CollectionSummary(
         'col_id', 'title', 'category', 'objective', 'en', [],
         constants.ACTIVITY_STATUS_PUBLIC, True, ['owner_id'],
         ['editor_id'], ['viewer_id'], ['contributor_id'], {}, 1, 1,
         datetime.datetime.utcnow(), datetime.datetime.utcnow())
     self.assertFalse(self.collection_summary.is_private())
Ejemplo n.º 8
0
def get_collection_summary_from_model(collection_summary_model):
    return collection_domain.CollectionSummary(
        collection_summary_model.id, collection_summary_model.title,
        collection_summary_model.category, collection_summary_model.objective,
        collection_summary_model.status,
        collection_summary_model.community_owned,
        collection_summary_model.owner_ids,
        collection_summary_model.editor_ids,
        collection_summary_model.viewer_ids, collection_summary_model.version,
        collection_summary_model.collection_model_created_on,
        collection_summary_model.collection_model_last_updated)
Ejemplo n.º 9
0
 def test_is_solely_owned_by_user_multiple_owners(self) -> None:
     self.assertTrue(
         self.collection_summary.is_solely_owned_by_user('owner_id'))
     self.assertFalse(
         self.collection_summary.is_solely_owned_by_user('other_id'))
     self.collection_summary = collection_domain.CollectionSummary(
         'col_id', 'title', 'category', 'objective', 'en', [],
         constants.ACTIVITY_STATUS_PUBLIC, True, ['owner_id', 'other_id'],
         ['editor_id'], ['viewer_id'], ['contributor_id'], {}, 1, 1,
         datetime.datetime.utcnow(), datetime.datetime.utcnow())
     self.assertFalse(
         self.collection_summary.is_solely_owned_by_user('owner_id'))
     self.assertFalse(
         self.collection_summary.is_solely_owned_by_user('other_id'))
Ejemplo n.º 10
0
def compute_summary_of_collection(collection, contributor_id_to_add):
    """Create a CollectionSummary domain object for a given Collection domain
    object and return it.

    Args:
        collection: Collection. The domain object.
        contributor_id_to_add: str. ID of the contributor to be added to the
            collection summary.

    Returns:
        CollectionSummary. The computed summary for the given collection.
    """
    collection_rights = collection_models.CollectionRightsModel.get_by_id(
        collection.id)
    collection_summary_model = (
        collection_models.CollectionSummaryModel.get_by_id(collection.id))

    # Update the contributor id list if necessary (contributors
    # defined as humans who have made a positive (i.e. not just
    # a revert) change to an collection's content).
    contributors_summary = (
        collection_summary_model.contributors_summary
        if collection_summary_model else {})

    if contributor_id_to_add is None:
        # Recalculate the contributors because revert was done.
        contributors_summary = compute_collection_contributors_summary(
            collection.id)
    elif contributor_id_to_add not in constants.SYSTEM_USER_IDS:
        contributors_summary[contributor_id_to_add] = (
            contributors_summary.get(contributor_id_to_add, 0) + 1)

    contributor_ids = list(contributors_summary.keys())

    collection_model_last_updated = collection.last_updated
    collection_model_created_on = collection.created_on
    collection_model_node_count = len(collection.nodes)

    collection_summary = collection_domain.CollectionSummary(
        collection.id, collection.title, collection.category,
        collection.objective, collection.language_code, collection.tags,
        collection_rights.status, collection_rights.community_owned,
        collection_rights.owner_ids, collection_rights.editor_ids,
        collection_rights.viewer_ids, contributor_ids, contributors_summary,
        collection.version, collection_model_node_count,
        collection_model_created_on, collection_model_last_updated
    )

    return collection_summary
Ejemplo n.º 11
0
def get_summary_of_collection(collection):
    """Create a CollectionSummary domain object for a given Collection domain
    object and return it.
    """
    collection_rights = collection_models.CollectionRightsModel.get_by_id(
        collection.id)
    collection_summary_model = (
        collection_models.CollectionSummaryModel.get_by_id(collection.id))

    collection_model_last_updated = collection.last_updated
    collection_model_created_on = collection.created_on

    collection_summary = collection_domain.CollectionSummary(
        collection.id, collection.title, collection.category,
        collection.objective, collection_rights.status,
        collection_rights.community_owned, collection_rights.owner_ids,
        collection_rights.editor_ids, collection_rights.viewer_ids,
        collection.version, collection_model_created_on,
        collection_model_last_updated)

    return collection_summary