@Override public Group createAdministrators(Context context, Community community) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create more Admins AuthorizeUtil.authorizeManageAdminGroup(context, community); Group admins = community.getAdministrators(); if (admins == null) { // turn off authorization so that Community Admins can create Sub-Community Admins context.turnOffAuthorisationSystem(); admins = groupService.create(context); context.restoreAuthSystemState(); admins.setName(context, "COMMUNITY_" + community.getID() + "_ADMIN"); groupService.update(context, admins); } authorizeService.addPolicy(context, community, Constants.ADMIN, admins); // register this as the admin group community.setAdmins(admins); return admins; }
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()); }