Skip to content

Commit

Permalink
Merge pull request sakaiproject#739 from frasese/SAK-29585
Browse files Browse the repository at this point in the history
SAK-29585 : Add additional roles permissions to Admin Site Perms tool
  • Loading branch information
buckett committed Nov 4, 2015
2 parents d641930 + b4ffa2c commit c980f04
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ public List<String> getValidRoles() {
Collections.sort(roles);
return roles;
}

/**
* @return a list of additional valid roles
*/
public List<AdditionalRole> getAdditionalRoles() {
HashSet<AdditionalRole> roleSet = new HashSet<AdditionalRole>();
roleSet.add(new AdditionalRole(".anon", authzGroupService.getRoleName(".anon")));
roleSet.add(new AdditionalRole(".auth", authzGroupService.getRoleName(".auth")));

for(String roleId : authzGroupService.getAdditionalRoles())
roleSet.add(new AdditionalRole(roleId, authzGroupService.getRoleName(roleId)));

List<AdditionalRole> ret = new ArrayList<AdditionalRole>(roleSet);
Collections.sort(ret);
return ret;
}

/**
* @return true if current user is super admin
Expand Down Expand Up @@ -363,6 +379,50 @@ public static String makeStringFromArray(String[] array) {
}
return sb.toString();
}

public class AdditionalRole implements Comparable<AdditionalRole> {
private String id;
private String name;
private String groupId;

public AdditionalRole(String id, String name) {
this.id = id;
this.name = name;

int index = id.lastIndexOf(".");
this.groupId = (index >= 0) ? id.substring(0, index) : "";
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getGroupId() {
return groupId;
}

public boolean equals(Object obj) {
if (!(obj instanceof AdditionalRole))
return false;
if (obj == this)
return true;
return this.id.equals(((AdditionalRole) obj).id);
}

public int hashCode(){
return id.hashCode();
}

@Override
public int compareTo(AdditionalRole arg0) {
if(arg0 == null) return 1;
return (this.groupId+"_"+this.name).compareTo(arg0.groupId+"_"+arg0.name);
}
}


private AuthzGroupService authzGroupService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpSer
model.put("siteTypes", sitePermsService.getSiteTypes());
model.put("roles", sitePermsService.getValidRoles());
model.put("permissions", sitePermsService.getPermissions());
model.put("additionalRoles", sitePermsService.getAdditionalRoles());

return new ModelAndView("sitePerms", model);
}
Expand Down
13 changes: 13 additions & 0 deletions site/admin-perms-tool/src/main/webapp/WEB-INF/jsp/sitePerms.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
<label for="roleSelect-${role}">${role}</label>
</li>
</c:forEach>
<c:if test="${not empty additionalRoles}">
<c:set var="lastGroupRole" value="-none-"/>
<c:forEach var="additionalrole" items="${additionalRoles}" varStatus="counter">
<c:if test="${lastGroupRole != additionalrole.groupId}">
<li><hr/></li>
</c:if>
<li class="checkbox">
<input id="roleSelect-${additionalrole.id}" type="checkbox" name="site-role" value="${additionalrole.id}" />
<label for="roleSelect-${additionalrole.id}">${additionalrole.name}</label>
</li>
<c:set var="lastGroupRole" value="${additionalrole.groupId}"/>
</c:forEach>
</c:if>
</ul>
</fieldset>
</div>
Expand Down

0 comments on commit c980f04

Please sign in to comment.