def put(self, exploration_id): """Unpublishes the given exploration, and sends an email to all its owners. """ exploration = exp_fetchers.get_exploration_by_id(exploration_id) email_body = self.payload.get('email_body') version = self.payload.get('version') _require_valid_version(version, exploration.version) # If moderator emails can be sent, check that all the prerequisites are # satisfied, otherwise do nothing. if feconf.REQUIRE_EMAIL_ON_MODERATOR_ACTION: if not email_body: raise self.InvalidInputException( 'Moderator actions should include an email to the ' 'recipient.') email_manager.require_moderator_email_prereqs_are_satisfied() # Unpublish exploration. rights_manager.unpublish_exploration(self.user, exploration_id) search_services.delete_explorations_from_search_index([exploration_id]) exp_rights = rights_manager.get_exploration_rights(exploration_id) # If moderator emails can be sent, send an email to the all owners of # the exploration notifying them of the change. if feconf.REQUIRE_EMAIL_ON_MODERATOR_ACTION: for owner_id in exp_rights.owner_ids: email_manager.send_moderator_action_email( self.user_id, owner_id, 'unpublish_exploration', exploration.title, email_body) self.render_json({ 'rights': exp_rights.to_dict(), })
def test_delete_explorations_from_search_index(self): def _mock_delete_docs(ids, index): """Mocks delete_documents_from_index().""" self.assertEqual(ids, [self.EXP_ID]) self.assertEqual(index, search_services.SEARCH_INDEX_EXPLORATIONS) delete_docs_counter = test_utils.CallCounter(_mock_delete_docs) delete_docs_swap = self.swap( gae_search_services, 'delete_documents_from_index', delete_docs_counter) with delete_docs_swap: search_services.delete_explorations_from_search_index([self.EXP_ID]) self.assertEqual(delete_docs_counter.times_called, 1)
def test_delete_explorations_from_search_index(self) -> None: def _mock_delete_docs(ids: List[str], index: str) -> None: """Mocks delete_documents_from_index().""" self.assertEqual(ids, [self.EXP_ID]) self.assertEqual(index, search_services.SEARCH_INDEX_EXPLORATIONS) delete_docs_counter = test_utils.CallCounter( _mock_delete_docs) # type: ignore[no-untyped-call] delete_docs_swap = self.swap(gae_search_services, 'delete_documents_from_index', delete_docs_counter) with delete_docs_swap: search_services.delete_explorations_from_search_index( [self.EXP_ID]) self.assertEqual(delete_docs_counter.times_called, 1)