casbin / casbin-pg-adapter

A go-pg adapter for casbin
https://github.com/casbin/casbin
Apache License 2.0
38 stars 28 forks source link

Add updatePolicies() API to this adapter #21

Closed arafat-java closed 3 years ago

arafat-java commented 3 years ago

I wanted transaction in my project where I am using casbin-pg-adapter

So the approach that I am taking is

e.EnableAutoSave(false)
e.addPolicy(abc...)
e.addPolicy(uvw...)
e.addPolicy(xyz...)
e.SavePolicy()

But when I call "e.SavePolicy()" it clears the database because it fires the following query

DELETE FROM casbin_rule_falcon AS "casbin_rule" WHERE (id IS NOT NULL)

  1. Can this be fixed
  2. Is there am alternate approach that I can take for transaction management
hsluoyz commented 3 years ago

@arafat-java use addPolicies().

arafat-java commented 3 years ago

I have been using addPolicies... but I need to first delete the existing policies for that object and hence would need the transaction management I tried updatePolicies but it seems that this adapter doesn't support updatePolicies

hsluoyz commented 3 years ago

@arafat-java then we need to add updatePolicies() to this adapter. @closetool can you take a look at it?

See some details at:

arafat-java commented 3 years ago

Even if we add the updatePolicies to this adapter wouldn't it still be a bug if e.SavePolicy() clears the database? Is there a specific reason for calling 'DELETE FROM casbin_rule_falcon AS "casbin_rule" WHERE (id IS NOT NULL) ' when e.SavePolicy is called

hsluoyz commented 3 years ago

e.SavePolicy()'s logic is just deleting all in DB, then add all from local to DB. This is the expected behavior starting from the initial design.

arafat-java commented 3 years ago

Any rough estimate when the UpdatePolicies will be implemented in the adapter

hsluoyz commented 3 years ago

@arafat-java PR ready.

hsluoyz commented 3 years ago

@closetool PR merged, plz make a new release.

hsluoyz commented 3 years ago

@arafat-java released: https://github.com/casbin/casbin-pg-adapter/releases/tag/v0.1.8

arafat-java commented 3 years ago

I pulled the latest code and I can see that UpdatePolicies is implemented. But the implementation is buggy. Have raised https://github.com/casbin/casbin-pg-adapter/issues/23 for the same