Skip to content

Commit

Permalink
Merge branch 'main' into feature/remove-legeacy-mat-checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mimse authored Aug 28, 2023
2 parents 067531a + f0870b1 commit c19171c
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 163 deletions.
6 changes: 6 additions & 0 deletions apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public GraphQLQuery()
var gridAreas = await client.GetGridAreasAsync();
var gridAreaLookup = gridAreas.ToDictionary(x => x.Id);
var actorDto = await client.GetActorAsync(context.GetArgument<Guid>("id"));
var organization = await client.GetOrganizationAsync(actorDto.OrganizationId);
var actor = new Actor(actorDto.ActorId, actorDto.Name.Value, actorDto.ActorNumber.Value)
{
GridAreas = actorDto.MarketRoles
Expand All @@ -236,6 +238,7 @@ public GraphQLQuery()
MarketRole = actorDto.MarketRoles.FirstOrDefault()?.EicFunction,
Status = actorDto.Status,
Organization = organization,
};
return actor;
});
Expand All @@ -249,6 +252,8 @@ public GraphQLQuery()
{
var eicFunctions = context.GetArgument("eicFunctions", Array.Empty<EicFunction>());
var gridAreas = await client.GetGridAreasAsync();
var organizations = await client.GetOrganizationsAsync();
var organizationLookup = organizations.ToDictionary(x => x.OrganizationId);
var gridAreaLookup = gridAreas.ToDictionary(x => x.Id);
var actors = await client.GetActorsAsync();
Expand All @@ -270,6 +275,7 @@ public GraphQLQuery()
MarketRole = x.MarketRoles.FirstOrDefault()?.EicFunction,
Status = x.Status,
Organization = organizationLookup[x.OrganizationId],
});
// TODO: Is this the right place to filter this list?
Expand Down
2 changes: 2 additions & 0 deletions apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Actor

public ActorStatus Status { get; set; }

public OrganizationDto? Organization { get; set; }

public Actor(Guid id, string name, string glnOrEicNumber)
{
Id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public ActorDtoType()
.Resolve(x => x.Source.Status)
.Description("The status of the actor.");

Field<OrganizationDtoType>("organization")
.Resolve(x => x.Source.Organization)
.Description("The organization of the actor.");

// Below are commented out since the actor number is currently
// the only field that market participant and wholesale have in common
// AND it is also not currently possible to get actor information from
Expand Down
209 changes: 105 additions & 104 deletions libs/dh/shared/domain/src/lib/generated/graphql.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export class EoScopeGuard implements CanActivate {

return this.authStore.getScope$.pipe(
map((scope) => {
if (scope.includes('not-accepted-terms')) this.router.navigate(['/terms']);
if (scope.includes('not-accepted-privacypolicy-terms')) this.router.navigate(['/terms']);
if (!this.authStore.token.getValue()) this.router.navigate(['']);

return !!scope.includes('accepted-terms');
return !scope.includes('not-accepted-privacypolicy-terms');
})
);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/eo/core/shell/src/lib/eo-login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class EoLoginComponent {
this.router.navigate(['/'], { queryParamsHandling: 'preserve' });
} else if (isTokenExpired) {
this.service.logout();
} else if (scope.includes('not-accepted-terms')) {
} else if (scope.includes('not-accepted-privacypolicy-terms')) {
this.router.navigate(['/terms']);
} else if (scope.includes('accepted-terms') && scope.includes('dashboard')) {
} else if (scope.includes('dashboard')) {
this.router.navigate(['/dashboard']);
} else this.router.navigate(['/'], { queryParamsHandling: 'preserve' });
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "version": 1 }
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AsyncPipe } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AsyncPipe, NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

import { WattEmptyStateComponent } from '@energinet-datahub/watt/empty-state';

import { EoScrollViewComponent } from '@energinet-datahub/eo/shared/atomic-design/ui-atoms';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [EoScrollViewComponent, AsyncPipe],
imports: [EoScrollViewComponent, AsyncPipe, NgIf, WattEmptyStateComponent],
selector: 'eo-privacy-policy',
styles: [
`
:host {
display: block;
}
small {
color: var(--watt-color-neutral-grey-700);
}
.policy ::ng-deep {
:host ::ng-deep {
h2 {
margin-bottom: 16px;
}
Expand Down Expand Up @@ -85,10 +83,21 @@ import { EoScrollViewComponent } from '@energinet-datahub/eo/shared/atomic-desig
}
`,
],
template: ` <div class="policy" [innerHTML]="privacyPolicy$ | async"></div> `,
template: `
<ng-container *ngIf="policy; else fallback">
<div [innerHTML]="policy"></div>
</ng-container>
<ng-template #fallback>
<watt-empty-state
icon="danger"
title="Oops, we could not load the privacy policy!"
message="Please ensure that you have no browser extensions blocking the privacy policy enabled. Try turning off possible ad blockers and reloading the page."
></watt-empty-state>
</ng-template>
`,
})
export class EoPrivacyPolicyComponent {
privacyPolicy$ = this.http.get('/assets/html/privacy-policy.html', { responseType: 'text' });

constructor(private http: HttpClient) {}
@Input() policy!: string | null;
@Input() hasError = false;
}
5 changes: 1 addition & 4 deletions libs/eo/shared/services/src/auth/auth.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export interface EoLoginToken {
exp?: number;
name?: string;
nbf?: number;
/** @example "accepted-terms dashboard production meters certificates" */
/** @example "dashboard production meters certificates" */
scope?: string;
sub?: string;
/** @example 3 - To indicate that the latest terms version is 3 */
trm?: number;
tin?: string;
}

