def post(self): username = self.payload.get('username') role = self.payload.get('role') topic_id = self.payload.get('topic_id') user_id = user_services.get_user_id_from_username(username) if user_id is None: raise self.InvalidInputException( 'User with given username does not exist.') if (user_services.get_user_role_from_id(user_id) == feconf.ROLE_ID_TOPIC_MANAGER): topic_services.deassign_user_from_all_topics( user_services.get_system_user(), user_id) user_services.update_user_role(user_id, role) role_services.log_role_query(self.user_id, feconf.ROLE_ACTION_UPDATE, role=role, username=username) if topic_id: user = user_services.UserActionsInfo(user_id) topic_services.assign_role(user_services.get_system_user(), user, topic_domain.ROLE_MANAGER, topic_id) self.render_json({})
def post(self): username = self.payload.get('username') role = self.payload.get('role') user_id = user_services.get_user_id_from_username(username) if user_id is None: raise self.InvalidInputException( 'User with given username does not exist.') user_services.update_user_role(user_id, role) role_services.log_role_query(self.user_id, feconf.ROLE_ACTION_UPDATE, role=role, username=username) self.render_json({})
def test_update_user_role(self): user_id = 'test_id' user_name = 'testname' user_email = '*****@*****.**' user_services.create_new_user(user_id, user_email) user_services.set_username(user_id, user_name) self.assertEqual(user_services.get_user_role_from_id(user_id), feconf.ROLE_EXPLORATION_EDITOR) user_services.update_user_role(user_id, feconf.ROLE_COLLECTION_EDITOR) self.assertEqual(user_services.get_user_role_from_id(user_id), feconf.ROLE_COLLECTION_EDITOR)
def test_pre_delete_user_with_activities_multiple_owners(self): user_services.update_user_role( self.user_1_id, feconf.ROLE_ID_COLLECTION_EDITOR) user_1_actions = user_services.UserActionsInfo(self.user_1_id) self.save_new_valid_exploration('exp_id', self.user_1_id) rights_manager.assign_role_for_exploration( user_1_actions, 'exp_id', self.user_2_id, rights_manager.ROLE_OWNER) self.save_new_valid_collection( 'col_id', self.user_1_id, exploration_id='exp_id') rights_manager.assign_role_for_collection( user_1_actions, 'col_id', self.user_2_id, rights_manager.ROLE_OWNER) wipeout_service.pre_delete_user(self.user_1_id) pending_deletion_model = ( user_models.PendingDeletionRequestModel.get_by_id(self.user_1_id)) self.assertEqual( pending_deletion_model.exploration_ids, []) self.assertEqual(pending_deletion_model.collection_ids, [])
def setUp(self): """Completes the sign-up process for self.VOICE_ARTIST_EMAIL.""" super(VoiceArtistManagementTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.VOICE_ARTIST_EMAIL, self.VOICE_ARTIST_USERNAME) self.signup(self.VOICEOVER_ADMIN_EMAIL, self.VOICEOVER_ADMIN_USERNAME) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.voice_artist_id = self.get_user_id_from_email( self.VOICE_ARTIST_EMAIL) self.voiceover_admin_id = self.get_user_id_from_email( self.VOICEOVER_ADMIN_EMAIL) self.owner = user_services.get_user_actions_info(self.owner_id) self.save_new_valid_exploration(self.published_exp_id_1, self.owner_id) self.save_new_valid_exploration(self.published_exp_id_2, self.owner_id) self.save_new_valid_exploration(self.private_exp_id_1, self.owner_id) self.save_new_valid_exploration(self.private_exp_id_2, self.owner_id) rights_manager.publish_exploration(self.owner, self.published_exp_id_1) rights_manager.publish_exploration(self.owner, self.published_exp_id_2) user_services.update_user_role(self.voiceover_admin_id, feconf.ROLE_ID_VOICEOVER_ADMIN)
def test_get_user_ids_by_role(self): user_ids = ['test1', 'test2', 'test3', 'test4'] usernames = ['name1', 'name2', 'name3', 'name4'] user_emails = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ] for uid, email, name in zip(user_ids, user_emails, usernames): user_services.create_new_user(uid, email) user_services.set_username(uid, name) user_services.update_user_role(user_ids[0], feconf.ROLE_ID_MODERATOR) user_services.update_user_role(user_ids[1], feconf.ROLE_ID_MODERATOR) user_services.update_user_role(user_ids[2], feconf.ROLE_ID_BANNED_USER) user_services.update_user_role(user_ids[3], feconf.ROLE_ID_BANNED_USER) self.assertEqual( set(user_services.get_user_ids_by_role(feconf.ROLE_ID_MODERATOR)), set(['test1', 'test2'])) self.assertEqual( set(user_services.get_user_ids_by_role( feconf.ROLE_ID_BANNED_USER)), set(['test3', 'test4']))
def test_cannot_update_user_role_with_invalid_role(self): with self.assertRaisesRegexp(Exception, 'Role invalid_role does not exist.'): user_services.update_user_role(self.owner_id, 'invalid_role')