Repository: medtagger/MedTagger

Issue:
User personal information cannot be changed
## Expected Behavior

User can change its personal information at any time using Settings page.

User should only be able to change their first and last name. The E-mail field should be grayed out.

## Actual Behavior

Form fields are filled with user data but there is no way to change them. User cannot modify these fields and there is no "Save" button available.

## Steps to Reproduce the Problem

  1. Go to Settings page.
  2. Open "User data" section.
  3. Done.

## Additional comment

Consider changing the name of the section from "User data" to something else.



Discussion:

Resolving patch:
diff --git a/backend/medtagger/api/users/business.py b/backend/medtagger/api/users/business.py
--- a/backend/medtagger/api/users/business.py
+++ b/backend/medtagger/api/users/business.py
@@ -1,6 +1,9 @@
 """Module responsible for business logic for users administration."""
 from typing import List
 
+from sqlalchemy.orm.exc import NoResultFound
+
+from medtagger.api import InvalidArgumentsException
 from medtagger.database.models import User
 from medtagger.repositories.users import UsersRepository
 from medtagger.repositories.roles import RolesRepository
@@ -14,3 +17,12 @@ def get_all_users() -> List[User]:
 def set_user_role(user_id: int, role_name: str) -> None:
     """Set user's role. Old role is being replaced."""
     RolesRepository.set_user_role(user_id, role_name)
+
+
+def set_user_info(user_id: int, firstName: str, lastName: str) -> None:
+    """Set user's information."""
+    try:
+        user = UsersRepository.get_user_by_id(user_id)
+        UsersRepository.set_user_info(user, firstName, lastName)
+    except NoResultFound:
+        raise InvalidArgumentsException('User with this id does not exist.')
diff --git a/backend/medtagger/api/users/service.py b/backend/medtagger/api/users/service.py
--- a/backend/medtagger/api/users/service.py
+++ b/backend/medtagger/api/users/service.py
@@ -6,7 +6,7 @@
 
 from medtagger.api import api
 from medtagger.api.users import serializers
-from medtagger.api.users.business import get_all_users, set_user_role
+from medtagger.api.users.business import get_all_users, set_user_role, set_user_info
 from medtagger.api.utils import get_current_user
 from medtagger.api.security import login_required, role_required
 
@@ -55,3 +55,18 @@ def get() -> Any:
         """Get user info."""
         user = get_current_user()
         return user, 200
+
+
+@users_ns.route('/<int:user_id>')
+class SetUserInfo(Resource):
+    """Set user's information (first name and last name)."""
+
+    @staticmethod
+    @login_required
+    @users_ns.doc(security='token')
+    def put(user_id: int) -> Any:
+        """Set user info."""
+        if get_current_user().id != user_id:
+            return {}, 403
+        set_user_info(user_id, request.json['firstName'], request.json['lastName'])
+        return {}, 204
diff --git a/backend/medtagger/repositories/users.py b/backend/medtagger/repositories/users.py
--- a/backend/medtagger/repositories/users.py
+++ b/backend/medtagger/repositories/users.py
@@ -35,3 +35,11 @@ def get_user_by_email(user_email: str) -> Optional[User]:
     def get_user_by_id(user_id: int) -> User:
         """Get user with given id."""
         return User.query.filter(User.id == user_id).one()
+
+    @staticmethod
+    def set_user_info(user: User, firstName: str, lastName: str) -> None:
+        """Set user's info."""
+        with db_session() as session:
+            user.first_name = firstName
+            user.last_name = lastName
+            session.add(user)


Test patch: