Skip to content

Commit 397d973

Browse files
author
stonex
committed
fix: fix casbin::Enforcer::AddPolicies() (#117)
- change FileAdaptor to BatchFileAdaptor when construct file adopter - #117 Signed-off-by: stonex <[email protected]>
1 parent ad6268e commit 397d973

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

casbin/enforcer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "./enforcer.h"
2626
#include "./persist/watcher_ex.h"
2727
#include "./persist/file_adapter/file_adapter.h"
28+
#include "./persist/file_adapter/batch_file_adapter.h"
2829
#include "./rbac/default_role_manager.h"
2930
#include "./effect/default_effector.h"
3031
#include "./exception/casbin_adapter_exception.h"
@@ -179,7 +180,7 @@ Enforcer ::Enforcer() {
179180
* @param policyFile the path of the policy file.
180181
*/
181182
Enforcer ::Enforcer(const std::string& model_path, const std::string& policy_file)
182-
: Enforcer(model_path, std::make_shared<FileAdapter>(policy_file)) {
183+
: Enforcer(model_path, std::make_shared<BatchFileAdapter>(policy_file)) {
183184
}
184185

185186
/**
@@ -233,14 +234,14 @@ Enforcer ::Enforcer(const std::string& model_path): Enforcer(model_path, "") {
233234
* @param enableLog whether to enable Casbin's log.
234235
*/
235236
Enforcer::Enforcer(const std::string& model_path, const std::string& policy_file, bool enable_log)
236-
: Enforcer(model_path, std::make_shared<FileAdapter>(policy_file)) {
237+
: Enforcer(model_path, std::make_shared<BatchFileAdapter>(policy_file)) {
237238
this->EnableLog(enable_log);
238239
}
239240

240241

241242
// InitWithFile initializes an enforcer with a model file and a policy file.
242243
void Enforcer::InitWithFile(const std::string& model_path, const std::string& policy_path) {
243-
std::shared_ptr<Adapter> a = std::make_shared<FileAdapter>(policy_path);
244+
std::shared_ptr<Adapter> a = std::make_shared<BatchFileAdapter>(policy_path);
244245
this->InitWithAdapter(model_path, a);
245246
}
246247

tests/rbac_api_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ TEST(TestRBACAPI, TestImplicitUserAPI) {
222222
e.ClearPolicy();
223223
e.AddPolicy({ "admin", "data1", "read" });
224224
e.AddPolicy({ "bob", "data1", "read" });
225+
e.AddPolicies({{ "tom", "data1", "read" }, {"john", "data1", "read" }});
225226
e.AddGroupingPolicy({ "alice", "admin" });
226-
ASSERT_TRUE(casbin::ArrayEquals({ "alice", "bob" }, e.GetImplicitUsersForPermission({ "data1", "read" })));
227+
228+
ASSERT_TRUE(casbin::ArrayEquals({ "alice", "bob", "tom", "john"}, e.GetImplicitUsersForPermission({ "data1", "read" })));
227229
}
228230

229231
} // namespace

0 commit comments

Comments
 (0)