casbin / casbin-pg-adapter

A go-pg adapter for casbin

Home Page:https://github.com/casbin/casbin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AddPolicies does not act as expected for new additions.

adamwoolhether opened this issue · comments

Per documentaiton: "AddPolicies adds authorization rules to the current policy. If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. Otherwise the function returns true for the corresponding rule by adding the new rule."

Upon loading policies to a clean DB table, all policies are updated.

Closing the my application, adding new rules to the policies file, and restarting the application, newly added policies are not added.

Instead, I have to range over my rules [][]string calling, AddPolicy each iteration to order to add the new policies.

This also begs the question, how to update policies deleted from the file, how are we supposed "sync" our db's casbin_rule table with our source-policy file, or is this possible? Right now, the only solution i have is the call ClearPolicy() and AddPolicies() each time at app-initialization.

go v1.17.6
postgresql 11.12.0
github.com/casbin/casbin-pg-adapter v1.0.4
github.com/casbin/casbin/v2 v2.41.0

@adamwoolhether

Closing the my application, adding new rules to the policies file, and restarting the application, newly added policies are not added.

See: https://casbin.org/docs/en/adapters#autosave

This also begs the question, how to update policies deleted from the file, how are we supposed "sync" our db's casbin_rule table with our source-policy file, or is this possible?

See: https://casbin.org/docs/en/adapters#migrateconvert-between-different-adapter

@adamwoolhether

  1. First of all, it should be clear that file and database are two different adapters. Generally only choose one of them instead of using them together.
  2. file adapter is read-only and not writable
  3. You have to keep the file and the database in sync, I think it's weird, casbin doesn't seem to help you with that, you have to write your own code to write policies to the file.

Closed as resolved.