sergey-telpuk / nestjs-rbac

Awesome RBAC for NestJs
Other
426 stars 36 forks source link

CRUD integration #63

Closed Piranit closed 4 years ago

Piranit commented 4 years ago

Hi! Currently I'm using CRUD (https://github.com/nestjsx/crud). Is there any quick solution to integrate your RBAC without rewriting CRUD methods?

sergey-telpuk commented 4 years ago

@Piranit Hi, I'm not sure, I'll look at it and response to you

sergey-telpuk commented 4 years ago

@Piranit hi, it's supported https://github.com/sergey-telpuk/nestjs-rbac#using-for-a-whole-controller now

Piranit commented 4 years ago

No, you did not understand the problem. How to add permission for an entire controller i know. The problem is that the @Crud(...) decorator from https://github.com/nestjsx/crud adds dynamic routes to the controller.

And the actual question was how to add a @RBAcPermissions(...) decorator to these methods.

sergey-telpuk commented 4 years ago

@Piranit why not, check it out, for example

@Crud({
    model: {
        type: Company,
    },
    routes: {
        getManyBase: {
            interceptors : [],
            decorators: [RBAcPermissions('permission1')],
        },
        createOneBase: {
            interceptors : [],
            decorators: [RBAcPermissions('permission2')],
        },
    },
})
@UseGuards(
    AuthGuard,
    RBAcGuard,
)
@Controller('companies')
export class CompaniesController implements CrudController<Company> {
    constructor(public service: CompaniesService) {
    }
}