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
|
|
|
|
|
2021-02-05 05:29:29 +00:00
|
|
|
from common.http import is_true
|
2022-09-13 07:41:39 +00:00
|
|
|
from common.mixins.api import RoleAdminMixin
|
|
|
|
from common.mixins.api import 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
|
2022-08-23 02:23:48 +00:00
|
|
|
from perms.utils.user_permission import UserGrantedTreeRefreshController
|
2020-08-16 15:08:58 +00:00
|
|
|
|
|
|
|
|
2022-09-13 07:41:39 +00:00
|
|
|
class RebuildTreeMixin:
|
2021-02-05 05:29:29 +00:00
|
|
|
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
|
|
|
|
2022-09-13 07:41:39 +00:00
|
|
|
class AssetRoleAdminMixin(RebuildTreeMixin, RoleAdminMixin):
|
2022-02-17 12:13:31 +00:00
|
|
|
rbac_perms = (
|
|
|
|
('list', 'perms.view_userassets'),
|
|
|
|
('retrieve', 'perms.view_userassets'),
|
|
|
|
('get_tree', 'perms.view_userassets'),
|
|
|
|
('GET', 'perms.view_userassets'),
|
|
|
|
)
|
2019-09-19 09:27:49 +00:00
|
|
|
|
2019-09-17 04:34:47 +00:00
|
|
|
|
2022-09-13 07:41:39 +00:00
|
|
|
class AssetRoleUserMixin(RebuildTreeMixin, RoleUserMixin):
|
2022-02-17 12:13:31 +00:00
|
|
|
rbac_perms = (
|
|
|
|
('list', 'perms.view_myassets'),
|
|
|
|
('retrieve', 'perms.view_myassets'),
|
|
|
|
('get_tree', 'perms.view_myassets'),
|
|
|
|
('GET', 'perms.view_myassets'),
|
|
|
|
)
|