Skip to content

Commit

Permalink
Updated Moderator Check to Use Permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelicButter committed Nov 14, 2024
1 parent 4304e91 commit 947e5a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/app/constants/UserPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export enum UserPermissions {
UPDATE_USERS = "update_users",
ADD_ENTRY = "add_entry",
DELETE_ENTRY = "delete_entry",
MODIFY_ENTRY = "modify_entry"
MODIFY_ENTRY = "modify_entry",
STAFF = "staff"
}
2 changes: 1 addition & 1 deletion src/app/services/authentication/auth-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AuthUserService {
}

isModerator() {
return this.user !== null && !this.user.role_name.includes("user");
return this.user !== null && this.userPermissions.includes(UserPermissions.STAFF);
}

isSameUser(username: string) {
Expand Down
17 changes: 5 additions & 12 deletions src/app/services/authentication/is-moderator.guard.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import { inject } from "@angular/core";
import { Router } from "@angular/router";
import { tap } from "rxjs";
import { AuthenticationService } from "./authentication.service";
import { AuthUserService } from "./auth-user.service";

export const IsModeratorGuard = () => {
const router = inject(Router);
const authService = inject(AuthenticationService);
const AuthUser = inject(AuthUserService);

if (!AuthUser.user) {
router.navigate(["/"]);
return;
}

return authService.validateCookies().pipe(
tap((value) => {
if (!value || !AuthUser.isModerator()) {
router.navigate(["/login"]);
return;
}
if (!AuthUser.isModerator()) {
router.navigate(["/login"]);
return;
}

return true;
})
);
return true;
};

0 comments on commit 947e5a1

Please sign in to comment.