Open jjbell170 opened 9 months ago
3494684b47
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the GitHub Actions logs prior to making any changes:
a02af35
Checking src/interfaces/permissions.interface.ts for syntax errors... ✅ src/interfaces/permissions.interface.ts has no syntax errors!
1/1 ✓Checking src/interfaces/permissions.interface.ts for syntax errors... ✅ src/interfaces/permissions.interface.ts has no syntax errors!
Sandbox passed on the latest master
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/interfaces/permissions.interface.ts
✓ https://github.com/jjbell170/nest-casl/commit/19e309ff8d02021413d8c14e8157aac668a04e43 Edit
Modify src/interfaces/permissions.interface.ts with contents:
• Modify the `DefinePermissions` type to allow the `Subjects` type parameter to also accept string literals. This can be done by changing the `Subjects extends Subject = Subject` to `Subjects extends Subject | string = Subject | string`.
• Similarly, modify the `Permissions` type to allow the `Subjects` type parameter to accept string literals by changing `Subjects extends Subject = Subject` to `Subjects extends Subject | string = Subject | string`.
• These changes will allow the permissions definitions to accept both class types and string literals as valid subjects.
--- +++ @@ -29,14 +29,14 @@ } export type DefinePermissions< - Subjects extends Subject = Subject, + Subjects extends Subject | string = Subject | string, Actions extends string = DefaultActions, User extends AuthorizableUser= AuthorizableUser, > = (builder: UserAbilityBuilder ) => void; export type Permissions< Roles extends string, - Subjects extends Subject = Subject, + Subjects extends Subject | string = Subject | string, Actions extends string = DefaultActions, User extends AuthorizableUser = AuthorizableUser , > = Partial >>;
src/interfaces/permissions.interface.ts
✓ Edit
Check src/interfaces/permissions.interface.ts with contents:
Ran GitHub Actions for 19e309ff8d02021413d8c14e8157aac668a04e43:
src/__specs__/app/post/post.permissions.ts
✓ https://github.com/jjbell170/nest-casl/commit/b1e0f7d0bfe0b6ed0c0f4ae822d15505b85c3df6 Edit
Modify src/__specs__/app/post/post.permissions.ts with contents:
• Change the `Subjects` type alias to also include string literals by modifying `type Subjects = InferSubjects;` to `type Subjects = InferSubjects | string;`.
• This change will reflect the updated type definitions and allow the `post.permissions.ts` file to define permissions using string subjects.
--- +++ @@ -3,7 +3,7 @@ import { Roles } from '../app.roles'; import { Post } from './dtos/post.dto'; -type Subjects = InferSubjects; +type Subjects = InferSubjects | string; export const permissions: Permissions = { everyone({ can }) {
src/__specs__/app/post/post.permissions.ts
✓ Edit
Check src/__specs__/app/post/post.permissions.ts with contents:
Ran GitHub Actions for b1e0f7d0bfe0b6ed0c0f4ae822d15505b85c3df6:
README.md
✓ https://github.com/jjbell170/nest-casl/commit/2e3085291cece35cc4cfd0008507d6b2b4a92354 Edit
Modify README.md with contents:
• Update the example in the README to reflect the new type definitions. Change the `Subjects` type alias to include string literals by modifying `export type Subjects = InferSubjects;` to `export type Subjects = InferSubjects | string;`.
• Update the `permissions` constant definition to reflect the new `Subjects` type that includes string literals.
--- +++ @@ -85,12 +85,12 @@ import { Post } from './dtos/post.dto'; import { Comment } from './dtos/comment.dto'; -export type Subjects = InferSubjects; +export type Subjects = InferSubjects | string; export const permissions: Permissions = { everyone({ can }) { - can(Actions.read, Post); - can(Actions.create, Post); + can(Actions.read, 'Post'); + can(Actions.create, 'Post'); }, customer({ user, can }) {
README.md
✓ Edit
Check README.md with contents:
Ran GitHub Actions for 2e3085291cece35cc4cfd0008507d6b2b4a92354:
README.md
✓ https://github.com/jjbell170/nest-casl/commit/59f26f15d22cf1f77e8603c98aa91cb644f06fee Edit
Modify README.md with contents:
• In the example provided in the README, add a comment explaining that subjects can now be string literals as well as class types, to inform users of the new capability.
• This comment will help users understand how to use the updated library with string subjects.
--- +++ @@ -85,12 +85,12 @@ import { Post } from './dtos/post.dto'; import { Comment } from './dtos/comment.dto'; -export type Subjects = InferSubjects; +export type Subjects = InferSubjects | string; export const permissions: Permissions = { everyone({ can }) { - can(Actions.read, Post); - can(Actions.create, Post); + can(Actions.read, 'Post'); // Subjects can now be specified as string literals in addition to class types + can(Actions.create, 'Post'); // This flexibility allows for defining permissions without a corresponding DTO }, customer({ user, can }) {
README.md
✓ Edit
Check README.md with contents:
Ran GitHub Actions for 59f26f15d22cf1f77e8603c98aa91cb644f06fee:
I have finished reviewing the code for completeness. I did not find errors for sweep/update_the_library_to_support_string_as_66c1b
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
This is an automated message generated by Sweep AI.
You can define permissions like:
export const userPermissions: Permissions<Roles, Subjects, Actions> = { everyone({ user, can }) { can(Actions.read, 'User', { userId: user.id }); }, }; However, the types of the @UseAbility decorator cannot take a string for the subject parameter so @UseAbility(Actions.read, 'User') shows a type error.
Fix this.
Checklist
- [X] Modify `src/interfaces/permissions.interface.ts` ✓ https://github.com/jjbell170/nest-casl/commit/19e309ff8d02021413d8c14e8157aac668a04e43 [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/src/interfaces/permissions.interface.ts#L30-L41) - [X] Running GitHub Actions for `src/interfaces/permissions.interface.ts` ✓ [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/src/interfaces/permissions.interface.ts#L30-L41) - [X] Modify `src/__specs__/app/post/post.permissions.ts` ✓ https://github.com/jjbell170/nest-casl/commit/b1e0f7d0bfe0b6ed0c0f4ae822d15505b85c3df6 [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/src/__specs__/app/post/post.permissions.ts#L5-L5) - [X] Running GitHub Actions for `src/__specs__/app/post/post.permissions.ts` ✓ [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/src/__specs__/app/post/post.permissions.ts#L5-L5) - [X] Modify `README.md` ✓ https://github.com/jjbell170/nest-casl/commit/2e3085291cece35cc4cfd0008507d6b2b4a92354 [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/README.md#L88-L90) - [X] Running GitHub Actions for `README.md` ✓ [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/README.md#L88-L90) - [X] Modify `README.md` ✓ https://github.com/jjbell170/nest-casl/commit/59f26f15d22cf1f77e8603c98aa91cb644f06fee [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/README.md#L100-L106) - [X] Running GitHub Actions for `README.md` ✓ [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as_66c1b/README.md#L100-L106)