diff --git a/angular.json b/angular.json index 6cf75b3..cd622ea 100644 --- a/angular.json +++ b/angular.json @@ -104,8 +104,8 @@ "browserTarget": "dafa-web:build:production" }, "api": { - "proxyConfig": "./config/proxy.conf.api.json", - "browserTarget": "dafa-web:build:api" + "browserTarget": "dafa-web:build:api", + "proxyConfig": "./config/proxy.conf.api.json" } } }, diff --git a/apps/dafa-web/src/app/app-routing.module.ts b/apps/dafa-web/src/app/app-routing.module.ts index e3f4280..8d1e1f4 100644 --- a/apps/dafa-web/src/app/app-routing.module.ts +++ b/apps/dafa-web/src/app/app-routing.module.ts @@ -1,56 +1,60 @@ import { NgModule } from '@angular/core'; import { ExtraOptions, RouterModule, Routes } from '@angular/router'; import { environment } from '@dafa-environment'; +import { AuthGuard } from '@dafa-guards/auth.guard'; const routes: Routes = [ { path: '', data: { title: '' }, loadChildren: () => import('./pages/start/start.module').then(m => m.StartModule), + canActivate: [AuthGuard], }, { path: 'administration', data: { title: 'Administration' }, loadChildren: () => import('./pages/administration/administration.module').then(m => m.AdministrationModule), + canActivate: [AuthGuard], }, { path: 'deltagare', data: { title: 'Deltagare' }, loadChildren: () => import('./pages/participants/participants.module').then(m => m.ParticipantsModule), + canActivate: [AuthGuard], }, { path: 'avrop', data: { title: 'Avrop' }, loadChildren: () => import('./pages/avrop/avrop.module').then(m => m.AvropModule), + canActivate: [AuthGuard], }, { path: 'meddelanden', data: { title: 'Meddelanden' }, loadChildren: () => import('./pages/messages/messages.module').then(m => m.MessagesModule), + canActivate: [AuthGuard], }, { path: 'statistik', data: { title: 'Statistik' }, loadChildren: () => import('./pages/statistics/statistics.module').then(m => m.StatisticsModule), + canActivate: [AuthGuard], }, { path: 'installningar', data: { title: 'Inställningar' }, loadChildren: () => import('./pages/settings/settings.module').then(m => m.SettingsModule), + canActivate: [AuthGuard], }, { path: 'releases', data: { title: 'Releases' }, loadChildren: () => import('./pages/releases/releases.module').then(m => m.ReleasesModule), - }, - { - path: 'ciam-landing', - data: { title: 'Ciam landing page' }, - loadChildren: () => import('./pages/ciam-landing/ciam-landing.module').then(m => m.CiamLandingModule), + canActivate: [AuthGuard], }, { path: 'logout', - data: { title: 'Ciam landing page' }, + data: { title: 'Logga ut' }, loadChildren: () => import('./pages/logout/logout.module').then(m => m.LogoutModule), }, ]; @@ -67,6 +71,7 @@ routes.push({ path: '**', data: { title: 'Sidan hittas inte' }, loadChildren: () => import('./pages/page-not-found/page-not-found.module').then(m => m.PageNotFoundModule), + canActivate: [AuthGuard], }); const options: ExtraOptions = { diff --git a/apps/dafa-web/src/app/app.component.html b/apps/dafa-web/src/app/app.component.html index c26b887..ea627a3 100644 --- a/apps/dafa-web/src/app/app.component.html +++ b/apps/dafa-web/src/app/app.component.html @@ -1,2 +1,3 @@ + - + diff --git a/apps/dafa-web/src/app/app.component.spec.ts b/apps/dafa-web/src/app/app.component.spec.ts index ba91f8b..7195d7e 100644 --- a/apps/dafa-web/src/app/app.component.spec.ts +++ b/apps/dafa-web/src/app/app.component.spec.ts @@ -3,16 +3,13 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; -import { NavigationModule } from './components/navigation/navigation.module'; -import { SidebarModule } from './components/sidebar/sidebar.module'; -import { SkipToContentModule } from './components/skip-to-content/skip-to-content.module'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [AppComponent], - imports: [RouterTestingModule, HttpClientTestingModule, SkipToContentModule, NavigationModule, SidebarModule], + imports: [RouterTestingModule, HttpClientTestingModule], }).compileComponents(); }); diff --git a/apps/dafa-web/src/app/app.component.ts b/apps/dafa-web/src/app/app.component.ts index 2f19f01..4dc758e 100644 --- a/apps/dafa-web/src/app/app.component.ts +++ b/apps/dafa-web/src/app/app.component.ts @@ -6,6 +6,4 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; styleUrls: ['./app.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AppComponent { - -} +export class AppComponent {} diff --git a/apps/dafa-web/src/app/app.module.ts b/apps/dafa-web/src/app/app.module.ts index ffcd494..8f8db09 100644 --- a/apps/dafa-web/src/app/app.module.ts +++ b/apps/dafa-web/src/app/app.module.ts @@ -1,42 +1,24 @@ -import { DigiNgNavigationBreadcrumbsModule } from '@af/digi-ng/_navigation/navigation-breadcrumbs'; -import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http'; +import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { ErrorHandler, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; -import { RouterModule } from '@angular/router'; +import { AuthGuard } from '@dafa-guards/auth.guard'; import { CustomErrorHandler } from '@dafa-interceptors/custom-error-handler.module'; -import { MarkdownModule } from 'ngx-markdown'; +import { AuthInterceptor } from '@dafa-services/api/auth.interceptor'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; -import { FooterModule } from './components/footer/footer.module'; -import { NavigationModule } from './components/navigation/navigation.module'; -import { SidebarModule } from './components/sidebar/sidebar.module'; -import { SkipToContentModule } from './components/skip-to-content/skip-to-content.module'; import { ToastListModule } from './components/toast-list/toast-list.module'; -import { AuthInterceptor } from '@dafa-services/api/auth.interceptor'; import { AvropModule } from './pages/avrop/avrop.module'; @NgModule({ declarations: [AppComponent], - imports: [ - BrowserModule, - HttpClientModule, - AppRoutingModule, - RouterModule, - SkipToContentModule, - NavigationModule, - SidebarModule, - ToastListModule, - FooterModule, - MarkdownModule.forRoot({ loader: HttpClient }), - DigiNgNavigationBreadcrumbsModule, - AvropModule, - ], + imports: [BrowserModule, HttpClientModule, AppRoutingModule, ToastListModule, AvropModule], providers: [ { provide: ErrorHandler, useClass: CustomErrorHandler, }, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }, + AuthGuard, ], bootstrap: [AppComponent], }) diff --git a/apps/dafa-web/src/app/components/logged-in-shell/logged-in-shell.module.ts b/apps/dafa-web/src/app/components/logged-in-shell/logged-in-shell.module.ts deleted file mode 100644 index 808e94e..0000000 --- a/apps/dafa-web/src/app/components/logged-in-shell/logged-in-shell.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { LoggedInShellComponent } from './logged-in-shell.component'; -import { SkipToContentModule } from '../skip-to-content/skip-to-content.module'; -import { NavigationModule } from '../navigation/navigation.module'; -import { SidebarModule } from '../sidebar/sidebar.module'; -import { DigiNgNavigationBreadcrumbsModule } from '@af/digi-ng/_navigation/navigation-breadcrumbs'; -import { FooterModule } from '../footer/footer.module'; -import { ToastListModule } from '../toast-list/toast-list.module'; -import { RouterModule } from '@angular/router'; - -@NgModule({ - imports: [ - RouterModule, - CommonModule, - SkipToContentModule, - NavigationModule, - SidebarModule, - DigiNgNavigationBreadcrumbsModule, - FooterModule, - ToastListModule, - ], - declarations: [LoggedInShellComponent], - exports: [LoggedInShellComponent], -}) -export class LoggedInShellModule {} diff --git a/apps/dafa-web/src/app/data/models/authentication.model.ts b/apps/dafa-web/src/app/data/models/authentication.model.ts index 8187b51..5629677 100644 --- a/apps/dafa-web/src/app/data/models/authentication.model.ts +++ b/apps/dafa-web/src/app/data/models/authentication.model.ts @@ -1,15 +1,9 @@ - - export interface AuthenticationResult { idToken: string; expiresIn: number; } export interface AuthenticationApiResponse { - data: AuthenticationApiResponseData; -} - -export interface AuthenticationApiResponseData { id: string; access_token: string; scope: string; @@ -18,12 +12,10 @@ export interface AuthenticationApiResponseData { expires_in: number; } -export function mapAuthApiResponseToAuthenticationResult(data: AuthenticationApiResponseData): AuthenticationResult { - const { - id_token, - expires_in } = data; +export function mapAuthApiResponseToAuthenticationResult(data: AuthenticationApiResponse): AuthenticationResult { + const { id_token, expires_in } = data; return { idToken: id_token, - expiresIn: expires_in + expiresIn: expires_in, }; } diff --git a/apps/dafa-web/src/app/guards/auth.guard.ts b/apps/dafa-web/src/app/guards/auth.guard.ts new file mode 100644 index 0000000..1a6ebd0 --- /dev/null +++ b/apps/dafa-web/src/app/guards/auth.guard.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router'; +import { environment } from '@dafa-environment'; +import { AuthenticationService } from '@dafa-services/api/authentication.service'; +import { Observable, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; + +@Injectable() +export class AuthGuard implements CanActivate { + constructor(private authenticationService: AuthenticationService, private router: Router) {} + + canActivate(route: ActivatedRouteSnapshot): Observable { + return this.authenticationService.isLoggedIn$.pipe( + switchMap(loggedIn => { + if (loggedIn) { + return of(true); + } else if (route.queryParams.code) { + return this.authenticationService.login$(route.queryParams.code).pipe(map(result => !!result)); + } + + if (environment.environment === 'local') { + void this.router.navigateByUrl(environment.loginUrl); + } else { + document.location.href = `${environment.loginUrl}&client_id=${environment.clientId}&redirect_uri=${environment.redirectUri}`; + } + return of(false); + }) + ); + } +} diff --git a/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.component.html b/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.component.html index 802374d..cb67d50 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.component.html +++ b/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.component.html @@ -1,4 +1,4 @@ - +
@@ -90,4 +90,4 @@ Info saknas - + diff --git a/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.module.ts b/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.module.ts index 48a0f03..456023e 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.module.ts +++ b/apps/dafa-web/src/app/pages/administration/pages/employee-card/employee-card.module.ts @@ -3,10 +3,10 @@ import { DigiNgSkeletonBaseModule } from '@af/digi-ng/_skeleton/skeleton-base'; import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; +import { HideTextModule } from '@dafa-shared/components/hide-text/hide-text.module'; +import { LayoutModule } from '@dafa-shared/components/layout/layout.module'; import { LocalDatePipeModule } from '@dafa-shared/pipes/local-date/local-date.module'; import { EmployeeCardComponent } from './employee-card.component'; -import { LoggedInShellModule } from '../../../../components/logged-in-shell/logged-in-shell.module'; -import { HideTextModule } from '@dafa-shared/components/hide-text/hide-text.module'; @NgModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], @@ -14,11 +14,11 @@ import { HideTextModule } from '@dafa-shared/components/hide-text/hide-text.modu imports: [ CommonModule, RouterModule.forChild([{ path: '', component: EmployeeCardComponent }]), + LayoutModule, DigiNgSkeletonBaseModule, DigiNgLayoutExpansionPanelModule, LocalDatePipeModule, HideTextModule, - LoggedInShellModule ], }) export class EmployeeCardModule {} diff --git a/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.component.html b/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.component.html index 48811a8..0ebeedf 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.component.html +++ b/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.component.html @@ -1,158 +1,164 @@ - +
- -

Skapa nytt konto

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam magna neque, interdum vel massa eget, condimentum - rutrum velit. Sed vitae ullamcorper sem. Aliquam malesuada nunc sed purus mollis scelerisque. Curabitur bibendum - leo quis ante porttitor tincidunt. Nam tincidunt imperdiet tortor eu suscipit. Maecenas ut dui est. -

-
-
- - {{ - error.message - }} - + +

Skapa nytt konto

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam magna neque, interdum vel massa eget, condimentum + rutrum velit. Sed vitae ullamcorper sem. Aliquam malesuada nunc sed purus mollis scelerisque. Curabitur bibendum + leo quis ante porttitor tincidunt. Nam tincidunt imperdiet tortor eu suscipit. Maecenas ut dui est. +

+
+ + + {{ + error.message + }} + -
- -

Personuppgifter

-
- - - -
-
-
+
- Tjänster +

Personuppgifter

+ + + +
+
+
+ + Tjänster + -
    -
  • - -
  • -
- +
  • + +
  • + + + {{ servicesControl.errors.message }} + +
    +
    + +
    +
    + + Tilldela behörigheter + + +
      +
    • + + + Läs mer + +
    • +
    + + {{ authorizationsControl.errors.message }} + +
    +
    + +
    -
    + Registrera konto +
    -
    -
    - - Tilldela behörigheter - + + +

    + Behörigheten passar personer som arbetar nära deltagare. Behörigheten kan användas av exempelvis handledare, + coacher, studie- och yrkesvägledare, lärare eller annan roll som behöver kunna se information om deltager, + kontakta deltagare, planera aktiviteter med deltagre och hantera rapporter för deltagre. +

    -
      -
    • - - - Läs mer - -
    • -
    - - {{ authorizationsControl.errors.message }} - -
    -
    +

    Behörigheten ger tillgång till och utföra aktiviteter i följande funktioner i systemet:

    - - - - -

    - Behörigheten passar personer som arbetar nära deltagare. - Behörigheten kan användas av exempelvis handledare, coacher, studie- och yrkesvägledare, - lärare eller annan roll som behöver kunna se information om deltager, kontakta deltagare, - planera aktiviteter med deltagre och hantera rapporter för deltagre. -

    - -

    - Behörigheten ger tillgång till och utföra aktiviteter i följande funktioner i systemet: -

    - -

    - - Deltagarlista
    - - Information om deltagare
    - - Resultatrapporter
    - - Slutredovisning
    - - Informativ rapport
    - - Skicka välkomstbrev *
    - - Planera deltagares aktiviteter
    - - Deltagares schema
    - - Avvikelserapporter
    - - Närvaro- och frånvarorapporter

    -

    -
    - -
    -
    +

    + - Deltagarlista
    + - Information om deltagare
    + - Resultatrapporter
    + - Slutredovisning
    + - Informativ rapport
    + - Skicka välkomstbrev *
    + - Planera deltagares aktiviteter
    + - Deltagares schema
    + - Avvikelserapporter
    + - Närvaro- och frånvarorapporter

    +

    + + + + diff --git a/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.module.ts b/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.module.ts index 323ea66..adf1668 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.module.ts +++ b/apps/dafa-web/src/app/pages/administration/pages/employee-form/employee-form.module.ts @@ -1,3 +1,4 @@ +import { DigiNgDialogModule } from '@af/digi-ng/_dialog/dialog'; import { DigiNgFormCheckboxModule } from '@af/digi-ng/_form/form-checkbox'; import { DigiNgFormDatepickerModule } from '@af/digi-ng/_form/form-datepicker'; import { DigiNgFormInputModule } from '@af/digi-ng/_form/form-input'; @@ -8,10 +9,9 @@ import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { ReactiveFormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; +import { LayoutModule } from '@dafa-shared/components/layout/layout.module'; import { LocalDatePipeModule } from '@dafa-shared/pipes/local-date/local-date.module'; import { EmployeeFormComponent } from './employee-form.component'; -import { DigiNgDialogModule } from '@af/digi-ng/_dialog/dialog'; -import { LoggedInShellModule } from '../../../../components/logged-in-shell/logged-in-shell.module'; @NgModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], @@ -19,6 +19,7 @@ import { LoggedInShellModule } from '../../../../components/logged-in-shell/logg imports: [ CommonModule, RouterModule.forChild([{ path: '', component: EmployeeFormComponent }]), + LayoutModule, ReactiveFormsModule, LocalDatePipeModule, DigiNgFormInputModule, @@ -28,7 +29,6 @@ import { LoggedInShellModule } from '../../../../components/logged-in-shell/logg DigiNgPopoverModule, DigiNgFormCheckboxModule, DigiNgDialogModule, - LoggedInShellModule - ] + ], }) export class EmployeeFormModule {} diff --git a/apps/dafa-web/src/app/pages/administration/pages/employees/components/employees-list/employees-list.component.html b/apps/dafa-web/src/app/pages/administration/pages/employees/components/employees-list/employees-list.component.html index 913239a..caaefb6 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employees/components/employees-list/employees-list.component.html +++ b/apps/dafa-web/src/app/pages/administration/pages/employees/components/employees-list/employees-list.component.html @@ -4,9 +4,13 @@ -