From 2f43428b1c51a8baf2fa05f6c1bf811fe3c1cd34 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 3 Nov 2025 16:44:35 +0330 Subject: [PATCH] filter permissions by modify_state --- apps/authorization/api/v1/serializers.py | 16 ++- logs/django_requests.log | 171 +++++++++++++++++++++++ 2 files changed, 180 insertions(+), 7 deletions(-) diff --git a/apps/authorization/api/v1/serializers.py b/apps/authorization/api/v1/serializers.py index 6021570..7a162d1 100644 --- a/apps/authorization/api/v1/serializers.py +++ b/apps/authorization/api/v1/serializers.py @@ -65,20 +65,22 @@ class PermissionSerializer(serializers.ModelSerializer): permissions = permissions.select_related('page') grouped = defaultdict(set) + modifier_states = defaultdict(set) for permission in permissions: if getattr(permission, 'is_active', True): page_name = getattr(permission.page, 'name', None) if page_name: grouped[page_name].add(permission.name) + modifier_states[page_name].add(permission.modify_state) - structure = [ - { - 'page_name': page, - 'page_access': sorted(list(access)) - } - for page, access in grouped.items() - ] + structure = [] + for page, access in grouped.items(): + if not any(modifier_states[page]): + structure.append({ + 'page_name': page, + 'page_access': sorted(list(access)) + }) return structure diff --git a/logs/django_requests.log b/logs/django_requests.log index adb7bed..c790ed8 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -878,3 +878,174 @@ TypeError: int() argument must be a string, a bytes-like object or a real number [2025-11-03 12:50:20,385] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-11-03 12:53:15,308] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. [2025-11-03 12:53:21,968] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 15:36:20,728] WARNING django.request | IP: 127.0.0.1 | Path: /product/web/api/v1/quota_pricing_items/ | Unauthorized: /product/web/api/v1/quota_pricing_items/ +[2025-11-03 15:36:20,730] WARNING django.server | IP: - | Path: - | "POST /product/web/api/v1/quota_pricing_items/ HTTP/1.1" 401 191 +[2025-11-03 15:36:26,532] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16743 +[2025-11-03 15:51:36,622] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 15:51:39,772] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 15:53:21,647] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 15:53:27,161] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 15:57:43,213] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 15:57:48,582] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 15:58:11,303] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 15:58:13,833] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 15:58:26,830] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user-relations/ | Internal Server Error: /auth/api/v1/user-relations/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py", line 184, in list + return self.get_paginated_response(serializer.data) + ^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 797, in data + ret = super().data + ^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 251, in data + self._data = self.to_representation(self.instance) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 716, in to_representation + self.child.to_representation(item) for item in iterable + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 154, in to_representation + representation['permissions'] = PermissionSerializer.permissions_structure_output( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 80, in permissions_structure_output + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 80, in + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ~~~~^^^^^^ +TypeError: string indices must be integers, not 'str' +[2025-11-03 15:58:26,898] ERROR django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 500 152522 +[2025-11-03 16:03:07,822] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user-relations/ | Internal Server Error: /auth/api/v1/user-relations/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py", line 184, in list + return self.get_paginated_response(serializer.data) + ^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 797, in data + ret = super().data + ^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 251, in data + self._data = self.to_representation(self.instance) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 716, in to_representation + self.child.to_representation(item) for item in iterable + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 154, in to_representation + representation['permissions'] = PermissionSerializer.permissions_structure_output( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 80, in permissions_structure_output + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 80, in + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ~~~~^^^^^^ +TypeError: string indices must be integers, not 'str' +[2025-11-03 16:03:07,882] ERROR django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 500 152522 +[2025-11-03 16:04:08,208] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:04:10,523] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:04:18,566] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user-relations/ | Internal Server Error: /auth/api/v1/user-relations/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py", line 184, in list + return self.get_paginated_response(serializer.data) + ^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 797, in data + ret = super().data + ^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 251, in data + self._data = self.to_representation(self.instance) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 716, in to_representation + self.child.to_representation(item) for item in iterable + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 155, in to_representation + representation['permissions'] = PermissionSerializer.permissions_structure_output( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 81, in permissions_structure_output + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py", line 81, in + } if any(item[page] for item in modifier_states) else {} for page, access in grouped.items() + ~~~~^^^^^^ +TypeError: string indices must be integers, not 'str' +[2025-11-03 16:04:18,633] ERROR django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 500 152476 +[2025-11-03 16:10:34,806] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:10:40,278] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:11:07,838] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14353 +[2025-11-03 16:15:38,099] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:16:04,013] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:16:48,853] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:16:59,214] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16743 +[2025-11-03 16:17:18,124] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:17:22,597] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:17:31,122] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14353 +[2025-11-03 16:19:15,872] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:19:18,898] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:19:27,237] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14315 +[2025-11-03 16:19:31,306] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14315 +[2025-11-03 16:30:33,204] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14315 +[2025-11-03 16:36:31,835] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:36:37,069] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 16:36:44,782] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 14315 +[2025-11-03 16:43:51,156] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 16:43:57,776] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader