def post(self): username = self.payload.get('username') user_id = user_services.get_user_id_from_username(username) if user_id is None: raise self.InvalidInputException('Invalid username: %s' % username) category = self.payload.get('category') language_code = self.payload.get('language_code', None) if category == constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_TRANSLATION: if not utils.is_supported_audio_language_code(language_code): raise self.InvalidInputException( 'Invalid language_code: %s' % language_code) if user_services.can_review_translation_suggestions( user_id, language_code=language_code): raise self.InvalidInputException( 'User %s already has rights to review translation in ' 'language code %s' % (username, language_code)) user_services.allow_user_to_review_translation_in_language( user_id, language_code) elif category == constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_VOICEOVER: if not utils.is_supported_audio_language_code(language_code): raise self.InvalidInputException( 'Invalid language_code: %s' % language_code) if user_services.can_review_voiceover_applications( user_id, language_code=language_code): raise self.InvalidInputException( 'User %s already has rights to review voiceover in ' 'language code %s' % (username, language_code)) user_services.allow_user_to_review_voiceover_in_language( user_id, language_code) elif category == constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_QUESTION: if user_services.can_review_question_suggestions(user_id): raise self.InvalidInputException( 'User %s already has rights to review question.' % ( username)) user_services.allow_user_to_review_question(user_id) elif category == constants.CONTRIBUTION_RIGHT_CATEGORY_SUBMIT_QUESTION: if user_services.can_submit_question_suggestions(user_id): raise self.InvalidInputException( 'User %s already has rights to submit question.' % ( username)) user_services.allow_user_to_submit_question(user_id) else: raise self.InvalidInputException( 'Invalid category: %s' % category) if category in [ constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_TRANSLATION, constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_VOICEOVER, constants.CONTRIBUTION_RIGHT_CATEGORY_REVIEW_QUESTION ]: email_manager.send_email_to_new_contribution_reviewer( user_id, category, language_code=language_code) self.render_json({})
def post(self): new_reviewer_username = self.payload.get('username') new_reviewer_user_id = ( user_services.get_user_id_from_username(new_reviewer_username)) if new_reviewer_user_id is None: raise self.InvalidInputException('Invalid username: %s' % new_reviewer_username) review_category = self.payload.get('review_category') language_code = self.payload.get('language_code', None) if review_category == constants.REVIEW_CATEGORY_TRANSLATION: if not utils.is_supported_audio_language_code(language_code): raise self.InvalidInputException('Invalid language_code: %s' % language_code) if user_services.can_review_translation_suggestions( new_reviewer_user_id, language_code=language_code): raise self.InvalidInputException( 'User %s already has rights to review translation in ' 'language code %s' % (new_reviewer_username, language_code)) user_services.allow_user_to_review_translation_in_language( new_reviewer_user_id, language_code) elif review_category == constants.REVIEW_CATEGORY_VOICEOVER: if not utils.is_supported_audio_language_code(language_code): raise self.InvalidInputException('Invalid language_code: %s' % language_code) if user_services.can_review_voiceover_applications( new_reviewer_user_id, language_code=language_code): raise self.InvalidInputException( 'User %s already has rights to review voiceover in ' 'language code %s' % (new_reviewer_username, language_code)) user_services.allow_user_to_review_voiceover_in_language( new_reviewer_user_id, language_code) elif review_category == constants.REVIEW_CATEGORY_QUESTION: if user_services.can_review_question_suggestions( new_reviewer_user_id): raise self.InvalidInputException( 'User %s already has rights to review question.' % (new_reviewer_username)) user_services.allow_user_to_review_question(new_reviewer_user_id) else: raise self.InvalidInputException('Invalid review_category: %s' % review_category) email_manager.send_email_to_new_community_reviewer( new_reviewer_user_id, review_category, language_code=language_code) self.render_json({})