Skip to content

Commit

Permalink
[IMP] Introduced permission check in the business layer
Browse files Browse the repository at this point in the history
  • Loading branch information
c8y3 committed Mar 20, 2024
1 parent 1218653 commit 3eabbd5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/app/business/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

from app import app
from app.models.authorization import CaseAccessLevel
from app.models.authorization import Permissions
from app.iris_engine.module_handler.module_handler import call_modules_hook
from app.iris_engine.utils.tracker import track_activity
from app.datamgmt.manage.manage_cases_db import delete_case
from app.business.errors import BusinessProcessingError
from app.business.permissions import check_current_user_has_some_case_access
from app.business.permissions import check_current_user_has_some_permission


def delete(case_identifier, context_case_identifier):
check_current_user_has_some_permission([Permissions.standard_user])
check_current_user_has_some_case_access(case_identifier, [CaseAccessLevel.full_access])

if case_identifier == 1:
Expand Down
16 changes: 16 additions & 0 deletions source/app/business/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from flask import session
from flask_login import current_user

from app.models.authorization import Permissions
from app.iris_engine.access_control.utils import ac_get_effective_permissions_of_user
from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access
from app.business.errors import PermissionDeniedError


def check_current_user_has_some_case_access(case_identifier, access_levels):
if not ac_fast_check_current_user_has_case_access(case_identifier, access_levels):
raise PermissionDeniedError()


def check_current_user_has_some_permission(permissions):
if 'permissions' not in session:
session['permissions'] = ac_get_effective_permissions_of_user(current_user)

for permission in permissions:
if session['permissions'] & permission.value:
return

raise PermissionDeniedError()

0 comments on commit 3eabbd5

Please sign in to comment.