@Override public void canEdit(Context context, Community community) throws AuthorizeException, SQLException { List<Community> parents = getAllParents(context, community); for (Community parent : parents) { if (authorizeService.authorizeActionBoolean(context, parent, Constants.WRITE)) { return; } if (authorizeService.authorizeActionBoolean(context, parent, Constants.ADD)) { return; } } authorizeService.authorizeAction(context, community, Constants.WRITE); }
@Override public void delete(Context context, Community community) throws SQLException, AuthorizeException, IOException { // Check authorisation // FIXME: If this was a subcommunity, it is first removed from it's // parent. // This means the parentCommunity == null // But since this is also the case for top-level communities, we would // give everyone rights to remove the top-level communities. // The same problem occurs in removing the logo if (!authorizeService.authorizeActionBoolean( context, getParentObject(context, community), Constants.REMOVE)) { authorizeService.authorizeAction(context, community, Constants.DELETE); } ArrayList<String> removedIdentifiers = getIdentifiers(context, community); String removedHandle = community.getHandle(); UUID removedId = community.getID(); // If not a top-level community, have parent remove me; this // will call rawDelete() before removing the linkage Community parent = (Community) getParentObject(context, community); if (parent != null) { // remove the subcommunities first Iterator<Community> subcommunities = community.getSubcommunities().iterator(); while (subcommunities.hasNext()) { Community subCommunity = subcommunities.next(); subcommunities.remove(); delete(context, subCommunity); } // now let the parent remove the community removeSubcommunity(context, parent, community); return; } rawDelete(context, community); context.addEvent( new Event( Event.REMOVE, Constants.SITE, siteService.findSite(context).getID(), Constants.COMMUNITY, removedId, removedHandle, removedIdentifiers)); }
@Override public Bitstream setLogo(Context context, Community community, InputStream is) throws AuthorizeException, IOException, SQLException { // Check authorisation // authorized to remove the logo when DELETE rights // authorized when canEdit if (!((is == null) && authorizeService.authorizeActionBoolean(context, community, Constants.DELETE))) { canEdit(context, community); } // First, delete any existing logo Bitstream oldLogo = community.getLogo(); if (oldLogo != null) { log.info(LogManager.getHeader(context, "remove_logo", "community_id=" + community.getID())); community.setLogo(null); bitstreamService.delete(context, oldLogo); } if (is != null) { Bitstream newLogo = bitstreamService.create(context, is); community.setLogo(newLogo); // now create policy for logo bitstream // to match our READ policy List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, community, Constants.READ); authorizeService.addPolicies(context, policies, newLogo); log.info( LogManager.getHeader( context, "set_logo", "community_id=" + community.getID() + "logo_bitstream_id=" + newLogo.getID())); } return community.getLogo(); }
@Override public Community create(Community parent, Context context, String handle) throws SQLException, AuthorizeException { if (!(authorizeService.isAdmin(context) || (parent != null && authorizeService.authorizeActionBoolean(context, parent, Constants.ADD)))) { throw new AuthorizeException("Only administrators can create communities"); } Community newCommunity = communityDAO.create(context, new Community()); try { if (handle == null) { handleService.createHandle(context, newCommunity); } else { handleService.createHandle(context, newCommunity, handle); } } catch (IllegalStateException ie) { // If an IllegalStateException is thrown, then an existing object is already using this handle throw ie; } if (parent != null) { parent.addSubCommunity(newCommunity); newCommunity.addParentCommunity(parent); } // create the default authorization policy for communities // of 'anonymous' READ Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS); authorizeService.createResourcePolicy( context, newCommunity, anonymousGroup, null, Constants.READ, null); communityDAO.save(context, newCommunity); context.addEvent( new Event( Event.CREATE, Constants.COMMUNITY, newCommunity.getID(), newCommunity.getHandle(), getIdentifiers(context, newCommunity))); // if creating a top-level Community, simulate an ADD event at the Site. if (parent == null) { context.addEvent( new Event( Event.ADD, Constants.SITE, siteService.findSite(context).getID(), Constants.COMMUNITY, newCommunity.getID(), newCommunity.getHandle(), getIdentifiers(context, newCommunity))); } log.info( LogManager.getHeader(context, "create_community", "community_id=" + newCommunity.getID()) + ",handle=" + newCommunity.getHandle()); return newCommunity; }
public void addBody(Body body) throws SAXException, WingException, SQLException { // Get our parameters and state; UUID collectionID = UUID.fromString(parameters.getParameter("collectionID", null)); Collection collection = collectionService.find(context, collectionID); List<Item> items = getMappedItems(collection); // DIVISION: browse-items Division div = body.addInteractiveDivision( "browse-items", contextPath + "/admin/mapper", Division.METHOD_GET, "primary administrative mapper"); div.setHead(T_head1); if (authorizeService.authorizeActionBoolean(context, collection, Constants.REMOVE)) { Para actions = div.addPara(); actions.addButton("submit_unmap").setValue(T_submit_unmap); actions.addButton("submit_return").setValue(T_submit_return); } else { Para actions = div.addPara(); Button button = actions.addButton("submit_unmap"); button.setValue(T_submit_unmap); button.setDisabled(); actions.addButton("submit_return").setValue(T_submit_return); div.addPara().addHighlight("fade").addContent(T_no_remove); } Table table = div.addTable("browse-items-table", 1, 1); Row header = table.addRow(Row.ROLE_HEADER); header.addCellContent(T_column1); header.addCellContent(T_column2); header.addCellContent(T_column3); header.addCellContent(T_column4); for (Item item : items) { String itemID = String.valueOf(item.getID()); Collection owningCollection = item.getOwningCollection(); String owning = owningCollection.getName(); String author = "unknown"; List<MetadataValue> dcAuthors = itemService.getMetadata( item, MetadataSchema.DC_SCHEMA, "contributor", Item.ANY, Item.ANY); if (dcAuthors != null && dcAuthors.size() >= 1) { author = dcAuthors.get(0).getValue(); } String title = "untitled"; List<MetadataValue> dcTitles = itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY); if (dcTitles != null && dcTitles.size() >= 1) { title = dcTitles.get(0).getValue(); } String url = contextPath + "/handle/" + item.getHandle(); Row row = table.addRow(); CheckBox select = row.addCell().addCheckBox("itemID"); select.setLabel("Select"); select.addOption(itemID); row.addCellContent(owning); row.addCell().addXref(url, author); row.addCell().addXref(url, title); } if (authorizeService.authorizeActionBoolean(context, collection, Constants.REMOVE)) { Para actions = div.addPara(); actions.addButton("submit_unmap").setValue(T_submit_unmap); actions.addButton("submit_return").setValue(T_submit_return); } else { Para actions = div.addPara(); Button button = actions.addButton("submit_unmap"); button.setValue(T_submit_unmap); button.setDisabled(); actions.addButton("submit_return").setValue(T_submit_return); div.addPara().addHighlight("fade").addContent(T_no_remove); } div.addHidden("administrative-continue").setValue(knot.getId()); }