Repository: oppia/oppia

Issue:
Unable to add user to translator role in production.
I just tried to add a translator to the Fractions 1 exploration on oppia.org. On doing this, I get an error message: "Invalid role: translator".

I think the issue might be in email_manager.EDITOR_ROLE_EMAIL_HTML_ROLES. We should fix that and add tests for this part of the pipeline.

AFAICT, the effect of this is that the user got successfully added, but did not receive an email.
Unable to add user to translator role in production.
I just tried to add a translator to the Fractions 1 exploration on oppia.org. On doing this, I get an error message: "Invalid role: translator".

I think the issue might be in email_manager.EDITOR_ROLE_EMAIL_HTML_ROLES. We should fix that and add tests for this part of the pipeline.

AFAICT, the effect of this is that the user got successfully added, but did not receive an email.


Discussion:

Resolving patch:
diff --git a/core/domain/email_manager.py b/core/domain/email_manager.py
--- a/core/domain/email_manager.py
+++ b/core/domain/email_manager.py
@@ -101,20 +101,25 @@ def log_new_error(*args, **kwargs):
 
 EXPLORATION_ROLE_MANAGER = 'manager rights'
 EXPLORATION_ROLE_EDITOR = 'editor rights'
+EXPLORATION_ROLE_TRANSLATOR = 'translator rights'
 EXPLORATION_ROLE_PLAYTESTER = 'playtest access'
 
 EDITOR_ROLE_EMAIL_HTML_ROLES = {
     rights_manager.ROLE_OWNER: EXPLORATION_ROLE_MANAGER,
     rights_manager.ROLE_EDITOR: EXPLORATION_ROLE_EDITOR,
+    rights_manager.ROLE_TRANSLATOR: EXPLORATION_ROLE_TRANSLATOR,
     rights_manager.ROLE_VIEWER: EXPLORATION_ROLE_PLAYTESTER
 }
 
 _EDITOR_ROLE_EMAIL_HTML_RIGHTS = {
     'can_manage': '<li>Change the exploration permissions</li><br>',
     'can_edit': '<li>Edit the exploration</li><br>',
+    'can_translate': '<li>Translate the exploration</li><br>',
     'can_play': '<li>View and playtest the exploration</li><br>'
 }
 
+# We don't include "can_translate" for managers and editors, since this is
+# implied by the email description for "can_edit".
 EDITOR_ROLE_EMAIL_RIGHTS_FOR_ROLE = {
     EXPLORATION_ROLE_MANAGER: (
         _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_manage'] +
@@ -123,6 +128,9 @@ def log_new_error(*args, **kwargs):
     EXPLORATION_ROLE_EDITOR: (
         _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'] +
         _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']),
+    EXPLORATION_ROLE_TRANSLATOR: (
+        _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_translate'] +
+        _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']),
     EXPLORATION_ROLE_PLAYTESTER: _EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']
 }
 


Test patch:
diff --git a/core/domain/email_manager_test.py b/core/domain/email_manager_test.py
--- a/core/domain/email_manager_test.py
+++ b/core/domain/email_manager_test.py
@@ -297,6 +297,66 @@ def test_correct_rights_are_written_in_editor_role_email_body(self):
                 messages[0].body.decode(),
                 expected_email_text_body)
 
+    def test_correct_rights_are_written_in_translator_role_email_body(self):
+        expected_email_html_body = (
+            'Hi newuser,<br>'
+            '<br>'
+            '<b>editor</b> has granted you translator rights to their '
+            'exploration, '
+            '"<a href="https://www.oppia.org/create/A">Title</a>"'
+            ', on Oppia.org.<br>'
+            '<br>'
+            'This allows you to:<br>'
+            '<ul>'
+            '<li>Translate the exploration</li><br>'
+            '<li>View and playtest the exploration</li><br>'
+            '</ul>'
+            'You can find the exploration '
+            '<a href="https://www.oppia.org/create/A">here</a>.<br>'
+            '<br>'
+            'Thanks, and happy collaborating!<br>'
+            '<br>'
+            'Best wishes,<br>'
+            'The Oppia Team<br>'
+            '<br>'
+            'You can change your email preferences via the '
+            '<a href="https://www.example.com">Preferences</a> page.')
+
+        expected_email_text_body = (
+            'Hi newuser,\n'
+            '\n'
+            'editor has granted you translator rights to their '
+            'exploration, "Title", on Oppia.org.\n'
+            '\n'
+            'This allows you to:\n'
+            '- Translate the exploration\n'
+            '- View and playtest the exploration\n'
+            'You can find the exploration here.\n'
+            '\n'
+            'Thanks, and happy collaborating!\n'
+            '\n'
+            'Best wishes,\n'
+            'The Oppia Team\n'
+            '\n'
+            'You can change your email preferences via the Preferences page.')
+
+        with self.can_send_emails_ctx, self.can_send_editor_role_email_ctx:
+            # Check that correct email content is sent for Translator.
+            email_manager.send_role_notification_email(
+                self.editor_id, self.new_user_id,
+                rights_manager.ROLE_TRANSLATOR, self.exploration.id,
+                self.exploration.title)
+
+            messages = self.mail_stub.get_sent_messages(to=self.NEW_USER_EMAIL)
+            self.assertEqual(len(messages), 1)
+
+            self.assertEqual(
+                messages[0].html.decode(),
+                expected_email_html_body)
+            self.assertEqual(
+                messages[0].body.decode(),
+                expected_email_text_body)
+
     def test_correct_rights_are_written_in_playtester_role_email_body(self):
         expected_email_html_body = (
             'Hi newuser,<br>'