2021-08-31 06:13:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-11-11 07:04:31 +00:00
|
|
|
|
|
|
|
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-16 03:29:02 +00:00
|
|
|
__all__ = ["ActionChoices"]
|
2022-11-11 07:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ActionChoices(BitChoices):
|
2023-11-14 02:41:00 +00:00
|
|
|
connect = bit(1), _("Connect (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)")
|
|
|
|
share = bit(7), _("Share (SSH)")
|
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]),
|
2023-11-08 09:46:32 +00:00
|
|
|
cls.share
|
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
|
2022-11-17 07:07:23 +00:00
|
|
|
|
2024-04-03 07:44:32 +00:00
|
|
|
@classmethod
|
|
|
|
def contains_all(cls, total, action_values):
|
|
|
|
return all(cls.contains(total, action) for action in action_values)
|
|
|
|
|
2022-11-17 07:07:23 +00:00
|
|
|
@classmethod
|
|
|
|
def display(cls, value):
|
2022-11-17 09:34:52 +00:00
|
|
|
return ', '.join([str(c.label) for c in cls if c.value & value == c.value])
|