node-casbin
node-casbin copied to clipboard
Fix: Discrepancy between `getAllNamedRoles` function implementation and comments
Title: Discrepancy between getAllNamedRoles
function implementation and comments
Body:
Hello,
I was going through the getAllNamedRoles
function in the managementEnforcer.ts
file and noticed a discrepancy between the function's implementation and the comments.
According to the comments, the function is supposed to collect the 0-index elements of the policy rules. However, in the implementation, it seems to be collecting the 1-index elements instead:
public async getAllNamedRoles(ptype: string): Promise<string[]> { return this.model.getValuesForFieldInPolicy('g', ptype, 1); }
Could you please clarify if this is the intended behavior or if it's a mistake in the comments or the implementation?
In the meantime, could you suggest any alternative function that collects the 0-index elements as described in the comments?
Thank you for your time and for maintaining this project.
Best regards, Divyank
@nodece @Shivansh-yadav13
@divyank-sc see Go Casbin
The node implementation has comment stating that it fetches 0-index element. In go there isn't any such comment but underlying implementation seems same in both. Have attached SS below for your ref.
PS: Our project in which we are using casbin is in node:
@divyank-sc hi, can you make a PR to fix it?
@hsluoyz I have raised the fix for correcting the index that is being used to collect policies (changed it from 1 to 0) and not the actual documentation. I hope that is fine since we also got to the bug because of that itself as our use case also called for policies to be collected on 0 based index.
Please let me know of semantics related issue if any, in the raised PR.
Closed, see: https://github.com/casbin/node-casbin/pull/477#issuecomment-2082355776