Update permission service cache when roles for member changed
This commit is contained in:
parent
3c21b68b0c
commit
6fafbfae83
@ -15,7 +15,7 @@ from bot_core.service.client_utils_service import ClientUtilsService
|
||||
from bot_core.service.config_service import ConfigService
|
||||
from bot_core.service.data_integrity_service import DataIntegrityService
|
||||
from bot_core.service.message_service import MessageService
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class CoreModule(ModuleABC):
|
||||
@ -30,7 +30,7 @@ class CoreModule(ModuleABC):
|
||||
services.add_transient(MessageServiceABC, MessageService)
|
||||
services.add_transient(ClientUtilsABC, ClientUtilsService)
|
||||
services.add_transient(DataIntegrityService)
|
||||
services.add_singleton(PermissionServiceABC, PermissionService)
|
||||
services.add_singleton(PermissionServiceABC, PermissionServiceWithCache)
|
||||
|
||||
# pipes
|
||||
services.add_transient(DateTimeOffsetPipe)
|
||||
|
@ -12,7 +12,7 @@ from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class PermissionService(PermissionServiceABC):
|
||||
class PermissionServiceWithCache(PermissionServiceABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
@ -12,7 +12,7 @@ from bot_core.exception.service_exception import ServiceException
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.environment_variables import MAINTENANCE
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
from bot_data.model.achievement import Achievement
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
@ -82,7 +82,7 @@ class QueryABC(ObjectType):
|
||||
return config
|
||||
|
||||
services = get_services()
|
||||
permissions: PermissionService = services.get_service(PermissionService)
|
||||
permissions: PermissionServiceWithCache = services.get_service(PermissionServiceWithCache)
|
||||
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
|
||||
config = get_config()
|
||||
|
||||
@ -245,7 +245,7 @@ class QueryABC(ObjectType):
|
||||
def _can_user_mutate_data(
|
||||
self, server: Server, permission: UserRoleEnum, services: ServiceProviderABC, config: ConfigurationABC
|
||||
):
|
||||
permissions: PermissionService = services.get_service(PermissionService)
|
||||
permissions: PermissionServiceWithCache = services.get_service(PermissionServiceWithCache)
|
||||
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
|
||||
|
||||
auth_user = Route.get_user()
|
||||
|
@ -6,7 +6,7 @@ from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.achievement import Achievement
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class AchievementMutation(QueryABC):
|
||||
@ -16,7 +16,7 @@ class AchievementMutation(QueryABC):
|
||||
achievements: AchievementRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
):
|
||||
QueryABC.__init__(self, "AchievementMutation")
|
||||
|
||||
|
@ -10,7 +10,7 @@ from bot_data.model.scheduled_event import ScheduledEvent
|
||||
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class ScheduledEventMutation(QueryABC):
|
||||
@ -20,7 +20,7 @@ class ScheduledEventMutation(QueryABC):
|
||||
scheduled_events: ScheduledEventRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
):
|
||||
QueryABC.__init__(self, "ScheduledEventMutation")
|
||||
|
||||
|
@ -13,7 +13,7 @@ from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class ServerConfigMutation(QueryABC):
|
||||
@ -25,7 +25,7 @@ class ServerConfigMutation(QueryABC):
|
||||
server_configs: ServerConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
config_service: ConfigService,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
):
|
||||
QueryABC.__init__(self, "ServerConfigMutation")
|
||||
|
||||
|
@ -6,7 +6,7 @@ from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryA
|
||||
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 bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
from modules.short_role_name.service.short_role_name_service import ShortRoleNameService
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class ShortRoleNameMutation(QueryABC):
|
||||
short_role_names: ShortRoleNameRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
short_role_name_service: ShortRoleNameService,
|
||||
):
|
||||
QueryABC.__init__(self, "ShortRoleNameMutation")
|
||||
|
@ -16,7 +16,7 @@ from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_data.service.technician_config_seeder import TechnicianConfigSeeder
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class TechnicianConfigMutation(QueryABC):
|
||||
@ -31,7 +31,7 @@ class TechnicianConfigMutation(QueryABC):
|
||||
config_service: ConfigService,
|
||||
tech_seeder: TechnicianConfigSeeder,
|
||||
client_utils: ClientUtilsABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
):
|
||||
QueryABC.__init__(self, "TechnicianConfigMutation")
|
||||
|
||||
|
@ -11,7 +11,7 @@ from flask import request
|
||||
from bot_api.configuration.authentication_settings import AuthenticationSettings
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -40,7 +40,7 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
user_game_idents: UserGameIdentRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
auth_settings: AuthenticationSettings,
|
||||
):
|
||||
QueryABC.__init__(self, "UserJoinedGameServerMutation")
|
||||
|
@ -4,7 +4,7 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.service.permission_service import PermissionService
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
@ -23,7 +23,7 @@ class UserMutation(QueryABC):
|
||||
users: UserRepositoryABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
permissions: PermissionServiceWithCache,
|
||||
levels: LevelRepositoryABC,
|
||||
level_service: LevelService,
|
||||
user_warnings: UserWarningsRepositoryABC,
|
||||
|
@ -8,6 +8,7 @@ from bot_core.abc.module_abc import ModuleABC
|
||||
from bot_core.abc.task_abc import TaskABC
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from modules.base.command.scheduled_events_group import ScheduledEventsCommand
|
||||
from modules.base.events.base_on_member_update_event import BaseOnMemberUpdateEvent
|
||||
from modules.base.tasks.birthday_watcher import BirthdayWatcher
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
from modules.base.command.game_server_group import GameServerGroup
|
||||
@ -117,3 +118,7 @@ class BaseModule(ModuleABC):
|
||||
DiscordEventTypesEnum.on_guild_join.value,
|
||||
BaseOnGuildJoinEvent,
|
||||
)
|
||||
services.add_transient(
|
||||
DiscordEventTypesEnum.on_member_update.value,
|
||||
BaseOnMemberUpdateEvent
|
||||
)
|
||||
|
25
bot/src/modules/base/events/base_on_member_update_event.py
Normal file
25
bot/src/modules/base/events/base_on_member_update_event.py
Normal file
@ -0,0 +1,25 @@
|
||||
import discord
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events import OnMemberUpdateABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_core.service.permission_service_with_cache import PermissionServiceWithCache
|
||||
|
||||
|
||||
class BaseOnMemberUpdateEvent(OnMemberUpdateABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
permissions: PermissionServiceWithCache,
|
||||
):
|
||||
OnMemberUpdateABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._permissions = permissions
|
||||
|
||||
async def on_member_update(self, before: discord.member.Member, after: discord.member.Member):
|
||||
if before.roles != after.roles:
|
||||
self._permissions.reset_cache()
|
Loading…
Reference in New Issue
Block a user