Auth for everything (and everything auth) #6 #35

Merged
philipp merged 39 commits from feature/6-api_auth into dev 2020-12-18 21:53:18 +00:00
Showing only changes of commit 6a7e8ccc37 - Show all commits

View File

@ -59,6 +59,8 @@ export class PermissionController {
} catch (error) { } catch (error) {
throw error; throw error;
} }
let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: permission.principal }, { relations: ['principal'] });
if (existingPermission) { return new ResponsePermission(existingPermission); }
permission = await this.permissionRepository.save(permission); permission = await this.permissionRepository.save(permission);
permission = await this.permissionRepository.findOne(permission, { relations: ['principal'] }); permission = await this.permissionRepository.findOne(permission, { relations: ['principal'] });
@ -84,6 +86,11 @@ export class PermissionController {
if (oldPermission.id != permission.id) { if (oldPermission.id != permission.id) {
throw new PermissionIdsNotMatchingError(); throw new PermissionIdsNotMatchingError();
} }
let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: permission.principal }, { relations: ['principal'] });
if (existingPermission) {
await this.remove(permission.id, true);
return new ResponsePermission(existingPermission);
}
await this.permissionRepository.update(oldPermission, await permission.toPermission()); await this.permissionRepository.update(oldPermission, await permission.toPermission());