Expand All @@ -46,7 +44,6 @@ export class EoAuthStore extends ComponentStore<AuthState> {
getScope$ = this.select((state) => state.scope?.split(' ') ?? []);
getTokenNotBefore$ = this.select((state) => state.nbf ?? 0);
getTokenExpiry$ = this.select((state) => state.exp ?? 0);
getTermsVersion$ = this.select((state) => state.trm);
getTin$ = this.select((state) => state.tin);
isTokenExpired$ = this.select((state) => Date.now() / 1000 > (state.exp ?? 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
import { EoAuthStore } from '../auth/auth.store';

const knownFeatures = [
'not-accepted-terms',
'accepted-terms',
'not-accepted-privacypolicy-terms',
'dashboard',
'production',
'meters',
Expand Down
27 changes: 6 additions & 21 deletions libs/eo/shared/services/src/terms/eo-terms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,25 @@
import { HttpClient } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { EoApiEnvironment, eoApiEnvironmentToken } from '@energinet-datahub/eo/shared/environments';
import { switchMap } from 'rxjs';
import { EoAuthStore } from '../auth/auth.store';

export interface AuthTermsResponse {
/**
* A single line of raw text
*/
readonly headline: string;
/**
* A string containing safe HTML
*/
readonly terms: string;
/**
* A string: I.eg: "0.1"
*/
readonly version: string;
}

@Injectable({
providedIn: 'root',
})
export class EoTermsService {
#apiBase: string;
private currentVersion = -1;
constructor(
private http: HttpClient,
private authStore: EoAuthStore,
@Inject(eoApiEnvironmentToken) apiEnvironment: EoApiEnvironment
) {
this.#apiBase = `${apiEnvironment.apiBase}`;
}

setVersion(version: number) {
this.currentVersion = version;
}

acceptTerms() {
return this.authStore.getTermsVersion$.pipe(
switchMap((version) => this.http.put(`${this.#apiBase}/terms/accept`, { version }))
);
return this.http.put(`${this.#apiBase}/terms/user/accept/${this.currentVersion}`, null);
}
}
60 changes: 45 additions & 15 deletions libs/eo/terms/src/lib/eo-terms.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AsyncPipe, NgIf } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { catchError, of, switchMap } from 'rxjs';

import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattCheckboxComponent } from '@energinet-datahub/watt/checkbox';
import { WattSpinnerComponent } from '@energinet-datahub/watt/spinner';

import { EoPrivacyPolicyComponent } from '@energinet-datahub/eo/shared/atomic-design/feature-molecules';
import { EoScrollViewComponent } from '@energinet-datahub/eo/shared/atomic-design/ui-atoms';
import {
EoFooterComponent,
EoHeaderComponent,
} from '@energinet-datahub/eo/shared/atomic-design/ui-organisms';
import { EoAuthService, EoAuthStore, EoTermsService } from '@energinet-datahub/eo/shared/services';
import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattCheckboxComponent } from '@energinet-datahub/watt/checkbox';
import { WattSpinnerComponent } from '@energinet-datahub/watt/spinner';
import { EoAuthService, EoTermsService } from '@energinet-datahub/eo/shared/services';

interface VersionResponse {
version: number;
}
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
Expand All @@ -42,6 +49,7 @@ import { WattSpinnerComponent } from '@energinet-datahub/watt/spinner';
EoScrollViewComponent,
WattSpinnerComponent,
NgIf,
AsyncPipe,
],
selector: 'eo-auth-terms',
styles: [
Expand Down Expand Up @@ -71,10 +79,17 @@ import { WattSpinnerComponent } from '@energinet-datahub/watt/spinner';
<div class="eo-layout-centered-content">
<div class="content-wrapper">
<eo-scroll-view class="watt-space-stack-l">
<eo-privacy-policy class="watt-space-stack-l"></eo-privacy-policy>
<eo-privacy-policy
class="watt-space-stack-l"
[policy]="privacyPolicy$ | async"
[hasError]="loadingPrivacyPolicyFailed"
></eo-privacy-policy>
</eo-scroll-view>
<div class="watt-space-stack-m">
<watt-checkbox [(ngModel)]="hasAcceptedPrivacyPolicy">
<watt-checkbox
[(ngModel)]="hasAcceptedPrivacyPolicy"
[disabled]="loadingPrivacyPolicyFailed"
>
I have seen the Privacy Policy
</watt-checkbox>
</div>
Expand All @@ -99,16 +114,31 @@ import { WattSpinnerComponent } from '@energinet-datahub/watt/spinner';
`,
})
export class EoTermsComponent {
private http = inject(HttpClient);
private termsService = inject(EoTermsService);
private authService = inject(EoAuthService);
private router = inject(Router);
private policyVersion$ = this.http.get<VersionResponse>(
'/assets/configuration/privacy-policy.json'
);

loadingPrivacyPolicyFailed = false;
privacyPolicy$ = this.policyVersion$.pipe(
switchMap((response) => {
this.termsService.setVersion(response.version);
return this.http.get('/assets/html/privacy-policy.html', { responseType: 'text' });
}),
catchError(() => {
this.termsService.setVersion(-1);
this.loadingPrivacyPolicyFailed = true;

return of(null);
})
);

hasAcceptedPrivacyPolicy = false;
startedAcceptFlow = false;

constructor(
private authService: EoAuthService,
private termsService: EoTermsService,
private authStore: EoAuthStore,
private router: Router
) {}

onCancel() {
this.authService.logout();
}
Expand Down
3 changes: 3 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ type Actor {

"""The status of the actor."""
status: ActorStatus

"""The organization of the actor."""
organization: Organization
}

enum ActorStatus {
Expand Down

0 comments on commit c19171c

Please sign in to comment.