Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1099 from astrozzc/fix
Browse files Browse the repository at this point in the history
Fix calling params if not set
  • Loading branch information
astrozzc authored May 16, 2024
2 parents a7ec032 + c70b752 commit 588908e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rbac/internal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ def ocm_performance(request):
return HttpResponse('Invalid method, only "POST" is allowed.', status=405)


def get_param_list(request, param_name):
"""Get a list of params from a request."""
params = request.GET.get(param_name, [])
if params:
params = params.split(",")
return params


def role_migration(request):
"""View method for running role migrations from V1 to V2 spiceDB schema.
Expand All @@ -481,9 +489,10 @@ def role_migration(request):
if request.method != "POST":
return HttpResponse('Invalid method, only "POST" is allowed.', status=405)
logger.info("Running V1 Role migration.")

args = {
"exclude_apps": request.GET.get("exclude_apps", "").split(","),
"orgs": request.GET.get("orgs", "").split(","),
"exclude_apps": get_param_list(request, "exclude_apps"),
"orgs": get_param_list(request, "orgs"),
}
migrate_roles_in_worker.delay(args)
return HttpResponse("Role migration from V1 to V2 are running in a background worker.", status=202)
Expand Down
13 changes: 13 additions & 0 deletions tests/internal/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,16 @@ def test_run_migrations_of_roles(self, migration_mock):
response.content.decode(),
"Role migration from V1 to V2 are running in a background worker.",
)

# Without params
migration_mock.reset_mock()
response = self.client.post(
f"/_private/api/utils/role_migration/",
**self.request.META,
)
migration_mock.assert_called_once_with({"exclude_apps": [], "orgs": []})
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(
response.content.decode(),
"Role migration from V1 to V2 are running in a background worker.",
)

0 comments on commit 588908e

Please sign in to comment.