diff --git a/README.md b/README.md index be3247bc..6507f3ba 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ We recommend installing using Ubuntu 22.04 with python 3.10. Required packages are listed in the ```settings.json``` file, for now the packages must be installed manually. ```bash -pip install openpyxl==3.1.4 awesome-slugify==1.6.5 fastapi==0.111.0 pydantic==2.7.4 peewee==3.17.5 psutil==5.9.8 pyjwt==2.8.0 pymysql==1.1.1 python-multipart==0.0.9 starlette-context==0.3.6 uvicorn==0.30.1 charset-normalizer==3.3.2 dill==0.3.8 numpy==1.26.4 pandas==2.2.2 matplotlib==3.9.0 scipy==1.13.1 scikit-learn==1.5.0 openai==1.34.0 typing_extensions==4.12.2 boto3==1.34.127 "boto3-stubs[s3]==1.34.127" plotly==5.22.0 simplejson==3.19.2 xmltodict==0.13.0 streamlit==1.35.0 beautifulsoup4==4.12.3 grpcio==1.64.1 +pip install openpyxl==3.1.4 awesome-slugify==1.6.5 fastapi==0.111.0 pydantic==2.7.4 peewee==3.17.5 psutil==5.9.8 pyjwt==2.8.0 pymysql==1.1.1 python-multipart==0.0.9 starlette-context==0.3.6 uvicorn==0.30.1 charset-normalizer==2.1.1 dill==0.3.8 numpy==1.26.4 pandas==2.2.2 matplotlib==3.9.0 scipy==1.13.1 scikit-learn==1.5.0 openai==1.34.0 typing_extensions==4.12.2 boto3==1.34.127 "boto3-stubs[s3]==1.34.127" plotly==5.22.0 simplejson==3.19.2 xmltodict==0.13.0 streamlit==1.35.0 beautifulsoup4==4.12.3 grpcio==1.64.1 ``` #### Usage diff --git a/src/gws_core/user/current_user_service.py b/src/gws_core/user/current_user_service.py index a86849b2..9dc14b84 100644 --- a/src/gws_core/user/current_user_service.py +++ b/src/gws_core/user/current_user_service.py @@ -88,14 +88,14 @@ def check_is_sysuser(cls): raise UnauthorizedException(detail="Unauthorized: sysuser required") @classmethod - def check_is_owner(cls): + def check_is_admin(cls): try: user = CurrentUserService.get_and_check_current_user() except: - raise UnauthorizedException(detail="Unauthorized: owner required") + raise UnauthorizedException(detail="Unauthorized: admin required") - if not user.is_owner: - raise UnauthorizedException(detail="Unauthorized: owner required") + if not user.is_admin: + raise UnauthorizedException(detail="Unauthorized: admin required") class AuthenticateUser: diff --git a/src/gws_core/user/user.py b/src/gws_core/user/user.py index 0dfdff4c..03a82468 100644 --- a/src/gws_core/user/user.py +++ b/src/gws_core/user/user.py @@ -13,17 +13,6 @@ @final class User(Model): - """ - User class - - :property email: The user email - :type email: `str` - :property group: The user group (`sysuser`, `admin`, `owner` or `user`) - :type group: `str` - :property is_active: True if the is active, False otherwise - :type is_active: `bool` - """ - email: str = CharField(default=False, index=True) first_name: str = CharField(default=False) last_name: str = CharField(default=False) @@ -68,8 +57,8 @@ def full_name(self): return " ".join([self.first_name, self.last_name]).strip() @property - def is_owner(self): - return self.group == UserGroup.OWNER + def is_admin(self): + return self.group == UserGroup.ADMIN @property def is_sysuser(self): diff --git a/src/gws_core/user/user_group.py b/src/gws_core/user/user_group.py index 403406ae..2672a16e 100644 --- a/src/gws_core/user/user_group.py +++ b/src/gws_core/user/user_group.py @@ -7,7 +7,7 @@ # Enum to define the role needed for a protocol class UserGroup(Enum): SYSUSER = "SYSUSER" - OWNER = "OWNER" + ADMIN = "ADMIN" USER = "USER" @classmethod @@ -21,7 +21,7 @@ def get_value(cls, user_group: 'UserGroup') -> int: switcher = { UserGroup.SYSUSER: 0, - UserGroup.OWNER: 5, + UserGroup.ADMIN: 5, UserGroup.USER: 15, } return switcher.get(user_group) diff --git a/src/gws_core/user/user_service.py b/src/gws_core/user/user_service.py index d1f36767..35e77513 100644 --- a/src/gws_core/user/user_service.py +++ b/src/gws_core/user/user_service.py @@ -66,10 +66,10 @@ def set_user_active(cls, id_: str, is_active: bool) -> User: if not is_active: if user.is_sysuser: raise BadRequestException("Cannot deactivate the system user") - if user.is_owner: - # check if this is the last owner - if User.select().where((User.group == UserGroup.OWNER) & (User.is_active == True)).count() == 1: - raise BadRequestException("Cannot deactivate the last owner") + if user.is_admin: + # check if this is the last admin + if User.select().where((User.group == UserGroup.ADMIN) & (User.is_active == True)).count() == 1: + raise BadRequestException("Cannot deactivate the last admin") user.is_active = is_active return user.save() diff --git a/tests/test_gws_core/test_dev_env_service.py b/tests/test_gws_core/test_dev_env_service.py index e3085eb3..c39cf161 100644 --- a/tests/test_gws_core/test_dev_env_service.py +++ b/tests/test_gws_core/test_dev_env_service.py @@ -17,7 +17,7 @@ def test_dev_login(self): email="test_mail@gencovery.com", first_name="Firstname test", last_name="Lastname test", - group=UserGroup.OWNER, + group=UserGroup.ADMIN, is_active=True, theme=UserTheme.LIGHT_THEME, lang=UserLanguage.EN, diff --git a/tests/test_gws_core/test_user.py b/tests/test_gws_core/test_user.py index 90ae97bf..3d2ac046 100644 --- a/tests/test_gws_core/test_user.py +++ b/tests/test_gws_core/test_user.py @@ -66,14 +66,14 @@ def test_deactivate_user(self): user.email = "testpol@gencovery.com" user.first_name = "Michel" user.last_name = "Pol" - user.group = UserGroup.OWNER + user.group = UserGroup.ADMIN user.save() user2: User = User() user2.email = "testbeau@gencovery.com" user2.first_name = "Jack" user2.last_name = "Beauregard" - user2.group = UserGroup.OWNER + user2.group = UserGroup.ADMIN user2.save() user3: User = User() @@ -86,7 +86,7 @@ def test_deactivate_user(self): UserService.deactivate_user(user.id) UserService.deactivate_user(user3.id) - # can't deactivate the last owner + # can't deactivate the last admin self.assertRaises(BadRequestException, UserService.deactivate_user, user2.id) def test_user_search(self):