Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create api routes for /admin #1318

Merged
merged 33 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1c04768
chore: generate app-api lib with nx with ProjectApiService
derschnee68 Nov 30, 2023
13b56b8
feat: add user-api service
derschnee68 Dec 1, 2023
b082586
feat: add group-api service
derschnee68 Dec 1, 2023
07922e9
feat: add list-api service
derschnee68 Dec 4, 2023
6388b93
feat: add health and version api service
derschnee68 Dec 4, 2023
1514d42
feat: add permissions service
derschnee68 Dec 4, 2023
5a02e5d
feat: add listv2 api service
derschnee68 Dec 4, 2023
309b282
chore: move admin services
derschnee68 Dec 4, 2023
1b40c19
wip
derschnee68 Dec 4, 2023
03d50ad
Merge branch 'main' into feature/dev-3042-create-project-api-service
derschnee68 Dec 4, 2023
0190e0e
feat: works but I have added too many files
derschnee68 Dec 4, 2023
8cfcefd
chore: remove added useless files
derschnee68 Dec 5, 2023
17e3108
feat: add list-v2-api service
derschnee68 Dec 6, 2023
461702f
feat: add ontology-v2-api service
derschnee68 Dec 7, 2023
2dde94f
feat: add ontology api service
derschnee68 Dec 8, 2023
004afc4
feat: refactor list info form
derschnee68 Dec 8, 2023
7fafe20
refactor: use internal http for /admin/projects endpoint
derschnee68 Dec 11, 2023
27d79b4
refactor: use internal http for /admin/users endpoint
derschnee68 Dec 11, 2023
0da6e44
refactor: use internal http for /admin/lists endpoint
derschnee68 Dec 11, 2023
3dde1d2
refactor: update user components
derschnee68 Dec 11, 2023
eb54298
Merge remote-tracking branch 'origin/main' into feature/dev-3042-crea…
derschnee68 Dec 11, 2023
99f6361
fix: linting no-unused-vars
derschnee68 Dec 11, 2023
96ba949
fix: linting works within all apps
derschnee68 Dec 11, 2023
ece02cf
wip: improve auth workflow
derschnee68 Dec 11, 2023
622ca77
Merge remote-tracking branch 'origin/main' into feature/dev-3042-crea…
derschnee68 Dec 12, 2023
11dc40d
chore: rollback files only changed with indentation
derschnee68 Dec 12, 2023
8f4f489
refactor: add auth interceptor
derschnee68 Dec 12, 2023
317baa1
fix: read project bug
derschnee68 Dec 12, 2023
e27c1aa
fix: project issues
derschnee68 Dec 13, 2023
49d2e25
Merge remote-tracking branch 'origin/main' into feature/dev-3042-crea…
derschnee68 Dec 15, 2023
a34e18a
Merge remote-tracking branch 'origin/main' into feature/dev-3042-crea…
derschnee68 Dec 18, 2023
a99e6f9
fix: dont use cache for CI
derschnee68 Dec 18, 2023
a1e4a6f
fix: mixed-object lint errors
derschnee68 Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: "Run npm install"
run: |
npm install
npx nx run-many --all --target=lint
npx nx run-many --all --target=lint --skip-nx-cache
# npx nx run-many --all --target=test --configuration=ci
env:
TZ: Europe/Zurich
Expand Down
2 changes: 1 addition & 1 deletion apps/dateAdapter/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class AppComponent {
`,
styleUrls: [],
})
export class HeaderComponent<D> implements OnInit {
export class HeaderComponent implements OnInit {
constructor(
private _calendar: MatCalendar<JDNConvertibleCalendar>,
private _dateAdapter: DateAdapter<JDNConvertibleCalendar>,
Expand Down
3 changes: 2 additions & 1 deletion apps/dsp-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const routes: Routes = [
},
{
path: `${RouteConstants.list}/:${RouteConstants.listParameter}`,
component: ListComponent
component: ListComponent,
canActivate: [AuthGuard]
},
{
path: RouteConstants.settings,
Expand Down
36 changes: 23 additions & 13 deletions apps/dsp-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-disable max-len */
import { ClipboardModule } from '@angular/cdk/clipboard';
import { CommonModule } from '@angular/common';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import {
HTTP_INTERCEPTORS,
HttpClient,
HttpClientModule,
} from '@angular/common/http';
import { ErrorHandler, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
Expand All @@ -13,7 +17,14 @@
import { MatJDNConvertibleCalendarDateAdapterModule } from '@dasch-swiss/jdnconvertiblecalendardateadapter';
import { PdfViewerModule } from 'ng2-pdf-viewer';
import { ColorPickerModule } from 'ngx-color-picker';
import { AppConfigService } from '@dasch-swiss/vre/shared/app-config';
import {
AppConfigService,
buildTagFactory,
BuildTagToken,
DspApiConfigToken,
DspAppConfigToken,
DspInstrumentationToken,
} from '@dasch-swiss/vre/shared/app-config';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ConfirmationDialogComponent } from './main/action/confirmation-dialog/confirmation-dialog.component';
Expand All @@ -22,11 +33,6 @@
import { SelectedResourcesComponent } from './main/action/selected-resources/selected-resources.component';
import { SortButtonComponent } from './main/action/sort-button/sort-button.component';
import { CookiePolicyComponent } from './main/cookie-policy/cookie-policy.component';
import {
DspApiConfigToken,
DspAppConfigToken,
DspInstrumentationToken,
} from '@dasch-swiss/vre/shared/app-config';
import { DialogHeaderComponent } from './main/dialog/dialog-header/dialog-header.component';
import { DialogComponent } from './main/dialog/dialog.component';
import { AdminImageDirective } from './main/directive/admin-image/admin-image.directive';
Expand Down Expand Up @@ -148,21 +154,19 @@
import { ProjectTileComponent } from './system/project-tile/project-tile.component';
import { CommentFormComponent } from './workspace/resource/values/comment-form/comment-form.component';
import { DataModelsComponent } from './project/data-models/data-models.component';
import { ResourceClassPropertyInfoComponent } from '@dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component';

Check warning on line 157 in apps/dsp-app/src/app/app.module.ts

View workflow job for this annotation

GitHub Actions / DSP-APP

Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component"

Check warning on line 157 in apps/dsp-app/src/app/app.module.ts

View workflow job for this annotation

GitHub Actions / test

Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component"
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging';
import {
buildTagFactory,
BuildTagToken,
} from '@dasch-swiss/vre/shared/app-config';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { AppDatePickerComponent } from '@dasch-swiss/vre/shared/app-date-picker';
import { AdvancedSearchComponent } from '@dasch-swiss/vre/advanced-search';
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
import { apiConnectionTokenProvider } from './providers/api-connection-token.provider';
import { NgxsStoreModule } from '@dasch-swiss/vre/shared/app-state';
import { AppProgressIndicatorComponent } from "@dasch-swiss/vre/shared/app-progress-indicator";
import {AppStringLiteralComponent} from "@dasch-swiss/vre/shared/app-string-literal";
import { AppProgressIndicatorComponent } from '@dasch-swiss/vre/shared/app-progress-indicator';
import { AppStringLiteralComponent } from '@dasch-swiss/vre/shared/app-string-literal';
import { IsFalsyPipe } from './main/pipes/isFalsy.piipe';
import { AuthGuardComponent } from '@dsp-app/src/app/main/guard/auth-guard.component';

Check warning on line 168 in apps/dsp-app/src/app/app.module.ts

View workflow job for this annotation

GitHub Actions / DSP-APP

Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@dsp-app/src/app/main/guard/auth-guard.component"
import { AuthInterceptor } from './main/http-interceptors/auth-interceptor';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
Expand All @@ -180,6 +184,7 @@
AppComponent,
ArchiveComponent,
AudioComponent,
AuthGuardComponent,
AvTimelineComponent,
DescriptionComponent,
BooleanValueComponent,
Expand Down Expand Up @@ -360,6 +365,11 @@
useClass: AppErrorHandler,
deps: [AppLoggingService],
},
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true,
},
],
bootstrap: [AppComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class ConfirmationDialogComponent {
}

onConfirmClick(): void {
const z = 0;
const payload = new ConfirmationDialogValueDeletionPayload();
payload.confirmed = true;
payload.deletionComment = this.confirmationMessageComponent.comment
Expand Down
14 changes: 14 additions & 0 deletions apps/dsp-app/src/app/main/guard/auth-guard.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Router } from '@angular/router';
import { RouteConstants } from '@dasch-swiss/vre/shared/app-config';

// empty component used as a redirect when the user logs in
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
template: ''
})
export class AuthGuardComponent {
constructor(private router: Router) {
this.router.navigate([RouteConstants.home], { replaceUrl: true });
}
}
71 changes: 27 additions & 44 deletions apps/dsp-app/src/app/main/guard/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,58 @@
import { ChangeDetectionStrategy, Component, Inject, Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { Inject, Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { Actions, ofActionCompleted, Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { concatMap, map, switchMap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ReadUser } from '@dasch-swiss/dsp-js';
import { AuthService } from '@dasch-swiss/vre/shared/app-session';
import { RouteConstants } from '@dasch-swiss/vre/shared/app-config';
import { CurrentPageSelectors, SetUserAction, UserSelectors } from '@dasch-swiss/vre/shared/app-state';

import {
CurrentPageSelectors,
SetUserAction,
UserSelectors,
} from '@dasch-swiss/vre/shared/app-state';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class AuthGuard implements CanActivate {

isLoggedIn$: Observable<boolean> = this._authService.isLoggedIn$;

@Select(UserSelectors.user) user$: Observable<ReadUser>;

constructor(
private store: Store,
private _authService: AuthService,
private actions$: Actions,
@Inject(DOCUMENT) private document: Document
) {
}
) {}

canActivate(): Observable<boolean> {
return this.user$.pipe(
switchMap((user) => {
if (!user) {
if (this.store.selectSnapshot(UserSelectors.isLoading)) {
return this.actions$.pipe(
ofActionCompleted(SetUserAction),
concatMap(() => {
return this.isLoggedIn$;
})
);
} else {
return this.store.dispatch(new SetUserAction(user)).pipe(
concatMap(() => {
return this.isLoggedIn$;
})
);
}
if (user) return of(null);

if (this.store.selectSnapshot(UserSelectors.isLoading)) {
return this.actions$.pipe(ofActionCompleted(SetUserAction));
} else {
return this.store.dispatch(new SetUserAction(user));
}
return this.isLoggedIn$;
}),
switchMap(() => this._authService.isLoggedIn$),
map((isLoggedIn) => {
if (isLoggedIn) {
return true;
} else {
this._goToHomePage();
return false;
}
this.document.defaultView.location.href =
`${this.document.defaultView.location.href}?` +
`returnLink=${this.store.selectSnapshot(
CurrentPageSelectors.loginReturnLink
)}`;
return false;
})
);
}
}

// empty component used as a redirect when the user logs in
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
template: ''
})
export class AuthGuardComponent {
constructor(private router: Router) {
this.router.navigate([RouteConstants.home], { replaceUrl: true });
private _goToHomePage() {
this.document.defaultView.location.href =
`${this.document.defaultView.location.href}?` +
`returnLink=${this.store.selectSnapshot(
CurrentPageSelectors.loginReturnLink
)}`;
}
}
33 changes: 33 additions & 0 deletions apps/dsp-app/src/app/main/http-interceptors/auth-interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
HttpHandler,
HttpInterceptor,
HttpRequest,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthService } from '@dasch-swiss/vre/shared/app-session';
import { AppConfigService } from '@dasch-swiss/vre/shared/app-config';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(
private _authService: AuthService,
private _appConfigService: AppConfigService
) {}

intercept(req: HttpRequest<any>, next: HttpHandler) {
if (!req.url.startsWith(this._appConfigService.dspApiConfig.apiUrl)) {
return next.handle(req);
}

const authToken = this._authService.getAccessToken();
if (!authToken) return next.handle(req);

const authReq = req.clone({
headers: req.headers.set(
'Authorization',
`Bearer ${this._authService.getAccessToken()}`
),
});
return next.handle(authReq);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DataModelsComponent extends ProjectBase implements OnInit {
if (!uuid) {
return of({} as OntologyMetadata[]);
}

return this._store.select(OntologiesSelectors.projectOntologies)
.pipe(
map(ontologies => {
Expand Down Expand Up @@ -66,9 +66,6 @@ export class DataModelsComponent extends ProjectBase implements OnInit {

ngOnInit(): void {
super.ngOnInit();
const uuid = this._route.parent.snapshot.params.uuid;
//TODO Soft or Hard loading?
//this._store.dispatch(new LoadListsInProjectAction(uuid));
}

trackByFn = (index: number, item: ListNodeInfo) => `${index}-${item.id}`;
Expand Down