Merge pull request '#440' (#441) from #440 into dev
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 4m43s

Reviewed-on: #441
This commit is contained in:
Sven Heidemann 2023-11-19 14:18:54 +01:00
commit 026331b397
14 changed files with 204 additions and 87 deletions

View File

@ -14,7 +14,10 @@ from bot_api.model.reset_password_dto import ResetPasswordDTO
from bot_api.model.token_dto import TokenDTO
from bot_api.model.update_auth_user_dto import UpdateAuthUserDTO
from bot_api.route.route import Route
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_data.model.auth_role_enum import AuthRoleEnum
from bot_data.model.technician_config import TechnicianConfig
class AuthController:
@ -30,6 +33,7 @@ class AuthController:
mail_settings: EMailClientSettings,
mailer: EMailClientABC,
auth_service: AuthServiceABC,
technician_config: TechnicianConfig,
):
self._config = config
self._env = env
@ -39,6 +43,7 @@ class AuthController:
self._mail_settings = mail_settings
self._mailer = mailer
self._auth_service = auth_service
self._technician_config = technician_config
@Route.get(f"{BasePath}/users")
@Route.authorize(role=AuthRoleEnum.admin)
@ -70,17 +75,32 @@ class AuthController:
@Route.post(f"{BasePath}/register")
async def register(self):
if not FeatureFlagsSettings.get_flag_from_dict(
self._technician_config.feature_flags, FeatureFlagsEnum.basic_registration
):
return
dto: AuthUserDTO = JSONProcessor.process(AuthUserDTO, request.get_json(force=True, silent=True))
self._auth_service.add_auth_user(dto)
return "", 200
@Route.post(f"{BasePath}/register-by-id/<id>")
async def register_id(self, id: str):
if not FeatureFlagsSettings.get_flag_from_dict(
self._technician_config.feature_flags, FeatureFlagsEnum.basic_registration
):
return
result = await self._auth_service.confirm_email_async(id)
return jsonify(result)
@Route.post(f"{BasePath}/login")
async def login(self) -> Response:
if not FeatureFlagsSettings.get_flag_from_dict(
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
):
return jsonify({})
dto: AuthUserDTO = JSONProcessor.process(AuthUserDTO, request.get_json(force=True, silent=True))
result = await self._auth_service.login_async(dto)
return jsonify(result.to_dict())
@ -100,6 +120,11 @@ class AuthController:
@Route.post(f"{BasePath}/forgot-password/<email>")
async def forgot_password(self, email: str):
if not FeatureFlagsSettings.get_flag_from_dict(
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
):
return "", 409
await self._auth_service.forgot_password_async(email)
return "", 200
@ -110,6 +135,11 @@ class AuthController:
@Route.post(f"{BasePath}/reset-password")
async def reset_password(self):
if not FeatureFlagsSettings.get_flag_from_dict(
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
):
return "", 409
dto: ResetPasswordDTO = JSONProcessor.process(ResetPasswordDTO, request.get_json(force=True, silent=True))
await self._auth_service.reset_password_async(dto)
return "", 200

View File

@ -12,6 +12,9 @@ from bot_api.logging.api_logger import ApiLogger
from bot_api.model.settings_dto import SettingsDTO
from bot_api.model.version_dto import VersionDTO
from bot_api.route.route import Route
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_data.model.technician_config import TechnicianConfig
class GuiController:
@ -82,3 +85,11 @@ class GuiController:
)
self._mailer.send_mail(mail)
return "", 200
@Route.get(f"{BasePath}/has-feature-flag/<flag>")
async def has_feature_flag(self, flag: str):
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
return {
"key": flag,
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)),
}

View File

@ -28,3 +28,5 @@ class FeatureFlagsEnum(Enum):
technician_full_access = "TechnicianFullAccess"
steam_special_offers = "SteamSpecialOffers"
scheduled_events = "ScheduledEvents"
basic_registration = "BasicRegistration"
basic_login = "BasicLogin"

View File

