jumpserver/apps/perms/const.py

46 lines
1.2 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):
2023-05-29 10:23:26 +00:00
connect = bit(1), _("Connect") + " ({})".format(_("All protocols"))
upload = bit(2), _("Upload") + " (RDP, SFTP)"
download = bit(3), _("Download") + " (RDP, SFTP)"
copy = bit(4), _("Copy") + " (RDP, VNC)"
paste = bit(5), _("Paste") + " (RDP, VNC)"
delete = bit(6), _("Delete") + " (SFTP)"
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,
2023-05-25 10:42:54 +00:00
(_("Transfer"), [cls.upload, cls.download, cls.delete]),
2022-11-11 09:28:13 +00:00
(_("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):
2023-05-25 10:42:54 +00:00
return cls.upload | cls.download | cls.delete
2022-11-23 08:11:17 +00:00
@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])