2021-09-06 17:27:01 +00:00
|
|
|
import logging
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
from app.classes.models.crafty_permissions import (
|
2022-04-14 02:10:25 +00:00
|
|
|
PermissionsCrafty,
|
|
|
|
EnumPermissionsCrafty,
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
from app.classes.models.users import ApiKeys
|
2021-09-06 17:27:01 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
class CraftyPermsController:
|
2021-09-06 17:27:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def list_defined_crafty_permissions():
|
2022-04-14 02:10:25 +00:00
|
|
|
permissions_list = PermissionsCrafty.get_permissions_list()
|
2021-09-06 17:27:01 +00:00
|
|
|
return permissions_list
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2021-09-06 17:27:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_mask_crafty_permissions(user_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
permissions_mask = PermissionsCrafty.get_crafty_permissions_mask(user_id)
|
2021-09-06 17:27:01 +00:00
|
|
|
return permissions_mask
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
2022-03-23 02:50:12 +00:00
|
|
|
def set_permission(
|
2022-04-14 02:10:25 +00:00
|
|
|
permission_mask, permission_tested: EnumPermissionsCrafty, value
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2022-04-14 02:10:25 +00:00
|
|
|
return PermissionsCrafty.set_permission(
|
2022-03-23 02:50:12 +00:00
|
|
|
permission_mask, permission_tested, value
|
|
|
|
)
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2021-09-06 17:27:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def can_create_server(user_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return PermissionsCrafty.can_add_in_crafty(
|
|
|
|
user_id, EnumPermissionsCrafty.SERVER_CREATION
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2021-09-06 17:27:01 +00:00
|
|
|
@staticmethod
|
2022-05-18 20:41:14 +00:00
|
|
|
def can_add_user(user_id):
|
2022-05-18 18:33:22 +00:00
|
|
|
return PermissionsCrafty.can_add_in_crafty(
|
|
|
|
user_id, EnumPermissionsCrafty.USER_CONFIG
|
|
|
|
)
|
2021-09-06 17:27:01 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-05-18 20:41:14 +00:00
|
|
|
def can_add_role(user_id):
|
2022-05-18 18:33:22 +00:00
|
|
|
return PermissionsCrafty.can_add_in_crafty(
|
|
|
|
user_id, EnumPermissionsCrafty.ROLES_CONFIG
|
|
|
|
)
|
2021-09-06 17:27:01 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def list_all_crafty_permissions_quantity_limits():
|
2022-04-14 02:10:25 +00:00
|
|
|
return PermissionsCrafty.get_all_permission_quantity_list()
|
2021-09-06 17:27:01 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def list_crafty_permissions_quantity_limits(user_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return PermissionsCrafty.get_permission_quantity_list(user_id)
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2021-09-06 17:27:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_crafty_permissions_list(user_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
permissions_mask = PermissionsCrafty.get_crafty_permissions_mask(user_id)
|
|
|
|
permissions_list = PermissionsCrafty.get_permissions(permissions_mask)
|
2021-09-06 17:27:01 +00:00
|
|
|
return permissions_list
|
2021-10-09 08:59:54 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_api_key_permissions_list(key: ApiKeys):
|
2022-04-14 02:10:25 +00:00
|
|
|
return PermissionsCrafty.get_api_key_permissions_list(key)
|