diff --git a/src/conode/application/services/access_control.py b/src/conode/application/services/access_control.py index 0d18862..956f8a1 100644 --- a/src/conode/application/services/access_control.py +++ b/src/conode/application/services/access_control.py @@ -290,6 +290,10 @@ async def ensure_user_can_manipulate_groups( "Not enough rights to perform operation", None ) + def ensure_user_can_verify_companies(self, user: User) -> None: + if user.system_role != UserSystemRole.ADMIN: + raise NotEnoughRightsError("Not enough rights to perform operation", None) + def ensure_user_can_manipulate_user_profiles(self, user: User) -> None: if user.system_role != UserSystemRole.ADMIN: raise NotEnoughRightsError("Not enough rights to perform operation", None) diff --git a/src/conode/application/verify_company/verify_company.py b/src/conode/application/verify_company/verify_company.py index 601bf9a..1f11aba 100644 --- a/src/conode/application/verify_company/verify_company.py +++ b/src/conode/application/verify_company/verify_company.py @@ -2,7 +2,6 @@ from conode.application.errors import ( CompanyNotFoundError, - NotEnoughRightsError, ) from conode.application.interfaces.repositories import CompanyRepository from conode.application.interfaces.transaction_manager import TransactionManager @@ -20,11 +19,7 @@ async def execute(self, company_id: CompanyId) -> None: async with self.transaction_manager: user = await self.access_control_service.get_authorized_user() - if not user.is_admin(): - raise NotEnoughRightsError( - "Not enough rights to perform operation", - [{"key": "user_id", "value": user.id}], - ) + self.access_control_service.ensure_user_can_verify_companies(user) company = await self.company_repository.get_by_id(company_id) if company is None: diff --git a/tests/e2e/company/test_verify_company.py b/tests/e2e/company/test_verify_company.py index fb11883..1640074 100644 --- a/tests/e2e/company/test_verify_company.py +++ b/tests/e2e/company/test_verify_company.py @@ -1,6 +1,7 @@ from http import HTTPStatus import pytest +from dirty_equals import IsPartialDict from httpx import AsyncClient from conode.application.interfaces.repositories import CompanyRepository @@ -49,3 +50,7 @@ async def test_verify_company_user_not_admin( assert response.status_code == HTTPStatus.FORBIDDEN assert not company.verified + assert response.json() == IsPartialDict( + detail="Not enough rights to perform operation", + meta=None, + )