From d5f1e47a67bbed20ca4e0aaba2e39e890666b1e9 Mon Sep 17 00:00:00 2001 From: basakest Date: Thu, 26 Aug 2021 00:46:46 +0800 Subject: [PATCH] fix: Amend some variables of savePolicy method --- composer.lock | 12 ++++++------ src/Adapter.php | 4 ++-- tests/DatabaseAdapterTest.php | 14 ++++++++++++++ tests/casbin-model.conf | 3 +++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 4d488c0..9ddc349 100644 --- a/composer.lock +++ b/composer.lock @@ -182,16 +182,16 @@ }, { "name": "casbin/casbin", - "version": "v3.7.0", + "version": "v3.8.0", "source": { "type": "git", "url": "/~https://github.com/php-casbin/php-casbin.git", - "reference": "a3d99663905d8211b9e4510578ed6c5800efb29b" + "reference": "ad35666742008b0105688ec3fbc69894f01cb2c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-casbin/php-casbin/zipball/a3d99663905d8211b9e4510578ed6c5800efb29b", - "reference": "a3d99663905d8211b9e4510578ed6c5800efb29b", + "url": "https://api.github.com/repos/php-casbin/php-casbin/zipball/ad35666742008b0105688ec3fbc69894f01cb2c3", + "reference": "ad35666742008b0105688ec3fbc69894f01cb2c3", "shasum": "", "mirrors": [ { @@ -238,7 +238,7 @@ ], "support": { "issues": "/~https://github.com/php-casbin/php-casbin/issues", - "source": "/~https://github.com/php-casbin/php-casbin/tree/v3.7.0" + "source": "/~https://github.com/php-casbin/php-casbin/tree/v3.8.0" }, "funding": [ { @@ -246,7 +246,7 @@ "type": "open_collective" } ], - "time": "2021-08-09T11:57:38+00:00" + "time": "2021-08-24T02:27:43+00:00" }, { "name": "composer/ca-bundle", diff --git a/src/Adapter.php b/src/Adapter.php index 1ed180d..f9dc629 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -62,13 +62,13 @@ public function loadPolicy($model): void public function savePolicy($model): void { - foreach ($model->model['p'] as $ptype => $ast) { + foreach ($model['p'] as $ptype => $ast) { foreach ($ast->policy as $rule) { $this->savePolicyLine($ptype, $rule); } } - foreach ($model->model['g'] as $ptype => $ast) { + foreach ($model['g'] as $ptype => $ast) { foreach ($ast->policy as $rule) { $this->savePolicyLine($ptype, $rule); } diff --git a/tests/DatabaseAdapterTest.php b/tests/DatabaseAdapterTest.php index 6bf551f..0bdd56d 100644 --- a/tests/DatabaseAdapterTest.php +++ b/tests/DatabaseAdapterTest.php @@ -95,6 +95,20 @@ public function testAddPolicies() $this->assertEquals($policies, $e->getPolicy()); } + public function testSavePolicy() + { + $e = $this->getEnforcer(); + $this->assertFalse($e->enforce('alice', 'data4', 'read')); + + $model = $e->getModel(); + $model->clearPolicy(); + $model->addPolicy('p', 'p', ['alice', 'data4', 'read']); + + $adapter = $e->getAdapter(); + $adapter->savePolicy($model); + $this->assertTrue($e->enforce('alice', 'data4', 'read')); + } + public function testRemovePolicy() { $e = $this->getEnforcer(); diff --git a/tests/casbin-model.conf b/tests/casbin-model.conf index dc6da81..6926caf 100644 --- a/tests/casbin-model.conf +++ b/tests/casbin-model.conf @@ -4,6 +4,9 @@ r = sub, obj, act [policy_definition] p = sub, obj, act +[role_definition] +g = _, _ + [policy_effect] e = some(where (p.eft == allow))