Skip to content

Commit

Permalink
minor permission & form fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 15, 2024
1 parent ba5de76 commit a38ce39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/ansible-webui/aw/templatetags/form_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_form_field_value(bf: BoundField, existing: dict) -> (str, None):

@register.filter
def get_form_field_select(bf: BoundField, existing: dict) -> str:
multi = False
selected = None
if bf.name in existing:
selected = str(existing[bf.name])
Expand All @@ -87,21 +88,23 @@ def get_form_field_select(bf: BoundField, existing: dict) -> str:
# todo: selected for multi-select
options_str += ' multiple'
selected = None # not implemented
multi = True

options_str += '>'

if not hasattr(bf.field, '_choices'):
raise AttributeError(f"Field '{bf.name}' is of an invalid type: {type(bf.field)} - {bf.field.__dict__}")

if bf.field.required:
if selected is None:
options_str += '<option disabled selected value>Choose an option</option>'
if not multi:
if bf.field.required:
if selected is None:
options_str += '<option disabled selected value>Choose an option</option>'

else:
if selected is None:
options_str += '<option selected value>None</option>'
else:
options_str += '<option value>None</option>'
if selected is None:
options_str += '<option selected value>None</option>'
else:
options_str += '<option value>None</option>'

# pylint: disable=W0212
for option in bf.field._choices:
Expand Down
6 changes: 3 additions & 3 deletions src/ansible-webui/aw/utils/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def _has_permission(
return True

# if one of the permissions allows a group that the user is a member of
groups = JobPermissionMemberGroup.objects.filter(permission=link.permission)
if groups.exists() and user.groups.filter(name__in=[
group.name for group in groups
links = JobPermissionMemberGroup.objects.filter(permission=link.permission)
if links.exists() and user.groups.filter(name__in=[
link.group.name for link in links
]).exists():
return True

Expand Down
3 changes: 3 additions & 0 deletions src/ansible-webui/aw/views/system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sys import version_info
from importlib import metadata
from os import environ

from django.urls import path
from django.shortcuts import HttpResponse
Expand Down Expand Up @@ -46,7 +47,9 @@ def _parsed_ansible_collections() -> dict:


def _parsed_ansible_config() -> dict:
environ['ANSIBLE_FORCE_COLOR'] = '0'
config_raw = get_ansible_config(action='dump', quiet=True)[0].split('\n')
environ['ANSIBLE_FORCE_COLOR'] = '1'
config = {}

for line in config_raw:
Expand Down
2 changes: 2 additions & 0 deletions test/demo/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ then
docker image rm ansible-webui:latest
fi

echo '### CLEANUP ###'
cp /var/local/ansible-webui/aw.db.bak /var/local/ansible-webui/aw.db
rm /var/local/ansible-webui/log/*

echo '### BUILDING LATEST ###'
cd /tmp
Expand Down

0 comments on commit a38ce39

Please sign in to comment.