Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
9a33abf
Started implementation of POST /api/v2/alerts-filters
Elise17 Oct 8, 2025
b7088fd
Fixed analysis check
Elise17 Oct 8, 2025
103ed2c
Added function _load
Elise17 Oct 8, 2025
82bfec6
Deprecated endpoint POST /filters/add in favor of POST /api/v2/alerts…
Elise17 Oct 8, 2025
5b1290e
Added test create alert when filter data is missing
Elise17 Oct 8, 2025
ea45b99
Added test test_create_alert_filter_should_return_filter_type
Elise17 Oct 8, 2025
4c5ddd6
Added test_create_alert_filter_should_return_filter_name
Elise17 Oct 8, 2025
0a0f63d
Added test_create_alert_filter_should_return_in_filter_data_alert_title
Elise17 Oct 8, 2025
af0bf2b
Started implementation of GET /api/v2/alerts-filters/{identifier}
Elise17 Oct 17, 2025
0c911fe
Fixed check analysis
Elise17 Oct 17, 2025
8559ad7
Fixed importation problem
Elise17 Oct 17, 2025
7440b09
Fixed static analysis
Elise17 Oct 17, 2025
0690eb0
Removed user in test
Elise17 Oct 17, 2025
1129b73
Added test_get_alert_filter_should_return_filter_name
Elise17 Oct 17, 2025
97a89e5
Deprecated endpoint GET /filters/{identifier}
Elise17 Oct 17, 2025
622b46a
Added test_get_alert_filter_should_return_404
Elise17 Oct 17, 2025
9a1fffd
Added test_get_alert_filter_should_return_404_when_user_has_not_creat…
Elise17 Oct 17, 2025
e4b4998
Fixed static analysis
Elise17 Oct 17, 2025
69e38c8
Started implementation of PUT /api/v2/alerts-filters/{identifier}
Elise17 Oct 21, 2025
ec809ef
Fixed static analysis
Elise17 Oct 21, 2025
f438d3b
Added test_update_alert_filter_should_return_filter_name
Elise17 Oct 21, 2025
930e94c
Added test_update_alert_filter_should_return_filter_description
Elise17 Oct 21, 2025
120bed5
Added test_update_alert_filter_should_return_filter_type
Elise17 Oct 21, 2025
48c0957
Added test_update_alert_filter_should_return_filter_data_alert_title
Elise17 Oct 21, 2025
657d441
Added test_update_alert_filter_should_return_404_when_alert_filter_is…
Elise17 Oct 21, 2025
1008f29
Removed identifietr in test_update_alert_filter_should_return_404_whe…
Elise17 Oct 21, 2025
78234ef
Deprecated endpoint POST /filters/update/{identifier}
Elise17 Oct 21, 2025
eb541cb
Started implmentation of endpoint DELETE /api/v2/alerts-filters/{iden…
Elise17 Oct 21, 2025
745739c
Added test_delete_alert_filter_should_return_404_when_alert_not_found
Elise17 Oct 21, 2025
74bf4ea
test_get_alert_filter_should_return_404_after_delete_alert_filter
Elise17 Oct 21, 2025
157d749
Deprecated endpoint DELETE /api/v2/alerts-filters/{identifier}
Elise17 Oct 21, 2025
9a5a4c7
Fixed check analysis
Elise17 Oct 21, 2025
cb3ec88
Changed indentation and added ValidationError
Elise17 Oct 21, 2025
8d345f3
Changed indentation and added ValidationError
Elise17 Oct 21, 2025
b68b34c
Added new test test_update_alert_filter_should_return_400
Elise17 Oct 21, 2025
2dbfb95
Renamed method
c8y3 Oct 6, 2025
d1986e9
Renamed method
c8y3 Oct 6, 2025
7a8cfc5
Aligned method call
c8y3 Oct 6, 2025
ddef892
Started implementation of GET /api/v2/manage/customers/{identifier}
c8y3 Oct 6, 2025
6096f3b
Moved code down into persistence layer
c8y3 Oct 8, 2025
c7c77d0
Removed unused imports
c8y3 Oct 8, 2025
115d9ae
Added tow new import constraints: do not import marshables and do not…
c8y3 Oct 8, 2025
497135d
One import per line
c8y3 Oct 8, 2025
2651462
Removed dead code
c8y3 Oct 8, 2025
358d2d1
One import per line
c8y3 Oct 8, 2025
2c041aa
Following calling conventions
c8y3 Oct 8, 2025
3a6204b
Moved code down into the business and persistence layers
c8y3 Oct 8, 2025
acd242b
Early return
c8y3 Oct 8, 2025
cef2751
Simple quotes
c8y3 Oct 8, 2025
3fe05d1
Introduced method to get a customer by its name
c8y3 Oct 8, 2025
99842fc
Ruff warning
c8y3 Oct 8, 2025
50b4982
Added method to create a customer in the business layer
c8y3 Oct 8, 2025
3282472
Added a TODO
c8y3 Oct 8, 2025
7791840
Do not import iris_current_user from app.business.cases
c8y3 Oct 8, 2025
573a842
Removed unnecessary method parameter
c8y3 Oct 8, 2025
5411f32
Parameter need not be optional
c8y3 Oct 8, 2025
c1a2036
Extracted method
c8y3 Oct 8, 2025
410cdac
Extracted method
c8y3 Oct 8, 2025
f009aba
Removed one call to iris_current_user from iris_engine
c8y3 Oct 8, 2025
e1e3691
Moved code down into models
c8y3 Oct 8, 2025
1754dbf
Moved test .env file at the top level as .env.tests.model
c8y3 Oct 22, 2025
7ceee59
Renamed method to follow conventions
c8y3 Oct 24, 2025
e73af4d
GET /api/v2/customers/{identifier} should return 404 when it doesn't …
c8y3 Oct 24, 2025
30f49e2
Renamed test
c8y3 Oct 24, 2025
31e8495
Deprecate GET /manage/customers/{client_id}
c8y3 Oct 24, 2025
f3163c8
GET /api/v2/manage/customers/{identifier} returns 403 when user has n…
c8y3 Oct 24, 2025
df5de76
Removed methods which seem to be dead
c8y3 Oct 24, 2025
d912cac
Added rule RUF100
c8y3 Oct 24, 2025
74b9866
Added ruff rule RUF029
c8y3 Oct 24, 2025
e0ba692
Added ruff rules FURB14*
c8y3 Oct 24, 2025
405e758
Added ruff rule ARG003 and ARG005
c8y3 Oct 24, 2025
0d4f59f
Added ruff rules PYI*
c8y3 Oct 24, 2025
86e556b
Fixed and added all ruff B00* rules
c8y3 Oct 24, 2025
0329817
Set ruff rules FURB142, FURB145 and FURB148 rather than RUF14* (I am …
c8y3 Oct 24, 2025
4070b55
Removed PYI rules: we do not seem to use pyi
c8y3 Oct 24, 2025
535556f
Added dead code check with vulture
c8y3 Oct 24, 2025
9cc46da
Renamed vulture ignore file so that ruff does not parse it as a pytho…
c8y3 Oct 24, 2025
3fb283a
Removed validate_asset_type from vulture ignore list to check it fail…
c8y3 Oct 24, 2025
13bb46c
Removed seemingly dead methods
c8y3 Oct 24, 2025
e89de9e
Commented seemingly dead code which is used by iris-module-interface
c8y3 Oct 24, 2025
e080126
Started implementation of PUT /api/v2/manage/customers/{identifier}
c8y3 Oct 29, 2025
b400f72
PUT /api/v2/manage/customers/{identifier} should return 400 when anot…
c8y3 Oct 29, 2025
e6625f1
Moved database code out of marshables into the persistence layer
c8y3 Oct 29, 2025
39ac885
Added some ignored files to vulture
c8y3 Oct 29, 2025
33a4a4e
Improved configuration of vulture somewhat
c8y3 Oct 29, 2025
de86e58
Improved configuration of vulture somewhat
c8y3 Oct 29, 2025
f25c442
Improved configuration of vulture somewhat
c8y3 Oct 29, 2025
de3b44e
Organized vulture ignore file a bit more
c8y3 Oct 29, 2025
c4a4881
Simplified vulture ignore file somewhat
c8y3 Oct 29, 2025
97ee448
Deprecated PUT /manage/customers/update/<int:client_id>
c8y3 Oct 29, 2025
48c1209
Removed one occurence of ElementNotFoundException (use ObjectNotFound…
c8y3 Oct 29, 2025
ee14b4a
Removed unnecessary parameter
c8y3 Oct 29, 2025
ed60317
Removed exception ElementNotFoundException
c8y3 Oct 29, 2025
c5c4dd1
Fixed some deepsource warnings
c8y3 Oct 29, 2025
2105ca1
Added E20* ruff rules, and fixed warnings
c8y3 Oct 29, 2025
e25ba98
Added ruff rule W391
c8y3 Oct 29, 2025
20b074c
Fixed ruff warnings
c8y3 Oct 29, 2025
6a55d46
Started implmentation of DELETE /api/v2/manage/customers/{identifier}
c8y3 Oct 31, 2025
2f01f79
DELETE /api/v2/manage/customers/{identifier} should return 400 when c…
c8y3 Oct 31, 2025
2c4925d
Renamed test
c8y3 Oct 31, 2025
5cbdaf1
Moved business error definitions out of business into model
c8y3 Oct 31, 2025
9ab53e4
Fixed import constraint
c8y3 Oct 31, 2025
c7c3a0f
Use annotations to define endpoints on groups
c8y3 Oct 31, 2025
20bb8d9
Fixed ruff warnings
c8y3 Oct 31, 2025
a9079a7
Added import constraint: Do not import marshmallow from the persisten…
c8y3 Oct 31, 2025
ab8c8ee
Tyring to move dependence to marshmallow up in the API layer
c8y3 Oct 31, 2025
c1fc3a2
Fixed incorrect typing
c8y3 Oct 31, 2025
2c76991
Removed an marshable import from the persistence layer
c8y3 Oct 31, 2025
197de4f
Fixed ruff warning
c8y3 Oct 31, 2025
5b308a0
Deprecated POST /manage/customers/delete/<int:client_id>
c8y3 Oct 31, 2025
901098b
Removed unnecessary file
c8y3 Nov 5, 2025
0b2b15f
Removed all unit tests which have not been run in a long time. Added …
c8y3 Nov 5, 2025
c099fef
Started implementation of GET /api/v2/manage/customers
c8y3 Nov 5, 2025
4ae9af9
Fixed ruff warning
c8y3 Nov 5, 2025
7eb8971
Moved method into API layer
c8y3 Nov 5, 2025
704bb07
app.datamgmt.alerts.alerts_db should not import app.blueprints.access…
c8y3 Nov 5, 2025
cc14de1
Fixed ruff warning
c8y3 Nov 5, 2025
221ea9d
Removed seemingly dead method
c8y3 Nov 5, 2025
dcc4830
Factored code somewhat
c8y3 Nov 5, 2025
76acb33
Removed cycle
c8y3 Nov 5, 2025
5244279
Use method from the business layer
c8y3 Nov 5, 2025
0f4319e
Use method from the API layer
c8y3 Nov 5, 2025
8f3bf8e
Fixed incorrect retrieval of identifier
c8y3 Nov 5, 2025
88d09a3
Import db directly from app.db rather than from app
c8y3 Nov 5, 2025
ebe8870
Deprecated GET /manage/customers/list
c8y3 Nov 5, 2025
08db0cd
Fixed deepsource warning
c8y3 Nov 5, 2025
be022b8
Fixed missing parameters
c8y3 Nov 5, 2025
6fe4364
Fixed bug when checking for permission
c8y3 Nov 5, 2025
216b57c
Started implementation of POST /api/v2/global-tasks
c8y3 Nov 7, 2025
87b0949
Fixed ruff warnings
c8y3 Nov 7, 2025
70f262c
Factored code to create an object in database
c8y3 Nov 7, 2025
005ab91
Removed unnecessary return values
c8y3 Nov 7, 2025
d7393b9
Generalized import-linter constraint somewhat
c8y3 Nov 7, 2025
1862bb7
Calling conventions
c8y3 Nov 7, 2025
5544829
Added a FIXME
c8y3 Nov 7, 2025
8fa3305
Removed unnecessary return
c8y3 Nov 7, 2025
c69dcf5
Added import constraint: Do not import the persistence layer from the…
c8y3 Nov 7, 2025
1daa99c
Deprecated POST /global/tasks/add
c8y3 Nov 7, 2025
7a1b747
Removed an import app
c8y3 Nov 7, 2025
c345e41
Removed an import app
c8y3 Nov 7, 2025
5c474c1
Removed an import app
c8y3 Nov 7, 2025
d4346fd
Started GET /api/v2/global-tasks/{identifier}
c8y3 Nov 12, 2025
b314c45
Removed unnecessary return
c8y3 Nov 12, 2025
ed4d0d5
Removed seemingly unnecessary method
c8y3 Nov 12, 2025
149d3c9
Fixed ruff warning
c8y3 Nov 12, 2025
3b57d7f
Fixed import to Client
c8y3 Nov 12, 2025
aa735c4
Removed one use of too generic method get_or_create in models
c8y3 Nov 12, 2025
002d718
Fixed ruff warning
c8y3 Nov 12, 2025
3af00d3
Added test to check Analysts group autofollow is set to false
c8y3 Nov 12, 2025
8e6f5ca
Removed some usages of get_or_create
c8y3 Nov 12, 2025
21c01f4
Removed method get_or_create
c8y3 Nov 12, 2025
6644e6c
Moved CaseStatus into app.models.cases
c8y3 Nov 12, 2025
be4a6c0
Moved ReviewStatusList into app.models.cases
c8y3 Nov 12, 2025
4479bd2
Put Client model in its own module
c8y3 Nov 12, 2025
63a55b6
Deprecated GET /global/tasks/<int:cur_id>
c8y3 Nov 12, 2025
b854cda
Moved CaseAssets out of app.models.models into app.models.assets
c8y3 Nov 12, 2025
50f88d1
Moved AnalysisStatus in app.models.assets
c8y3 Nov 12, 2025
c846f0e
Moved CaseClassification into app.models.cases
c8y3 Nov 12, 2025
b252df8
Fixed ruff warnings
c8y3 Nov 12, 2025
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
File renamed without changes.
24 changes: 10 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ jobs:
uses: astral-sh/ruff-action@v3
with:
args: check --output-format=github
- name: Check dependencies with import-linter
- name: Check import dependencies with import-linter
run: |
python -m venv venv
source venv/bin/activate
pip install import-linter
PYTHONPATH=source lint-imports
- name: Looking for dead code with vulture
run: |
pip install vulture
vulture

build-docker-db:
name: Build docker db
Expand Down Expand Up @@ -131,10 +133,8 @@ jobs:
uses: actions/checkout@v4
- name: Start development server
run: |
# Even though, we use --env-file option when running docker compose, this is still necessary, because the compose has a env_file attribute :(
# TODO should move basic.env file, which is in directory tests, up. It's used in several places. Maybe, rename it into dev.env
cp tests/data/basic.env .env
docker compose --file docker-compose.dev.yml --env-file tests/data/basic.env up --detach --wait
cp .env.tests.model .env
docker compose --file docker-compose.dev.yml up --detach --wait
- name: Generate GraphQL documentation
run: |
npx spectaql@^3.0.2 source/spectaql/config.yml
Expand Down Expand Up @@ -170,9 +170,7 @@ jobs:
uses: actions/checkout@v4
- name: Start development server
run: |
# Even though, we use --env-file option when running docker compose, this is still necessary, because the compose has a env_file attribute :(
# TODO should move basic.env file, which is in directory tests, up. It's used in several places. Maybe, rename it into dev.env
cp tests/data/basic.env .env
cp .env.tests.model .env
docker compose --file docker-compose.dev.yml up --detach --wait
- name: Inspect development server start failure
if: ${{ failure() || cancelled() }}
Expand Down Expand Up @@ -226,8 +224,7 @@ jobs:
- name: Check out iris
uses: actions/checkout@v4
- name: Set up .env file
# TODO should move basic.env file, which is in directory tests, up. It's used in several places. Maybe, rename it into dev.env?
run: cp tests/data/basic.env .env
run: cp .env.tests.model .env
- name: Run tests
working-directory: tests_database_migration
run: |
Expand Down Expand Up @@ -277,8 +274,7 @@ jobs:
run: npx playwright install chromium firefox
- name: Start development server
run: |
# TODO should move basic.env file, which is in directory tests, up. It's used in several places. Maybe, rename it into dev.env
cp tests/data/basic.env .env
cp .env.tests.model .env
docker compose --file docker-compose.dev.yml up --detach --wait
- name: Run end to end tests
working-directory: e2e
Expand Down
454 changes: 454 additions & 0 deletions .vulture.ignore

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[tool.ruff.lint]
preview = true
select = ["E101", "E225", "E23", "E24", "E3", "E4", "E7", "E9", "F", "PLR0402", "RET506", "TID252", "UP032", "W29"]
select = ["ARG003", "ARG005", "B00", "E101", "E20", "E225", "E23", "E24", "E3", "E4", "E7", "E9", "F", "FURB142", "FURB145", "FURB148", "PLR0402", "RET506", "RUF029", "RUF100", "TID252", "UP032", "W29", "W391"]
ignore = ["E402", "E711", "E712", "E721", "E722"]

[tool.vulture]
paths = ["source/app", ".vulture.ignore"]
ignore_decorators = ["@*.route", "@app.*", "@*.post", "@*.get", "@*.put", "@*.delete", "@pre_load", "@post_load"]

[tool.importlinter]
root_package = "app"
include_external_packages = true
Expand All @@ -24,8 +28,8 @@ allow_indirect_imports = true
[[tool.importlinter.contracts]]
name = "Do not import API layer from the business layer"
type = "forbidden"
source_modules = ["app.business.access_controls", "app.business.assets"]
forbidden_modules = "app.blueprints.iris_user"
source_modules = ["app.business.access_controls", "app.business.assets", "app.business.cases", "app.business.alerts"]
forbidden_modules = "app.blueprints"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
Expand All @@ -39,6 +43,41 @@ allow_indirect_imports = true
name = "Do not import API layer from the persistence layer"
type = "forbidden"
source_modules = "app.datamgmt.dashboard"
forbidden_modules = "app.blueprints.iris_user"
forbidden_modules = "app.blueprints"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
name = "Do not import API layer from the persistence layer (access_controls)"
type = "forbidden"
source_modules = "app.datamgmt"
forbidden_modules = "app.blueprints.access_controls"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
name = "Do not import marshables from the persistence layer"
type = "forbidden"
source_modules = ["app.datamgmt.manage.manage_case_state_db", "app.datamgmt.manage.manage_groups_db"]
forbidden_modules = "app.schema.marshables"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
name = "Do not import marshmallow from the persistence layer"
type = "forbidden"
source_modules = "app.datamgmt.client"
forbidden_modules = "marshmallow"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
name = "Do not import the engine from the persistence layer"
type = "forbidden"
source_modules = "app.datamgmt.case"
forbidden_modules = "app.iris_engine"
allow_indirect_imports = true

[[tool.importlinter.contracts]]
name = "Do not import the persistence layer from the models"
type = "forbidden"
source_modules = "app.models.cases"
forbidden_modules = "app.datamgmt"
allow_indirect_imports = true

1 change: 0 additions & 1 deletion scripts/gunicorn-cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@

def worker_exit(server, worker):
sys.exit(4)

25 changes: 11 additions & 14 deletions source/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import collections
import json
import os
from flask import Flask, g
from flask import Flask
from flask import g
from flask import session
from flask_bcrypt import Bcrypt
from flask_caching import Cache
from flask_cors import CORS

from flask_login import LoginManager
from flask_marshmallow import Marshmallow
from flask_socketio import SocketIO, Namespace
from flask_sqlalchemy import SQLAlchemy
from functools import partial
from flask_socketio import SocketIO
from flask_socketio import Namespace

from werkzeug.middleware.proxy_fix import ProxyFix

Expand All @@ -39,6 +37,8 @@
from app.iris_engine.tasker.celery import set_celery_flask_context
from app.iris_engine.access_control.oidc_handler import get_oidc_client
from app.jinja_filters import register_jinja_filters
from app.models.authorization import ac_flag_match_mask
from app.db import db


class ReverseProxied(object):
Expand All @@ -59,12 +59,6 @@ class AlertsNamespace(Namespace):
APP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(APP_PATH, 'templates/')

SQLALCHEMY_ENGINE_OPTIONS = {
"json_deserializer": partial(json.loads, object_pairs_hook=collections.OrderedDict),
"pool_pre_ping": True
}

db = SQLAlchemy(engine_options=SQLALCHEMY_ENGINE_OPTIONS) # flask-sqlalchemy
bc = Bcrypt() # flask-bcrypt
ma = Marshmallow()
celery = make_celery(__name__)
Expand All @@ -75,10 +69,13 @@ def ac_current_user_has_permission(*permissions):
"""
Return True if current user has permission
"""
if 'permissions' not in session:
return False

current_user_permissions = session['permissions']
for permission in permissions:

if ('permissions' in session and
session['permissions'] & permission.value == permission.value):
if ac_flag_match_mask(current_user_permissions, permission.value):
return True

return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ def upgrade():

def downgrade():
pass

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# revision identifiers, used by Alembic.
from app.alembic.alembic_utils import _table_has_column
from app.models.models import CompromiseStatus
from app.models.assets import CompromiseStatus

revision = '4ecdfcb34f7c'
down_revision = 'a929ef458490'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ def upgrade():
def downgrade():
op.drop_column('ioc_type', 'type_validation_regex')
op.drop_column('ioc_type', 'type_validation_expect')

Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ def upgrade():

def downgrade():
pass

Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ def downgrade():

# Drop AlertSimilarity table
op.drop_table('alert_similarity')

18 changes: 15 additions & 3 deletions source/app/blueprints/access_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
from app.business.auth import validate_auth_token
from app.business.auth import update_session_current_case
from app.datamgmt.case.case_db import get_case
from app.datamgmt.manage.manage_access_control_db import user_has_client_access
from app.business.access_controls import access_controls_user_has_customer_access
from app.datamgmt.manage.manage_users_db import get_user
from app.blueprints.iris_user import iris_current_user
from app.business.access_controls import ac_fast_check_user_has_case_access
from app.iris_engine.access_control.utils import ac_get_effective_permissions_of_user
from app.iris_engine.utils.tracker import track_activity
from app.models.authorization import Permissions
from app.models.authorization import ac_flag_match_mask
from app.models.authorization import CaseAccessLevel


Expand Down Expand Up @@ -388,7 +389,7 @@ def inner_wrap(f):
@wraps(f)
def wrap(*args, **kwargs):
client_id = kwargs.get('client_id')
if not user_has_client_access(iris_current_user.id, client_id):
if not ac_current_user_has_customer_access(client_id):
return _ac_return_access_denied()

return f(*args, **kwargs)
Expand Down Expand Up @@ -438,7 +439,7 @@ def inner_wrap(f):
@wraps(f)
def wrap(*args, **kwargs):
client_id = kwargs.get('client_id')
if not user_has_client_access(iris_current_user.id, client_id):
if not ac_current_user_has_customer_access(client_id):
return response_error("Permission denied", status=403)

return f(*args, **kwargs)
Expand Down Expand Up @@ -582,3 +583,14 @@ def is_authentication_ldap():

def ac_fast_check_current_user_has_case_access(cid, access_level):
return ac_fast_check_user_has_case_access(iris_current_user.id, cid, access_level)


def ac_current_user_has_permission(permission):
"""
Return True if current user has permission
"""
return ac_flag_match_mask(session['permissions'], permission.value)


def ac_current_user_has_customer_access(customer_identifier):
return access_controls_user_has_customer_access(iris_current_user, session['permissions'], customer_identifier)
11 changes: 5 additions & 6 deletions source/app/blueprints/graphql/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from graphene import Float
from graphene import String

from app.blueprints.access_controls import ac_current_user_has_customer_access
from app.models.cases import Cases
from app.models.authorization import Permissions
from app.models.authorization import CaseAccessLevel
Expand All @@ -36,14 +37,12 @@
from app.business.cases import cases_delete
from app.business.cases import cases_update
from app.business.cases import cases_get_by_identifier
from app.business.errors import BusinessProcessingError
from app.models.errors import BusinessProcessingError
from app.blueprints.graphql.permissions import permissions_check_current_user_has_some_permission
from app.blueprints.graphql.permissions import permissions_check_current_user_has_some_case_access
from app.iris_engine.module_handler.module_handler import call_deprecated_on_preload_modules_hook
from app.schema.marshables import CaseSchema
from app.blueprints.iris_user import iris_current_user
from app.datamgmt.manage.manage_access_control_db import user_has_client_access

from app.blueprints.graphql.iocs import IOCConnection


Expand Down Expand Up @@ -111,11 +110,11 @@ def mutate(root, info, name, description, client_id, soc_id=None, classification
if classification_id:
request['classification_id'] = classification_id

request_data = call_deprecated_on_preload_modules_hook('case_create', request, None)
request_data = call_deprecated_on_preload_modules_hook('case_create', request)
schema = CaseSchema()
case = schema.load(request_data)
case_template_id = request_data.pop('case_template_id', None)
result = cases_create(case, case_template_id)
result = cases_create(iris_current_user, case, case_template_id)
return CaseCreate(case=result)


Expand Down Expand Up @@ -185,7 +184,7 @@ def mutate(root, info, case_id, name=None, soc_id=None, classification_id=None,

# If user tries to update the customer, check if the user has access to the new customer
if request.get('case_customer') and request.get('case_customer') != case.client_id:
if not user_has_client_access(iris_current_user.id, request.get('case_customer')):
if not ac_current_user_has_customer_access(request.get('case_customer')):
raise BusinessProcessingError('Invalid customer ID. Permission denied.')

if 'case_name' in request:
Expand Down
1 change: 0 additions & 1 deletion source/app/blueprints/graphql/sliced_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ def __getitem__(self, index: slice) -> any:

def __len__(self) -> int:
return self._total

6 changes: 2 additions & 4 deletions source/app/blueprints/pages/alerts/alerts_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
from werkzeug import Response

from app.datamgmt.alerts.alerts_db import get_alert_by_id
from app.datamgmt.manage.manage_access_control_db import user_has_client_access
from app.models.authorization import Permissions
from app.blueprints.responses import response_error
from app.blueprints.access_controls import ac_requires
from app.blueprints.iris_user import iris_current_user
from app.blueprints.access_controls import ac_requires, ac_current_user_has_customer_access

alerts_blueprint = Blueprint(
'alerts',
Expand Down Expand Up @@ -78,7 +76,7 @@ def alert_comment_modal(cur_id, caseid, url_redir):
if not alert:
return response_error('Invalid alert ID')

if not user_has_client_access(iris_current_user.id, alert.alert_customer_id):
if not ac_current_user_has_customer_access(alert.alert_customer_id):
return response_error('User not entitled to update alerts for the client', status=403)

return render_template("modal_conversation.html", element_id=cur_id, element_type='alerts',
Expand Down
2 changes: 1 addition & 1 deletion source/app/blueprints/pages/case/case_ioc_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from flask import url_for

from app.business.iocs import iocs_get
from app.business.errors import ObjectNotFoundError
from app.models.errors import ObjectNotFoundError
from app.datamgmt.case.assets_type import get_assets_types
from app.datamgmt.case.case_db import get_case
from app.datamgmt.case.case_iocs_db import get_case_iocs_comments_count
Expand Down
2 changes: 1 addition & 1 deletion source/app/blueprints/pages/case/case_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from app.forms import PipelinesCaseForm
from app.iris_engine.access_control.utils import ac_get_all_access_level
from app.iris_engine.module_handler.module_handler import list_available_pipelines
from app.models.models import CaseStatus
from app.models.cases import CaseStatus
from app.models.authorization import CaseAccessLevel
from app.blueprints.access_controls import ac_case_requires

Expand Down
2 changes: 1 addition & 1 deletion source/app/blueprints/pages/login/login_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from app import app
from app import bc
from app import db
from app.db import db
from app import oidc_client
from app.blueprints.access_controls import is_authentication_oidc
from app.blueprints.access_controls import is_authentication_ldap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from app import app
from app.forms import AddAssetForm
from app.models.authorization import Permissions
from app.models.models import AssetsType
from app.models.assets import AssetsType
from app.blueprints.access_controls import ac_requires
from app.blueprints.responses import response_error

Expand Down
Loading
Loading