Skip to content

Commit

Permalink
fixup!: more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rgraber committed Nov 26, 2024
1 parent e6f33f2 commit 5a181da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions kobo/apps/audit_log/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ def create_from_permissions_request(cls, request):
'asset_uid': asset_uid,
'log_subtype': PROJECT_HISTORY_LOG_PERMISSION_SUBTYPE,
}
# we'll be bulk creating logs instead of using .create, so we have to set
# all fields manually
log_base = {
'user': request.user,
'object_id': asset_id,
Expand All @@ -669,6 +671,7 @@ def create_from_permissions_request(cls, request):
'log_type': AuditType.PROJECT_HISTORY,
'user_uid': request.user.extra_details.uid,
}
# get all users whose permissions changed
for username in {
*permissions_added,
*permissions_removed,
Expand Down Expand Up @@ -712,11 +715,16 @@ def handle_anonymous_user_permissions(
log_base,
logs,
):
# go through all the usual anonymous user permissions and create
# logs if they were changed
# remove each permission as it is logged so we can see if there
# are any unusual ones left over
for combination, action in ANONYMOUS_USER_PERMISSION_ACTIONS.items():
permission, added = combination
relevant_list = perms_added if added else perms_removed
if permission in relevant_list:
relevant_list.discard(permission)
# ANONYMOUS_USER_PERMIISSION_ACTIONS has tuples as keys
permission, was_added = combination
list_to_update = perms_added if was_added else perms_removed
if permission in list_to_update:
list_to_update.discard(permission)
logs.append(
ProjectHistoryLog(
**log_base,
Expand Down
2 changes: 1 addition & 1 deletion kobo/apps/audit_log/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def add_assigned_perms(sender, instance, user, codename, deny, **kwargs):

@receiver(post_remove_perm, sender=Asset)
def add_removed_perms(sender, instance, user, codename, **kwargs):
logging.info(f'remove perms {codename=}')
request = get_current_request()
if request is None or instance.asset_type != ASSET_TYPE_SURVEY:
return
Expand All @@ -73,6 +72,7 @@ def add_assigned_partial_perms(sender, instance, user, perms, **kwargs):
perms_as_list_of_dicts = [
{'code': k, 'filters': v} for k, v in perms.items()
]
# partial permissions are replaced rather than added
request.partial_permissions_added[user.username] = perms_as_list_of_dicts


Expand Down

0 comments on commit 5a181da

Please sign in to comment.