Skip to content

Commit

Permalink
fix(public forms): correct permission checks to allow unauthenticated…
Browse files Browse the repository at this point in the history
… users access to forms again (#2700)
  • Loading branch information
sleidig authored Dec 3, 2024
1 parent 8c9c39a commit 5136835
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/app/core/permissions/ability/ability.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export class AbilityService extends LatestEntityLoader<Config<DatabaseRules>> {
rules: DatabaseRule[],
): Promise<DatabaseRule[]> {
const sessionInfo: SessionInfo = this.sessionInfo.value;
if (!sessionInfo) {
// for unauthenticated users, no user variables are available and interpolated
return rules;
}

const user = await firstValueFrom(
// only emit once user entity is loaded (or "null" for user account without entity)
Expand Down
15 changes: 4 additions & 11 deletions src/app/features/public-form/public-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { EntityFormComponent } from "../../core/common-components/entity-form/entity-form/entity-form.component";
import { MatButtonModule } from "@angular/material/button";
import { ConfigService } from "../../core/config/config.service";
import { EntitySchemaService } from "../../core/entity/schema/entity-schema.service";
import { MatSnackBar } from "@angular/material/snack-bar";
import { MatCardModule } from "@angular/material/card";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
Expand Down Expand Up @@ -43,7 +42,6 @@ export class PublicFormComponent<E extends Entity> implements OnInit {
private entityMapper: EntityMapperService,
private entityFormService: EntityFormService,
private configService: ConfigService,
private entitySchemaService: EntitySchemaService,
private snackbar: MatSnackBar,
) {}

Expand Down Expand Up @@ -139,14 +137,9 @@ export class PublicFormComponent<E extends Entity> implements OnInit {

private async initForm() {
this.entity = new this.entityType();
this.entityFormService
.createEntityForm(
[].concat(...this.fieldGroups.map((group) => group.fields)),
this.entity,
)
.then((value) => {
this.form = value;
const formControls = this.form.formGroup.controls;
});
this.form = await this.entityFormService.createEntityForm(
[].concat(...this.fieldGroups.map((group) => group.fields)),
this.entity,
);
}
}

0 comments on commit 5136835

Please sign in to comment.