Skip to content

Commit d4dba11

Browse files
committed
fix: formatting of role manager of implementation
1 parent 269bbec commit d4dba11

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

casbin/rbac/default_role_manager.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ void Role :: AddRole(Role* role) {
2222

2323
void Role :: DeleteRole(Role* role) {
2424
for (int i = 0; i < roles.size();i++) {
25-
if (!roles[i]->name.compare(role->name)) {
25+
if (!roles[i]->name.compare(role->name))
2626
roles.erase(roles.begin()+i);
27-
}
2827
}
2928
}
3029

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

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

4242
return false;
4343
}
4444

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

5051
return false;
5152
}
@@ -73,10 +74,12 @@ vector<string> Role :: GetRoles() {
7374

7475
bool DefaultRoleManager :: HasRole(string name) {
7576
bool ok = false;
76-
if (this->has_pattern)
77-
for (unordered_map<string, Role*> :: iterator it = this->all_roles.begin() ; it != this->all_roles.end() ; it++)
77+
if (this->has_pattern){
78+
for (unordered_map<string, Role*> :: iterator it = this->all_roles.begin() ; it != this->all_roles.end() ; it++){
7879
if (this->matching_func(name, it->first))
7980
ok = true;
81+
}
82+
}
8083
else
8184
ok = this->all_roles.find(name) != this->all_roles.end();
8285

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

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

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

222225
return roles;
223226
}
@@ -238,9 +241,10 @@ vector<string> DefaultRoleManager :: GetUsers(string name, vector<string> domain
238241
names.push_back(role->name);
239242
}
240243

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

245249
return names;
246250
}

0 commit comments

Comments
 (0)