Repository: oppia/oppia

Issue:
[BUG]: Error Message is wrong when adding an invalid username to provide exploration voiceovers
### Describe the bug

When I try to add a voice artist, it says "could not assign voice artist to private activity". The unit topic is Place Values and the chapter is "What are the Place Values?"

### Steps To Reproduce

1) Go to learn tab 
2) Go to the Lesson "Place Values" 
3) Click Chapter 1: What are the Place Values? 
4) Switch to edit mode by going to URL and replacing the part that says "explore" with "create" 
5) Then go to settings gear 
6) Scroll to add voice artists 
7) Click edit 
8) When I tried adding someone besides myself (such as a volunteer), it doesn't work. [**EDIT**: This was actually done with an invalid username.]

### Expected Behavior

~~I expect to be able to add the voiceover artist onto the chapter.~~ The error message should indicate that the username is invalid, rather than that the exploration is private (which isn't true).

### Screenshots/Videos

<img width="1432" alt="Screen Shot 2023-02-20 at 10 19 14 PM" src="https://user-images.githubusercontent.com/125941694/220245624-cb622ed3-dbf6-495d-a99e-e2072be385ca.png">


### What device are you using?

Desktop

### Operating System

MacOS

### What browsers are you seeing the problem on?

Chrome, Safari

### Browser version

Version 110.0.5481.100 (Chrome),

### Additional context

_No response_
[BUG]: Error Message is wrong when adding an invalid username to provide exploration voiceovers
### Describe the bug

When I try to add a voice artist, it says "could not assign voice artist to private activity". The unit topic is Place Values and the chapter is "What are the Place Values?"

### Steps To Reproduce

1) Go to learn tab 
2) Go to the Lesson "Place Values" 
3) Click Chapter 1: What are the Place Values? 
4) Switch to edit mode by going to URL and replacing the part that says "explore" with "create" 
5) Then go to settings gear 
6) Scroll to add voice artists 
7) Click edit 
8) When I tried adding someone besides myself (such as a volunteer), it doesn't work. [**EDIT**: This was actually done with an invalid username.]

### Expected Behavior

~~I expect to be able to add the voiceover artist onto the chapter.~~ The error message should indicate that the username is invalid, rather than that the exploration is private (which isn't true).

### Screenshots/Videos

<img width="1432" alt="Screen Shot 2023-02-20 at 10 19 14 PM" src="https://user-images.githubusercontent.com/125941694/220245624-cb622ed3-dbf6-495d-a99e-e2072be385ca.png">


### What device are you using?

Desktop

### Operating System

MacOS

### What browsers are you seeing the problem on?

Chrome, Safari

### Browser version

Version 110.0.5481.100 (Chrome),

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/core/controllers/voice_artist.py b/core/controllers/voice_artist.py
--- a/core/controllers/voice_artist.py
+++ b/core/controllers/voice_artist.py
@@ -226,7 +226,9 @@ def post(self, unused_entity_type: str, entity_id: str) -> None:
         voice_artist = self.normalized_payload['username']
         voice_artist_id = user_services.get_user_id_from_username(
             voice_artist)
-        assert voice_artist_id is not None
+        if voice_artist_id is None:
+            raise self.InvalidInputException(
+                'Sorry, we could not find the specified user.')
         rights_manager.assign_role_for_exploration(
             self.user, entity_id, voice_artist_id,
             rights_domain.ROLE_VOICE_ARTIST)


Test patch:
diff --git a/core/controllers/voice_artist_test.py b/core/controllers/voice_artist_test.py
--- a/core/controllers/voice_artist_test.py
+++ b/core/controllers/voice_artist_test.py
@@ -440,3 +440,20 @@ def test_cannot_deassign_random_user_from_voice_artist(self) -> None:
             response['error']
         )
         self.logout()
+
+    def test_cannot_assign_voice_artist_to_invalid_user(self) -> None:
+        self.login(self.VOICEOVER_ADMIN_EMAIL)
+        params = {
+            'username': 'invalid'
+        }
+        csrf_token = self.get_new_csrf_token()
+        response = self.post_json(
+            '/voice_artist_management_handler/exploration/%s'
+            % self.published_exp_id_1, params, csrf_token=csrf_token,
+            expected_status_int=400)
+        self.assertEqual(
+            response['error'],
+            'Sorry, we could not find the specified user.'
+        )
+
+        self.logout()