diff --git a/sitestats/sitestats-tool/src/java/org/sakaiproject/sitestats/tool/wicket/pages/ReportsEditPage.java b/sitestats/sitestats-tool/src/java/org/sakaiproject/sitestats/tool/wicket/pages/ReportsEditPage.java index ae25e4c5e941..ba746bb17cfb 100644 --- a/sitestats/sitestats-tool/src/java/org/sakaiproject/sitestats/tool/wicket/pages/ReportsEditPage.java +++ b/sitestats/sitestats-tool/src/java/org/sakaiproject/sitestats/tool/wicket/pages/ReportsEditPage.java @@ -64,7 +64,7 @@ import org.apache.wicket.model.StringResourceModel; import org.apache.wicket.util.convert.IConverter; import org.apache.wicket.util.convert.converter.IntegerConverter; - +import org.sakaiproject.authz.api.GroupNotDefinedException; import org.sakaiproject.authz.api.Role; import org.sakaiproject.event.api.EventTrackingService; import org.sakaiproject.exception.IdUnusedException; @@ -1119,16 +1119,24 @@ private List getGroups() { } private List getRoles() { + Set siteIdWithRoles = new HashSet<>(Arrays.asList(siteId)); + + if ("!admin".equals(siteId) || "~admin".equals(siteId)) { + siteIdWithRoles.add("!site.template"); + siteIdWithRoles.add("!site.user"); + Locator.getFacade().getSiteService().getSiteTypes().stream().map(s -> "!site.template." + s).forEach(siteIdWithRoles::add); + } + List roles = new ArrayList(); - try{ - Set roleSet = Locator.getFacade().getSiteService().getSite(siteId).getRoles(); - Iterator i = roleSet.iterator(); - while(i.hasNext()){ - Role r = i.next(); - roles.add(r.getId()); + try { + for (String s : siteIdWithRoles) { + Set roleSet = Locator.getFacade().getAuthzGroupService().getAuthzGroup(s).getRoles(); + for (Role r : roleSet) { + roles.add(r.getId()); + } } - }catch(IdUnusedException e){ - log.warn("Site does not exist: " + siteId); + }catch(GroupNotDefinedException e){ + log.warn("Site does not exist: {}", siteIdWithRoles); } return roles; @@ -1194,7 +1202,7 @@ && getReportParams().isWhatLimitedResourceIds() // check WHO if(getReportParams().getWho().equals(ReportManager.WHO_ROLE)){ - if(site.getUsersHasRole(getReportParams().getWhoRoleId()).isEmpty()) + if(!siteId.equals("!admin") && !siteId.equals("~admin") && site.getUsersHasRole(getReportParams().getWhoRoleId()).isEmpty()) error((String) new ResourceModel("report_err_emptyrole").getObject()); }else if(getReportParams().getWho().equals(ReportManager.WHO_GROUPS)){ if(getReportParams().getWhoGroupId() == null || getReportParams().getWhoGroupId().equals(""))