From 24cf9b7456d2ec4e440832733d57619946e1e0e2 Mon Sep 17 00:00:00 2001 From: ngovinh2k2 Date: Fri, 7 Nov 2025 15:44:26 +0700 Subject: [PATCH] fix: update refresh token --- common/apps/organization_role/constants.py | 32 ++++++++++++++++++++++ common/apps/refresh_tokens/serializers.py | 11 +------- common/apps/space_role/constants.py | 6 ++++ 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 common/apps/organization_role/constants.py diff --git a/common/apps/organization_role/constants.py b/common/apps/organization_role/constants.py new file mode 100644 index 0000000..b79bc07 --- /dev/null +++ b/common/apps/organization_role/constants.py @@ -0,0 +1,32 @@ +from django.db import models + + +class OrganizationRoleType(models.TextChoices): + OWNER_ROLE = "Owner" + ADMIN_ROLE = "Admin" + EDITOR_ROLE = "Editor" + VIEWER_ROLE = "Viewer" + + +class OrganizationPermission(models.TextChoices): + # Organization + UPDATE_ORGANIZATION = "UPDATE_ORGANIZATION" + DELETE_ORGANIZATION = "DELETE_ORGANIZATION" + + # Organization Role + READ_ORGANIZATION_ROLE = "READ_ORGANIZATION_ROLE" + CREATE_ORGANIZATION_ROLE = "CREATE_ORGANIZATION_ROLE" + UPDATE_ORGANIZATION_ROLE = "UPDATE_ORGANIZATION_ROLE" + DELETE_ORGANIZATION_ROLE = "DELETE_ORGANIZATION_ROLE" + + # Organization Member + READ_ORGANIZATION_MEMBER = "READ_ORGANIZATION_MEMBER" + INVITE_ORGANIZATION_MEMBER = "INVITE_ORGANIZATION_MEMBER" + UPDATE_ORGANIZATION_MEMBER_ROLE = "UPDATE_ORGANIZATION_MEMBER_ROLE" + REMOVE_ORGANIZATION_MEMBER = "REMOVE_ORGANIZATION_MEMBER" + + # Organization Device + READ_ORGANIZATION_DEVICE = "READ_ORGANIZATION_DEVICE" + CREATE_ORGANIZATION_DEVICE = "CREATE_ORGANIZATION_DEVICE" + UPDATE_ORGANIZATION_DEVICE = "UPDATE_ORGANIZATION_DEVICE" + DELETE_ORGANIZATION_DEVICE = "DELETE_ORGANIZATION_DEVICE" diff --git a/common/apps/refresh_tokens/serializers.py b/common/apps/refresh_tokens/serializers.py index c8d4ec2..cbc8a78 100644 --- a/common/apps/refresh_tokens/serializers.py +++ b/common/apps/refresh_tokens/serializers.py @@ -92,16 +92,7 @@ def validate(self, attrs): if refresh_token_obj.family.status != RefreshTokenFamilyStatus.Active: raise TokenError(_("Refresh token is inactive")) - if "access_token_handler" in self.context: - params = { - "access_token": refresh.access_token, - "user_id": refresh.payload["user_id"], - **self.context["access_token_handler_params"], - } - access = self.context["access_token_handler"](**params) - data = {"access": str(access)} - else: - data = {"access": str(refresh.access_token)} + data = {"access": str(refresh.access_token)} refresh.set_jti() refresh.set_exp() diff --git a/common/apps/space_role/constants.py b/common/apps/space_role/constants.py index ffeb4c6..252fd44 100644 --- a/common/apps/space_role/constants.py +++ b/common/apps/space_role/constants.py @@ -1,6 +1,12 @@ from django.db import models +class SpaceRoleType(models.TextChoices): + ADMIN_ROLE = "Admin" + EDITOR_ROLE = "Editor" + VIEWER_ROLE = "Viewer" + + class SpacePermission(models.TextChoices): # Space UPDATE_SPACE = "UPDATE_SPACE"