Skip to content

Commit

Permalink
SAK-41268 Wrap site perms in an ActionReturn (sakaiproject#6514)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored and ern committed Feb 5, 2019
1 parent 03a98d6 commit a3ea7f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.Set;
import java.util.TreeSet;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.azeckoski.reflectutils.ReflectUtils;
Expand Down Expand Up @@ -91,46 +93,19 @@
* @author Aaron Zeckoski (azeckoski @ gmail.com)
*/
@Slf4j
@Setter
public class SiteEntityProvider extends AbstractEntityProvider implements CoreEntityProvider,
RESTful, ActionsExecutable, Redirectable, RequestStorable, DepthLimitable {

@Getter
private int maxDepth = 7;
public void setMaxDepth(int maxDepth) {
this.maxDepth = maxDepth;
}
public int getMaxDepth() {
return maxDepth;
}

private SiteService siteService;
public void setSiteService(SiteService siteService) {
this.siteService = siteService;
}

private AuthzGroupService authzGroupService;
public void setAuthzGroupService(AuthzGroupService authzGroupService) {
this.authzGroupService = authzGroupService;
}

private FunctionManager functionManager;
public void setFunctionManager(FunctionManager functionManager) {
this.functionManager = functionManager;
}

private UserEntityProvider userEntityProvider;
public void setUserEntityProvider(UserEntityProvider userEntityProvider) {
this.userEntityProvider = userEntityProvider;
}

private ServerConfigurationService serverConfigurationService;
public void setServerConfigurationService(ServerConfigurationService serverConfigurationService) {
this.serverConfigurationService = serverConfigurationService;
}

private SecurityService securityService;
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}

public static String PREFIX = "site";
public String getEntityPrefix() {
Expand Down Expand Up @@ -228,7 +203,8 @@ public void handleRoles(EntityView view) {
}

@EntityCustomAction(action = "perms", viewKey = EntityView.VIEW_SHOW)
public Map<String, Set<String>> handlePerms(EntityView view) {
public ActionReturn handlePerms(EntityView view, Map<String, Object> params) {

// expects site/siteId/perms[/:PREFIX:]
String prefix = view.getPathSegment(3);

Expand All @@ -241,10 +217,10 @@ public Map<String, Set<String>> handlePerms(EntityView view) {
String siteId = view.getEntityReference().getId();
Site site = getSiteById(siteId);
Set<Role> roles = site.getRoles();
Map<String, Set<String>> perms = new HashMap<String, Set<String>>();
Map<String, Set<String>> on = new HashMap<>();
for (Role role : roles) {
Set<String> functions = role.getAllowedFunctions();
Set<String> filteredFunctions = new TreeSet<String>();
Set<String> filteredFunctions = new TreeSet<>();
if (prefix != null) {
for (String function : functions) {
if (function.startsWith(prefix)) {
Expand All @@ -254,9 +230,18 @@ public Map<String, Set<String>> handlePerms(EntityView view) {
} else {
filteredFunctions = functions;
}
perms.put(role.getId(), filteredFunctions);
on.put(role.getId(), filteredFunctions);
}

if (params.getOrDefault("includeAvailable", "false").equals("true")) {
List<String> available = functionManager.getRegisteredFunctions(prefix);
Map<String, Object> data = new HashMap<>();
data.put("on", on);
data.put("available", available);
return new ActionReturn(data);
} else {
return new ActionReturn(on);
}
return perms;
}

@EntityCustomAction(action="setPerms", viewKey=EntityView.VIEW_EDIT)
Expand Down
2 changes: 1 addition & 1 deletion roster2/tool/src/webapp/lib/sakai_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
dataType: "json",
cache: false,
success: function (p) {
callback(p.data);
callback(p);
},
error: function (xmlHttpRequest, stat, error) {
alert("Failed to get permissions. Status: " + stat + ". Error: " + error);
Expand Down

0 comments on commit a3ea7f5

Please sign in to comment.