Show user warnings in profile & lazy load other stuff #402
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
| from cpl_core.dependency_injection import ServiceProviderABC | ||||
| from cpl_query.extension import List | ||||
|  | ||||
| from bot_data.model.user import User | ||||
| @@ -5,9 +6,14 @@ from bot_graphql.abc.filter_abc import FilterABC | ||||
|  | ||||
|  | ||||
| class AchievementFilter(FilterABC): | ||||
|     def __init__(self): | ||||
|     def __init__( | ||||
|         self, | ||||
|         services: ServiceProviderABC, | ||||
|     ): | ||||
|         FilterABC.__init__(self) | ||||
|  | ||||
|         self._services = services | ||||
|  | ||||
|         self._id = None | ||||
|         self._name = None | ||||
|         self._description = None | ||||
|   | ||||
							
								
								
									
										56
									
								
								kdb-bot/src/bot_graphql/filter/user_warning_filter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								kdb-bot/src/bot_graphql/filter/user_warning_filter.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| from cpl_core.dependency_injection import ServiceProviderABC | ||||
| from cpl_query.extension import List | ||||
|  | ||||
| from bot_data.model.user_warnings import UserWarnings | ||||
| from bot_graphql.abc.filter_abc import FilterABC | ||||
|  | ||||
|  | ||||
| class UserWarningFilter(FilterABC): | ||||
|     def __init__( | ||||
|         self, | ||||
|         services: ServiceProviderABC, | ||||
|     ): | ||||
|         FilterABC.__init__(self) | ||||
|  | ||||
|         self._services = services | ||||
|  | ||||
|         self._id = None | ||||
|         self._user = None | ||||
|         self._description = None | ||||
|         self._author = None | ||||
|  | ||||
|     def from_dict(self, values: dict): | ||||
|         if "id" in values: | ||||
|             self._id = int(values["id"]) | ||||
|  | ||||
|         if "user" in values: | ||||
|             from bot_graphql.filter.user_filter import UserFilter | ||||
|  | ||||
|             self._user: UserFilter = self._services.get_service(UserFilter) | ||||
|             self._user.from_dict(values["user"]) | ||||
|  | ||||
|         if "description" in values: | ||||
|             self._description = values["description"] | ||||
|  | ||||
|         if "author" in values: | ||||
|             from bot_graphql.filter.user_filter import UserFilter | ||||
|  | ||||
|             self._author: UserFilter = self._services.get_service(UserFilter) | ||||
|             self._author.from_dict(values["author"]) | ||||
|  | ||||
|     def filter(self, query: List[UserWarnings]) -> List[UserWarnings]: | ||||
|         if self._id is not None: | ||||
|             query = query.where(lambda x: x.id == self._id) | ||||
|  | ||||
|         if self._user is not None: | ||||
|             users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id) | ||||
|             query = query.where(lambda x: x.id in users) | ||||
|  | ||||
|         if self._description is not None: | ||||
|             query = query.where(lambda x: x.description == self._description or self._description in x.description) | ||||
|  | ||||
|         if self._author is not None: | ||||
|             users = self._author.filter(query.select(lambda x: x.author)).select(lambda x: x.id) | ||||
|             query = query.where(lambda x: x.id in users) | ||||
|  | ||||
|         return query | ||||
| @@ -41,6 +41,9 @@ type Query { | ||||
|     shortRoleNames(filter: ShortRoleNameFilter, page: Page, sort: Sort): [ShortRoleName] | ||||
|     shortRoleNamePositions: [String] | ||||
|  | ||||
|     userWarningCount: Int | ||||
|     userWarnings(filter: UserWarningFilter, page: Page, sort: Sort): [UserWarning] | ||||
|  | ||||
|     technicianConfig: TechnicianConfig | ||||
|     possibleFeatureFlags: [String] | ||||
|     discord: Discord | ||||
|   | ||||
| @@ -20,6 +20,9 @@ type User implements TableWithHistoryQuery { | ||||
|     achievementCount: Int | ||||
|     achievements(filter: AchievementFilter, page: Page, sort: Sort): [Achievement] | ||||
|  | ||||
|     userWarningCount: Int | ||||
|     userWarnings(filter: UserWarningFilter, page: Page, sort: Sort): [UserWarning] | ||||
|  | ||||
|     server: Server | ||||
|     leftServer: Boolean | ||||
|  | ||||
|   | ||||
							
								
								
									
										27
									
								
								kdb-bot/src/bot_graphql/graphql/userWarning.gql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								kdb-bot/src/bot_graphql/graphql/userWarning.gql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| type UserWarning implements TableWithHistoryQuery { | ||||
|     id: ID | ||||
|     user: User | ||||
|     description: String | ||||
|     author: User | ||||
|  | ||||
|     createdAt: String | ||||
|     modifiedAt: String | ||||
|  | ||||
|     history: [UserWarningHistory] | ||||
| } | ||||
|  | ||||
| type UserWarningHistory implements HistoryTableQuery { | ||||
|     id: ID | ||||
|     user: ID | ||||
|     description: String | ||||
|     author: ID | ||||
|  | ||||
|     deleted: Boolean | ||||
|     dateFrom: String | ||||
|     dateTo: String | ||||
| } | ||||
|  | ||||
| input UserWarningFilter { | ||||
|     id: ID | ||||
|     user: UserFilter | ||||
| } | ||||
| @@ -18,6 +18,7 @@ from bot_graphql.filter.user_filter import UserFilter | ||||
| from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter | ||||
| from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter | ||||
| from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter | ||||
| from bot_graphql.filter.user_warning_filter import UserWarningFilter | ||||
| from bot_graphql.graphql_service import GraphQLService | ||||
| from bot_graphql.mutation import Mutation | ||||
| from bot_graphql.mutations.achievement_mutation import AchievementMutation | ||||
| @@ -66,6 +67,8 @@ from bot_graphql.queries.user_joined_server_query import UserJoinedServerQuery | ||||
| from bot_graphql.queries.user_joined_voice_channel_history_query import UserJoinedVoiceChannelHistoryQuery | ||||
| from bot_graphql.queries.user_joined_voice_channel_query import UserJoinedVoiceChannelQuery | ||||
| from bot_graphql.queries.user_query import UserQuery | ||||
| from bot_graphql.queries.user_warning_history_query import UserWarningHistoryQuery | ||||
| from bot_graphql.queries.user_warning_query import UserWarningQuery | ||||
| from bot_graphql.query import Query | ||||
| from bot_graphql.schema import Schema | ||||
|  | ||||
| @@ -115,6 +118,8 @@ class GraphQLModule(ModuleABC): | ||||
|         services.add_transient(QueryABC, UserJoinedGameServerQuery) | ||||
|         services.add_transient(QueryABC, ShortRoleNameHistoryQuery) | ||||
|         services.add_transient(QueryABC, ShortRoleNameQuery) | ||||
|         services.add_transient(QueryABC, UserWarningHistoryQuery) | ||||
|         services.add_transient(QueryABC, UserWarningQuery) | ||||
|  | ||||
|         services.add_transient(QueryABC, DiscordQuery) | ||||
|         services.add_transient(QueryABC, GuildQuery) | ||||
| @@ -135,6 +140,7 @@ class GraphQLModule(ModuleABC): | ||||
|         services.add_transient(FilterABC, UserJoinedVoiceChannelFilter) | ||||
|         services.add_transient(FilterABC, UserJoinedGameServerFilter) | ||||
|         services.add_transient(FilterABC, ShortRoleNameFilter) | ||||
|         services.add_transient(FilterABC, UserWarningFilter) | ||||
|  | ||||
|         # mutations | ||||
|         services.add_transient(QueryABC, AutoRoleMutation) | ||||
|   | ||||
| @@ -6,6 +6,7 @@ from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC | ||||
| from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC | ||||
| from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC | ||||
| from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC | ||||
| from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC | ||||
| from bot_data.model.user import User | ||||
| from bot_data.model.user_history import UserHistory | ||||
| from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC | ||||
| @@ -13,6 +14,7 @@ from bot_graphql.filter.achievement_filter import AchievementFilter | ||||
| from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter | ||||
| from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter | ||||
| from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter | ||||
| from bot_graphql.filter.user_warning_filter import UserWarningFilter | ||||
| from modules.level.service.level_service import LevelService | ||||
| from modules.permission.abc.permission_service_abc import PermissionServiceABC | ||||
|  | ||||
| @@ -29,6 +31,7 @@ class UserQuery(DataQueryWithHistoryABC): | ||||
|         user_joined_game_server: UserJoinedGameServerRepositoryABC, | ||||
|         permissions: PermissionServiceABC, | ||||
|         achievements: AchievementRepositoryABC, | ||||
|         user_warnings: UserWarningsRepositoryABC, | ||||
|     ): | ||||
|         DataQueryWithHistoryABC.__init__(self, "User", "UsersHistory", UserHistory, db) | ||||
|  | ||||
| @@ -67,6 +70,9 @@ class UserQuery(DataQueryWithHistoryABC): | ||||
|         self.add_collection( | ||||
|             "achievement", lambda user, *_: achievements.get_achievements_by_user_id(user.id), AchievementFilter | ||||
|         ) | ||||
|         self.add_collection( | ||||
|             "userWarning", lambda user, *_: user_warnings.get_user_warnings_by_user_id(user.id), UserWarningFilter | ||||
|         ) | ||||
|  | ||||
|         self.set_field("server", self.resolve_server) | ||||
|         self.set_field("leftServer", self.resolve_left_server) | ||||
|   | ||||
| @@ -0,0 +1,11 @@ | ||||
| from bot_graphql.abc.history_query_abc import HistoryQueryABC | ||||
|  | ||||
|  | ||||
| class UserWarningHistoryQuery(HistoryQueryABC): | ||||
|     def __init__(self): | ||||
|         HistoryQueryABC.__init__(self, "UserWarning") | ||||
|  | ||||
|         self.set_field("id", lambda x, *_: x.id) | ||||
|         self.set_field("user", lambda x, *_: x.user) | ||||
|         self.set_field("description", lambda x, *_: x.description) | ||||
|         self.set_field("author", lambda x, *_: x.author) | ||||
							
								
								
									
										17
									
								
								kdb-bot/src/bot_graphql/queries/user_warning_query.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								kdb-bot/src/bot_graphql/queries/user_warning_query.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| from cpl_core.database.context import DatabaseContextABC | ||||
|  | ||||
| from bot_data.model.user_warnings_history import UserWarningsHistory | ||||
| from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC | ||||
|  | ||||
|  | ||||
| class UserWarningQuery(DataQueryWithHistoryABC): | ||||
|     def __init__( | ||||
|         self, | ||||
|         db: DatabaseContextABC, | ||||
|     ): | ||||
|         DataQueryWithHistoryABC.__init__(self, "UserWarning", "UserWarningsHistory", UserWarningsHistory, db) | ||||
|  | ||||
|         self.set_field("id", lambda x, *_: x.id) | ||||
|         self.set_field("user", lambda x, *_: x.user) | ||||
|         self.set_field("description", lambda x, *_: x.description) | ||||
|         self.set_field("author", lambda x, *_: x.author) | ||||
| @@ -15,6 +15,7 @@ from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameSe | ||||
| from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC | ||||
| from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC | ||||
| from bot_data.abc.user_repository_abc import UserRepositoryABC | ||||
| from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC | ||||
| from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEnum | ||||
| from bot_graphql.abc.query_abc import QueryABC | ||||
| from bot_graphql.filter.achievement_filter import AchievementFilter | ||||
| @@ -28,6 +29,7 @@ from bot_graphql.filter.user_filter import UserFilter | ||||
| from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter | ||||
| from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter | ||||
| from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter | ||||
| from bot_graphql.filter.user_warning_filter import UserWarningFilter | ||||
| from bot_graphql.model.discord import Discord | ||||
| from modules.achievements.achievement_service import AchievementService | ||||
|  | ||||
| @@ -48,6 +50,7 @@ class Query(QueryABC): | ||||
|         users: UserRepositoryABC, | ||||
|         achievements: AchievementRepositoryABC, | ||||
|         short_role_names: ShortRoleNameRepositoryABC, | ||||
|         user_warnings: UserWarningsRepositoryABC, | ||||
|         achievement_service: AchievementService, | ||||
|         technician_config: TechnicianConfigRepositoryABC, | ||||
|     ): | ||||
| @@ -76,11 +79,13 @@ class Query(QueryABC): | ||||
|         self.add_collection("user", lambda *_: users.get_users(), UserFilter) | ||||
|         self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter) | ||||
|         self.add_collection("shortRoleName", lambda *_: short_role_names.get_short_role_names(), ShortRoleNameFilter) | ||||
|         self.add_collection("userWarning", lambda *_: user_warnings.get_user_warnings(), UserWarningFilter) | ||||
|  | ||||
|         self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config()) | ||||
|  | ||||
|         self.set_field("achievementAttributes", lambda *_: achievement_service.get_attributes()) | ||||
|         self.set_field("achievementOperators", lambda *_: achievement_service.get_operators()) | ||||
|         self.set_field("shortRoleNamePositions", lambda *_: [x.value for x in ShortRoleNamePositionEnum]) | ||||
|  | ||||
|         self.set_field("possibleFeatureFlags", lambda *_: [e.value for e in FeatureFlagsEnum]) | ||||
|         self.set_field("discord", lambda *_: Discord(bot.guilds, List(any).extend(bot.users))) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user