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

Add a system_auditor role who has read on everything. #2157

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
40 changes: 40 additions & 0 deletions galaxy_ng/app/migrations/0053_create_system_auditor_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.13 on 2024-06-06 19:13

from django.db import migrations


def create_system_auditor_role(apps, schema_editor):
Role = apps.get_model("core", "Role")
Permission = apps.get_model("auth", "Permission")

# Create the role
role, created = Role.objects.get_or_create(
name='galaxy.system_auditor',
jctanner marked this conversation as resolved.
Show resolved Hide resolved
defaults={'description': 'Role with read-only permissions to all resources'}
)

for permission in Permission.objects.filter(codename__icontains='view'):
role.permissions.add(permission)


def delete_system_auditor_role(apps, schema_editor):
Role = apps.get_model("core", "Role")

try:
role = Role.objects.get(name='galaxy.system_auditor')
except Role.DoesNotExist:
return

# Delete the role
role.delete()


class Migration(migrations.Migration):

dependencies = [
("galaxy", "0052_alter_organization_created_by_and_more"),
]

operations = [
migrations.RunPython(create_system_auditor_role, delete_system_auditor_role),
]
39 changes: 39 additions & 0 deletions galaxy_ng/tests/integration/api/test_system_auditor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import os
import uuid

import pytest


pytestmark = pytest.mark.qa # noqa: F821


@pytest.mark.deployment_standalone
@pytest.mark.min_hub_version("4.10dev")
@pytest.mark.skipif(
os.getenv("ENABLE_DAB_TESTS"),
reason="Skipping test because ENABLE_DAB_TESTS is set"
)
def test_system_auditor_role_permissions_without_gateway(galaxy_client):
"""Tests the galaxy.system_auditor role can be added to a user and has the right perms."""

gc = galaxy_client("admin", ignore_cache=True)

# make a random user
username = str(uuid.uuid4())
uinfo = gc.post(
"_ui/v1/users/",
body=json.dumps({"username": username, "password": "redhat1234"})
)
uid = uinfo["id"]

# assign the galaxy.system_auditor role to the user
rinfo = gc.post(
f"pulp/api/v3/users/{uid}/roles/",
body=json.dumps({'content_object': None, 'role': 'galaxy.system_auditor'})
)

# check that all the permssions are view_* only ...
for perm_code in rinfo["permissions"]:
perm_name = perm_code.split(".", 1)[1]
assert "view_" in perm_name, f"{perm_code} is not a view-only permission"
Loading