From b1b8f34af1d32bcf8a06ad2b2d1a625b14818aff Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Mon, 30 Sep 2024 15:24:58 +0200 Subject: [PATCH] Fix template; make pairing node specific; add debugging command for permissions --- acl/management/commands/acl_show.py | 32 +++++++++++++++++++++++++ acl/views.py | 9 +++---- pettycash/templates/pettycash/pair.html | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 acl/management/commands/acl_show.py diff --git a/acl/management/commands/acl_show.py b/acl/management/commands/acl_show.py new file mode 100644 index 0000000..4bc8ed2 --- /dev/null +++ b/acl/management/commands/acl_show.py @@ -0,0 +1,32 @@ +import sys + +from django.core.management.base import BaseCommand + +from acl.views import tags4machineBIN + +from members.models import User +from acl.models import Machine, useNeedsToStateStr + +class Command(BaseCommand): + help = "Export binary tag/member file for a given machine." + + def add_arguments(self, parser): + parser.add_argument("machine", type=str, help="Machine this list is for") + parser.add_argument("user", type=str, help="User that list is for") + + def handle(self, *args, **options): + rc = 0 + + terminal = None + machine = options["machine"] + user = options["user"] + + machine = Machine.objects.get(node_machine_name=machine) + user = User.objects.get(last_name=user) + + (needs, has) = machine.useState(user) + res = needs & has + print(f"has({has:X}) & needs({needs:X}) = {res:X}") + print(useNeedsToStateStr(needs,has)) + + sys.exit(rc) diff --git a/acl/views.py b/acl/views.py index 263bb65..5d359bc 100644 --- a/acl/views.py +++ b/acl/views.py @@ -614,7 +614,7 @@ def api_gettags4machine(request, terminal=None, machine=None): try: machine = Machine.objects.get(name=machine) except ObjectDoesNotExist: - logger.error(f"Machine {machine} not found, denied.") + logger.error(f"get4machine: Machine '{machine}' not found, denied.") return HttpResponse("Machine not found", status=404, content_type="text/plain") out = [] @@ -709,9 +709,10 @@ def byte_xor(ba1, ba2): # def tags4machineBIN(terminal=None, machine=None): try: - machine = Machine.objects.get(name=machine) + machine = Machine.objects.get(node_machine_name=machine) ctc = change_tracker_counter() except ObjectDoesNotExist: + logger.error(f"BIN request for an unknown machine: {machine} (node-machine-name)") raise ObjectDoesNotExist tl = [] @@ -802,7 +803,7 @@ def api_gettags4machineBIN(request, terminal=None, machine=None): try: out = tags4machineBIN(terminal, machine) except ObjectDoesNotExist: - logger.error(f"Machine {machine} not found, denied.") + logger.error(f"getBIN: Machine '{machine}' not found, denied.") return HttpResponse("Machine not found", status=404, content_type="text/plain") except Exception as e: logger.error(f"Exception: {e}") @@ -818,7 +819,7 @@ def api_getok(request, machine=None, tag=None): try: machine = Machine.objects.get(node_machine_name=machine) except ObjectDoesNotExist: - logger.error("Machine '{}' not found, denied.".format(machine)) + logger.error("getok: Machine '{}' not found, denied.".format(machine)) return HttpResponse("Machine not found", status=404, content_type="text/plain") try: r = RecentUse(user=tag.owner, machine=machine) diff --git a/pettycash/templates/pettycash/pair.html b/pettycash/templates/pettycash/pair.html index 48a9510..7301c92 100644 --- a/pettycash/templates/pettycash/pair.html +++ b/pettycash/templates/pettycash/pair.html @@ -15,6 +15,6 @@

-Back to unpaired devices overview +Back to unpaired devices overview

{% endblock %}