Compare commits
No commits in common. "936b8e9cb653af26b467f6950382fb8d32ec6610" and "1d1fc8a876d95863979b0f6a29671ec4bcc283ff" have entirely different histories.
936b8e9cb6
...
1d1fc8a876
@ -26,7 +26,7 @@
|
|||||||
"PyJWT==2.6.0",
|
"PyJWT==2.6.0",
|
||||||
"waitress==2.1.2",
|
"waitress==2.1.2",
|
||||||
"Flask-SocketIO==5.3.2",
|
"Flask-SocketIO==5.3.2",
|
||||||
"eventlet==0.33.3",
|
"eventlet==0.33.2",
|
||||||
"requests-oauthlib==1.3.1",
|
"requests-oauthlib==1.3.1",
|
||||||
"icmplib==3.0.3",
|
"icmplib==3.0.3",
|
||||||
"ariadne==0.17.1"
|
"ariadne==0.17.1"
|
||||||
|
@ -13,6 +13,7 @@ from bot_api.api import Api
|
|||||||
from bot_api.api_thread import ApiThread
|
from bot_api.api_thread import ApiThread
|
||||||
from bot_api.controller.auth_controller import AuthController
|
from bot_api.controller.auth_controller import AuthController
|
||||||
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
||||||
|
from bot_api.controller.discord.server_controller import ServerController
|
||||||
from bot_api.controller.grahpql_controller import GraphQLController
|
from bot_api.controller.grahpql_controller import GraphQLController
|
||||||
from bot_api.controller.gui_controller import GuiController
|
from bot_api.controller.gui_controller import GuiController
|
||||||
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
||||||
@ -45,6 +46,7 @@ class ApiModule(ModuleABC):
|
|||||||
services.add_transient(AuthDiscordController)
|
services.add_transient(AuthDiscordController)
|
||||||
services.add_transient(GuiController)
|
services.add_transient(GuiController)
|
||||||
services.add_transient(DiscordService)
|
services.add_transient(DiscordService)
|
||||||
|
services.add_transient(ServerController)
|
||||||
services.add_transient(GraphQLController)
|
services.add_transient(GraphQLController)
|
||||||
|
|
||||||
# cpl-discord
|
# cpl-discord
|
||||||
|
@ -2,9 +2,12 @@ from cpl_core.application import ApplicationExtensionABC
|
|||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
|
|
||||||
|
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||||
|
from bot_api.configuration.authentication_settings import AuthenticationSettings
|
||||||
from bot_api.route.route import Route
|
from bot_api.route.route import Route
|
||||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||||
|
|
||||||
|
|
||||||
class AppApiExtension(ApplicationExtensionABC):
|
class AppApiExtension(ApplicationExtensionABC):
|
||||||
@ -16,4 +19,7 @@ class AppApiExtension(ApplicationExtensionABC):
|
|||||||
if not feature_flags.get_flag(FeatureFlagsEnum.api_module):
|
if not feature_flags.get_flag(FeatureFlagsEnum.api_module):
|
||||||
return
|
return
|
||||||
|
|
||||||
Route.init_authorize()
|
auth_settings: AuthenticationSettings = config.get_configuration(AuthenticationSettings)
|
||||||
|
auth_users: AuthUserRepositoryABC = services.get_service(AuthUserRepositoryABC)
|
||||||
|
auth: AuthServiceABC = services.get_service(AuthServiceABC)
|
||||||
|
Route.init_authorize(auth_users, auth)
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 27289afd5e2d020cd9fcec62a682204a93688f25
|
Subproject commit e6046881b562982008583afa973b39ff08b6a3c7
|
@ -8,7 +8,7 @@ from cpl_core.utils import CredentialManager
|
|||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_translation import TranslatePipe
|
from cpl_translation import TranslatePipe
|
||||||
from flask import jsonify, Response
|
from flask import jsonify, Response
|
||||||
from flask import request
|
from flask import request, session
|
||||||
from requests_oauthlib import OAuth2Session
|
from requests_oauthlib import OAuth2Session
|
||||||
|
|
||||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||||
@ -16,8 +16,10 @@ from bot_api.api import Api
|
|||||||
from bot_api.configuration.discord_authentication_settings import (
|
from bot_api.configuration.discord_authentication_settings import (
|
||||||
DiscordAuthenticationSettings,
|
DiscordAuthenticationSettings,
|
||||||
)
|
)
|
||||||
|
from bot_api.json_processor import JSONProcessor
|
||||||
from bot_api.logging.api_logger import ApiLogger
|
from bot_api.logging.api_logger import ApiLogger
|
||||||
from bot_api.model.auth_user_dto import AuthUserDTO
|
from bot_api.model.auth_user_dto import AuthUserDTO
|
||||||
|
from bot_api.model.o_auth_dto import OAuthDTO
|
||||||
from bot_api.route.route import Route
|
from bot_api.route.route import Route
|
||||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ class AuthDiscordController:
|
|||||||
self._bot.user.id,
|
self._bot.user.id,
|
||||||
redirect_uri=self._auth_settings.redirect_url,
|
redirect_uri=self._auth_settings.redirect_url,
|
||||||
state=request.args.get("state"),
|
state=request.args.get("state"),
|
||||||
scope=self._auth_settings.scope.to_list(),
|
scope=self._auth_settings.scope,
|
||||||
)
|
)
|
||||||
token = discord.fetch_token(
|
token = discord.fetch_token(
|
||||||
self._auth_settings.token_url,
|
self._auth_settings.token_url,
|
||||||
@ -72,7 +74,7 @@ class AuthDiscordController:
|
|||||||
oauth = OAuth2Session(
|
oauth = OAuth2Session(
|
||||||
self._bot.user.id,
|
self._bot.user.id,
|
||||||
redirect_uri=self._auth_settings.redirect_url,
|
redirect_uri=self._auth_settings.redirect_url,
|
||||||
scope=self._auth_settings.scope.to_list(),
|
scope=self._auth_settings.scope,
|
||||||
)
|
)
|
||||||
login_url, state = oauth.authorization_url(self._auth_settings.auth_url)
|
login_url, state = oauth.authorization_url(self._auth_settings.auth_url)
|
||||||
return jsonify({"loginUrl": login_url})
|
return jsonify({"loginUrl": login_url})
|
||||||
|
26
kdb-bot/src/bot_api/controller/discord/__init__.py
Normal file
26
kdb-bot/src/bot_api/controller/discord/__init__.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
bot Keksdose bot
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Discord bot for the Keksdose discord Server
|
||||||
|
|
||||||
|
:copyright: (c) 2022 - 2023 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = "bot_api.controller.discord"
|
||||||
|
__author__ = "Sven Heidemann"
|
||||||
|
__license__ = "MIT"
|
||||||
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
|
__version__ = "0.3.1"
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
|
version_info = VersionInfo(major="0", minor="3", micro="1")
|
67
kdb-bot/src/bot_api/controller/discord/server_controller.py
Normal file
67
kdb-bot/src/bot_api/controller/discord/server_controller.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.environment import ApplicationEnvironmentABC
|
||||||
|
from cpl_core.mailing import EMailClientABC, EMailClientSettings
|
||||||
|
from cpl_translation import TranslatePipe
|
||||||
|
from flask import Response, jsonify, request
|
||||||
|
|
||||||
|
from bot_api.api import Api
|
||||||
|
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||||
|
from bot_api.json_processor import JSONProcessor
|
||||||
|
from bot_api.logging.api_logger import ApiLogger
|
||||||
|
from bot_api.route.route import Route
|
||||||
|
from bot_api.service.discord_service import DiscordService
|
||||||
|
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||||
|
|
||||||
|
|
||||||
|
class ServerController:
|
||||||
|
BasePath = f"/api/discord/server"
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
env: ApplicationEnvironmentABC,
|
||||||
|
logger: ApiLogger,
|
||||||
|
t: TranslatePipe,
|
||||||
|
api: Api,
|
||||||
|
mail_settings: EMailClientSettings,
|
||||||
|
mailer: EMailClientABC,
|
||||||
|
discord_service: DiscordService,
|
||||||
|
):
|
||||||
|
self._config = config
|
||||||
|
self._env = env
|
||||||
|
self._logger = logger
|
||||||
|
self._t = t
|
||||||
|
self._api = api
|
||||||
|
self._mail_settings = mail_settings
|
||||||
|
self._mailer = mailer
|
||||||
|
self._discord_service = discord_service
|
||||||
|
|
||||||
|
@Route.get(f"{BasePath}/get/servers")
|
||||||
|
@Route.authorize(role=AuthRoleEnum.admin)
|
||||||
|
async def get_all_servers(self) -> Response:
|
||||||
|
result = await self._discord_service.get_all_servers()
|
||||||
|
result = result.select(lambda x: x.to_dict()).to_list()
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
@Route.get(f"{BasePath}/get/servers-by-user")
|
||||||
|
@Route.authorize
|
||||||
|
async def get_all_servers_by_user(self) -> Response:
|
||||||
|
result = await self._discord_service.get_all_servers_by_user()
|
||||||
|
result = result.select(lambda x: x.to_dict()).to_list()
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
@Route.post(f"{BasePath}/get/filtered")
|
||||||
|
@Route.authorize
|
||||||
|
async def get_filtered_servers(self) -> Response:
|
||||||
|
dto: ServerSelectCriteria = JSONProcessor.process(
|
||||||
|
ServerSelectCriteria, request.get_json(force=True, silent=True)
|
||||||
|
)
|
||||||
|
result = await self._discord_service.get_filtered_servers_async(dto)
|
||||||
|
result.result = result.result.select(lambda x: x.to_dict()).to_list()
|
||||||
|
return jsonify(result.to_dict())
|
||||||
|
|
||||||
|
@Route.get(f"{BasePath}/get/<id>")
|
||||||
|
@Route.authorize
|
||||||
|
async def get_server_by_id(self, id: int) -> Response:
|
||||||
|
result = await self._discord_service.get_server_by_id_async(id).to_list()
|
||||||
|
return jsonify(result.to_dict())
|
@ -25,15 +25,10 @@ class GraphQLController:
|
|||||||
self._schema = schema
|
self._schema = schema
|
||||||
|
|
||||||
@Route.get(f"{BasePath}/playground")
|
@Route.get(f"{BasePath}/playground")
|
||||||
@Route.authorize(skip_in_dev=True)
|
|
||||||
async def playground(self):
|
async def playground(self):
|
||||||
if self._env.environment_name != "development":
|
|
||||||
return "", 403
|
|
||||||
|
|
||||||
return PLAYGROUND_HTML, 200
|
return PLAYGROUND_HTML, 200
|
||||||
|
|
||||||
@Route.post(f"{BasePath}")
|
@Route.post(f"{BasePath}")
|
||||||
@Route.authorize
|
|
||||||
async def graphql(self):
|
async def graphql(self):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@ import functools
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
|
||||||
from cpl_core.environment import ApplicationEnvironmentABC
|
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
|
|
||||||
@ -20,25 +18,19 @@ class Route:
|
|||||||
|
|
||||||
_auth_users: Optional[AuthUserRepositoryABC] = None
|
_auth_users: Optional[AuthUserRepositoryABC] = None
|
||||||
_auth: Optional[AuthServiceABC] = None
|
_auth: Optional[AuthServiceABC] = None
|
||||||
_env = "production"
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ServiceProviderABC.inject
|
def init_authorize(cls, auth_users: AuthUserRepositoryABC, auth: AuthServiceABC):
|
||||||
def init_authorize(cls, env: ApplicationEnvironmentABC, auth_users: AuthUserRepositoryABC, auth: AuthServiceABC):
|
|
||||||
cls._auth_users = auth_users
|
cls._auth_users = auth_users
|
||||||
cls._auth = auth
|
cls._auth = auth
|
||||||
cls._env = env.environment_name
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authorize(cls, f: Callable = None, role: AuthRoleEnum = None, skip_in_dev=False):
|
def authorize(cls, f: Callable = None, role: AuthRoleEnum = None):
|
||||||
if f is None:
|
if f is None:
|
||||||
return functools.partial(cls.authorize, role=role, skip_in_dev=skip_in_dev)
|
return functools.partial(cls.authorize, role=role)
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
async def decorator(*args, **kwargs):
|
async def decorator(*args, **kwargs):
|
||||||
if skip_in_dev and cls._env == "development":
|
|
||||||
return await f(*args, **kwargs)
|
|
||||||
|
|
||||||
token = None
|
token = None
|
||||||
if "Authorization" in request.headers:
|
if "Authorization" in request.headers:
|
||||||
bearer = request.headers.get("Authorization")
|
bearer = request.headers.get("Authorization")
|
||||||
|
@ -2,7 +2,6 @@ type Server implements TableQuery {
|
|||||||
id: ID
|
id: ID
|
||||||
discordId: String
|
discordId: String
|
||||||
name: String
|
name: String
|
||||||
iconURL: String
|
|
||||||
|
|
||||||
autoRoleCount: Int
|
autoRoleCount: Int
|
||||||
autoRoles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
autoRoles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
||||||
|
@ -35,7 +35,6 @@ class ServerQuery(DataQueryABC):
|
|||||||
self.set_field("id", self.resolve_id)
|
self.set_field("id", self.resolve_id)
|
||||||
self.set_field("discordId", self.resolve_discord_id)
|
self.set_field("discordId", self.resolve_discord_id)
|
||||||
self.set_field("name", self.resolve_name)
|
self.set_field("name", self.resolve_name)
|
||||||
self.set_field("iconURL", self.resolve_icon_url)
|
|
||||||
|
|
||||||
self.add_collection(
|
self.add_collection(
|
||||||
"autoRole", lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.server_id)
|
"autoRole", lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.server_id)
|
||||||
@ -55,7 +54,3 @@ class ServerQuery(DataQueryABC):
|
|||||||
def resolve_name(self, server: Server, *_):
|
def resolve_name(self, server: Server, *_):
|
||||||
guild = self._bot.get_guild(server.discord_server_id)
|
guild = self._bot.get_guild(server.discord_server_id)
|
||||||
return None if guild is None else guild.name
|
return None if guild is None else guild.name
|
||||||
|
|
||||||
def resolve_icon_url(self, server: Server, *_):
|
|
||||||
guild = self._bot.get_guild(server.discord_server_id)
|
|
||||||
return None if guild is None else guild.icon.url
|
|
||||||
|
41105
kdb-web/package-lock.json
generated
41105
kdb-web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kdb-web",
|
"name": "kdb-web",
|
||||||
"version": "0.3.dev162-2",
|
"version": "0.3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"update-version": "ts-node-esm update-version.ts",
|
"update-version": "ts-node-esm update-version.ts",
|
||||||
@ -16,29 +16,29 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^15.1.4",
|
"@angular/animations": "^14.0.0",
|
||||||
"@angular/common": "^15.1.4",
|
"@angular/common": "^14.0.0",
|
||||||
"@angular/compiler": "^15.1.4",
|
"@angular/compiler": "^14.0.0",
|
||||||
"@angular/core": "^15.1.4",
|
"@angular/core": "^14.0.0",
|
||||||
"@angular/forms": "^15.1.4",
|
"@angular/forms": "^14.0.0",
|
||||||
"@angular/platform-browser": "^15.1.4",
|
"@angular/platform-browser": "^14.0.0",
|
||||||
"@angular/platform-browser-dynamic": "^15.1.4",
|
"@angular/platform-browser-dynamic": "^14.0.0",
|
||||||
"@angular/router": "^15.1.4",
|
"@angular/router": "^14.0.0",
|
||||||
"@auth0/angular-jwt": "^5.1.0",
|
"@auth0/angular-jwt": "^5.1.0",
|
||||||
"@microsoft/signalr": "^6.0.9",
|
"@microsoft/signalr": "^6.0.9",
|
||||||
"@ngx-translate/core": "^14.0.0",
|
"@ngx-translate/core": "^14.0.0",
|
||||||
"@ngx-translate/http-loader": "^7.0.0",
|
"@ngx-translate/http-loader": "^7.0.0",
|
||||||
"@types/socket.io-client": "^3.0.0",
|
"@types/socket.io-client": "^3.0.0",
|
||||||
"primeicons": "^6.0.1",
|
"primeicons": "^6.0.1",
|
||||||
"primeng": "^15.2.0",
|
"primeng": "^14.1.2",
|
||||||
"rxjs": "~7.5.0",
|
"rxjs": "~7.5.0",
|
||||||
"socket.io-client": "^4.5.3",
|
"socket.io-client": "^4.5.3",
|
||||||
"zone.js": "~0.11.4"
|
"zone.js": "~0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "^15.1.5",
|
"@angular-devkit/build-angular": "^14.0.0",
|
||||||
"@angular/cli": "~15.1.5",
|
"@angular/cli": "~14.0.0",
|
||||||
"@angular/compiler-cli": "^15.1.4",
|
"@angular/compiler-cli": "^14.0.0",
|
||||||
"@types/jasmine": "~4.0.0",
|
"@types/jasmine": "~4.0.0",
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^18.11.9",
|
||||||
"jasmine-core": "~4.1.0",
|
"jasmine-core": "~4.1.0",
|
||||||
@ -48,6 +48,6 @@
|
|||||||
"karma-jasmine": "~5.0.0",
|
"karma-jasmine": "~5.0.0",
|
||||||
"karma-jasmine-html-reporter": "~1.7.0",
|
"karma-jasmine-html-reporter": "~1.7.0",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "~4.9.5"
|
"typescript": "~4.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
|
import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
@ -47,8 +47,7 @@ import { SettingsService } from './services/settings/settings.service';
|
|||||||
useFactory: HttpLoaderFactory,
|
useFactory: HttpLoaderFactory,
|
||||||
deps: [HttpClient]
|
deps: [HttpClient]
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
HttpClientModule
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ export class SidebarComponent implements OnInit {
|
|||||||
isSidebarOpen: boolean = true;
|
isSidebarOpen: boolean = true;
|
||||||
menuItems!: MenuItem[];
|
menuItems!: MenuItem[];
|
||||||
|
|
||||||
private serverId?: number;
|
private serverId!: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
@ -40,7 +40,7 @@ export class SidebarComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serverId = server.id;
|
this.serverId = server.serverId;
|
||||||
this.setMenu();
|
this.setMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
export interface Data {
|
|
||||||
createdAt: string;
|
|
||||||
modifiedAt: string;
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import { Data } from "./data.model";
|
|
||||||
|
|
||||||
export interface Server extends Data {
|
|
||||||
id?: number;
|
|
||||||
discordId?: number;
|
|
||||||
name?: string;
|
|
||||||
iconURL?: string;
|
|
||||||
autoRoleCount?: number;
|
|
||||||
autoRoles?: [];
|
|
||||||
clientCount?: number;
|
|
||||||
clients?: [];
|
|
||||||
levelCount?: number;
|
|
||||||
levels?: [];
|
|
||||||
userCount?: number;
|
|
||||||
users?: [];
|
|
||||||
}
|
|
7
kdb-web/src/app/models/discord/server.dto.ts
Normal file
7
kdb-web/src/app/models/discord/server.dto.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface ServerDTO {
|
||||||
|
serverId: number;
|
||||||
|
discordId: number;
|
||||||
|
name: string;
|
||||||
|
memberCount: number;
|
||||||
|
iconURL: string | null;
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
export interface Page {
|
|
||||||
pageIndex?: number;
|
|
||||||
pageSize?: number;
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
export interface Sort {
|
|
||||||
sortColumn?: string;
|
|
||||||
sortDirection?: string;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
export class Queries {
|
|
||||||
static serverInfoQuery = `
|
|
||||||
query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) {
|
|
||||||
serverCount
|
|
||||||
servers(filter: $filter, page: $page, sort: $sort) {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
iconURL
|
|
||||||
userCount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
import { Server } from "../data/server.model";
|
|
||||||
|
|
||||||
export interface Query {
|
|
||||||
serverCount: number;
|
|
||||||
servers: Server[];
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import { Query } from "./query.model";
|
|
||||||
|
|
||||||
export interface QueryResult {
|
|
||||||
data: any;
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
import { Page } from "./filter/page.model";
|
|
||||||
import { Sort } from "./filter/sort.model";
|
|
||||||
|
|
||||||
export interface Variables {
|
|
||||||
filter?: object;
|
|
||||||
page?: Page;
|
|
||||||
sort?: Sort;
|
|
||||||
}
|
|
@ -0,0 +1,7 @@
|
|||||||
|
import { AuthUserDTO } from "../../auth/auth-user.dto";
|
||||||
|
import { ServerDTO } from "../../discord/server.dto";
|
||||||
|
|
||||||
|
export interface GetFilteredServersResultDTO {
|
||||||
|
servers: ServerDTO[];
|
||||||
|
totalCount: number;
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
import { SelectCriterion } from "../select-criterion.model";
|
||||||
|
|
||||||
|
export interface ServerSelectCriterion extends SelectCriterion {
|
||||||
|
name: string | null;
|
||||||
|
}
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
<div class="data">
|
<div class="data">
|
||||||
<i class="pi pi-users"></i>
|
<i class="pi pi-users"></i>
|
||||||
{{server.userCount}}
|
{{server.memberCount}}
|
||||||
{{'view.dashboard.server.member_count' | translate}}
|
{{'view.dashboard.server.member_count' | translate}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -47,4 +47,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -1,42 +1,35 @@
|
|||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
|
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||||
import { Router } from "@angular/router";
|
import { Router } from '@angular/router';
|
||||||
import { TranslateService } from "@ngx-translate/core";
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { LazyLoadEvent } from "primeng/api";
|
import { LazyLoadEvent } from 'primeng/api';
|
||||||
import { debounceTime, throwError } from "rxjs";
|
import { catchError, debounceTime, throwError } from 'rxjs';
|
||||||
import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service";
|
import { ServerDTO } from 'src/app/models/discord/server.dto';
|
||||||
import { DataService } from "src/app/services/data/data.service";
|
import { ServerSelectCriterion } from 'src/app/models/selection/server/server-select-criterion.dto';
|
||||||
import { ServerService } from "src/app/services/data/server.service";
|
import { ConfirmationDialogService } from 'src/app/services/confirmation-dialog/confirmation-dialog.service';
|
||||||
import { SpinnerService } from "src/app/services/spinner/spinner.service";
|
import { DataService } from 'src/app/services/data/data.service';
|
||||||
import { ToastService } from "src/app/services/toast/toast.service";
|
import { ServerService } from 'src/app/services/data/server.service';
|
||||||
import { Server } from "../../../../../models/data/server.model";
|
import { SpinnerService } from 'src/app/services/spinner/spinner.service';
|
||||||
import { catchError } from "rxjs/operators";
|
import { ToastService } from 'src/app/services/toast/toast.service';
|
||||||
import { Queries } from "../../../../../models/graphql/queries.model";
|
|
||||||
import { Page } from "../../../../../models/graphql/filter/page.model";
|
|
||||||
import { Sort } from "../../../../../models/graphql/filter/sort.model";
|
|
||||||
import { Query } from "../../../../../models/graphql/query.model";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-dashboard",
|
selector: 'app-dashboard',
|
||||||
templateUrl: "./dashboard.component.html",
|
templateUrl: './dashboard.component.html',
|
||||||
styleUrls: ["./dashboard.component.scss"]
|
styleUrls: ['./dashboard.component.scss']
|
||||||
})
|
})
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
|
|
||||||
servers: Server[] = [];
|
servers: ServerDTO[] = [];
|
||||||
|
|
||||||
|
searchCriterions: ServerSelectCriterion = {
|
||||||
|
name: null,
|
||||||
|
pageIndex: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
sortColumn: null,
|
||||||
|
sortDirection: null
|
||||||
|
};
|
||||||
totalRecords!: number;
|
totalRecords!: number;
|
||||||
|
|
||||||
filter = {
|
|
||||||
name: ""
|
|
||||||
};
|
|
||||||
|
|
||||||
page: Page = {
|
|
||||||
pageIndex: 0,
|
|
||||||
pageSize: 10
|
|
||||||
};
|
|
||||||
|
|
||||||
sort!: Sort;
|
|
||||||
|
|
||||||
filterForm!: FormGroup<{
|
filterForm!: FormGroup<{
|
||||||
name: FormControl<string | null>,
|
name: FormControl<string | null>,
|
||||||
@ -51,67 +44,60 @@ export class DashboardComponent implements OnInit {
|
|||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private serverService: ServerService
|
private serverService: ServerService
|
||||||
) {
|
) { }
|
||||||
}
|
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
this.spinnerService.showSpinner();
|
this.spinnerService.showSpinner();
|
||||||
|
|
||||||
this.setFilterForm();
|
this.setFilterForm();
|
||||||
this.loadNextPage();
|
this.loadNextPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
setFilterForm() {
|
setFilterForm() {
|
||||||
this.filterForm = this.fb.group({
|
this.filterForm = this.fb.group({
|
||||||
name: [""]
|
name: [''],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.filterForm.valueChanges.pipe(
|
this.filterForm.valueChanges.pipe(
|
||||||
debounceTime(600)
|
debounceTime(600)
|
||||||
).subscribe(async changes => {
|
).subscribe(changes => {
|
||||||
if (changes.name) {
|
if (changes.name) {
|
||||||
this.filter.name = changes.name;
|
this.searchCriterions.name = changes.name;
|
||||||
|
} else {
|
||||||
|
this.searchCriterions.name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.page.pageSize)
|
if (this.searchCriterions.pageSize)
|
||||||
this.page.pageSize = 10;
|
this.searchCriterions.pageSize = 10;
|
||||||
|
|
||||||
if (this.page.pageSize)
|
if (this.searchCriterions.pageSize)
|
||||||
this.page.pageIndex = 0;
|
this.searchCriterions.pageIndex = 0;
|
||||||
|
|
||||||
await this.loadNextPage();
|
this.loadNextPage();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadNextPage() {
|
loadNextPage() {
|
||||||
this.spinnerService.showSpinner();
|
this.spinnerService.showSpinner();
|
||||||
this.data.query<Query>(Queries.serverInfoQuery,{
|
this.data.getFilteredServers(this.searchCriterions).pipe(catchError(err => {
|
||||||
filter: this.filter,
|
|
||||||
page: this.page,
|
|
||||||
sort: this.sort,
|
|
||||||
}).pipe(catchError(err => {
|
|
||||||
this.spinnerService.hideSpinner();
|
this.spinnerService.hideSpinner();
|
||||||
return throwError(() => err);
|
return throwError(() => err);
|
||||||
})).subscribe(data => {
|
})).subscribe(list => {
|
||||||
this.totalRecords = data.serverCount;
|
this.totalRecords = list.totalCount;
|
||||||
this.servers = data.servers;
|
this.servers = list.servers;
|
||||||
this.spinnerService.hideSpinner();
|
this.spinnerService.hideSpinner();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
nextPage(event: LazyLoadEvent) {
|
nextPage(event: LazyLoadEvent) {
|
||||||
this.page.pageSize = event.rows ?? 0;
|
this.searchCriterions.pageSize = event.rows ?? 0;
|
||||||
if (event.first != null && event.rows != null)
|
if (event.first != null && event.rows != null)
|
||||||
this.page.pageIndex = event.first / event.rows;
|
this.searchCriterions.pageIndex = event.first / event.rows;
|
||||||
|
this.searchCriterions.sortColumn = event.sortField ?? null;
|
||||||
this.sort = {
|
this.searchCriterions.sortDirection = event.sortOrder === 1 ? 'asc' : event.sortOrder === -1 ? 'desc' : 'asc';
|
||||||
sortColumn: event.sortField ?? "",
|
|
||||||
sortDirection: event.sortOrder === 1 ? "asc" : event.sortOrder === -1 ? "desc" : "asc"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (event.filters) {
|
if (event.filters) {
|
||||||
// + "" => convert to string
|
// + "" => convert to string
|
||||||
this.filter.name = event.filters["name"] ? event.filters["name"] + "" : "";
|
this.searchCriterions.name = event.filters['name'] ? event.filters['name'] + "" : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadNextPage();
|
this.loadNextPage();
|
||||||
@ -121,9 +107,9 @@ export class DashboardComponent implements OnInit {
|
|||||||
this.filterForm.reset();
|
this.filterForm.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
selectServer(server: Server) {
|
selectServer(server: ServerDTO) {
|
||||||
this.serverService.server$.next(server);
|
this.serverService.server$.next(server);
|
||||||
this.router.navigate(["/server"]);
|
this.router.navigate(['/server']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<div class="data">
|
<div class="data">
|
||||||
<i class="pi pi-users"></i>
|
<i class="pi pi-users"></i>
|
||||||
{{server.userCount}}
|
{{server.memberCount}}
|
||||||
{{'view.dashboard.server.member_count' | translate}}
|
{{'view.dashboard.server.member_count' | translate}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -33,4 +33,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -1,9 +1,9 @@
|
|||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { Server } from "src/app/models/data/server.model";
|
import { ServerDTO } from 'src/app/models/discord/server.dto';
|
||||||
import { DataService } from "src/app/services/data/data.service";
|
import { DataService } from 'src/app/services/data/data.service';
|
||||||
import { ServerService } from "src/app/services/data/server.service";
|
import { ServerService } from 'src/app/services/data/server.service';
|
||||||
import { SpinnerService } from "src/app/services/spinner/spinner.service";
|
import { SpinnerService } from 'src/app/services/spinner/spinner.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-server-dashboard',
|
selector: 'app-server-dashboard',
|
||||||
@ -13,7 +13,7 @@ import { SpinnerService } from "src/app/services/spinner/spinner.service";
|
|||||||
export class ServerDashboardComponent implements OnInit {
|
export class ServerDashboardComponent implements OnInit {
|
||||||
|
|
||||||
id!: number;
|
id!: number;
|
||||||
server!: Server;
|
server!: ServerDTO;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -217,7 +217,7 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getDecodedToken(): { [key: string]: any } | null{
|
getDecodedToken(): { [key: string]: any } {
|
||||||
return this.jwtHelper.decodeToken(this.getToken().token);
|
return this.jwtHelper.decodeToken(this.getToken().token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,11 +288,10 @@ export class AuthService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const token = this.getDecodedToken();
|
const token = this.getDecodedToken();
|
||||||
if (!token) return false;
|
|
||||||
return AuthRoles[token['role']] === AuthRoles[role];
|
return AuthRoles[token['role']] === AuthRoles[role];
|
||||||
}
|
}
|
||||||
|
|
||||||
getEMailFromDecodedToken(token: { [key: string]: any } | null): string | null {
|
getEMailFromDecodedToken(token: { [key: string]: any }): string | null {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,53 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
import { SettingsService } from "../settings/settings.service";
|
import { Observable } from 'rxjs';
|
||||||
import { map, Observable } from "rxjs";
|
import { ServerDTO } from 'src/app/models/discord/server.dto';
|
||||||
import { Variables } from "../../models/graphql/variables.model";
|
import { GetFilteredServersResultDTO } from 'src/app/models/selection/server/get-filtered-servers-result.dto';
|
||||||
|
import { ServerSelectCriterion } from 'src/app/models/selection/server/server-select-criterion.dto';
|
||||||
|
import { SettingsService } from '../settings/settings.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root"
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class DataService {
|
export class DataService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private appsettings: SettingsService,
|
private appsettings: SettingsService,
|
||||||
private http: HttpClient
|
private http: HttpClient,
|
||||||
) {
|
) { }
|
||||||
}
|
|
||||||
|
|
||||||
// query(query: string, variables: object = {}): Observable<QueryResult> {
|
|
||||||
// return this.http.post<QueryResult>(`${this.appsettings.getApiURL()}/api/graphql`,
|
|
||||||
// JSON.stringify({
|
|
||||||
// query, variables
|
|
||||||
// }), {
|
|
||||||
// headers: new HttpHeaders({
|
|
||||||
// "Content-Type": "application/json"
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
public query<T>(query: string, variables?: Variables): Observable<T> {
|
|
||||||
return this.http
|
/* data requests */
|
||||||
.post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, {
|
getAllServers(): Observable<Array<ServerDTO>> {
|
||||||
query: query,
|
return this.http.get<Array<ServerDTO>>(`${this.appsettings.getApiURL()}/api/discord/server/servers`, {
|
||||||
variables: variables
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
})
|
})
|
||||||
.pipe(map((d) => d.data));
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllServersByUser(): Observable<Array<ServerDTO>> {
|
||||||
|
return this.http.get<Array<ServerDTO>>(`${this.appsettings.getApiURL()}/api/discord/server/servers-by-user`, {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFilteredServers(selectCriterions: ServerSelectCriterion): Observable<GetFilteredServersResultDTO> {
|
||||||
|
return this.http.post<GetFilteredServersResultDTO>(`${this.appsettings.getApiURL()}/api/discord/server/get/filtered`, selectCriterions, {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getServerByID(id: number): Observable<ServerDTO> {
|
||||||
|
return this.http.get<ServerDTO>(`${this.appsettings.getApiURL()}/api/discord/server/get/${id}`, {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
import { BehaviorSubject } from "rxjs";
|
import { BehaviorSubject, Subject } from 'rxjs';
|
||||||
import { Server } from "src/app/models/data/server.model";
|
import { ServerDTO } from 'src/app/models/discord/server.dto';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ServerService {
|
export class ServerService {
|
||||||
|
|
||||||
private server!: Server;
|
private server!: ServerDTO;
|
||||||
server$ = new BehaviorSubject<Server | null>(null);
|
server$ = new BehaviorSubject<ServerDTO | null>(null);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.server$.subscribe(server => {
|
this.server$.subscribe(server => {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"WebVersion": {
|
"WebVersion": {
|
||||||
"Major": "0",
|
"Major": "0",
|
||||||
"Minor": "3",
|
"Minor": "3",
|
||||||
"Micro": "dev162-2"
|
"Micro": "0"
|
||||||
},
|
},
|
||||||
"Themes": [
|
"Themes": [
|
||||||
{
|
{
|
||||||
|
@ -7,8 +7,20 @@ import {
|
|||||||
platformBrowserDynamicTesting
|
platformBrowserDynamicTesting
|
||||||
} from '@angular/platform-browser-dynamic/testing';
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
|
|
||||||
|
declare const require: {
|
||||||
|
context(path: string, deep?: boolean, filter?: RegExp): {
|
||||||
|
<T>(id: string): T;
|
||||||
|
keys(): string[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// First, initialize the Angular testing environment.
|
// First, initialize the Angular testing environment.
|
||||||
getTestBed().initTestEnvironment(
|
getTestBed().initTestEnvironment(
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting(),
|
platformBrowserDynamicTesting(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Then we find all the tests.
|
||||||
|
const context = require.context('./', true, /\.spec\.ts$/);
|
||||||
|
// And load the modules.
|
||||||
|
context.keys().forEach(context);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
{
|
{
|
||||||
"ts-node": {
|
"ts-node": {
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
@ -20,15 +21,12 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "ES2022",
|
"target": "es2020",
|
||||||
"module": "es2020",
|
"module": "es2020",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2020",
|
"es2020",
|
||||||
"dom",
|
"dom"
|
||||||
"esnext.asynciterable"
|
]
|
||||||
],
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"useDefineForClassFields": false
|
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"enableI18nLegacyMessageIdFormat": false,
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
@ -36,4 +34,4 @@
|
|||||||
"strictInputAccessModifiers": true,
|
"strictInputAccessModifiers": true,
|
||||||
"strictTemplates": true
|
"strictTemplates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user