-
Notifications
You must be signed in to change notification settings - Fork 36
Added support for Loading Filtered Policies from DB #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added support for loading filtered policies
|
Please fix the CI error. |
sorry, is this comment (for CI error) for me to check?....If yes then I tried to analyse as much possible from my side however I did not find anything relevant with respect to my code...I believe this is generic issue of CI/CD pipeline.... |
|
@vinod827 You implement |
How to implement filtered adapter?We need to abide by the following rules. loadPolicyWhen the method is done, set loadFilteredPolicyWhen the method is done, set
|
Is there any example code to set this filtered flag to true? |
|
Hi All, Please check the build. Only 1 is failing due to some issue. Kindly assist to review the PR as well. |
|
Hi @vinod827 , example FilteredAdapter: class TestAdapter implements FilteredAdapter {
private filtered = false;
isFiltered(): boolean {
return this.filtered;
}
async loadPolicy(model: Model): Promise<void> {
// do something - load policy from db
this.filtered = false;
return undefined;
}
async addPolicy(sec: string, ptype: string, rule: string[]): Promise<void> {
if (this.filtered) {
throw new Error("un-support removePolicy in filter model")
}
// do something
}
async loadFilteredPolicy(model: Model, filter: any): Promise<void> {
// do something - load policy from db
this.filtered = true;
}
async removeFilteredPolicy(sec: string, ptype: string, fieldIndex: number, ...fieldValues: string[]): Promise<void> {
if (this.filtered) {
throw new Error("un-support removePolicy in filter model")
}
// do something
}
async removePolicy(sec: string, ptype: string, rule: string[]): Promise<void> {
if (this.filtered) {
throw new Error("un-support removePolicy in filter model")
}
// do something
}
async savePolicy(model: Model): Promise<boolean> {
if (this.filtered) {
throw new Error("un-support removePolicy in filter model")
}
// do something
return true;
}
}
``` |
|
@vinod827 You can remove node6 in CI. mysql2 doesn't support node6. |
test/adapter.test.ts
Outdated
| ['data2_admin', 'data2', 'write']]); | ||
|
|
||
| // Load Filtered Policy | ||
| /*await a.loadFilteredPolicy(e.getModel(), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vinod827 Remove the comments. Run it on test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
README.md
Outdated
| }); | ||
|
|
||
| // Check the permission. | ||
| e.enforce('alice', 'data1', 'read'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
miss await
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, will add, thanks
src/adapter.ts
Outdated
| * TypeORMAdapter represents the TypeORM adapter for policy storage. | ||
| */ | ||
| export default class TypeORMAdapter implements Adapter { | ||
| export default class TypeORMAdapter implements Adapter, FilteredAdapter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good: export default class TypeORMAdapter implements FilteredAdapter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
|
@vinod827 Why remove the |
okay, will add test, thanks |
|
Hi Team, I have incorporated all the review comments as suggested and pushed the changes again. This time only build failed due to some other CI error:- I would really appreciate if you can please have a look and approve my PR after review as this functionality is really important and urgent for us. Thank you, |
|
LGTM, thank @vinod827 for your contribution! Could you rewrite your commits? It's looks chaos :( After that, I will merge it into the master. |
|
@nodece why the CI is still failing? |
|
@hsluoyz Due mysql2 doesn't support node@6: https://travis-ci.org/github/node-casbin/typeorm-adapter/jobs/692144298#L217 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Regard to CI issue, drop the Node.js v6 support from Travis CI. We need to publish it as a major release then.
|
Hm, I thought, |

Hi,
I have coded a new method called loadFilteredPolicy() to load filtered policies from a given entity repo based on filtered object passed to it.
We are using TypeORM Adapter for Casbin in our project and this is an urgent requirement for us to have this missing functionality so I have added in it and raised PR.
Kindly assist to review my PR and approve it.
Thank you,
Vinod Kumar