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 @@ -17,8 +17,7 @@
icon="fa-light fa-check-to-slot"
severity="info"
size="small"
[routerLink]="['/votes', 'create']"
[queryParams]="createVoteQueryParams()"
(click)="onCreateVote()"
data-testid="committee-votes-create-btn"></lfx-button>
}
</lfx-votes-table>
Expand All @@ -30,8 +29,7 @@
icon="fa-light fa-check-to-slot"
severity="info"
size="small"
[routerLink]="['/votes', 'create']"
[queryParams]="createVoteQueryParams()"
(click)="onCreateVote()"
data-testid="committee-votes-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, Vote } from '@lfx-one/shared/interfaces';
import { buildCommitteeCreateQueryParams } from '@lfx-one/shared/utils';
import { VotesTableComponent } from '@app/modules/votes/components/votes-table/votes-table.component';
import { VoteResultsDrawerComponent } from '@app/modules/votes/components/vote-results-drawer/vote-results-drawer.component';
import { CommitteeService } from '@services/committee.service';
import { LensService } from '@services/lens.service';
import { VoteService } from '@services/vote.service';
import { MessageService } from 'primeng/api';
import { catchError, filter, finalize, of, switchMap } from 'rxjs';
import { catchError, filter, finalize, of, switchMap, take } from 'rxjs';

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

// Inputs
public committee = input.required<Committee>();
Expand All @@ -38,6 +44,31 @@ export class CommitteeVotesComponent {
public votes: Signal<Vote[]> = this.initVotes();
public createVoteQueryParams: Signal<Record<string, string>> = this.initCreateVoteQueryParams();

/** Checks committee write permission fresh before navigating to the create-vote route.
* Redirects to project overview with _notice=votes if permission has been revoked
* since the page loaded — consistent with the writerGuard denial flow. */
public onCreateVote(): void {
const committee = this.committee();
const overviewPath = this.lensService.activeLens() === 'foundation' ? '/foundation/overview' : '/project/overview';
const denyParams: Record<string, string> = { _notice: 'votes' };
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(['/votes', 'create'], { queryParams: this.createVoteQueryParams() });
},
error: () => deny(),
});
}

/** Opens the vote results drawer for the selected vote. */
public viewVoteResults(voteUid: string): void {
const vote = this.votes().find((v) => v.uid === voteUid) || null;
Expand Down
Loading