Skip to content

Commit

Permalink
Merge pull request #156 from sheny1xuan/fix_Enforcer_AddPolicy
Browse files Browse the repository at this point in the history
fix: fix casbin::Enforcer::AddPolicies() (#117)
  • Loading branch information
hsluoyz authored Oct 27, 2021
2 parents ad6268e + 397d973 commit c14bf4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions casbin/enforcer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "./enforcer.h"
#include "./persist/watcher_ex.h"
#include "./persist/file_adapter/file_adapter.h"
#include "./persist/file_adapter/batch_file_adapter.h"
#include "./rbac/default_role_manager.h"
#include "./effect/default_effector.h"
#include "./exception/casbin_adapter_exception.h"
Expand Down Expand Up @@ -179,7 +180,7 @@ Enforcer ::Enforcer() {
* @param policyFile the path of the policy file.
*/
Enforcer ::Enforcer(const std::string& model_path, const std::string& policy_file)
: Enforcer(model_path, std::make_shared<FileAdapter>(policy_file)) {
: Enforcer(model_path, std::make_shared<BatchFileAdapter>(policy_file)) {
}

/**
Expand Down Expand Up @@ -233,14 +234,14 @@ Enforcer ::Enforcer(const std::string& model_path): Enforcer(model_path, "") {
* @param enableLog whether to enable Casbin's log.
*/
Enforcer::Enforcer(const std::string& model_path, const std::string& policy_file, bool enable_log)
: Enforcer(model_path, std::make_shared<FileAdapter>(policy_file)) {
: Enforcer(model_path, std::make_shared<BatchFileAdapter>(policy_file)) {
this->EnableLog(enable_log);
}


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

Expand Down
4 changes: 3 additions & 1 deletion tests/rbac_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ TEST(TestRBACAPI, TestImplicitUserAPI) {
e.ClearPolicy();
e.AddPolicy({ "admin", "data1", "read" });
e.AddPolicy({ "bob", "data1", "read" });
e.AddPolicies({{ "tom", "data1", "read" }, {"john", "data1", "read" }});
e.AddGroupingPolicy({ "alice", "admin" });
ASSERT_TRUE(casbin::ArrayEquals({ "alice", "bob" }, e.GetImplicitUsersForPermission({ "data1", "read" })));

ASSERT_TRUE(casbin::ArrayEquals({ "alice", "bob", "tom", "john"}, e.GetImplicitUsersForPermission({ "data1", "read" })));
}

} // namespace

0 comments on commit c14bf4e

Please sign in to comment.