support #381
@ -5,6 +5,7 @@ type Mutation {
|
||||
user: UserMutation
|
||||
userJoinedGameServer: UserJoinedGameServerMutation
|
||||
achievement: AchievementMutation
|
||||
shortRoleName: ShortRoleNameMutation
|
||||
technicianConfig: TechnicianConfigMutation
|
||||
serverConfig: ServerConfigMutation
|
||||
}
|
@ -26,6 +26,7 @@ from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
|
||||
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
|
||||
from bot_graphql.mutations.level_mutation import LevelMutation
|
||||
from bot_graphql.mutations.server_config_mutation import ServerConfigMutation
|
||||
from bot_graphql.mutations.short_role_name_mutation import ShortRoleNameMutation
|
||||
from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation
|
||||
from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation
|
||||
from bot_graphql.mutations.user_mutation import UserMutation
|
||||
@ -142,6 +143,7 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_transient(QueryABC, LevelMutation)
|
||||
services.add_transient(QueryABC, UserMutation)
|
||||
services.add_transient(QueryABC, AchievementMutation)
|
||||
services.add_transient(QueryABC, ShortRoleNameMutation)
|
||||
services.add_transient(QueryABC, UserJoinedGameServerMutation)
|
||||
services.add_transient(QueryABC, TechnicianConfigMutation)
|
||||
services.add_transient(QueryABC, ServerConfigMutation)
|
||||
|
@ -5,6 +5,7 @@ from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
|
||||
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
|
||||
from bot_graphql.mutations.level_mutation import LevelMutation
|
||||
from bot_graphql.mutations.server_config_mutation import ServerConfigMutation
|
||||
from bot_graphql.mutations.short_role_name_mutation import ShortRoleNameMutation
|
||||
from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation
|
||||
from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation
|
||||
from bot_graphql.mutations.user_mutation import UserMutation
|
||||
@ -21,6 +22,7 @@ class Mutation(MutationType):
|
||||
user_joined_game_server: UserJoinedGameServerMutation,
|
||||
technician_config: TechnicianConfigMutation,
|
||||
server_config: ServerConfigMutation,
|
||||
short_role_name_mutation: ShortRoleNameMutation,
|
||||
):
|
||||
MutationType.__init__(self)
|
||||
|
||||
@ -30,5 +32,6 @@ class Mutation(MutationType):
|
||||
self.set_field("user", lambda *_: user_mutation)
|
||||
self.set_field("achievement", lambda *_: achievement_mutation)
|
||||
self.set_field("userJoinedGameServer", lambda *_: user_joined_game_server)
|
||||
self.set_field("shortRoleName", lambda *_: short_role_name_mutation)
|
||||
self.set_field("technicianConfig", lambda *_: technician_config)
|
||||
self.set_field("serverConfig", lambda *_: server_config)
|
||||
|
@ -0,0 +1,80 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryABC
|
||||
from bot_data.model.short_role_name import ShortRoleName
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from modules.permission.service.permission_service import PermissionService
|
||||
|
||||
|
||||
class ShortRoleNameMutation(QueryABC):
|
||||
def __init__(
|
||||
self,
|
||||
servers: ServerRepositoryABC,
|
||||
short_role_names: ShortRoleNameRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
):
|
||||
QueryABC.__init__(self, "ShortRoleNameMutation")
|
||||
|
||||
self._servers = servers
|
||||
self._short_role_names = short_role_names
|
||||
self._bot = bot
|
||||
self._db = db
|
||||
self._permissions = permissions
|
||||
|
||||
self.set_field("createShortRoleName", self.resolve_create_short_role_name)
|
||||
self.set_field("updateShortRoleName", self.resolve_update_short_role_name)
|
||||
self.set_field("deleteShortRoleName", self.resolve_delete_short_role_name)
|
||||
|
||||
def resolve_create_short_role_name(self, *_, input: dict):
|
||||
server = self._servers.get_server_by_id(input["serverId"])
|
||||
self._can_user_mutate_data(server, UserRoleEnum.admin)
|
||||
|
||||
short_role_name = ShortRoleName(
|
||||
input["shortName"],
|
||||
input["roleId"],
|
||||
input["position"],
|
||||
server,
|
||||
)
|
||||
self._short_role_names.add_short_role_name(short_role_name)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_new_short_role_name(srn: ShortRoleName):
|
||||
return (
|
||||
srn.short_name == short_role_name.short_name
|
||||
and srn.role_id == short_role_name.role_id
|
||||
and srn.position == short_role_name.position
|
||||
)
|
||||
|
||||
return (
|
||||
self._short_role_names.get_short_role_names_by_server_id(short_role_name.server.id)
|
||||
.where(get_new_short_role_name)
|
||||
.last()
|
||||
)
|
||||
|
||||
def resolve_update_short_role_name(self, *_, input: dict):
|
||||
short_role_name = self._short_role_names.get_short_role_name_by_id(input["id"])
|
||||
self._can_user_mutate_data(short_role_name.server, UserRoleEnum.moderator)
|
||||
|
||||
short_role_name.short_name = input["shortName"] if "shortName" in input else short_role_name.short_name
|
||||
short_role_name.role_id = input["roleId"] if "roleId" in input else short_role_name.role_id
|
||||
short_role_name.position = input["position"] if "position" in input else short_role_name.position
|
||||
|
||||
self._short_role_names.update_short_role_name(short_role_name)
|
||||
self._db.save_changes()
|
||||
|
||||
short_role_name = self._short_role_names.get_short_role_name_by_id(input["id"])
|
||||
return short_role_name
|
||||
|
||||
def resolve_delete_short_role_name(self, *_, id: int):
|
||||
short_role_name = self._short_role_names.get_short_role_name_by_id(id)
|
||||
self._can_user_mutate_data(short_role_name.server, UserRoleEnum.admin)
|
||||
|
||||
self._short_role_names.delete_short_role_name(short_role_name)
|
||||
self._db.save_changes()
|
||||
|
||||
return short_role_name
|
Loading…
Reference in New Issue
Block a user