Skip to content

Commit

Permalink
fix: formatting of role manager of implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
divy9881 committed Jun 27, 2020
1 parent 269bbec commit d4dba11
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions casbin/rbac/default_role_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ void Role :: AddRole(Role* role) {

void Role :: DeleteRole(Role* role) {
for (int i = 0; i < roles.size();i++) {
if (!roles[i]->name.compare(role->name)) {
if (!roles[i]->name.compare(role->name))
roles.erase(roles.begin()+i);
}
}
}

Expand All @@ -35,17 +34,19 @@ bool Role :: HasRole(string name, int hierarchy_level) {
if (hierarchy_level <= 0)
return false;

for(int i = 0 ; i < roles.size() ; i++)
for(int i = 0 ; i < roles.size() ; i++){
if (roles[i]->HasRole(name, hierarchy_level - 1))
return true;
}

return false;
}

bool Role :: HasDirectRole(string name) {
for(int i = 0 ; i < roles.size() ; i++)
for(int i = 0 ; i < roles.size() ; i++){
if (!roles[i]->name.compare(name))
return true;
}

return false;
}
Expand Down Expand Up @@ -73,10 +74,12 @@ vector<string> Role :: GetRoles() {

bool DefaultRoleManager :: HasRole(string name) {
bool ok = false;
if (this->has_pattern)
for (unordered_map<string, Role*> :: iterator it = this->all_roles.begin() ; it != this->all_roles.end() ; it++)
if (this->has_pattern){
for (unordered_map<string, Role*> :: iterator it = this->all_roles.begin() ; it != this->all_roles.end() ; it++){
if (this->matching_func(name, it->first))
ok = true;
}
}
else
ok = this->all_roles.find(name) != this->all_roles.end();

Expand Down Expand Up @@ -146,9 +149,8 @@ void DefaultRoleManager :: AddLink(string name1, string name2, vector<string> do
if (domain.size() == 1) {
name1 = domain[0] + "::" + name1;
name2 = domain[0] + "::" + name2;
} else if (domain.size() > 1) {
} else if (domain.size() > 1)
throw CasbinRBACException("error: domain should be 1 parameter");
}

Role* role1 = this->CreateRole(name1);
Role* role2 = this->CreateRole(name2);
Expand Down Expand Up @@ -215,9 +217,10 @@ vector<string> DefaultRoleManager :: GetRoles(string name, vector<string> domain
}

vector<string> roles = this->CreateRole(name)->GetRoles();
if (domain_length == 1)
if (domain_length == 1){
for (int i = 0; i < roles.size(); i ++)
roles[i] = roles[i].substr(domain[0].length() + 2, roles[i].length() - domain[0].length() - 2);
}

return roles;
}
Expand All @@ -238,9 +241,10 @@ vector<string> DefaultRoleManager :: GetUsers(string name, vector<string> domain
names.push_back(role->name);
}

if (domain.size() == 1)
if (domain.size() == 1){
for (int i = 0 ; i < names.size() ; i++)
names[i] = names[i].substr(domain[0].length() + 2, names[i].length() - domain[0].length() - 2);
}

return names;
}
Expand Down

0 comments on commit d4dba11

Please sign in to comment.