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

Allow local edits if RESOURCE_SERVER not defined #15545

Draft
wants to merge 2 commits into
base: devel
Choose a base branch
from
Draft
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
18 changes: 13 additions & 5 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@
logger = logging.getLogger('awx.api.views')


def allow_local_edits() -> bool:
# Borrowed logic from django-ansible-base resource_server_defined
if settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
return True

Check warning on line 138 in awx/api/views/__init__.py

View check run for this annotation

Codecov / codecov/patch

awx/api/views/__init__.py#L138

Added line #L138 was not covered by tests
# Regardless of prior setting, local modifications are allowed if no resource server defined
return not bool(getattr(settings, 'RESOURCE_SERVER', {}).get('URL', ''))


def unpartitioned_event_horizon(cls):
with connection.cursor() as cursor:
cursor.execute(f"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '_unpartitioned_{cls._meta.db_table}';")
Expand Down Expand Up @@ -730,7 +738,7 @@

@functools.wraps(cls.create)
def create_wrapper(*args, **kwargs):
if settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if allow_local_edits():
return cls.original_create(*args, **kwargs)
raise PermissionDenied({'detail': _('Creation of this resource is not allowed. Create this resource via the platform ingress.')})

Expand All @@ -741,7 +749,7 @@

@functools.wraps(cls.delete)
def delete_wrapper(*args, **kwargs):
if settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if allow_local_edits():
return cls.original_delete(*args, **kwargs)
raise PermissionDenied({'detail': _('Deletion of this resource is not allowed. Delete this resource via the platform ingress.')})

Expand All @@ -752,7 +760,7 @@

@functools.wraps(cls.perform_update)
def update_wrapper(*args, **kwargs):
if not settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if not allow_local_edits():
view, serializer = args
instance = view.get_object()
if instance:
Expand Down Expand Up @@ -1340,7 +1348,7 @@

content_types = ContentType.objects.get_for_models(models.Organization, models.Team, models.Credential) # dict of {model: content_type}
# Prevent user to be associated with team/org when ALLOW_LOCAL_RESOURCE_MANAGEMENT is False
if not settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if not allow_local_edits():
for model in [models.Organization, models.Team]:
ct = content_types[model]
if role.content_type == ct and role.role_field in ['member_role', 'admin_role']:
Expand Down Expand Up @@ -4391,7 +4399,7 @@
role = self.get_parent_object()

content_types = ContentType.objects.get_for_models(models.Organization, models.Team, models.Credential) # dict of {model: content_type}
if not settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if not allow_local_edits():
for model in [models.Organization, models.Team]:
ct = content_types[model]
if role.content_type == ct and role.role_field in ['member_role', 'admin_role']:
Expand Down
3 changes: 2 additions & 1 deletion awx/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@

# If False, do not allow creation of resources that are shared with the platform ingress
# e.g. organizations, teams, and users
ALLOW_LOCAL_RESOURCE_MANAGEMENT = True
# This setting is ignored if RESOURCE_SERVER is not set, implying standalone config
ALLOW_LOCAL_RESOURCE_MANAGEMENT = False

# If True, allow users to be assigned to roles that were created via JWT
ALLOW_LOCAL_ASSIGNING_JWT_ROLES = False
Expand Down
2 changes: 1 addition & 1 deletion awx/sso/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __call__(self):
]
)

if settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT:
if settings.ALLOW_LOCAL_RESOURCE_MANAGEMENT or (not bool(getattr(settings, 'RESOURCE_SERVER', {}).get('URL', ''))):
###############################################################################
# AUTHENTICATION BACKENDS DYNAMIC SETTING
###############################################################################
Expand Down
Loading