2019-09-17 04:34:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2020-09-27 08:02:44 +00:00
|
|
|
from rest_framework.request import Request
|
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
from common.permissions import IsOrgAdminOrAppUser, IsValidUser
|
2021-02-05 05:29:29 +00:00
|
|
|
from common.http import is_true
|
2021-03-24 11:01:35 +00:00
|
|
|
from common.mixins.api import RoleAdminMixin as _RoleAdminMixin
|
|
|
|
from common.mixins.api import RoleUserMixin as _RoleUserMixin
|
2020-10-20 02:45:23 +00:00
|
|
|
from orgs.utils import tmp_to_root_org
|
2020-08-16 15:08:58 +00:00
|
|
|
from users.models import User
|
2021-02-05 05:29:29 +00:00
|
|
|
from perms.utils.asset.user_permission import UserGrantedTreeRefreshController
|
2020-08-16 15:08:58 +00:00
|
|
|
|
|
|
|
|
2021-02-05 05:29:29 +00:00
|
|
|
class PermBaseMixin:
|
|
|
|
user: User
|
2020-08-16 15:08:58 +00:00
|
|
|
|
2021-02-25 06:45:21 +00:00
|
|
|
def get(self, request: Request, *args, **kwargs):
|
2021-02-05 05:29:29 +00:00
|
|
|
force = is_true(request.query_params.get('rebuild_tree'))
|
|
|
|
controller = UserGrantedTreeRefreshController(self.user)
|
|
|
|
controller.refresh_if_need(force)
|
|
|
|
return super().get(request, *args, **kwargs)
|
2019-09-17 04:34:47 +00:00
|
|
|
|
2019-12-25 02:29:58 +00:00
|
|
|
|
2021-03-24 11:01:35 +00:00
|
|
|
class RoleAdminMixin(PermBaseMixin, _RoleAdminMixin):
|
2020-08-16 15:08:58 +00:00
|
|
|
permission_classes = (IsOrgAdminOrAppUser,)
|
2019-09-19 09:27:49 +00:00
|
|
|
|
2019-09-17 04:34:47 +00:00
|
|
|
|
2021-03-24 11:01:35 +00:00
|
|
|
class RoleUserMixin(PermBaseMixin, _RoleUserMixin):
|
2020-08-16 15:08:58 +00:00
|
|
|
permission_classes = (IsValidUser,)
|
2019-09-17 04:34:47 +00:00
|
|
|
|
2020-10-20 02:45:23 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
with tmp_to_root_org():
|
|
|
|
return super().get(request, *args, **kwargs)
|