Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
icon="fa-light fa-chart-simple"
severity="info"
size="small"
[routerLink]="['/surveys', 'create']"
[queryParams]="createSurveyQueryParams()"
(click)="onCreateSurvey()"
data-testid="committee-surveys-create-btn"></lfx-button>
}
</lfx-surveys-table>
Expand All @@ -29,8 +28,7 @@
icon="fa-light fa-chart-simple"
severity="info"
size="small"
[routerLink]="['/surveys', 'create']"
[queryParams]="createSurveyQueryParams()"
(click)="onCreateSurvey()"
data-testid="committee-surveys-empty-create-btn"></lfx-button>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

import { ChangeDetectionStrategy, Component, computed, inject, input, model, signal, Signal } from '@angular/core';
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
import { Router } from '@angular/router';
import { ButtonComponent } from '@components/button/button.component';
import { CardComponent } from '@components/card/card.component';
import { Committee, Survey } from '@lfx-one/shared/interfaces';
import { buildCommitteeCreateQueryParams } from '@lfx-one/shared/utils';
import { SurveysTableComponent } from '@app/modules/surveys/components/surveys-table/surveys-table.component';
import { SurveyResultsDrawerComponent } from '@app/modules/surveys/components/survey-results-drawer/survey-results-drawer.component';
import { CommitteeService } from '@services/committee.service';
import { LensService } from '@services/lens.service';
import { SurveyService } from '@services/survey.service';
import { MessageService } from 'primeng/api';
import { catchError, filter, finalize, of, switchMap, tap } from 'rxjs';
import { catchError, filter, finalize, of, switchMap, take, tap } from 'rxjs';

@Component({
selector: 'lfx-committee-surveys',
Expand All @@ -21,8 +24,11 @@ import { catchError, filter, finalize, of, switchMap, tap } from 'rxjs';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CommitteeSurveysComponent {
private readonly committeeService = inject(CommitteeService);
private readonly lensService = inject(LensService);
private readonly surveyService = inject(SurveyService);
private readonly messageService = inject(MessageService);
private readonly router = inject(Router);

// Inputs
public committee = input.required<Committee>();
Expand All @@ -38,6 +44,31 @@ export class CommitteeSurveysComponent {
public surveys: Signal<Survey[]> = this.initSurveys();
public createSurveyQueryParams: Signal<Record<string, string>> = this.initCreateSurveyQueryParams();

/** Checks committee write permission fresh before navigating to the create-survey route.
* Redirects to the lens-appropriate overview with _notice=surveys if permission has been
* revoked since the page loaded — consistent with the writerGuard denial flow. */
public onCreateSurvey(): void {
const committee = this.committee();
const overviewPath = this.lensService.activeLens() === 'foundation' ? '/foundation/overview' : '/project/overview';
const denyParams: Record<string, string> = { _notice: 'surveys' };
if (committee.project_slug) denyParams['project'] = committee.project_slug;
const deny = () => void this.router.navigate([overviewPath], { queryParams: denyParams });

this.committeeService
.getCommittee(committee.uid)
.pipe(take(1))
.subscribe({
next: (fresh) => {
if (fresh?.writer !== true) {
deny();
return;
}
void this.router.navigate(['/surveys', 'create'], { queryParams: this.createSurveyQueryParams() });
},
error: () => deny(),
});
}

public viewSurveyResults(survey: Survey): void {
this.selectedSurveyId.set(survey.uid);
this.selectedSurvey.set(survey);
Expand Down
Loading