def post(self): """Handles POST requests.""" exploration_id = self.payload.get('exploration_id') if not rights_manager.Actor(self.user_id).can_clone( exploration_id): raise Exception('You cannot copy this exploration.') self.render_json({ EXPLORATION_ID_KEY: exp_services.clone_exploration( self.user_id, exploration_id) })
def test_cloned_explorations_cannot_be_published(self): exp = exp_domain.Exploration.create_default_exploration( self.EXP_ID, 'A title', 'A category') exp_services.save_new_exploration(self.user_id_a, exp) rights_manager.publish_exploration(self.user_id_a, self.EXP_ID) new_exp_id = exp_services.clone_exploration( self.user_id_b, self.EXP_ID) self.assertFalse( rights_manager.Actor(self.user_id_b).can_edit(self.EXP_ID)) self.assertTrue( rights_manager.Actor(self.user_id_b).can_view(new_exp_id)) self.assertTrue( rights_manager.Actor(self.user_id_b).can_edit(new_exp_id)) self.assertFalse( rights_manager.Actor(self.user_id_b).can_publish(new_exp_id))
def test_cloned_explorations_cannot_be_published(self): exp = exp_domain.Exploration.create_default_exploration( self.EXP_ID, 'A title', 'A category') exp_services.save_new_exploration(self.user_id_a, exp) rights_manager.publish_exploration(self.user_id_a, self.EXP_ID) new_exp_id = exp_services.clone_exploration(self.user_id_b, self.EXP_ID) self.assertFalse( rights_manager.Actor(self.user_id_b).can_edit(self.EXP_ID)) self.assertTrue( rights_manager.Actor(self.user_id_b).can_view(new_exp_id)) self.assertTrue( rights_manager.Actor(self.user_id_b).can_edit(new_exp_id)) self.assertFalse( rights_manager.Actor(self.user_id_b).can_publish(new_exp_id))
def test_clone_exploration(self): """Test cloning an exploration with assets.""" exploration = self.save_new_default_exploration(self.EXP_ID) exploration.add_states(['New state']) exp_services._save_exploration(self.OWNER_ID, exploration, '', []) with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png')) as f: raw_image = f.read() fs = fs_domain.AbstractFileSystem( fs_domain.ExplorationFileSystem(exploration.id)) fs.commit(self.OWNER_ID, 'abc.png', raw_image) new_eid = exp_services.clone_exploration(self.OWNER_ID, exploration.id) new_fs = fs_domain.AbstractFileSystem( fs_domain.ExplorationFileSystem(new_eid)) new_exploration = exp_services.get_exploration_by_id(new_eid) self.assertEqual(new_exploration.title, 'Copy of A title') self.assertEqual(new_exploration.category, 'A category') self.assertEqual(new_fs.get('abc.png'), raw_image)