Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/iam issues #72

Merged
merged 2 commits into from
Feb 24, 2024
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
9 changes: 5 additions & 4 deletions backend/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from ciso_assistant.settings import CISO_ASSISTANT_SUPERUSER_EMAIL

import os

def startup(**kwargs):
"""
Implement CISO Assistant 1.0 default Roles and User Groups during migrate
This makes sure root folder and global groups are defined before any other object is created
Create superuser if CISO_ASSISTANT_SUPERUSER_EMAIL defined
"""

from django.contrib.auth.models import Permission
from iam.models import Folder, Role, RoleAssignment, User, UserGroup
print("post-migrate handler: initialize database")
print("startup handler: initialize database", kwargs)

auditor_permissions = Permission.objects.filter(
codename__in=[
Expand Down Expand Up @@ -328,4 +327,6 @@ class CoreConfig(AppConfig):
verbose_name = "Core"

def ready(self):
post_migrate.connect(startup, sender=self)
# avoid post_migrate handler if we are in the main, as it interferes with restore
if not os.environ.get('RUN_MAIN'):
post_migrate.connect(startup, sender=self)
3 changes: 2 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,10 @@ class UserFilter(df.FilterSet):
is_approver = df.BooleanFilter(method="filter_approver", label="Approver")

def filter_approver(self, queryset, name, value):
""" we don't know yet which folders will be used, so filter on any folder"""
approvers_id = []
for candidate in User.objects.all():
if RoleAssignment.has_permission(candidate, "approve_riskacceptance"):
if 'approve_riskacceptance' in candidate.permissions:
approvers_id.append(candidate.id)
if value:
return queryset.filter(id__in=approvers_id)
Expand Down
6 changes: 5 additions & 1 deletion backend/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,11 @@ def get_user_groups(self):

@property
def has_backup_permission(self) -> bool:
return RoleAssignment.has_permission(self, "backup")
return RoleAssignment.is_access_allowed(
user=self,
perm=Permission.objects.get(codename="backup"),
folder=Folder.get_root_folder(),
)

@property
def edit_url(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion backend/serdes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

urlpatterns = [
path("dump-db/", login_required(views.dump_db_view), name="dump-db"),
path("load-backup/", views.LoadBackupView.as_view(), name="load-backup"),
path("load-backup/", login_required(views.LoadBackupView.as_view()), name="load-backup"),
]
2 changes: 2 additions & 0 deletions backend/serdes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class LoadBackupView(APIView):
serializer_class = LoadBackupSerializer

def post(self, request, *args, **kwargs):
if not is_admin_check(request.user):
return Response(status=status.HTTP_403_FORBIDDEN)
if request.data:
sys.stdin = io.StringIO(json.dumps(request.data[1]))
request.session.flush()
Expand Down
Loading