Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tnramalho committed Jul 16, 2024
1 parent 6f00c3f commit 327d090
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/nestjs-access-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ Advanced access control guard for NestJS with optional per-request filtering.
## Getting Started with Access Control

### Installation

Install the `@concepta/nestjs-access-control` package using yarn or npm:

```sh
yarn add @concepta/nestjs-access-control
```

```sh
npm install @concepta/nestjs-access-control
```

## Basic Setup

To set up the `@concepta/nestjs-access-control` module, you need to define your access control rules, create a custom access query service, and import the `AccessControlModule` into your app module. This ensures that your application can enforce access control policies based on the defined rules and services.

Check notice on line 87 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L87

Expected: 80; Actual: 310
Expand Down Expand Up @@ -167,6 +170,7 @@ acRules.deny(allRoles).resource(AppResource.User).deleteOwn();
```

### create the Access Query service

```ts
import { plainToInstance } from 'class-transformer';
import { Injectable } from '@nestjs/common';
Expand Down Expand Up @@ -309,22 +313,28 @@ export class UserController {
}
}
```

# How-To Guides

Check notice on line 317 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L317

Multiple top-level headings in the same document

## Using `@AccessControlCreateOne` Decorator

### Description

The `@AccessControlCreateOne` decorator is used to grant create permissions for a single resource. This decorator is a shortcut for defining access control grants for creating one resource.

Check notice on line 323 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L323

Expected: 80; Actual: 189

### Setting Permissions

First, define your access control rules using the AccessControl library. This example shows how to set permissions for different roles.

Check notice on line 327 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L327

Expected: 80; Actual: 135

```ts
//...
ac.grant(AppRole.User)
.createOwn(AppResource.User);
//...
```

### Using in a Controller

Next, use the `@AccessControlCreateOne` decorator in your controller to protect the route that handles the creation of a single resource.

Check notice on line 338 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L338

Expected: 80; Actual: 137

```ts
Expand All @@ -335,13 +345,14 @@ Next, use the `@AccessControlCreateOne` decorator in your controller to protect
}
```


## Using `@AccessControlUpdateOne` Decorator

### Description

The `@AccessControlUpdateOne` decorator is used to grant update permissions for a single resource. This decorator is a shortcut for defining access control grants for updating one resource.

### Setting Permissions

Check notice on line 354 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L354

Multiple headings with the same content

First, define your access control rules using the `AccessControl` library. This example shows how to set permissions for different roles.

```ts
Expand All @@ -366,11 +377,12 @@ Next, use the `@AccessControlUpdateOne` decorator in your controller to protect
## Using `@AccessControlReadOne` Decorator

### Description

The `@AccessControlReadOne` decorator grants read permissions for a single resource. It is a shortcut for defining access control grants for reading one resource.

### Setting Permissions

First, define your access control rules using the `AccessControl` library. This example shows how to set permissions for different roles. Please refer [Important Notes Section](#IMPORTANT) for better understanding of the permissions.
First, define your access control rules using the `AccessControl` library. This example shows how to set permissions for different roles. Please refer [Important Notes Section](#important) for better understanding of the permissions.

```ts
//...
Expand Down Expand Up @@ -416,6 +428,7 @@ User that contains Role `Admin` can get any information of resource `User`.
## Using `@AccessControlDeleteOne` Decorator

### Description

The `@AccessControlDeleteOne` decorator is used to grant delete permissions for a single resource. This decorator is a shortcut for defining access control grants for deleting one resource.

Check notice on line 432 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L432

Expected: 80; Actual: 189

### Setting Permissions
Expand Down Expand Up @@ -446,6 +459,7 @@ Next, use the `@AccessControlDeleteOne` decorator in your controller to protect
## Using `@AccessControlCreateMany` Decorator

### Description

The `@AccessControlCreateMany` decorator is used to grant create permissions for multiple resources. This decorator is a shortcut for defining access control grants for creating many resources.

### Setting Permissions
Expand Down Expand Up @@ -476,6 +490,7 @@ Next, use the `@AccessControlCreateMany` decorator in your controller to protect
## Using `@AccessControlReadMany` Decorator

### Description

The `@AccessControlReadMany` decorator is used to grant read permissions for multiple resources. This decorator is a shortcut for defining access control grants for reading multiple resources.

Check notice on line 494 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L494

Expected: 80; Actual: 192

### Setting Permissions
Expand Down Expand Up @@ -504,6 +519,7 @@ Next, use the `@AccessControlReadMany` decorator in your controller to protect t
```

## Creating a Custom Service

To create a custom service, follow these steps:

1. **Define the Service**: Create a new service class that implements the required methods. you can take advantage of the service `UserAccessQueryService` from `@concepta/nestjs-user` to create a custom UserAccessQueryService pls reference [`@concepta/nestjs-user`](https://www.npmjs.com/package/@concepta/nestjs-user) for more details. The `canAccess` method will provide you all information you need to manage your access.
Expand Down Expand Up @@ -532,6 +548,7 @@ export class YourUserAccessQueryService extends UserAccessQueryService {
}
}
```

2. **Register the Service**: Register the custom service in your module.

```ts
Expand All @@ -543,7 +560,6 @@ AccessControlModule.forRoot({
//...
```


# Reference

Check notice on line 563 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L563

Multiple top-level headings in the same document

For more details, check the [official documentation](https://docs.nestjs.com/guards#access-control).
Expand Down Expand Up @@ -571,9 +587,11 @@ Here is the pattern:
### Conceptual Overview of Access Control

#### What is Access Control?

Access control in a software context refers to the selective restriction of access to resources. It ensures that only authorized users can access or modify data within an application.

Check notice on line 591 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L591

Expected: 80; Actual: 183

#### Benefits of Using Access Control

- **Security**: Restrict access to sensitive data and operations to authorized users only.
- **Flexibility**: Define granular access control rules to suit various application requirements.
- **Compliance**: Meet regulatory requirements by ensuring proper access controls are in place.

Check notice on line 597 in packages/nestjs-access-control/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/nestjs-access-control/README.md#L597

Expected: 80; Actual: 95
Expand Down Expand Up @@ -627,12 +645,15 @@ The `YourUserAccessQueryService` is designed to manage and control user access t
By using the `YourUserAccessQueryService`, you can create a robust and flexible access control system that enhances the security and integrity of your application.

#### Why Use Access Control?

Implementing access control ensures that your application maintains data integrity and security by allowing only authorized users to perform specific actions.

#### Synchronous vs Asynchronous Registration

- **Synchronous Registration**: Use when configuration options are static and available at startup.
- **Asynchronous Registration**: Use when configuration options need to be retrieved from external sources at runtime.

#### Global vs Feature-Specific Registration

- **Global Registration**: Makes the module available throughout the entire application.
- **Feature-Specific Registration**: Allows the module to be registered only for specific features or modules within the application.

0 comments on commit 327d090

Please sign in to comment.