Skip to content

Commit

Permalink
move user service to common
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmattig committed Nov 11, 2024
1 parent 277f085 commit fd033ff
Show file tree
Hide file tree
Showing 48 changed files with 474 additions and 511 deletions.
2 changes: 2 additions & 0 deletions projects/common/src/lib/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CommonConfigStructure {
readonly API_URL: string;
readonly DELAYS: Delays;
readonly PLOTS: Plots;
readonly AUTO_GUEST_LOGIN: boolean;
}

/**
Expand All @@ -31,6 +32,7 @@ export const DEFAULT_COMMON_CONFIG: CommonConfigStructure = {
PLOTS: {
THEME: 'excel',
},
AUTO_GUEST_LOGIN: true,
};

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion projects/common/src/lib/datasets/datasets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DatasetsService {

constructor(private sessionService: UserService) {
this.sessionService.getSessionStream().subscribe({
next: (session) => this.datasetApi.next(new DatasetsApi(apiConfigurationWithAccessKey(session.id))),
next: (session) => this.datasetApi.next(new DatasetsApi(apiConfigurationWithAccessKey(session.sessionToken))),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class LayersService {
private randomColorService: RandomColorService,
) {
this.sessionService.getSessionStream().subscribe({
next: (session) => this.layersApi.next(new LayersApi(apiConfigurationWithAccessKey(session.id))),
next: (session) => this.layersApi.next(new LayersApi(apiConfigurationWithAccessKey(session.sessionToken))),
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/common/src/lib/permissions/permissions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class PermissionsService {

constructor(private sessionService: UserService) {
this.sessionService.getSessionStream().subscribe({
next: (session) => this.permissionsApi.next(new PermissionsApi(apiConfigurationWithAccessKey(session.id))),
next: (session) => this.permissionsApi.next(new PermissionsApi(apiConfigurationWithAccessKey(session.sessionToken))),
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/common/src/lib/plots/plots.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PlotsService {

constructor(private sessionService: UserService) {
this.sessionService.getSessionStream().subscribe({
next: (session) => this.plotApi.next(new PlotsApi(apiConfigurationWithAccessKey(session.id))),
next: (session) => this.plotApi.next(new PlotsApi(apiConfigurationWithAccessKey(session.sessionToken))),
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/common/src/lib/uploads/uploads.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class UploadsService {

constructor(private sessionService: UserService) {
this.sessionService.getSessionStream().subscribe({
next: (session) => this.uploadsApi.next(new UploadsApi(apiConfigurationWithAccessKey(session.id))),
next: (session) => this.uploadsApi.next(new UploadsApi(apiConfigurationWithAccessKey(session.sessionToken))),
});
}

Expand Down
16 changes: 16 additions & 0 deletions projects/common/src/lib/user/session.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Moment} from 'moment';
import {Configuration, STRectangle} from '@geoengine/openapi-client';
import {UUID} from '../datasets/dataset.model';
import {User} from './user.model';

/**
* A user session after login
*/
export interface Session {
sessionToken: string;
user?: User; // TODO: split for pro
apiConfiguration: Configuration;
validUntil: Moment; // TODO: custom time point?
lastProjectId?: UUID;
lastView?: STRectangle;
}
53 changes: 53 additions & 0 deletions projects/common/src/lib/user/user.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {HttpErrorResponse} from '@angular/common/http';
import {Quota as QuotaDict} from '@geoengine/openapi-client';

/**
* This class represents a geo engine user.
*/
export class User {
id: string;

realName?: string;
email?: string;

isGuest: boolean;

constructor(config: {id: string; realName?: string; email?: string}) {
this.id = config.id;
this.realName = config.realName;
this.email = config.email;

this.isGuest = !config.email || !config.realName;
}
}

/**
* This interface represents the status of the used geo engine backend.
*/
export interface BackendStatus {
available: boolean;
httpError?: HttpErrorResponse;
initial?: boolean;
}

export class Quota {
protected _used: number;
protected _available: number;

constructor(used: number, available: number) {
this._used = used;
this._available = available;
}

get used(): number {
return this._used;
}

get available(): number {
return this._available;
}

static fromDict(dict: QuotaDict): Quota {
return new Quota(dict.used, dict.available);
}
}
Loading

0 comments on commit fd033ff

Please sign in to comment.