jumpserver/apps/perms/const.py

45 lines
1.0 KiB
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.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
__all__ = ["ActionChoices"]
2022-11-11 07:04:31 +00:00
class ActionChoices(BitChoices):
2022-11-16 11:35:16 +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-15 11:23:44 +00:00
cls.connect,
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
2022-11-23 08:11:17 +00:00
def transfer(cls):
return cls.upload | cls.download
@classmethod
def clipboard(cls):
return cls.copy | cls.paste
@classmethod
2023-02-21 09:39:33 +00:00
def contains(cls, total, action_value):
2022-11-14 06:44:18 +00:00
return action_value & total == action_value
@classmethod
def display(cls, value):
return ', '.join([str(c.label) for c in cls if c.value & value == c.value])