support in master #356

Merged
edraft merged 7 commits from support into master 2023-09-10 18:23:39 +02:00
Showing only changes of commit 3ce5471ef4 - Show all commits

View File

@ -10,6 +10,7 @@ from bot_api.exception.service_error_code_enum import ServiceErrorCode
from bot_api.exception.service_exception import ServiceException
from bot_api.route.route import Route
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_data.model.achievement import Achievement
from bot_data.model.auth_role_enum import AuthRoleEnum
from bot_data.model.auth_user import AuthUser
from bot_data.model.auto_role import AutoRole
@ -78,7 +79,17 @@ class QueryABC(ObjectType):
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
access = False
if type(element) == AutoRole:
if type(element) == Achievement:
edraft marked this conversation as resolved
Review

Ich sehe sehr oft doppelten Code. Wie wäre es, wenn wir dies in eine Methode auslagern?

if type(element) == Achievement:
    element: Achievement = element
    access = check_user_permission_by_server_id(permissions, bot, user, element.server.id:)
def check_user_permission_by_server_id(permissions: PermissionService, bot: DiscordBotServiceABC, user: AuthUser, server_id: int)
    for u in user.users:
        u: User = u
        guild = bot.get_guild(u.server.discord_id)
        member = guild.get_member(u.discord_id)
        if permissions.is_member_moderator(member) and u.server.id == server_id
            return true
Ich sehe sehr oft doppelten Code. Wie wäre es, wenn wir dies in eine Methode auslagern? ```python if type(element) == Achievement: element: Achievement = element access = check_user_permission_by_server_id(permissions, bot, user, element.server.id:) ``` ```python def check_user_permission_by_server_id(permissions: PermissionService, bot: DiscordBotServiceABC, user: AuthUser, server_id: int) for u in user.users: u: User = u guild = bot.get_guild(u.server.discord_id) member = guild.get_member(u.discord_id) if permissions.is_member_moderator(member) and u.server.id == server_id return true ```
Review

Zu selten der gleiche Code
Die Fallunterscheidung ist sehr Individuell gestaltet :/

Zu selten der gleiche Code Die Fallunterscheidung ist sehr Individuell gestaltet :/
element: Achievement = element
for u in user.users:
u: User = u
guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id)
if permissions.is_member_moderator(member) and u.server.id == element.server.id:
access = True
break
elif type(element) == AutoRole:
element: AutoRole = element
for u in user.users:
u: User = u