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 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) 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 test_contribution_msec(self): # Test the contribution time shows up correctly as None. self.signup(self.EMAIL, self.USERNAME) self.login(self.EMAIL) user_id = self.get_user_id_from_email(self.EMAIL) response_dict = self.get_json( '/profilehandler/data/%s' % self.USERNAME) self.assertIsNone(response_dict['first_contribution_msec']) # Update the first_contribution_msec to the current time in # milliseconds. first_time_in_msecs = utils.get_current_time_in_millisecs() user_services.update_first_contribution_msec_if_not_set( user_id, first_time_in_msecs) # Test the contribution date correctly changes to current_time_in_msecs. response_dict = self.get_json( '/profilehandler/data/%s' % self.USERNAME) self.assertEqual( response_dict['first_contribution_msec'], first_time_in_msecs) # Test that the contribution date is not changed after the first time it # is set. second_time_in_msecs = utils.get_current_time_in_millisecs() user_services.update_first_contribution_msec_if_not_set( user_id, second_time_in_msecs) response_dict = self.get_json( '/profilehandler/data/%s' % self.USERNAME) self.assertEqual( response_dict['first_contribution_msec'], first_time_in_msecs)
def reduce(user_id, stringified_commit_times_msec): commit_times_msec = [ ast.literal_eval(commit_time_string) for commit_time_string in stringified_commit_times_msec] first_contribution_msec = min(commit_times_msec) user_services.update_first_contribution_msec_if_not_set( user_id, first_contribution_msec)
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 reduce(user_id, stringified_commit_times_msec): """Implements the reduce function for this job.""" commit_times_msec = [ ast.literal_eval(commit_time_string) for commit_time_string in stringified_commit_times_msec] first_contribution_msec = min(commit_times_msec) user_services.update_first_contribution_msec_if_not_set( user_id, first_contribution_msec)
def publish_collection_and_update_user_profiles(committer_id, col_id): """Publishes the collection with publish_collection() function in rights_manager.py, as well as updates first_contribution_msec. It is the responsibility of the caller to check that the collection is valid prior to publication. """ rights_manager.publish_collection(committer_id, col_id) contribution_time_msec = utils.get_current_time_in_millisecs() collection_summary = get_collection_summary_by_id(col_id) contributor_ids = collection_summary.contributor_ids for contributor in contributor_ids: user_services.update_first_contribution_msec_if_not_set( contributor, contribution_time_msec)