Skip to content

Commit 68a063a

Browse files
committed
fix: update local user permissions to always reflect the user's assigned projects
fixes #2470
1 parent aab891a commit 68a063a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/app/core/entity/latest-entity-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export abstract class LatestEntityLoader<T extends Entity> {
4848
} catch (err) {
4949
if (err?.status !== HttpStatusCode.NotFound) {
5050
Logging.error(
51-
`Loading entity "${this.entityCtor.ENTITY_TYPE}:${this.entityID}" failed: ${this.entityID}`,
51+
`Initial loading of entity "${this.entityCtor.ENTITY_TYPE}:${this.entityID}" failed [Service based on LatestEntityLoader]`,
5252
err,
5353
);
5454
}

src/app/core/permissions/ability/ability.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { get } from "lodash-es";
99
import { LatestEntityLoader } from "../../entity/latest-entity-loader";
1010
import { SessionInfo, SessionSubject } from "../../session/auth/session-info";
1111
import { CurrentUserSubject } from "../../session/current-user-subject";
12+
import { merge } from "rxjs";
13+
import { map } from "rxjs/operators";
1214

1315
/**
1416
* This service sets up the `EntityAbility` injectable with the JSON defined rules for the currently logged in user.
@@ -18,6 +20,8 @@ import { CurrentUserSubject } from "../../session/current-user-subject";
1820
*/
1921
@Injectable()
2022
export class AbilityService extends LatestEntityLoader<Config<DatabaseRules>> {
23+
private currentRules: DatabaseRules;
24+
2125
constructor(
2226
private ability: EntityAbility,
2327
private sessionInfo: SessionSubject,
@@ -26,6 +30,8 @@ export class AbilityService extends LatestEntityLoader<Config<DatabaseRules>> {
2630
entityMapper: EntityMapperService,
2731
) {
2832
super(Config, Config.PERMISSION_KEY, entityMapper);
33+
34+
this.entityUpdated.subscribe((config) => (this.currentRules = config.data));
2935
}
3036

3137
async initializeRules() {
@@ -37,9 +43,11 @@ export class AbilityService extends LatestEntityLoader<Config<DatabaseRules>> {
3743
this.ability.update([{ action: "manage", subject: "all" }]);
3844
}
3945

40-
this.entityUpdated.subscribe((config) =>
41-
this.updateAbilityWithUserRules(config.data),
42-
);
46+
merge(
47+
this.entityUpdated.pipe(map((config) => config.data)),
48+
this.sessionInfo.pipe(map(() => this.currentRules)),
49+
this.currentUser.pipe(map(() => this.currentRules)),
50+
).subscribe((rules) => this.updateAbilityWithUserRules(rules));
4351
}
4452

4553
private async updateAbilityWithUserRules(rules: DatabaseRules): Promise<any> {

0 commit comments

Comments
 (0)