Skip to content

Commit

Permalink
fix: allow admins to still change locations
Browse files Browse the repository at this point in the history
  • Loading branch information
cskiwi committed Aug 26, 2024
1 parent 7452745 commit 988389b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
19 changes: 19 additions & 0 deletions badman.babel
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,25 @@
<folder_node>
<name>errors</name>
<children>
<concept_node>
<name>closed</name>
<description/>
<comment/>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-BE</language>
<approved>false</approved>
</translation>
<translation>
<language>nl-BE</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>date-out-of-period</name>
<description/>
Expand Down
1 change: 1 addition & 0 deletions libs/backend/translate/assets/i18n/en/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"description": "Disclaimer: this is a first version of the encounter relocation tool. Improvements are periodically being applied.",
"disclaimer-submit": "Once both teams are available, the selected day can be chosen in the checkbox by then clicking on send",
"errors": {
"closed": "Movements are closed",
"date-out-of-period": "The date is outside the allowed period (September to April)",
"exception-day": "No competition may be played on this day",
"invalid": "Please complete all availability before sending",
Expand Down
1 change: 1 addition & 0 deletions libs/backend/translate/assets/i18n/fr_BE/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"description": "Clause de non-responsabilité : Il s'agit d'une version initiale du module de déplacement des réunions. Des améliorations seront apportées périodiquement.",
"disclaimer-submit": "Lorsque les deux équipes sont disponibles, la date peut être choisie à l'aide de la case à cocher, puis en cliquant sur envoyer.",
"errors": {
"closed": "Les mouvements sont fermés",
"date-out-of-period": "La date est en dehors de la période autorisée (septembre à avril)",
"exception-day": "Aucune compétition ne peut être jouée ce jour-là",
"invalid": "Veuillez compléter toutes les disponibilités avant d'envoyer",
Expand Down
1 change: 1 addition & 0 deletions libs/backend/translate/assets/i18n/nl_BE/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"description": "Disclaimer: dit is een eerste versie van de verplaatsingsmodule voor ontmoetingen. Verbeteringen worden periodiek aangebracht.",
"disclaimer-submit": "Eenmaal beide teams beschikbaar zijn, kan de datum gekozen worden via de checkbox en door dan op verzenden te klikken",
"errors": {
"closed": "De verplaatsingen zijn gesloten",
"date-out-of-period": "De datum ligt buiten de toegelaten periode (September tot April)",
"exception-day": "Er mag geen competitie gespeeld worden op deze dag",
"invalid": "Gelieve alle beschikbaarheid aan te vullen voor het versturen.",
Expand Down
11 changes: 8 additions & 3 deletions libs/backend/translate/src/translate.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import fs from 'fs';
});
fs.writeFileSync(
file,
`import { Path } from "nestjs-i18n";
export type I18nTranslations = {};
export type I18nPath = Path<I18nTranslations>;`,
`/* DO NOT EDIT, file generated by nestjs-i18n */
/* eslint-disable */
/* prettier-ignore */
import { Path } from "nestjs-i18n";
/* prettier-ignore */
export type I18nTranslations = {};
export type I18nPath = Path<I18nTranslations>;`,
{ encoding: 'utf8' },
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Injectable, inject, isDevMode } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { UrlTree } from '@angular/router';
import { ClaimService } from '@badman/frontend-auth';
import { TranslateService } from '@ngx-translate/core';
import { Apollo, gql } from 'apollo-angular';
import { Observable, lastValueFrom } from 'rxjs';

Expand All @@ -9,9 +12,16 @@ import { map } from 'rxjs/operators';
providedIn: 'root',
})
export class CanChangeEncounterGuard {
private apollo = inject(Apollo);
private readonly apollo = inject(Apollo);
private readonly claimService = inject(ClaimService);
private readonly snackBar = inject(MatSnackBar);
private readonly translate = inject(TranslateService);

async canActivate(): Promise<Observable<boolean> | Promise<boolean | UrlTree> | boolean> {
if (isDevMode()) {
return true;
}

const openChangeEncounter = await lastValueFrom(
this.apollo
.query<{
Expand Down Expand Up @@ -42,10 +52,17 @@ export class CanChangeEncounterGuard {
),
);

if (openChangeEncounter || isDevMode()) {
if (openChangeEncounter) {
return true;
}

const canChangeAny = this.claimService.hasAnyClaims(['change-any:encounter']);
if (canChangeAny) {
return true;
}

this.snackBar.open(this.translate.instant('all.competition.change-encounter.errors.closed'));

return false;
}
}
1 change: 1 addition & 0 deletions libs/utils/src/lib/i18n.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type I18nTranslations = {
"description": string;
"disclaimer-submit": string;
"errors": {
"closed": string;
"date-out-of-period": string;
"exception-day": string;
"invalid": string;
Expand Down

0 comments on commit 988389b

Please sign in to comment.