/** * Look up the id of a group authorized for one of the given roles. If no group is currently * authorized to perform this role then a new group will be created and assigned the role. * * @param context The current DSpace context. * @param communityID The collection id. * @param roleName ADMIN. * @return The id of the group associated with that particular role, or -1 if the role was not * found. */ public static int getCommunityRole(Context context, int communityID, String roleName) throws SQLException, AuthorizeException, IOException { Community community = Community.find(context, communityID); // Determine the group based upon which role we are looking for. Group role = null; if (ROLE_ADMIN.equals(roleName)) { role = community.getAdministrators(); if (role == null) { role = community.createAdministrators(); } } // In case we needed to create a group, save our changes community.update(); context.commit(); // If the role name was valid then role should be non null, if (role != null) { return role.getID(); } return -1; }
public void addBody(Body body) throws WingException, SQLException, AuthorizeException { int communityID = parameters.getParameterAsInteger("communityID", -1); Community thisCommunity = Community.find(context, communityID); String baseURL = contextPath + "/admin/community?administrative-continue=" + knot.getId(); Group admins = thisCommunity.getAdministrators(); // DIVISION: main Division main = body.addInteractiveDivision( "community-assign-roles", contextPath + "/admin/community", Division.METHOD_POST, "primary administrative community"); main.setHead(T_main_head.parameterize(thisCommunity.getName())); List options = main.addList("options", List.TYPE_SIMPLE, "horizontal"); options.addItem().addXref(baseURL + "&submit_metadata", T_options_metadata); options.addItem().addHighlight("bold").addXref(baseURL + "&submit_roles", T_options_roles); options.addItem().addXref(baseURL + "&submit_curate", T_options_curate); // The table of admin roles Table rolesTable = main.addTable("roles-table", 6, 5); Row tableRow; // The header row Row tableHeader = rolesTable.addRow(Row.ROLE_HEADER); tableHeader.addCell().addContent(T_role_name); tableHeader.addCell().addContent(T_role_group); tableHeader.addCell().addContent(T_role_buttons); rolesTable.addRow(); /* * The community admins */ // data row tableRow = rolesTable.addRow(Row.ROLE_DATA); tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_admins); if (admins != null) { try { AuthorizeUtil.authorizeManageAdminGroup(context, thisCommunity); tableRow.addCell().addXref(baseURL + "&submit_edit_admin", admins.getName()); } catch (AuthorizeException authex) { // add a notice, the user is not authorized to create/edit community's admin group tableRow.addCell().addContent(T_sysadmins_only); } try { AuthorizeUtil.authorizeRemoveAdminGroup(context, thisCommunity); tableRow.addCell().addButton("submit_delete_admin").setValue(T_delete); } catch (AuthorizeException authex) { // nothing to add, the user is not allowed to delete the group } } else { tableRow.addCell().addContent(T_no_role); Cell commAdminCell = tableRow.addCell(); try { AuthorizeUtil.authorizeManageAdminGroup(context, thisCommunity); commAdminCell.addButton("submit_create_admin").setValue(T_create); } catch (AuthorizeException authex) { // add a notice, the user is not authorized to create/edit community's admin group addAdministratorOnlyButton(commAdminCell, "submit_create_admin", T_create); } } // help and directions row tableRow = rolesTable.addRow(Row.ROLE_DATA); tableRow.addCell(); tableRow.addCell(1, 2).addHighlight("fade offset").addContent(T_help_admins); try { AuthorizeUtil.authorizeManageCommunityPolicy(context, thisCommunity); // add one last link to edit the raw authorizations Cell authCell = rolesTable.addRow().addCell(1, 3); authCell.addXref(baseURL + "&submit_authorizations", T_edit_authorizations); } catch (AuthorizeException authex) { // nothing to add, the user is not authorized to manage community's policies } Para buttonList = main.addPara(); buttonList.addButton("submit_return").setValue(T_submit_return); main.addHidden("administrative-continue").setValue(knot.getId()); }