-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial analysis-permission implementation (#502)
* feat: add relational entity/interface between analysis + permission * feat: initial http controller for policy domain * feat: setup authup permission aggregation * feat: extend get{One,Many} policy handler output with authup resources * test: set up basic test suite for http endpoints * feat: initial http client for analysis-permission endpoints * test: create authup permission in test suite if client is usable * fix: adjusted analysis-permission validation
- Loading branch information
Showing
25 changed files
with
802 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/core-http-kit/src/domains/analysis-permission/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2021-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './module'; |
43 changes: 43 additions & 0 deletions
43
packages/core-http-kit/src/domains/analysis-permission/module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2021-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { BuildInput } from 'rapiq'; | ||
import { buildQuery } from 'rapiq'; | ||
import type { AnalysisPermission } from '@privateaim/core-kit'; | ||
import { BaseAPI } from '../base'; | ||
import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base'; | ||
|
||
export class AnalysisPermissionAPI extends BaseAPI { | ||
async getMany(options?: BuildInput<AnalysisPermission>): Promise<CollectionResourceResponse<AnalysisPermission>> { | ||
const { data: response } = await this.client.get(`analysis-permissions${buildQuery(options)}`); | ||
return response; | ||
} | ||
|
||
async getOne(id: AnalysisPermission['id']): Promise<SingleResourceResponse<AnalysisPermission>> { | ||
const { data: response } = await this.client.get(`analysis-permissions/${id}`); | ||
|
||
return response; | ||
} | ||
|
||
async delete(id: AnalysisPermission['id']): Promise<SingleResourceResponse<AnalysisPermission>> { | ||
const { data: response } = await this.client.delete(`analysis-permissions/${id}`); | ||
|
||
return response; | ||
} | ||
|
||
async update(id: AnalysisPermission['id'], data: Partial<AnalysisPermission>): Promise<SingleResourceResponse<AnalysisPermission>> { | ||
const { data: response } = await this.client.post(`analysis-permissions/${id}`, data); | ||
|
||
return response; | ||
} | ||
|
||
async create(data: Partial<AnalysisPermission>): Promise<SingleResourceResponse<AnalysisPermission>> { | ||
const { data: response } = await this.client.post('analysis-permissions', data); | ||
|
||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/core-kit/src/domains/analysis-permission/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2022-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { PermissionRelation, Realm } from '@authup/core-kit'; | ||
import type { Analysis } from '../analysis'; | ||
import type { DomainType } from '../constants'; | ||
import type { DomainEventBaseContext } from '../types-base'; | ||
|
||
export interface AnalysisPermission extends PermissionRelation { | ||
id: string; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
analysis_id: Analysis['id']; | ||
|
||
analysis: Analysis; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
analysis_realm: Realm | null; | ||
|
||
analysis_realm_id: Realm['id'] | null; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
created_at: Date | string; | ||
|
||
updated_at: Date | string; | ||
} | ||
|
||
export type AnalysisPermissionEventContext = DomainEventBaseContext & { | ||
type: `${DomainType.ANALYSIS_PERMISSION}`, | ||
data: AnalysisPermission | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2021-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './entity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/server-core/src/aggregators/authup/entities/permission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2023-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
import type { PermissionEventContext } from '@authup/core-kit'; | ||
import { useDataSource } from 'typeorm-extension'; | ||
import { AnalysisPermissionEntity } from '../../../domains'; | ||
|
||
export async function handleAuthupPermissionEvent(context: PermissionEventContext) { | ||
if (context.event !== 'deleted') { | ||
return; | ||
} | ||
|
||
const dataSource = await useDataSource(); | ||
const repository = dataSource.getRepository(AnalysisPermissionEntity); | ||
const entities = await repository.findBy({ | ||
permission_id: context.data.id, | ||
}); | ||
|
||
await repository.remove(entities); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/server-core/src/domains/analysis-permission/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2021-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
import type { | ||
Analysis, | ||
AnalysisPermission, | ||
} from '@privateaim/core-kit'; | ||
import type { Permission, Policy, Realm } from '@authup/core-kit'; | ||
import { AnalysisEntity } from '../analysis'; | ||
|
||
@Entity({ name: 'analysis_permissions' }) | ||
export class AnalysisPermissionEntity implements AnalysisPermission { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
@CreateDateColumn() | ||
created_at: Date; | ||
|
||
@UpdateDateColumn() | ||
updated_at: Date; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
@Column() | ||
analysis_id: Analysis['id']; | ||
|
||
@ManyToOne(() => AnalysisEntity, { onDelete: 'CASCADE' }) | ||
@JoinColumn({ name: 'analysis_id' }) | ||
analysis: AnalysisEntity; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
analysis_realm: Realm | null; | ||
|
||
@Column({ type: 'uuid', nullable: true }) | ||
analysis_realm_id: Realm['id'] | null; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
@Column({ type: 'uuid' }) | ||
permission_id: Permission['id']; | ||
|
||
permission: Permission; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
@Column({ type: 'uuid', nullable: true }) | ||
policy_id: Policy['id'] | null; | ||
|
||
policy: Policy | null; | ||
|
||
// ------------------------------------------------------------------ | ||
|
||
@Column({ type: 'uuid', nullable: true }) | ||
permission_realm_id: Realm['id'] | null; | ||
|
||
permission_realm: Realm | null; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/server-core/src/domains/analysis-permission/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2022-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './entity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/server-core/src/http/controllers/core/analysis-permission/handlers/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2022-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { ForbiddenError } from '@ebec/http'; | ||
import { PermissionID } from '@privateaim/core-kit'; | ||
import type { Request, Response } from 'routup'; | ||
import { sendCreated } from 'routup'; | ||
import { useDataSource } from 'typeorm-extension'; | ||
import { useRequestEnv } from '@privateaim/server-http-kit'; | ||
import { AnalysisPermissionEntity } from '../../../../../domains'; | ||
import { runAnalysisPermissionValidation } from '../utils'; | ||
|
||
export async function createAnalysisPermissionRouteHandler(req: Request, res: Response) : Promise<any> { | ||
const ability = useRequestEnv(req, 'abilities'); | ||
if (!ability.has(PermissionID.ANALYSIS_EDIT)) { | ||
throw new ForbiddenError(); | ||
} | ||
|
||
const result = await runAnalysisPermissionValidation(req, 'create'); | ||
|
||
const dataSource = await useDataSource(); | ||
const repository = dataSource.getRepository(AnalysisPermissionEntity); | ||
|
||
let entity = repository.create(result.data); | ||
|
||
entity = await repository.save(entity); | ||
|
||
entity.analysis = result.relation.analysis; | ||
|
||
return sendCreated(res, entity); | ||
} |
Oops, something went wrong.