Repository: oppia/oppia

Issue:
[BUG]: Invalid Author Details validation in Blog Dashboard
### Describe the bug

When asking for the author's name in the `author-detail-editor-modal`, we are not checking for the minimum length for the author's name. So, when the user enters the author name as a single character an invalid error is thrown saying

`Unable to update author details. Error: Author name can only have alphanumeric characters and spaces.` which indeed is thrown because of the `VALID_AUTHOR_NAME_REGEX` in the `constants.ts` file which expects a minimum of 2 characters.

### Steps To Reproduce

1. Assign yourself as Blog Admin on the admin page
2. Go to the `/blog-dashboard` endpoint and set the author name as a single character. (NOTE: Also there is a frontend validation of a minimum of 5 characters for bio in the frontend but it is not handled in the backend)
3. This should trigger the error

### Expected Behavior

It would be beneficial to include a minimum character count validation for the author's name and if possible also in the bio. This omission of a minimum character requirement has led to the issue at hand.


### Screenshots/Videos


https://github.com/oppia/oppia/assets/76906722/86c3a9ef-d414-4402-b418-4bdb773cb8be



### What device are you using?

Desktop

### Operating System

Windows, Linux

### What browsers are you seeing the problem on?

Edge

### Browser version

_No response_

### Additional context

_No response_

### Tips for developers

Before tackling the bug, please use `git bisect` (see https://git-scm.com/docs/git-bisect) to investigate which PR caused it (you only need to go back as far as commit https://github.com/oppia/oppia/commits/9a334e9). If you find the PR, leave a comment on this issue pointing to it, or just say that it happened before commit 9a334e9 if you could reproduce it there. This will help us fix the issue by reverting the faulty PR.

Also, if this is your first issue, please make sure to follow https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue and https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#setting-things-up before claiming it. Thanks!

[BUG]: Invalid Author Details validation in Blog Dashboard
### Describe the bug

When asking for the author's name in the `author-detail-editor-modal`, we are not checking for the minimum length for the author's name. So, when the user enters the author name as a single character an invalid error is thrown saying

`Unable to update author details. Error: Author name can only have alphanumeric characters and spaces.` which indeed is thrown because of the `VALID_AUTHOR_NAME_REGEX` in the `constants.ts` file which expects a minimum of 2 characters.

### Steps To Reproduce

1. Assign yourself as Blog Admin on the admin page
2. Go to the `/blog-dashboard` endpoint and set the author name as a single character. (NOTE: Also there is a frontend validation of a minimum of 5 characters for bio in the frontend but it is not handled in the backend)
3. This should trigger the error

### Expected Behavior

It would be beneficial to include a minimum character count validation for the author's name and if possible also in the bio. This omission of a minimum character requirement has led to the issue at hand.


### Screenshots/Videos


https://github.com/oppia/oppia/assets/76906722/86c3a9ef-d414-4402-b418-4bdb773cb8be



### What device are you using?

Desktop

### Operating System

Windows, Linux

### What browsers are you seeing the problem on?

Edge

### Browser version

_No response_

### Additional context

_No response_

### Tips for developers

Before tackling the bug, please use `git bisect` (see https://git-scm.com/docs/git-bisect) to investigate which PR caused it (you only need to go back as far as commit https://github.com/oppia/oppia/commits/9a334e9). If you find the PR, leave a comment on this issue pointing to it, or just say that it happened before commit 9a334e9 if you could reproduce it there. This will help us fix the issue by reverting the faulty PR.

Also, if this is your first issue, please make sure to follow https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue and https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#setting-things-up before claiming it. Thanks!



Discussion:
@seanlip I believe it would be a beneficial idea to include the validation. What are your thoughts on this? Thanks!
Sure, this seems reasonable -- let's disable the save button on the modal if the input is not valid (and also make sure that the modal can't be closed by hitting the Escape key). Thanks for suggesting it!
@seanlip I believe it would be a beneficial idea to include the validation. What are your thoughts on this? Thanks!
Sure, this seems reasonable -- let's disable the save button on the modal if the input is not valid (and also make sure that the modal can't be closed by hitting the Escape key). Thanks for suggesting it!

Resolving patch:
diff --git a/core/domain/blog_domain.py b/core/domain/blog_domain.py
--- a/core/domain/blog_domain.py
+++ b/core/domain/blog_domain.py
@@ -717,6 +717,8 @@ def require_valid_displayed_author_name(
 
         Raises:
             ValidationError. An empty author name is supplied.
+            ValidationError. The given author name falls short of the minimum
+                allowed number of characters.
             ValidationError. The given author name exceeds the maximum allowed
                 number of characters.
             ValidationError. The given author name contains non-alphanumeric
@@ -725,9 +727,13 @@ def require_valid_displayed_author_name(
         """
         if not author_name:
             raise utils.ValidationError('Empty author name supplied.')
+        if len(author_name) < constants.MIN_AUTHOR_NAME_LENGTH:
+            raise utils.ValidationError(
+                'Author name should have at least %s characters.'
+                % constants.MIN_AUTHOR_NAME_LENGTH)
         if len(author_name) > constants.MAX_AUTHOR_NAME_LENGTH:
             raise utils.ValidationError(
-                'A author name can have at most %s characters.'
+                'Author name can have at most %s characters.'
                 % constants.MAX_AUTHOR_NAME_LENGTH)
         if not re.match(constants.VALID_AUTHOR_NAME_REGEX, author_name):
             raise utils.ValidationError(


Test patch:
diff --git a/core/domain/blog_domain_test.py b/core/domain/blog_domain_test.py
--- a/core/domain/blog_domain_test.py
+++ b/core/domain/blog_domain_test.py
@@ -675,7 +675,9 @@ def test_author_username_validation_for_author_details(self) -> None:
         self._assert_valid_displayed_author_name(
             'Empty author name supplied.', '')
         self._assert_valid_displayed_author_name(
-            'A author name can have at most 35 characters.', 'user' * 10)
+            'Author name should have at least 2 characters.', 'A')
+        self._assert_valid_displayed_author_name(
+            'Author name can have at most 35 characters.', 'user' * 10)
         self._assert_valid_displayed_author_name(
             'Author name can only have alphanumeric characters and spaces.',
             'name..name'