jumpserver/apps/perms/const.py

38 lines
904 B
Python
Raw Normal View History

2021-08-31 06:13:05 +00:00
# -*- coding: utf-8 -*-
#
2022-11-11 07:04:31 +00:00
from django.db import models
from django.utils.translation import ugettext_lazy as _
from common.db.fields import BitChoices
2022-11-11 09:28:13 +00:00
from common.utils.integer import bit
2022-11-11 07:04:31 +00:00
2022-11-11 09:28:13 +00:00
__all__ = ["SpecialAccount", "ActionChoices"]
2022-11-11 07:04:31 +00:00
class ActionChoices(BitChoices):
2022-11-14 12:25:54 +00:00
connect = bit(1), _("Connect")
upload = bit(2), _("Upload")
download = bit(3), _("Download")
copy = bit(4), _("Copy")
paste = bit(5), _("Paste")
2022-11-11 09:28:13 +00:00
@classmethod
def is_tree(cls):
return True
2022-11-11 07:04:31 +00:00
@classmethod
def branches(cls):
return (
2022-11-11 09:28:13 +00:00
(_("Transfer"), [cls.upload, cls.download]),
(_("Clipboard"), [cls.copy, cls.paste]),
2022-11-11 07:04:31 +00:00
)
2022-11-14 06:44:18 +00:00
@classmethod
def has_perm(cls, action_name, total):
action_value = getattr(cls, action_name)
return action_value & total == action_value
2022-11-11 07:04:31 +00:00
class SpecialAccount(models.TextChoices):
2022-11-11 09:28:13 +00:00
ALL = "@ALL", "All"