Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/conode/application/services/access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 1 addition & 6 deletions src/conode/application/verify_company/verify_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/company/test_verify_company.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
Loading