Open jjbell170 opened 7 months ago
3c0219a360
)[!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/c7416542f2558694b9753db2fc10eda3033506c9 Edit
Modify src/interfaces/permissions.interface.ts with contents:
• Change the `Subjects` type parameter to include `string` as a possible type. This will allow the library to accept both class and string types for subjects.
• Update the `UserAbilityBuilder` class to reflect the new `Subjects` type parameter.
• Modify the `DefinePermissions` and `Permissions` type aliases to include `string` in their `Subjects` type parameter.
• Ensure that the `AnyPermissions` type alias is also updated to reflect the new `Subjects` type parameter.
--- +++ @@ -1,10 +1,10 @@ -import { Ability, AnyAbility, AbilityTuple, AbilityBuilder, Subject } from '@casl/ability'; + import { AnyClass } from '@casl/ability/dist/types/types'; import { DefaultActions } from '../actions.enum'; import { AuthorizableUser } from './authorizable-user.interface'; export class UserAbilityBuilder< - Subjects extends Subject = Subject, + Subjects extends Subject | string = Subject | string, Actions extends string = DefaultActions, User extends AuthorizableUser= AuthorizableUser, > extends AbilityBuilder { @@ -29,7 +29,7 @@ } export type DefinePermissions< - Subjects extends Subject = Subject, + Subjects extends Subject | string = Subject | string, Actions extends string = DefaultActions, User extends AuthorizableUser = AuthorizableUser, > = (builder: UserAbilityBuilder ) => void;
src/interfaces/permissions.interface.ts
✓ Edit
Check src/interfaces/permissions.interface.ts with contents:
Ran GitHub Actions for c7416542f2558694b9753db2fc10eda3033506c9:
src/__specs__/app/post/post.permissions.ts
✓ https://github.com/jjbell170/nest-casl/commit/fb8ec0f73b417a531d8c9a1a153043d950a9976b Edit
Modify src/__specs__/app/post/post.permissions.ts with contents:
• Update the `Subjects` type to include `string` as a possible type, ensuring that the example permissions provided are consistent with the updated type definitions in `permissions.interface.ts`.
• Modify the `permissions` object to reflect the new `Subjects` type, ensuring that string subjects can be used without causing type errors.
--- +++ @@ -3,18 +3,18 @@ import { Roles } from '../app.roles'; import { Post } from './dtos/post.dto'; -type Subjects = InferSubjects; +type Subjects = InferSubjects | string; export const permissions: Permissions = { everyone({ can }) { - can(Actions.read, Post); + can(Actions.read, 'Post'); }, customer({ user, can }) { - can(Actions.create, Post); - can(Actions.update, Post, { userId: user.id }); + can(Actions.create, 'Post'); + can(Actions.update, 'Post', { userId: user.id }); }, operator({ can, cannot }) { - can(Actions.manage, Post); - cannot(Actions.delete, Post); + can(Actions.manage, 'Post'); + cannot(Actions.delete, 'Post'); }, };
src/__specs__/app/post/post.permissions.ts
✓ Edit
Check src/__specs__/app/post/post.permissions.ts with contents:
Ran GitHub Actions for fb8ec0f73b417a531d8c9a1a153043d950a9976b:
I have finished reviewing the code for completeness. I did not find errors for sweep/update_the_library_to_support_string_as
.
💡 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.
There are a few places where we currently expect an object, make sure these all handle an object or a string.
Add new test cases for string, don't just replace the old ones, as both are valid test cases.
Use better typing for subject, that looks messy, avoid union types.
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, it must accept both. Ensure we also update code that expects it to be an object.
Checklist
- [X] Modify `src/interfaces/permissions.interface.ts` ✓ https://github.com/jjbell170/nest-casl/commit/c7416542f2558694b9753db2fc10eda3033506c9 [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as/src/interfaces/permissions.interface.ts#L5-L47) - [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/src/interfaces/permissions.interface.ts#L5-L47) - [X] Modify `src/__specs__/app/post/post.permissions.ts` ✓ https://github.com/jjbell170/nest-casl/commit/fb8ec0f73b417a531d8c9a1a153043d950a9976b [Edit](https://github.com/jjbell170/nest-casl/edit/sweep/update_the_library_to_support_string_as/src/__specs__/app/post/post.permissions.ts#L5-L18) - [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/src/__specs__/app/post/post.permissions.ts#L5-L18)