Skip to content

Commit

Permalink
move stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Dec 4, 2024
1 parent cfb80c0 commit 80a24bd
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 10 deletions.
5 changes: 3 additions & 2 deletions webapp/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Routes } from '@angular/router';
import { AboutComponent } from '@app/about/about.component';
import { HomeComponent } from '@app/home/home.component';
import { ChatComponent } from '@app/chat/chat/chat.component';
import { MentorComponent } from '@app/mentor/mentor.component';
import { WorkspaceComponent } from '@app/workspace/workspace.component';
import { UserProfileComponent } from '@app/user/user-profile.component';
import { WorkspaceUsersComponent } from './workspace/users/users.component';
Expand All @@ -12,6 +12,7 @@ import { ImprintComponent } from '@app/legal/imprint.component';
import { PrivacyComponent } from '@app/legal/privacy.component';
import { AdminGuard } from '@app/core/security/admin.guard';
import { AuthGuard } from '@app/core/security/auth.guard';
import { MentorGuard } from '@app/core/security/mentor.guard';

export const routes: Routes = [
// Public routes
Expand Down Expand Up @@ -39,7 +40,6 @@ export const routes: Routes = [
{ path: 'settings', component: SettingsComponent },
{ path: 'imprint', component: ImprintComponent },
{ path: 'privacy', component: PrivacyComponent },
{ path: 'chat', component: ChatComponent },
// Protected routes
{
path: '',
Expand All @@ -48,6 +48,7 @@ export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'user/:id', component: UserProfileComponent },
{ path: 'settings', component: SettingsComponent },
{ path: 'mentor', component: MentorComponent, canActivate: [MentorGuard] },
{ path: 'workspace', component: WorkspaceComponent, canActivate: [AdminGuard] }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class="border-cyan-500 cursor-pointer text-cyan-500 hover:text-cyan-500 hover:bg-cyan-500/10 dark:hover:bg-cyan-500/20 gap-2"
variant="outline"
[size]="iconOnly() ? 'icon' : 'default'"
[routerLink]="['/', 'chat']"
[routerLink]="['/', 'mentor']"
routerLinkActive="active"
>
<lucide-angular [img]="BotMessageSquare" class="size-4" />
Expand Down
26 changes: 26 additions & 0 deletions webapp/src/app/core/security/mentor.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { inject, Injectable, Injector } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { CanActivate, Router, UrlTree } from '@angular/router';
import { SecurityStore } from '@app/core/security/security-store.service';
import { filter, map, Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class MentorGuard implements CanActivate {
injector = inject(Injector);
securityStore = inject(SecurityStore);
router = inject(Router);

canActivate(): Observable<boolean | UrlTree> {
return toObservable(this.securityStore.loadedUser, { injector: this.injector }).pipe(
filter(Boolean),
map((user) => {
if (user && user.roles.includes('mentor_access')) {
return true;
}
return this.router.createUrlTree(['/']);
})
);
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { Component, inject, signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { lastValueFrom } from 'rxjs';
import { injectMutation, injectQuery } from '@tanstack/angular-query-experimental';
import { SessionsCardComponent } from '../sessions-card/sessions-card.component';
import { MessagesComponent } from '../messages/messages.component';
import { InputComponent } from '../input/input.component';
import { SessionsCardComponent } from './sessions-card/sessions-card.component';
import { MessagesComponent } from './messages/messages.component';
import { InputComponent } from './input/input.component';
import { SecurityStore } from '@app/core/security/security-store.service';
import { Message, Session } from '@app/core/modules/openapi';
import { MessageService, SessionService } from '@app/core/modules/openapi';
import { HlmButtonModule } from '@spartan-ng/ui-button-helm';
import { HlmSpinnerComponent } from '@spartan-ng/ui-spinner-helm';
import { FirstSessionCardComponent } from '../first-session-card/first-session-card.component';
import { FirstSessionCardComponent } from './first-session-card/first-session-card.component';

@Component({
selector: 'app-chat',
templateUrl: './chat.component.html',
selector: 'app-mentor',
templateUrl: './mentor.component.html',
standalone: true,
imports: [CommonModule, FirstSessionCardComponent, HlmSpinnerComponent, SessionsCardComponent, MessagesComponent, InputComponent, HlmButtonModule]
})
export class ChatComponent {
export class MentorComponent {
securityStore = inject(SecurityStore);
messageService = inject(MessageService);
sessionService = inject(SessionService);
Expand Down

0 comments on commit 80a24bd

Please sign in to comment.