Reviewed-on: sh-edraft.de/kd_discord_bot#257 Reviewed-by: edraft-dev <dev.sven.heidemann@sh-edraft.de> Closes #255
This commit is contained in:
commit
c311e534d7
@ -1,4 +1,4 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Queries } from "../../../../models/graphql/queries.model";
|
||||
import { UserListQuery } from "../../../../models/graphql/query.model";
|
||||
@ -10,17 +10,21 @@ import { AuthService } from "src/app/services/auth/auth.service";
|
||||
import { ToastService } from "src/app/services/toast/toast.service";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { Server } from "../../../../models/data/server.model";
|
||||
import { Subject } from "rxjs";
|
||||
import { takeUntil } from "rxjs/operators";
|
||||
|
||||
@Component({
|
||||
selector: "app-profile",
|
||||
templateUrl: "./profile.component.html",
|
||||
styleUrls: ["./profile.component.scss"]
|
||||
})
|
||||
export class ProfileComponent implements OnInit {
|
||||
export class ProfileComponent implements OnInit, OnDestroy {
|
||||
|
||||
user: User = { createdAt: "", modifiedAt: "" };
|
||||
private server: Server = {};
|
||||
|
||||
private unsubscriber = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
@ -32,10 +36,11 @@ export class ProfileComponent implements OnInit {
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
public ngOnInit(): void {
|
||||
this.route.params.pipe(takeUntil(this.unsubscriber)).subscribe(params => {
|
||||
this.data.getServerFromRoute(this.route).then(async (server) => {
|
||||
if (!this.route.snapshot.params["memberId"] || this.route.snapshot.params["memberId"] == "undefined") {
|
||||
this.router.navigate([`/server/${server.id}`]);
|
||||
if (!params["memberId"] || params["memberId"] == "undefined") {
|
||||
await this.router.navigate([`/server/${server.id}`]);
|
||||
return;
|
||||
}
|
||||
this.server = server;
|
||||
@ -43,17 +48,17 @@ export class ProfileComponent implements OnInit {
|
||||
let authUser = await this.auth.getLoggedInUser();
|
||||
this.spinner.showSpinner();
|
||||
let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
|
||||
if (!user || user?.id != this.route.snapshot.params["memberId"] && !user?.isModerator) {
|
||||
if (!user || user?.id != params["memberId"] && !user?.isModerator) {
|
||||
this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d"));
|
||||
this.spinner.hideSpinner();
|
||||
this.router.navigate(["/server", server.id]);
|
||||
await this.router.navigate(["/server", server.id]);
|
||||
return;
|
||||
}
|
||||
|
||||
this.data.query<UserListQuery>(Queries.usersQuery, {
|
||||
serverId: this.server.id,
|
||||
filter: {
|
||||
id: this.route.snapshot.params["memberId"]
|
||||
id: params["memberId"]
|
||||
}
|
||||
},
|
||||
(x: { servers: Server[] }) => {
|
||||
@ -67,7 +72,11 @@ export class ProfileComponent implements OnInit {
|
||||
this.spinner.hideSpinner();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
this.unsubscriber.next();
|
||||
this.unsubscriber.complete();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user