Example #1
0
    def get(self):
        """Sends each admin up to two emails: an email to alert the admins that
        there are suggestion types that need more reviewers and/or an email
        to alert the admins that specific suggestions have been waiting too long
        to get reviewed.
        """
        if not feconf.CAN_SEND_EMAILS:
            return
        admin_ids = user_services.get_user_ids_by_role(
            feconf.ROLE_ID_CURRICULUM_ADMIN)
        question_admin_ids = user_services.get_user_ids_by_role(
            feconf.ROLE_ID_QUESTION_ADMIN)
        translation_admin_ids = user_services.get_user_ids_by_role(
            feconf.ROLE_ID_QUESTION_ADMIN)

        if (config_domain.ENABLE_ADMIN_NOTIFICATIONS_FOR_REVIEWER_SHORTAGE.
                value):
            suggestion_types_needing_reviewers = (
                suggestion_services.get_suggestion_types_that_need_reviewers())
            email_manager.send_mail_to_notify_admins_that_reviewers_are_needed(
                admin_ids, translation_admin_ids, question_admin_ids,
                suggestion_types_needing_reviewers)
        if (config_domain.
                ENABLE_ADMIN_NOTIFICATIONS_FOR_SUGGESTIONS_NEEDING_REVIEW.value
            ):
            info_about_suggestions_waiting_too_long_for_review = (
                suggestion_services.
                get_info_about_suggestions_waiting_too_long_for_review())
            (email_manager.send_mail_to_notify_admins_suggestions_waiting_long(
                admin_ids, translation_admin_ids, question_admin_ids,
                info_about_suggestions_waiting_too_long_for_review))
Example #2
0
    def test_get_user_ids_by_role(self):
        user_ids = ['test1', 'test2', 'test3', 'test4']
        usernames = ['name1', 'name2', 'name3', 'name4']
        user_emails = [
            '*****@*****.**', '*****@*****.**', '*****@*****.**',
            '*****@*****.**'
        ]

        for uid, email, name in zip(user_ids, user_emails, usernames):
            user_services.create_new_user(uid, email)
            user_services.set_username(uid, name)

        user_services.update_user_role(user_ids[0], feconf.ROLE_ID_MODERATOR)
        user_services.update_user_role(user_ids[1], feconf.ROLE_ID_MODERATOR)
        user_services.update_user_role(user_ids[2], feconf.ROLE_ID_BANNED_USER)
        user_services.update_user_role(user_ids[3], feconf.ROLE_ID_BANNED_USER)

        self.assertEqual(
            set(user_services.get_user_ids_by_role(feconf.ROLE_ID_MODERATOR)),
            set(['test1', 'test2']))

        self.assertEqual(
            set(user_services.get_user_ids_by_role(
                feconf.ROLE_ID_BANNED_USER)), set(['test3', 'test4']))
def send_flag_exploration_email(
        exploration_title, exploration_id, reporter_id, report_text):
    """Send an email to all moderators when an exploration is flagged.

    Args:
        exploration_title: str. The title of the flagged exporation.
        exploration_id: str. The ID of the flagged exploration.
        reporter_id: str. The user ID of the reporter.
        report_text: str. The message entered by the reporter.
    """
    email_subject = 'Exploration flagged by user: "******"' % exploration_title

    email_body_template = (
        'Hello Moderator,<br>'
        '%s has flagged exploration "%s" on the following '
        'grounds: <br>'
        '%s .<br>'
        'You can modify the exploration by clicking '
        '<a href="https://www.oppia.org/create/%s">here</a>.<br>'
        '<br>'
        'Thanks!<br>'
        '- The Oppia Team<br>'
        '<br>%s')

    if not feconf.CAN_SEND_EMAILS:
        log_new_error('This app cannot send emails to users.')
        return

    email_body = email_body_template % (
        user_services.get_user_settings(reporter_id).username,
        exploration_title, report_text, exploration_id,
        EMAIL_FOOTER.value)

    recipient_list = user_services.get_user_ids_by_role(
        feconf.ROLE_ID_MODERATOR)
    for recipient_id in recipient_list:
        _send_email(
            recipient_id, feconf.SYSTEM_COMMITTER_ID,
            feconf.EMAIL_INTENT_REPORT_BAD_CONTENT,
            email_subject, email_body, feconf.NOREPLY_EMAIL_ADDRESS)