From c4f015df7986d558b279b9d06210a4f8a5941543 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 3 Nov 2025 12:54:08 +0330 Subject: [PATCH] add - modify state to permissions --- apps/authorization/api/v1/api.py | 2 +- apps/authorization/api/v1/serializers.py | 6 +- .../0021_permissions_modify_state.py | 18 ++++ apps/authorization/models.py | 1 + apps/pos_device/web/api/v1/viewsets/device.py | 1 - logs/django_requests.log | 102 ++++++++++++++++++ 6 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 apps/authorization/migrations/0021_permissions_modify_state.py diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index aa0d295..ed3f867 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -146,7 +146,7 @@ class PermissionViewSet(SoftDeleteMixin, viewsets.ModelViewSet): class UserRelationViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): """ Crud Operations for User Relations """ - queryset = UserRelations.objects.all() + queryset = UserRelations.objects.select_related('organization', 'role', 'user') serializer_class = UserRelationSerializer filter_backends = [filters.SearchFilter] search_fields = [ diff --git a/apps/authorization/api/v1/serializers.py b/apps/authorization/api/v1/serializers.py index bb3e4b1..6021570 100644 --- a/apps/authorization/api/v1/serializers.py +++ b/apps/authorization/api/v1/serializers.py @@ -47,7 +47,8 @@ class PermissionSerializer(serializers.ModelSerializer): 'description', 'category', 'page', - 'is_active' + 'is_active', + 'modify_state' ] def to_representation(self, instance): @@ -107,9 +108,6 @@ class RoleSerializer(serializers.ModelSerializer): representation['type'] = auth_serializer.OrganizationTypeSerializer(instance.type).data if instance.parent_role: representation['parent_role'] = {'name': instance.parent_role.role_name, 'id': instance.parent_role.id} - if instance.permissions: # noqa - permissions = instance.permissions.filter(is_active=True) - representation['permissions'] = PermissionSerializer(permissions, many=True).data return representation diff --git a/apps/authorization/migrations/0021_permissions_modify_state.py b/apps/authorization/migrations/0021_permissions_modify_state.py new file mode 100644 index 0000000..6064408 --- /dev/null +++ b/apps/authorization/migrations/0021_permissions_modify_state.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-11-03 09:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authorization', '0020_role_parent_role'), + ] + + operations = [ + migrations.AddField( + model_name='permissions', + name='modify_state', + field=models.BooleanField(default=False), + ), + ] diff --git a/apps/authorization/models.py b/apps/authorization/models.py index 7863af8..0e62ff7 100644 --- a/apps/authorization/models.py +++ b/apps/authorization/models.py @@ -44,6 +44,7 @@ class Permissions(BaseModel): null=True ) is_active = models.BooleanField(default=True) + modify_state = models.BooleanField(default=False) def __str__(self): return f'{self.name}-{self.description}' diff --git a/apps/pos_device/web/api/v1/viewsets/device.py b/apps/pos_device/web/api/v1/viewsets/device.py index e48a533..de60716 100644 --- a/apps/pos_device/web/api/v1/viewsets/device.py +++ b/apps/pos_device/web/api/v1/viewsets/device.py @@ -97,7 +97,6 @@ class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFi def my_devices(self, request): """ list of company devices """ organization = get_organization_by_user(request.user) - # using admin filter mixin to get query devices = self.get_queryset( visibility_by_org_scope=True ) if organization.free_visibility_by_scope else self.get_queryset() diff --git a/logs/django_requests.log b/logs/django_requests.log index 868bf3e..adb7bed 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -776,3 +776,105 @@ AssertionError: .validate() should return the validated data [2025-11-03 10:20:41,743] INFO django.server | IP: - | Path: - | "GET /pos_device/web/v1/pos/device/my_devices/ HTTP/1.1" 200 5059 [2025-11-03 10:22:41,485] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\pos_device\web\api\v1\viewsets\device.py changed, reloading. [2025-11-03 10:22:44,140] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 10:24:20,336] INFO django.server | IP: - | Path: - | "GET /pos_device/web/v1/pos/device/my_devices/ HTTP/1.1" 200 3818 +[2025-11-03 10:24:24,578] INFO django.server | IP: - | Path: - | "GET /pos_device/web/v1/pos/device/my_devices/ HTTP/1.1" 200 3818 +[2025-11-03 10:50:46,126] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\pos_device\web\api\v1\viewsets\device.py changed, reloading. +[2025-11-03 10:50:50,017] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:08:46,823] 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 175, in list + queryset = queryset.filter(role_id=int(role_param)) + ^^^^^^^^^^^^^^^ +TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' +[2025-11-03 11:08:46,910] ERROR django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/ HTTP/1.1" 500 110702 +[2025-11-03 11:09:47,885] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:11:46,647] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py changed, reloading. +[2025-11-03 11:11:49,193] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:12:04,322] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:12:08,580] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:12:17,975] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py changed, reloading. +[2025-11-03 11:12:20,142] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:12:27,460] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:12:33,244] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:25:15,907] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:25:18,495] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:25:27,012] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 26594 +[2025-11-03 11:25:31,406] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 26594 +[2025-11-03 11:25:37,301] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 26594 +[2025-11-03 11:25:43,604] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 26594 +[2025-11-03 11:25:49,102] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 26594 +[2025-11-03 11:25:53,397] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:25:59,155] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:26:09,126] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:26:14,944] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:26:18,507] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:26:22,852] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:26:27,120] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:28:04,004] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:28:08,299] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:28:17,455] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:28:19,540] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:28:26,719] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 10218 +[2025-11-03 11:28:28,228] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 10218 +[2025-11-03 11:28:30,712] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 10218 +[2025-11-03 11:28:32,551] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 10218 +[2025-11-03 11:28:34,480] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 10218 +[2025-11-03 11:28:42,753] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:28:46,713] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:28:54,701] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 28682 +[2025-11-03 11:29:01,262] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:29:05,250] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:29:13,611] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 15032 +[2025-11-03 11:29:17,271] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 15032 +[2025-11-03 11:29:20,718] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 15032 +[2025-11-03 11:29:23,912] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 15032 +[2025-11-03 11:29:27,323] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:29:31,603] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:29:38,004] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:29:44,885] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 33496 +[2025-11-03 11:39:56,430] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:39:58,952] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:40:06,833] INFO django.server | IP: - | Path: - | code 400, message Bad request syntax ('{') +[2025-11-03 11:40:06,833] WARNING django.server | IP: - | Path: - | "{" 400 - +[2025-11-03 11:40:06,833] INFO django.server | IP: - | Path: - | - Broken pipe from ('127.0.0.1', 10293) +[2025-11-03 11:40:07,432] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 11:48:55,345] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 11:48:59,639] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 11:49:03,660] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 11:50:25,789] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:50:30,249] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:52:22,211] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:52:24,339] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:52:33,243] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 9839 +[2025-11-03 11:52:36,216] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 9839 +[2025-11-03 11:52:39,283] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 9839 +[2025-11-03 11:52:42,239] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 9839 +[2025-11-03 11:52:47,010] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\serializers.py changed, reloading. +[2025-11-03 11:52:48,981] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-03 11:52:58,090] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 11:53:02,252] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 16741 +[2025-11-03 12:50:18,312] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\models.py changed, reloading. +[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