Fixed technician check when not on the server
All checks were successful
Deploy prod on push / pre-build (push) Successful in 1s
Deploy prod on push / build-bot (push) Successful in 3m5s
Deploy prod on push / build-web (push) Successful in 1m46s
Deploy prod on push / deploy (push) Successful in 21s

This commit is contained in:
Sven Heidemann 2024-02-09 08:07:54 +01:00
parent 3c21b68b0c
commit dc5ae365bb
2 changed files with 20 additions and 1 deletions

View File

@ -43,6 +43,8 @@ class AuthUserTransformer(TransformerABC):
def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC): def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
guild = bot.get_guild(user.server.discord_id) guild = bot.get_guild(user.server.discord_id)
member = guild.get_member(user.discord_id) member = guild.get_member(user.discord_id)
if member is None:
return False
return permissions.is_member_admin(member) return permissions.is_member_admin(member)
@staticmethod @staticmethod
@ -50,6 +52,8 @@ class AuthUserTransformer(TransformerABC):
def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC): def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
guild = bot.get_guild(user.server.discord_id) guild = bot.get_guild(user.server.discord_id)
member = guild.get_member(user.discord_id) member = guild.get_member(user.discord_id)
if member is None:
return False
return permissions.is_member_moderator(member) return permissions.is_member_moderator(member)
@classmethod @classmethod

View File

@ -5,11 +5,11 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from bot_core.abc.permission_service_abc import PermissionServiceABC
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
from bot_core.abc.permission_service_abc import PermissionServiceABC
class PermissionService(PermissionServiceABC): class PermissionService(PermissionServiceABC):
@ -112,3 +112,18 @@ class PermissionService(PermissionServiceABC):
except Exception as e: except Exception as e:
self._logger.error(__name__, "Permission check failed", e) self._logger.error(__name__, "Permission check failed", e)
return False return False
def is_member_technician_by_id(self, member_id: int):
has_permission_cached = self.get_cached_permission(member_id, TeamMemberTypeEnum.technician)
if has_permission_cached is not None:
return has_permission_cached
self._logger.debug(__name__, f"Checking is member {member_id} technician")
try:
has_permission = member_id in self._technician_configs.get_technician_config().technician_ids
self.set_cached_permission(has_permission, member_id, TeamMemberTypeEnum.technician)
return has_permission
except Exception as e:
self._logger.error(__name__, "Permission check failed", e)
return False