Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix operator reset and wait until they're loaded #4280

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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 @@ -68,7 +68,7 @@ export class VotingBannerService {
}

private updateBanner(polls: ViewPoll[], voted: { [key: Id]: Id[] }): void {
if (this.activeMeeting.meetingId && !this.operator.isAnonymous) {
if (this.activeMeeting.meetingId && !this.operator.isAnonymous && this.operator.readyDeferred.wasResolved) {
const checkUsers = [this.operator.user, ...(this.operator.user.vote_delegations_from() || [])];
this.pollsToVote = polls.filter(
poll => checkUsers.some(user => this.votingService.canVote(poll, user)) && voted[poll.id] !== undefined
Expand Down
26 changes: 17 additions & 9 deletions client/src/app/site/services/operator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ export class OperatorService {
}

public get isAnyManager(): boolean {
return this.isSuperAdmin || this.isOrgaManager || this.isCommitteeManager;
return this.isSuperAdmin || this.isOrgaManager || this.readyDeferred.wasResolved
? this.isCommitteeManager
: false;
}

public get knowsMultipleMeetings(): boolean {
return (
this.isAnyManager ||
(this.isAnonymous ? this.defaultAnonUser.hasMultipleMeetings : this.user.hasMultipleMeetings)
(this.isAnonymous
? this.defaultAnonUser.hasMultipleMeetings
: this.readyDeferred.wasResolved
? this.user?.hasMultipleMeetings
: false)
);
}

Expand Down Expand Up @@ -164,7 +170,7 @@ export class OperatorService {
}

public get ready(): Deferred<void> {
return this._readyDeferred;
return this.readyDeferred;
}

/**
Expand Down Expand Up @@ -227,7 +233,7 @@ export class OperatorService {
// State management
private _ready = false;

private _readyDeferred: Deferred<void> = new Deferred();
public readyDeferred: Deferred<void> = new Deferred();

private _groupsLoaded = false;
private _groupsLoadedDeferred: Deferred<void> = new Deferred();
Expand Down Expand Up @@ -436,7 +442,8 @@ export class OperatorService {
this._permissions !== undefined;
}
if (this.isAuthenticated) {
isReady = isReady && this._OML !== undefined && this._CML !== undefined;
isReady =
isReady && this._OML !== undefined && this._CML !== undefined && this._userSubject.value !== undefined;
}
// TODO: for developing some checks
// console.log(
Expand All @@ -457,22 +464,23 @@ export class OperatorService {
// );
if (isReady) {
this._ready = true;
this._readyDeferred.resolve();
this.readyDeferred.resolve();
this._operatorReadySubject.next(true);
}
}

private setNotReady(): void {
this._ready = false;
this._operatorReadySubject.next(false);
if (this._readyDeferred.wasResolved) {
if (this.readyDeferred.wasResolved) {
console.log(`operator: not ready`);
this._readyDeferred = new Deferred();
this._readyDeferred.then(() => console.log(`operator is ready!`));
this.readyDeferred = new Deferred();
this.readyDeferred.then(() => console.log(`operator is ready!`));
}
}

private resetOperatorData(): void {
this._userSubject.next(undefined);
this._meetingIds = undefined;
this._groupIds = undefined;
this._permissions = undefined;
Expand Down