@ -30,6 +30,8 @@ class FeatureFlagsSettings(ConfigurationModelABC):
FeatureFlagsEnum.technician_full_access.value: False, # 03.10.2023 #393
FeatureFlagsEnum.steam_special_offers.value: False, # 11.10.2023 #188
FeatureFlagsEnum.scheduled_events.value: False, # 14.11.2023 #410
FeatureFlagsEnum.basic_registration.value: False, # 19.11.2023 #440
FeatureFlagsEnum.basic_login.value: False, # 19.11.2023 #440
}
def __init__(self, **kwargs: dict):

View File

@ -50,4 +50,6 @@ type Query {
technicianConfig: TechnicianConfig
possibleFeatureFlags: [String]
discord: Discord
hasFeatureFlag(flag: String): FeatureFlag
}

View File

@ -1,7 +1,9 @@
from cpl_core.configuration import ConfigurationABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.client_repository_abc import ClientRepositoryABC
@ -22,6 +24,7 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
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_data.model.technician_config import TechnicianConfig
from bot_graphql.abc.query_abc import QueryABC
from bot_graphql.filter.achievement_filter import AchievementFilter
from bot_graphql.filter.auto_role_filter import AutoRoleFilter
@ -45,6 +48,7 @@ from modules.achievements.achievement_service import AchievementService
class Query(QueryABC):
def __init__(
self,
config: ConfigurationABC,
bot: DiscordBotServiceABC,
auto_roles: AutoRoleRepositoryABC,
clients: ClientRepositoryABC,
@ -65,6 +69,8 @@ class Query(QueryABC):
):
QueryABC.__init__(self, "Query")
self._config = config
self.add_collection("autoRole", lambda *_: auto_roles.get_auto_roles(), AutoRoleFilter)
self.add_collection(
"autoRoleRule",
@ -120,3 +126,17 @@ class Query(QueryABC):
self.set_field("possibleFeatureFlags", lambda *_: [e.value for e in FeatureFlagsEnum])
self.set_field("discord", lambda *_: Discord(bot.guilds, List(any).extend(bot.users)))
self.set_field(
"hasFeatureFlag",
lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs),
)
def _resolve_has_feature_flag(self, *_, **kwargs):
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
if "flag" not in kwargs:
return False
return {
"key": kwargs["flag"],
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
}

View File

