Add missing null in type in permissions service

The parameters of the permission checking methods were missing a null value for not set user. This is the case if user is not logged in and operating as guest.

Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
Yannick Bungers 2021-11-29 22:42:31 +01:00
parent 0881d5f041
commit 15e2e177fb

View file

@ -21,7 +21,7 @@ export enum GuestPermission {
@Injectable() @Injectable()
export class PermissionsService { export class PermissionsService {
public guestPermission: GuestPermission; // TODO change to configOption public guestPermission: GuestPermission; // TODO change to configOption
mayRead(user: User, note: Note): boolean { mayRead(user: User | null, note: Note): boolean {
if (this.isOwner(user, note)) return true; if (this.isOwner(user, note)) return true;
if (this.hasPermissionUser(user, note, false)) return true; if (this.hasPermissionUser(user, note, false)) return true;
@ -32,7 +32,7 @@ export class PermissionsService {
return false; return false;
} }
mayWrite(user: User, note: Note): boolean { mayWrite(user: User | null, note: Note): boolean {
if (this.isOwner(user, note)) return true; if (this.isOwner(user, note)) return true;
if (this.hasPermissionUser(user, note, true)) return true; if (this.hasPermissionUser(user, note, true)) return true;
@ -43,7 +43,7 @@ export class PermissionsService {
return false; return false;
} }
mayCreate(user: User): boolean { mayCreate(user: User | null): boolean {
if (user) { if (user) {
return true; return true;
} else { } else {
@ -58,14 +58,14 @@ export class PermissionsService {
return false; return false;
} }
isOwner(user: User, note: Note): boolean { isOwner(user: User | null, note: Note): boolean {
if (!user) return false; if (!user) return false;
if (!note.owner) return false; if (!note.owner) return false;
return note.owner.id === user.id; return note.owner.id === user.id;
} }
private hasPermissionUser( private hasPermissionUser(
user: User, user: User | null,
note: Note, note: Note,
wantEdit: boolean, wantEdit: boolean,
): boolean { ): boolean {
@ -84,7 +84,7 @@ export class PermissionsService {
} }
private hasPermissionGroup( private hasPermissionGroup(
user: User, user: User | null,
note: Note, note: Note,
wantEdit: boolean, wantEdit: boolean,
): boolean { ): boolean {