def test_can_access(self, thread_id, **kwargs): """Checks if the user can comment on the feedback thread. Args: thread_id: str. The feedback thread id. **kwargs: *. Keyword arguments. Returns: *. The return value of the decorated function. """ if not self.user_id: raise base.UserFacingExceptions.NotLoggedInException if '.' not in thread_id: raise self.InvalidInputException('Thread ID must contain a .') exploration_id = feedback_services.get_exp_id_from_thread_id(thread_id) if exploration_id in feconf.DISABLED_EXPLORATION_IDS: raise base.UserFacingExceptions.PageNotFoundException exploration_rights = rights_manager.get_exploration_rights( exploration_id, strict=False) if rights_manager.check_can_access_activity(self.user, exploration_rights): return handler(self, thread_id, **kwargs) else: raise self.UnauthorizedUserException( 'You do not have credentials to comment on exploration' ' feedback.')
def get(self, thread_id): """Handles GET requests.""" messages = feedback_services.get_messages(thread_id) author_ids = [m.author_id for m in messages] authors_settings = user_services.get_users_settings(author_ids) message_ids = [m.message_id for m in messages] feedback_services.update_messages_read_by_the_user( self.user_id, thread_id, message_ids) message_summary_list = [] suggestion = suggestion_services.get_suggestion_by_id(thread_id) suggestion_thread = feedback_services.get_thread(thread_id) exploration_id = feedback_services.get_exp_id_from_thread_id(thread_id) if suggestion: exploration = exp_fetchers.get_exploration_by_id(exploration_id) current_content_html = ( exploration.states[suggestion.change.state_name].content.html) suggestion_summary = { 'suggestion_html': suggestion.change.new_value['html'], 'current_content_html': current_content_html, 'description': suggestion_thread.subject, 'author_username': authors_settings[0].username, 'author_picture_data_url': (authors_settings[0].profile_picture_data_url), 'created_on_msecs': utils.get_time_in_millisecs(messages[0].created_on) } message_summary_list.append(suggestion_summary) messages.pop(0) authors_settings.pop(0) for m, author_settings in python_utils.ZIP(messages, authors_settings): if author_settings is None: author_username = None author_picture_data_url = None else: author_username = author_settings.username author_picture_data_url = ( author_settings.profile_picture_data_url) message_summary = { 'message_id': m.message_id, 'text': m.text, 'updated_status': m.updated_status, 'author_username': author_username, 'author_picture_data_url': author_picture_data_url, 'created_on_msecs': utils.get_time_in_millisecs(m.created_on) } message_summary_list.append(message_summary) self.render_json({'message_summary_list': message_summary_list})
def post(self, thread_id): exploration_id = feedback_services.get_exp_id_from_thread_id(thread_id) transaction_services.run_in_transaction( feedback_services.clear_feedback_message_references, self.user_id, exploration_id, thread_id) self.render_json(self.values)
def test_get_exp_id_from_thread_id(self): thread_id = 'exploration.exp1.1234' self.assertEqual( feedback_services.get_exp_id_from_thread_id(thread_id), 'exp1')