@ -1,56 +1,56 @@
{
"name": "web",
"version": "1.2.dev410",
"scripts": {
"ng": "ng",
"update-version": "ts-node update-version.ts",
"prestart": "npm run update-version",
"start": "ng serve",
"prebuild": "npm run update-version",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"gv": "echo $npm_package_version",
"predocker-build": "npm run update-version",
"docker-build": "export VERSION=$npm_package_version; ng build; docker build -t sh-edraft.de/sdb-web:$VERSION .",
"docker-build-dev": "export VERSION=$npm_package_version; ng build --configuration development; docker build -t sh-edraft.de/sdb-web:$VERSION .",
"docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t sh-edraft.de/sdb-web:$VERSION ."
},
"private": true,
"dependencies": {
"@angular/animations": "^15.1.4",
"@angular/common": "^15.1.4",
"@angular/compiler": "^15.1.4",
"@angular/core": "^15.1.4",
"@angular/forms": "^15.1.4",
"@angular/platform-browser": "^15.1.4",
"@angular/platform-browser-dynamic": "^15.1.4",
"@angular/router": "^15.1.4",
"@auth0/angular-jwt": "^5.1.0",
"@microsoft/signalr": "^6.0.9",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@types/socket.io-client": "^3.0.0",
"moment": "^2.29.4",
"primeicons": "^6.0.1",
"primeng": "^15.2.0",
"rxjs": "~7.5.0",
"socket.io-client": "^4.5.3",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.1.5",
"@angular/cli": "~15.1.5",
"@angular/compiler-cli": "^15.1.4",
"@types/jasmine": "~4.0.0",
"@types/node": "^18.11.9",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"tslib": "^2.4.1",
"typescript": "~4.9.5"
}
}
"name": "web",
"version": "1.2.2",
"scripts": {
"ng": "ng",
"update-version": "ts-node update-version.ts",
"prestart": "npm run update-version",
"start": "ng serve",
"prebuild": "npm run update-version",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"gv": "echo $npm_package_version",
"predocker-build": "npm run update-version",
"docker-build": "export VERSION=$npm_package_version; ng build; docker build -t sh-edraft.de/sdb-web:$VERSION .",
"docker-build-dev": "export VERSION=$npm_package_version; ng build --configuration development; docker build -t sh-edraft.de/sdb-web:$VERSION .",
"docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t sh-edraft.de/sdb-web:$VERSION ."
},
"private": true,
"dependencies": {
"@angular/animations": "^15.1.4",
"@angular/common": "^15.1.4",
"@angular/compiler": "^15.1.4",
"@angular/core": "^15.1.4",
"@angular/forms": "^15.1.4",
"@angular/platform-browser": "^15.1.4",
"@angular/platform-browser-dynamic": "^15.1.4",
"@angular/router": "^15.1.4",
"@auth0/angular-jwt": "^5.1.0",
"@microsoft/signalr": "^6.0.9",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@types/socket.io-client": "^3.0.0",
"moment": "^2.29.4",
"primeicons": "^6.0.1",
"primeng": "^15.2.0",
"rxjs": "~7.5.0",
"socket.io-client": "^4.5.3",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.1.5",
"@angular/cli": "~15.1.5",
"@angular/compiler-cli": "^15.1.4",
"@types/jasmine": "~4.0.0",
"@types/node": "^18.11.9",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"tslib": "^2.4.1",
"typescript": "~4.9.5"
}
}

View File

@ -108,6 +108,15 @@ export class Queries {
}
`;
static hasFeatureFlag = `
query HasFeatureFlag($flag: String) {
hasFeatureFlag(flag: $flag) {
key
value
}
}
`;
static hasServerFeatureFlag = `
query HasServerFeatureFlag($filter: ServerFilter, $flag: String) {
servers(filter: $filter) {

View File

@ -4,7 +4,9 @@
<form [formGroup]="loginForm">
<h1>{{'auth.header' | translate}}</h1>
<div class="input-field">
<input type="email" pInputText formControlName="email" placeholder="{{'common.email' | translate}}" [ngClass]="{ 'invalid-feedback-input': submitted && (
<input [disabled]="!basicLoginFeatureFlags" type="email" pInputText formControlName="email"
placeholder="{{'common.email' | translate}}"
[ngClass]="{ 'invalid-feedback-input': submitted && (
(loginForm.controls.email.errors && loginForm.controls.email.errors['required'] || authUserAtrErrors.email.required) ||
(authUserAtrErrors.email.wrongData) ||
(authUserAtrErrors.email.notConfirmed)
@ -24,7 +26,8 @@
styleClass="p-password p-component p-inputwrapper p-input-icon-right"
Remove after update!
-->
<p-password formControlName="password" placeholder="{{'auth.login.password' | translate}}" [ngClass]="{ 'invalid-feedback-input': submitted && (
<p-password [disabled]="!basicLoginFeatureFlags" formControlName="password"
placeholder="{{'auth.login.password' | translate}}" [ngClass]="{ 'invalid-feedback-input': submitted && (
(loginForm.controls.password.errors && loginForm.controls.password.errors['required'] || authUserAtrErrors.password.required) ||
(authUserAtrErrors.password.wrongData)
)}" [toggleMask]="true" [feedback]="false"
@ -39,17 +42,18 @@
</div>
<div class="login-form-submit">
<button pButton label="{{'auth.login.login' | translate}}" class="btn login-form-submit-btn" (click)="login()"
[disabled]="loginForm.invalid"></button>
[disabled]="loginForm.invalid || !basicLoginFeatureFlags"></button>
</div>
<div class="login-form-sub-button-wrapper" *ngIf="!code && !state">
<div class="login-form-sub-btn-wrapper">
<button pButton label="{{'auth.login.login_with_discord' | translate}}" class="btn login-form-sub-btn" (click)="discordLogin()"></button>
<button pButton label="{{'auth.login.login_with_discord' | translate}}" class="btn login-form-sub-btn"
(click)="discordLogin()"></button>
</div>
</div>
<div class="login-form-sub-button-wrapper">
<div class="login-form-sub-btn-wrapper">
<button pButton label="{{'auth.login.register' | translate}}" class="btn login-form-sub-btn"
(click)="register()"></button>
(click)="register()" [disabled]="!basicRegistrationFeatureFlags"></button>
</div>
<div class="login-form-sub-btn-wrapper">
<button pButton label="{{'auth.login.forgot_password' | translate}}"

