Skip to content

Commit

Permalink
feat: add create/edit/delete permissions (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG authored Apr 11, 2024
1 parent e5886da commit 621ff99
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/app/permission/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ export class AppDetailComponent implements OnInit, OnDestroy {
const pList = this.prepareProductList()
if (pList.length === 0) return // products are required
this.assApi
.grantAssignment({
.grantAssignments({
createProductAssignmentsRequest: {
roleId: role.id,
productNames: pList,
Expand Down
55 changes: 28 additions & 27 deletions src/app/permission/permission-detail/permission-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { TranslateService } from '@ngx-translate/core'

import { PortalMessageService, UserService } from '@onecx/portal-integration-angular'

import { /* CreateRoleRequest, UpdateRoleRequest, */ PermissionAPIService, Permission } from 'src/app/shared/generated'
import {
CreatePermissionRequest,
UpdatePermissionRequest,
PermissionAPIService,
Permission
} from 'src/app/shared/generated'
import { App, ChangeMode, PermissionViewRow } from 'src/app/permission/app-detail/app-detail.component'

@Component({
Expand Down Expand Up @@ -52,6 +57,10 @@ export class PermissionDetailComponent implements OnChanges {
if (this.userService.hasPermission('PERMISSION#EDIT') || this.userService.hasPermission('PERMISSION#CREATE'))
this.formGroup.enable()
else this.formGroup.disable()
if (this.changeMode === 'EDIT') {
this.formGroup.controls['appId'].disable()
this.formGroup.controls['productName'].disable()
}
}

public onClose(): void {
Expand Down Expand Up @@ -83,59 +92,52 @@ export class PermissionDetailComponent implements OnChanges {
return
}
}
console.info('form valid ' + this.formGroup.valid)
if (this.changeMode === 'CREATE') {
/* const permission = {
const permission = {
appId: this.formGroup.controls['appId'].value,
productName: this.formGroup.controls['productName'].value,
resource: this.formGroup.controls['resource'].value,
action: this.formGroup.controls['action'].value,
description: this.formGroup.controls['description'].value
} as CreateRoleRequest
} as CreatePermissionRequest

this.permApi.createPermission({
createRolesRequest: { permissions: [permission] }
})
.subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.PERMISSION_OK' })
this.dataChanged.emit(true)
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.PERMISSION_NOK' })
console.error(err)
}
})
*/
this.permApi.createPermission({ createPermissionRequest: permission }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.PERMISSION_OK' })
this.dataChanged.emit(true)
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.PERMISSION_NOK' })
console.error(err)
}
})
} else {
console.info('form valid ' + this.formGroup.valid)
//const roleNameChanged = this.formGroup.controls['name'].value !== this.permission?.name
/* const permission = {
const permission = {
modificationCount: this.permission?.modificationCount,
appId: this.formGroup.controls['appId'].value,
productName: this.formGroup.controls['productName'].value,
resource: this.formGroup.controls['resource'].value,
action: this.formGroup.controls['action'].value,
description: this.formGroup.controls['description'].value
} as UpdateRoleRequest
*/
/* this.permApi.updatePermission({ id: this.permission?.id ?? '', updateRoleRequest: permission }).subscribe({
} as UpdatePermissionRequest

this.permApi.updatePermission({ id: this.permission?.id ?? '', updatePermissionRequest: permission }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.EDIT.MESSAGE.PERMISSION_OK' })
this.dataChanged.emit(roleNameChanged)
this.dataChanged.emit(true)
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.EDIT.MESSAGE.PERMISSION_NOK' })
console.error(err)
}
})
*/
}
}

public onDeleteConfirmation() {
console.info('form valid ' + this.formGroup.valid)
/* this.permApi.deletePermission({ id: this.permission?.id ?? '' }).subscribe({
this.permApi.deletePermission({ id: this.permission?.id ?? '' }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.DELETE.MESSAGE.PERMISSION_OK' })
this.dataChanged.emit(true)
Expand All @@ -145,6 +147,5 @@ export class PermissionDetailComponent implements OnChanges {
console.error(err.error)
}
})
*/
}
}
2 changes: 2 additions & 0 deletions src/app/shared/generated/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ model/assignment.ts
model/assignmentPageResult.ts
model/assignmentSearchCriteria.ts
model/createAssignmentRequest.ts
model/createPermissionRequest.ts
model/createProductAssignmentsRequest.ts
model/createRoleRequest.ts
model/createRolesRequest.ts
Expand All @@ -40,6 +41,7 @@ model/revokeAssignmentRequest.ts
model/role.ts
model/rolePageResult.ts
model/roleSearchCriteria.ts
model/updatePermissionRequest.ts
model/updateRoleRequest.ts
model/workspaceAbstract.ts
model/workspaceDetails.ts
Expand Down
14 changes: 7 additions & 7 deletions src/app/shared/generated/api/assignment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface GetAssignmentRequestParams {
id: string;
}

export interface GrantAssignmentRequestParams {
export interface GrantAssignmentsRequestParams {
createProductAssignmentsRequest: CreateProductAssignmentsRequest;
}

Expand Down Expand Up @@ -314,18 +314,18 @@ export class AssignmentAPIService {
}

/**
* Create new assignments for products
* Create new assignments by criteria
* @param requestParameters
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public grantAssignment(requestParameters: GrantAssignmentRequestParams, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any>;
public grantAssignment(requestParameters: GrantAssignmentRequestParams, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<any>>;
public grantAssignment(requestParameters: GrantAssignmentRequestParams, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<any>>;
public grantAssignment(requestParameters: GrantAssignmentRequestParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
public grantAssignments(requestParameters: GrantAssignmentsRequestParams, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any>;
public grantAssignments(requestParameters: GrantAssignmentsRequestParams, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<any>>;
public grantAssignments(requestParameters: GrantAssignmentsRequestParams, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<any>>;
public grantAssignments(requestParameters: GrantAssignmentsRequestParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
const createProductAssignmentsRequest = requestParameters.createProductAssignmentsRequest;
if (createProductAssignmentsRequest === null || createProductAssignmentsRequest === undefined) {
throw new Error('Required parameter createProductAssignmentsRequest was null or undefined when calling grantAssignment.');
throw new Error('Required parameter createProductAssignmentsRequest was null or undefined when calling grantAssignments.');
}

let localVarHeaders = this.defaultHeaders;
Expand Down
Loading

0 comments on commit 621ff99

Please sign in to comment.