def put(self, exploration_id): """Updates the email notification preferences for the given exploration. Args: exploration_id: str. The exploration id. Raises: InvalidInputException: Invalid message type. """ mute = self.payload.get('mute') message_type = self.payload.get('message_type') if message_type == feconf.MESSAGE_TYPE_FEEDBACK: user_services.set_email_preferences_for_exploration( self.user_id, exploration_id, mute_feedback_notifications=mute) elif message_type == feconf.MESSAGE_TYPE_SUGGESTION: user_services.set_email_preferences_for_exploration( self.user_id, exploration_id, mute_suggestion_notifications=mute) else: raise self.InvalidInputException('Invalid message type.') exploration_email_preferences = ( user_services.get_email_preferences_for_exploration( self.user_id, exploration_id)) self.render_json( {'email_preferences': exploration_email_preferences.to_dict()})
def put(self, exploration_id): """Updates the email notification preferences for the given exploration. Args: exploration_id: str. The exploration id. Raises: InvalidInputException: Invalid message type. """ mute = self.payload.get('mute') message_type = self.payload.get('message_type') if message_type == feconf.MESSAGE_TYPE_FEEDBACK: user_services.set_email_preferences_for_exploration( self.user_id, exploration_id, mute_feedback_notifications=mute) elif message_type == feconf.MESSAGE_TYPE_SUGGESTION: user_services.set_email_preferences_for_exploration( self.user_id, exploration_id, mute_suggestion_notifications=mute) else: raise self.InvalidInputException( 'Invalid message type.') exploration_email_preferences = ( user_services.get_email_preferences_for_exploration( self.user_id, exploration_id)) self.render_json({ 'email_preferences': exploration_email_preferences.to_dict() })
def _get_exploration_data( self, exploration_id, apply_draft=False, version=None): """Returns a description of the given exploration.""" try: if apply_draft: exploration = exp_services.get_exp_with_draft_applied( exploration_id, self.user_id) else: exploration = exp_services.get_exploration_by_id( exploration_id, version=version) except: raise self.PageNotFoundException states = {} for state_name in exploration.states: state_dict = exploration.states[state_name].to_dict() states[state_name] = state_dict exp_user_data = user_models.ExplorationUserDataModel.get( self.user_id, exploration_id) draft_changes = (exp_user_data.draft_change_list if exp_user_data and exp_user_data.draft_change_list else None) is_version_of_draft_valid = ( exp_services.is_version_of_draft_valid( exploration_id, exp_user_data.draft_change_list_exp_version) if exp_user_data and exp_user_data.draft_change_list_exp_version else None) draft_change_list_id = (exp_user_data.draft_change_list_id if exp_user_data else 0) exploration_email_preferences = ( user_services.get_email_preferences_for_exploration( self.user_id, exploration_id)) editor_dict = { 'auto_tts_enabled': exploration.auto_tts_enabled, 'category': exploration.category, 'correctness_feedback_enabled': ( exploration.correctness_feedback_enabled), 'draft_change_list_id': draft_change_list_id, 'exploration_id': exploration_id, 'init_state_name': exploration.init_state_name, 'language_code': exploration.language_code, 'objective': exploration.objective, 'param_changes': exploration.param_change_dicts, 'param_specs': exploration.param_specs_dict, 'rights': rights_manager.get_exploration_rights( exploration_id).to_dict(), 'show_state_editor_tutorial_on_load': ( self.user_id and not self.has_seen_editor_tutorial), 'states': states, 'tags': exploration.tags, 'title': exploration.title, 'version': exploration.version, 'is_version_of_draft_valid': is_version_of_draft_valid, 'draft_changes': draft_changes, 'email_preferences': exploration_email_preferences.to_dict() } return editor_dict
def _get_exploration_data( self, exploration_id, apply_draft=False, version=None): """Returns a description of the given exploration.""" try: if apply_draft: exploration = exp_services.get_exp_with_draft_applied( exploration_id, self.user_id) else: exploration = exp_services.get_exploration_by_id( exploration_id, version=version) except: raise self.PageNotFoundException states = {} for state_name in exploration.states: state_dict = exploration.states[state_name].to_dict() states[state_name] = state_dict exp_user_data = user_models.ExplorationUserDataModel.get( self.user_id, exploration_id) draft_changes = (exp_user_data.draft_change_list if exp_user_data and exp_user_data.draft_change_list else None) is_version_of_draft_valid = ( exp_services.is_version_of_draft_valid( exploration_id, exp_user_data.draft_change_list_exp_version) if exp_user_data and exp_user_data.draft_change_list_exp_version else None) exploration_email_preferences = ( user_services.get_email_preferences_for_exploration( self.user_id, exploration_id)) editor_dict = { 'category': exploration.category, 'exploration_id': exploration_id, 'init_state_name': exploration.init_state_name, 'language_code': exploration.language_code, 'objective': exploration.objective, 'param_changes': exploration.param_change_dicts, 'param_specs': exploration.param_specs_dict, 'rights': rights_manager.get_exploration_rights( exploration_id).to_dict(), 'show_state_editor_tutorial_on_load': ( self.user_id and not self.has_seen_editor_tutorial), 'skin_customizations': exploration.skin_instance.to_dict()[ 'skin_customizations'], 'states': states, 'tags': exploration.tags, 'title': exploration.title, 'version': exploration.version, 'is_version_of_draft_valid': is_version_of_draft_valid, 'draft_changes': draft_changes, 'email_preferences': exploration_email_preferences.to_dict() } return editor_dict
def test_set_and_get_user_email_preferences_for_exploration(self): user_id = 'someUser' exploration_id = 'someExploration' username = '******' user_email = '*****@*****.**' user_services.get_or_create_user(user_id, user_email) user_services.set_username(user_id, username) # When ExplorationUserDataModel is yet to be created, the value # of mute_feedback_notifications and mute_suggestion_notifications # should match the default values. exploration_user_model = ( user_services.user_models.ExplorationUserDataModel.get( user_id, exploration_id)) self.assertIsNone(exploration_user_model) email_preferences = user_services.get_email_preferences_for_exploration( user_id, exploration_id) self.assertEquals( email_preferences.mute_feedback_notifications, feconf.DEFAULT_FEEDBACK_NOTIFICATIONS_MUTED_PREFERENCE) self.assertEquals( email_preferences.mute_suggestion_notifications, feconf.DEFAULT_SUGGESTION_NOTIFICATIONS_MUTED_PREFERENCE) # This initializes a ExplorationUserDataModel instance with # the default mute values. user_services.set_email_preferences_for_exploration( user_id, exploration_id, feconf.DEFAULT_FEEDBACK_NOTIFICATIONS_MUTED_PREFERENCE, feconf.DEFAULT_SUGGESTION_NOTIFICATIONS_MUTED_PREFERENCE) email_preferences = user_services.get_email_preferences_for_exploration( user_id, exploration_id) self.assertEquals( email_preferences.mute_feedback_notifications, feconf.DEFAULT_FEEDBACK_NOTIFICATIONS_MUTED_PREFERENCE) self.assertEquals( email_preferences.mute_suggestion_notifications, feconf.DEFAULT_SUGGESTION_NOTIFICATIONS_MUTED_PREFERENCE) # This sets only mute_suggestion_notifications property to True. # mute_feedback_notifications should remain same as before. user_services.set_email_preferences_for_exploration( user_id, exploration_id, mute_suggestion_notifications=True) email_preferences = user_services.get_email_preferences_for_exploration( user_id, exploration_id) self.assertEquals( email_preferences.mute_feedback_notifications, feconf.DEFAULT_FEEDBACK_NOTIFICATIONS_MUTED_PREFERENCE) self.assertTrue(email_preferences.mute_suggestion_notifications) # This sets only mute_feedback_notifications property to True. # mute_suggestion_notifications should remain same as before. user_services.set_email_preferences_for_exploration( user_id, exploration_id, mute_feedback_notifications=True) email_preferences = user_services.get_email_preferences_for_exploration( user_id, exploration_id) self.assertTrue(email_preferences.mute_feedback_notifications) self.assertTrue(email_preferences.mute_suggestion_notifications)