<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.HashSet" %> <%@ page import="org.crosswire.webtools.RightsAndRoles" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="org.crosswire.webtools.*" %> <%! @Description(value = "Retrieve membership status", name = "projectmanagement/usergroup/ismember") public static class MyParameters extends Parameters { @Description(value = "user group id to check", example = "32") public Integer userGroupID; @Description(value = "user group name to check", example = "ECM Matthew") public String userGroupName; @Description(value = "user id to check", example = "19763") public Integer userID; @Description(value = "user name to check", example = "joe") public String userName; @Override protected void customValidation() { if (userID == null && userName == null) { addError(-4, "Must supply either {userID} or {userName}."); return; } if (userGroupID == null && userGroupName == null) { addError(-4, "Must supply either {userGroupID} or {userGroupName}."); return; } } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { Set memberGroups = new HashSet(); if (params.userID != null) { memberGroups = RightsAndRoles.getInstance().getUserGroups(params.userID); } else { memberGroups = RightsAndRoles.getInstance().getUserGroups(params.userName); } params.getLogger().info("usergroup/ismember: userID: " + params.userID + "; userGroupID: " + params.userGroupID + "; userGroupName: " + params.userGroupName); boolean isMember = false; RightsAndRoles.UserGroup group = null; if (params.userGroupID != null) { RightsAndRoles.User u = (params.userID == null) ? RightsAndRoles.getInstance().getUser(params.userName) : RightsAndRoles.getInstance().getUser(params.userID); group = RightsAndRoles.getInstance().getUserGroup(params.userGroupID); if (group != null && u != null && u.getFullName().equals(group.getUserGroupName())) isMember = true; // personal site } if (!isMember) { for (RightsAndRoles.UserGroup g : memberGroups) { params.getLogger().debug("checking " + params.userGroupName + " == " + g.getUserGroupName() + "; " + params.userGroupID + " == " + g.getID()); if ( (params.userGroupID != null && g.getID() == params.userGroupID) || (params.userGroupName != null && params.userGroupName.equals(g.getUserGroupName()))) { group = g; isMember = true; break; } } } Serializer.output(response, out, params, XMLBlock.createXMLBlock( "" )); return; } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>