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

🐞 Archive parent/child elections (#356) #358

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
98 changes: 56 additions & 42 deletions iam/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,28 +903,35 @@ class Archive(View):
'''
def post(self, request, pk):
permission_required(request.user, 'AuthEvent', ['edit', 'archive'], pk)
auth_event = get_object_or_404(AuthEvent, pk=pk)

# Get all edit and view perms and convert edit into unarchive and view
# into view-archived permissions
acls = ACL.objects.filter(
perm__in=['edit', 'view'],
object_type='AuthEvent',
object_id=pk
)
converter_map = dict(edit='unarchive', view='view-archived')
for acl in acls:
acl.perm = converter_map[acl.perm]
acl.save()
def archive_pk(auth_event):
# Get all edit and view perms and convert edit into unarchive and view
# into view-archived permissions
acls = ACL.objects.filter(
perm__in=['edit', 'view'],
object_type='AuthEvent',
object_id=auth_event.id
)
converter_map = dict(edit='unarchive', view='view-archived')
for acl in acls:
acl.perm = converter_map[acl.perm]
acl.save()

# register the action
action = Action(
executer=request.user,
receiver=None,
action_name='authevent:archive',
event=auth_event,
metadata=dict())
action.save()
# register the action
action = Action(
executer=request.user,
receiver=None,
action_name='authevent:archive',
event=auth_event,
metadata=dict())
action.save()

auth_event = get_object_or_404(AuthEvent, pk=pk)
children = AuthEvent.objects.filter(parent_id=pk)

archive_pk(auth_event)
for child in children:
archive_pk(child)

return json_response()
archive = login_required(Archive.as_view())
Expand All @@ -936,30 +943,37 @@ class Unarchive(View):
'''
def post(self, request, pk):
permission_required(request.user, 'AuthEvent', ['unarchive'], pk)
auth_event = get_object_or_404(AuthEvent, pk=pk)

# Reverts the archiving of an auth-event
acls = ACL.objects.filter(
perm__in=['unarchive', 'view-archived'],
object_type='AuthEvent',
object_id=pk
)
converter_map = {
'unarchive': 'edit',
'view-archived': 'view'
}
for acl in acls:
acl.perm = converter_map[acl.perm]
acl.save()
def unarchive_pk(auth_event):
# Reverts the archiving of an auth-event
acls = ACL.objects.filter(
perm__in=['unarchive', 'view-archived'],
object_type='AuthEvent',
object_id=auth_event.id
)
converter_map = {
'unarchive': 'edit',
'view-archived': 'view'
}
for acl in acls:
acl.perm = converter_map[acl.perm]
acl.save()

# register the action
action = Action(
executer=request.user,
receiver=None,
action_name='authevent:unarchive',
event=auth_event,
metadata=dict())
action.save()

auth_event = get_object_or_404(AuthEvent, pk=pk)
children = AuthEvent.objects.filter(parent_id=pk)

# register the action
action = Action(
executer=request.user,
receiver=None,
action_name='authevent:unarchive',
event=auth_event,
metadata=dict())
action.save()
unarchive_pk(auth_event)
for child in children:
unarchive_pk(child)

return json_response()
unarchive = login_required(Unarchive.as_view())
Expand Down
Loading