View File

@ -13,6 +13,7 @@ import { ThemeService } from "src/app/services/theme/theme.service";
import { throwError } from "rxjs";
import { TranslateService } from "@ngx-translate/core";
import { ConfirmationDialogService } from "../../../../services/confirmation-dialog/confirmation-dialog.service";
import { GuiService } from "../../../../services/gui/gui.service";
@Component({
selector: "app-login",
@ -32,6 +33,8 @@ export class LoginComponent implements OnInit {
state!: string;
user!: AuthUserDTO;
oAuthId!: string;
public basicLoginFeatureFlags = false;
public basicRegistrationFeatureFlags = false;
constructor(
private authService: AuthService,
@ -41,11 +44,19 @@ export class LoginComponent implements OnInit {
private themeService: ThemeService,
private route: ActivatedRoute,
private confirmDialog: ConfirmationDialogService,
private translate: TranslateService
private translate: TranslateService,
private gui: GuiService
) {
}
ngOnInit(): void {
this.gui.hasFeatureFlag("BasicLogin").subscribe(flag => {
this.basicLoginFeatureFlags = flag.value;
});
this.gui.hasFeatureFlag("BasicRegistration").subscribe(flag => {
this.basicRegistrationFeatureFlags = flag.value;
});
this.initLoginForm();
this.spinnerService.showSpinner();
if (this.authService.isLoggedIn$.value) {
@ -107,8 +118,8 @@ export class LoginComponent implements OnInit {
initLoginForm(): void {
this.loginForm = this.formBuilder.group({
email: ["", [Validators.required, Validators.email]],
password: ["", [Validators.required, Validators.minLength(8)]]
email: [{ value: "", disabled: !this.basicLoginFeatureFlags }, [Validators.required, Validators.email]],
password: [{ value: "", disabled: !this.basicLoginFeatureFlags }, [Validators.required, Validators.minLength(8)]]
});
}

View File

@ -2,9 +2,10 @@
<div class="login-form-wrapper register-form-wrapper">
<div class="login-form">
<form [formGroup]="loginForm">
<h1>sh-edraft.de</h1>
<h1>{{'auth.header' | translate}}</h1>
<div class="input-field">
<input type="text" pInputText formControlName="firstName" placeholder="{{'auth.register.first_name' | translate}}"
<input type="text" pInputText formControlName="firstName"
placeholder="{{'auth.register.first_name' | translate}}"
autocomplete="given-name">
<div *ngIf="submitted" class="invalid-feedback">
<div
@ -15,7 +16,8 @@
</div>
<div class="input-field">
<input type="text" pInputText formControlName="lastName" placeholder="{{'auth.register.last_name' | translate}}"
<input type="text" pInputText formControlName="lastName"
placeholder="{{'auth.register.last_name' | translate}}"
autocomplete="family-name">
<div *ngIf="submitted" class="invalid-feedback">
<div
@ -74,12 +76,14 @@
</div>
<div class="login-form-submit">
<button pButton label="{{'auth.register.register' | translate}}" class="btn login-form-submit-btn" (click)="register()"
<button pButton label="{{'auth.register.register' | translate}}" class="btn login-form-submit-btn"
(click)="register()"
[disabled]="loginForm.invalid"></button>
</div>
<div class="login-form-sub-button-wrapper">
<div class="login-form-sub-btn-wrapper">
<button pButton label="{{'auth.register.login' | translate}}" class="btn login-form-sub-btn" (click)="login()"></button>
<button pButton label="{{'auth.register.login' | translate}}" class="btn login-form-sub-btn"
(click)="login()"></button>
</div>
</div>
</form>

View File

@ -12,6 +12,7 @@ import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { Subject, throwError } from "rxjs";
import { TranslateService } from "@ngx-translate/core";
import { SettingsService } from "../../../../services/settings/settings.service";
import { GuiService } from "../../../../services/gui/gui.service";
@Component({
selector: "app-registration",
@ -46,7 +47,8 @@ export class RegistrationComponent implements OnInit, OnDestroy {
private spinnerService: SpinnerService,
private route: ActivatedRoute,
private translate: TranslateService,
private settings: SettingsService
private settings: SettingsService,
private gui: GuiService
) {
this.spinnerService.showSpinner();
if (this.authService.isLoggedIn$.value) {
@ -56,6 +58,14 @@ export class RegistrationComponent implements OnInit, OnDestroy {
}
ngOnInit(): void {
this.gui.hasFeatureFlag("BasicRegistration").subscribe(flag => {
if (flag.value) {
return;
}
this.router.navigate(["/auth/login"]);
});
this.translate.onLangChange.pipe(takeUntil(this.unsubscriber)).subscribe(lang => {
this.confirmPrivacyString = this.translate.instant("auth.register.confirm_privacy", { url: this.settings.getPrivacyURL() });
});

View File

@ -1,24 +1,25 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, Subscribable } from 'rxjs';
import { SettingsDTO } from 'src/app/models/config/settings.dto';
import { SoftwareVersionDTO } from 'src/app/models/config/software-version.dto';
import { SettingsService } from '../settings/settings.service';
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { SettingsDTO } from "src/app/models/config/settings.dto";
import { SoftwareVersionDTO } from "src/app/models/config/software-version.dto";
import { SettingsService } from "../settings/settings.service";
@Injectable({
providedIn: 'root'
providedIn: "root"
})
export class GuiService {
constructor(
private appsettings: SettingsService,
private http: HttpClient,
) { }
private http: HttpClient
) {
}
getApiVersion(): Observable<SoftwareVersionDTO> {
return this.http.get<SoftwareVersionDTO>(`${this.appsettings.getApiURL()}/api/gui/api-version`, {
headers: new HttpHeaders({
'Content-Type': 'application/json'
"Content-Type": "application/json"
})
});
}
@ -26,7 +27,7 @@ export class GuiService {
getSettings(): Observable<SettingsDTO> {
return this.http.get<SettingsDTO>(`${this.appsettings.getApiURL()}/api/gui/settings`, {
headers: new HttpHeaders({
'Content-Type': 'application/json'
"Content-Type": "application/json"
})
});
}
@ -34,7 +35,18 @@ export class GuiService {
sendTestMail(mail: string): Observable<unknown> {
return this.http.post(`${this.appsettings.getApiURL()}/api/gui/send-test-mail/${mail}`, {
headers: new HttpHeaders({
'Content-Type': 'application/json'
"Content-Type": "application/json"
})
});
}
hasFeatureFlag(flag: string): Observable<{ key: string, value: boolean }> {
return this.http.get<{
key: string,
value: boolean
}>(`${this.appsettings.getApiURL()}/api/gui/has-feature-flag/${flag}`, {
headers: new HttpHeaders({
"Content-Type": "application/json"
})
});
}

View File

@ -1,7 +1,7 @@
{
"WebVersion": {
"Major": "1",
"Minor": "2",
"Micro": "dev410"
}
}
"WebVersion": {
"Major": "1",
"Minor": "2",
"Micro": "2"
}
}