maybe adding acls idk

This commit is contained in:
Evert Prants 2023-01-26 20:30:39 +02:00
parent c9184a9f82
commit 2e59d0b907
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
5 changed files with 66 additions and 3 deletions

View File

@ -114,7 +114,13 @@ export class AppStorageService {
set.storages = [...(set.storages || []), storage]; set.storages = [...(set.storages || []), storage];
return this.formatStorageSetNoItems(set); // Remove circular set reference
const respondWith = {
...set,
storages: set.storages.map((storage) => omit(storage, ['set'])),
};
return this.formatStorageSetNoItems(respondWith);
} }
async removeFromSet(set: StorageSet, storage: Storage) { async removeFromSet(set: StorageSet, storage: Storage) {
@ -421,7 +427,7 @@ export class AppStorageService {
...omit(storage, ['room', 'set']), ...omit(storage, ['room', 'set']),
items: !!storage.items?.length items: !!storage.items?.length
? storage.items.map((item) => this.formatStoredItem(item)) ? storage.items.map((item) => this.formatStoredItem(item))
: null, : [],
addedBy: storage.addedBy && this.formatActor(storage.addedBy), addedBy: storage.addedBy && this.formatActor(storage.addedBy),
}; };
} }

View File

@ -5,9 +5,18 @@ import { Building } from './entities/building.entity';
import { BuildingService } from './building.service'; import { BuildingService } from './building.service';
import { Floor } from './entities/floor.entity'; import { Floor } from './entities/floor.entity';
import { Room } from './entities/room.entity'; import { Room } from './entities/room.entity';
import { UserBuildingAccessControl } from './entities/acl.entity';
@Module({ @Module({
imports: [GroupModule, TypeOrmModule.forFeature([Building, Floor, Room])], imports: [
GroupModule,
TypeOrmModule.forFeature([
Building,
Floor,
Room,
UserBuildingAccessControl,
]),
],
providers: [BuildingService], providers: [BuildingService],
exports: [TypeOrmModule, BuildingService], exports: [TypeOrmModule, BuildingService],
}) })

View File

@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { GroupService } from '../group/group.service'; import { GroupService } from '../group/group.service';
import { UserBuildingAccessControl } from './entities/acl.entity';
import { Building } from './entities/building.entity'; import { Building } from './entities/building.entity';
import { Floor } from './entities/floor.entity'; import { Floor } from './entities/floor.entity';
import { Room } from './entities/room.entity'; import { Room } from './entities/room.entity';
@ -15,6 +16,8 @@ export class BuildingService {
private readonly floorRepository: Repository<Floor>, private readonly floorRepository: Repository<Floor>,
@InjectRepository(Room) @InjectRepository(Room)
private readonly roomRepository: Repository<Room>, private readonly roomRepository: Repository<Room>,
@InjectRepository(UserBuildingAccessControl)
private readonly aclRepository: Repository<UserBuildingAccessControl>,
private readonly groupService: GroupService, private readonly groupService: GroupService,
) {} ) {}

View File

@ -0,0 +1,37 @@
import { ApiProperty } from '@nestjs/swagger';
import { User } from 'src/objects/user/user.entity';
import { Building } from 'src/objects/building/entities/building.entity';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Group } from 'src/objects/group/group.entity';
import { Access } from 'src/objects/enums/access-control.enum';
@Entity()
export class UserBuildingAccessControl {
@PrimaryGeneratedColumn()
id: number;
@ApiProperty({ type: () => User })
@ManyToOne(() => User, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
user: User;
@ApiProperty({ type: () => Building })
@ManyToOne(() => Building, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
building: Building;
@ApiProperty({ type: () => Group })
@ManyToOne(() => Group, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
group: Group;
@ApiProperty({ enum: Access })
@Column({ type: String })
access: Access;
}

View File

@ -0,0 +1,8 @@
export enum Access {
ADMIN = 'ADMIN',
EDIT_FLOOR_PLAN = 'EDIT_FLOOR_PLAN',
MANAGE_STORAGE = 'MANAGE_STORAGE',
MANAGE_ACCESS = 'MANAGE_ACCESS',
MANAGE_FINANCE = 'MANAGE_FINANCE',
TODOLIST = 'TODOLIST',
}