node-casbin icon indicating copy to clipboard operation
node-casbin copied to clipboard

Fix: Discrepancy between `getAllNamedRoles` function implementation and comments

Open divyank-sc opened this issue 2 months ago • 5 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

divyank-sc avatar Apr 28 '24 06:04 divyank-sc

@nodece @Shivansh-yadav13

casbin-bot avatar Apr 28 '24 06:04 casbin-bot

@divyank-sc see Go Casbin

hsluoyz avatar Apr 28 '24 07:04 hsluoyz

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: Screenshot 2024-04-28 at 4 18 12 PM Screenshot 2024-04-28 at 4 18 20 PM

divyank-sc avatar Apr 28 '24 10:04 divyank-sc

@divyank-sc hi, can you make a PR to fix it?

hsluoyz avatar Apr 28 '24 17:04 hsluoyz

@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.

divyank-sc avatar Apr 29 '24 04:04 divyank-sc

Closed, see: https://github.com/casbin/node-casbin/pull/477#issuecomment-2082355776

hsluoyz avatar Apr 29 '24 10:04 hsluoyz