|
|
|
jesseeichar
|
Revision: 5422
http://geonetwork.svn.sourceforge.net/geonetwork/?rev=5422&view=rev Author: jesseeichar Date: 2009-11-03 11:59:05 +0000 (Tue, 03 Nov 2009) Log Message: ----------- Now one cannot import a metadata and replace an older metadata if the user does not have write access to the older metadata. Bug 17692 Modified Paths: -------------- sandbox/geocat.ch/trunk/jeeves/src/jeeves/exceptions/OperationNotAllowedEx.java sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/AccessManager.java sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/mef/Importer.java sandbox/geocat.ch/trunk/web/geonetwork/loc/deu/xml/strings.xml sandbox/geocat.ch/trunk/web/geonetwork/loc/eng/xml/strings.xml sandbox/geocat.ch/trunk/web/geonetwork/loc/fra/xml/strings.xml Modified: sandbox/geocat.ch/trunk/jeeves/src/jeeves/exceptions/OperationNotAllowedEx.java =================================================================== --- sandbox/geocat.ch/trunk/jeeves/src/jeeves/exceptions/OperationNotAllowedEx.java 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/jeeves/src/jeeves/exceptions/OperationNotAllowedEx.java 2009-11-03 11:59:05 UTC (rev 5422) @@ -35,11 +35,17 @@ public OperationNotAllowedEx() { - super("Operation not allowed", null); + this("Operation not allowed"); - id = "operation-not-allowed"; - code = 403; } + + public OperationNotAllowedEx(String errorMessage) + { + super(errorMessage, null); + id = "operation-not-allowed"; + code = 403; + // TODO Auto-generated constructor stub + } } //============================================================================= Modified: sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/AccessManager.java =================================================================== --- sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/AccessManager.java 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/AccessManager.java 2009-11-03 11:59:05 UTC (rev 5422) @@ -24,6 +24,7 @@ package org.fao.geonet.kernel; import java.sql.SQLException; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -279,8 +280,12 @@ //--- check if the user is a reviewer - if (!us.getProfile().equals(Geonet.Profile.REVIEWER)) + ArrayList<String> profiles = new ArrayList<String>(); + profiles.add(Geonet.Profile.REVIEWER); + profiles.add(Geonet.Profile.USER_ADMIN); + if (!profiles.contains(us.getProfile())) { return false; + } //--- if there is no group owner then the reviewer cannot review @@ -358,11 +363,11 @@ //--- //-------------------------------------------------------------------------- - private SettingManager settMan; - private HashSet<String> hsAllOps = new HashSet<String>(); + private final SettingManager settMan; + private final HashSet<String> hsAllOps = new HashSet<String>(); - private HashMap<Integer, String> hmIdToName = new HashMap<Integer, String>(); - private HashMap<String, Integer> hmNameToId = new HashMap<String, Integer>(); + private final HashMap<Integer, String> hmIdToName = new HashMap<Integer, String>(); + private final HashMap<String, Integer> hmNameToId = new HashMap<String, Integer>(); } //============================================================================= Modified: sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/mef/Importer.java =================================================================== --- sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/mef/Importer.java 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/mef/Importer.java 2009-11-03 11:59:05 UTC (rev 5422) @@ -34,6 +34,7 @@ import java.util.UUID; import jeeves.exceptions.BadFormatEx; +import jeeves.exceptions.OperationNotAllowedEx; import jeeves.resources.dbms.Dbms; import jeeves.server.context.ServiceContext; import jeeves.utils.BinaryFile; @@ -47,6 +48,7 @@ import org.fao.geonet.kernel.DataManager; import org.fao.geonet.lib.Lib; import org.fao.geonet.util.ISODate; +import org.fao.geonet.util.LangUtils; import org.fao.oaipmh.exceptions.BadArgumentException; import org.jdom.Element; @@ -174,7 +176,7 @@ // XML and MEF2 files insertion use this parameters groupId = Util.getParam(params, Params.GROUP); validate = Util.getParam(params, Params.VALIDATE, "off").equals("on"); - + // Handle non MEF files insertion if (info.getChildren().size() == 0) { source = Util.getParam(params, Params.SITE_ID, gc @@ -264,12 +266,23 @@ try { if (dm.existsMetadataUuid(dbms, uuid) && !uuidAction.equals(Params.NOTHING)) { - dm.deleteMetadata(dbms, dm.getMetadataId(dbms, uuid)) ; + String metadataId = dm.getMetadataId(dbms, uuid); + if( !dm.getAccessManager().canEdit(context, metadataId)) { + String appDir = context.getAppPath(); + String langCode = context.getLanguage(); + String defVal = "A metadata record exists that you cannot replace because of insufficient privileges"; + throw new OperationNotAllowedEx(LangUtils.translate(appDir, langCode, "insufficient.privileges.import.replace", defVal)); + } + dm.deleteMetadata(dbms, metadataId) ; Log.debug(Geonet.MEF, "Deleting existing metadata with UUID : " + uuid ); } } catch (Exception e) { - throw new Exception(" Existing metadata with same UUID could not be deleted."); + if(e instanceof OperationNotAllowedEx) { + throw e; + } else { + throw new Exception(" Existing metadata with same UUID could not be deleted."); + } } Log.debug(Geonet.MEF, "Adding metadata with uuid=" + uuid); Modified: sandbox/geocat.ch/trunk/web/geonetwork/loc/deu/xml/strings.xml =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/loc/deu/xml/strings.xml 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/web/geonetwork/loc/deu/xml/strings.xml 2009-11-03 11:59:05 UTC (rev 5422) @@ -842,4 +842,5 @@ <desc>Beschreibung</desc> <url>URL</url> <rm>Rätoromanisch</rm> + <insufficient.privileges.import.replace>A metadata record exists that you cannot replace because of insufficient privileges</insufficient.privileges.import.replace> </strings> Modified: sandbox/geocat.ch/trunk/web/geonetwork/loc/eng/xml/strings.xml =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/loc/eng/xml/strings.xml 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/web/geonetwork/loc/eng/xml/strings.xml 2009-11-03 11:59:05 UTC (rev 5422) @@ -863,4 +863,5 @@ <desc>Description</desc> <url>URL</url> <rm>Romanche</rm> + <insufficient.privileges.import.replace>A metadata record exists that you cannot replace because of insufficient privileges</insufficient.privileges.import.replace> </strings> Modified: sandbox/geocat.ch/trunk/web/geonetwork/loc/fra/xml/strings.xml =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/loc/fra/xml/strings.xml 2009-11-03 10:40:44 UTC (rev 5421) +++ sandbox/geocat.ch/trunk/web/geonetwork/loc/fra/xml/strings.xml 2009-11-03 11:59:05 UTC (rev 5422) @@ -864,4 +864,5 @@ <desc>Description</desc> <url>URL</url> <rm>Romanche</rm> + <insufficient.privileges.import.replace>A metadata record exists that you cannot replace because of insufficient privileges</insufficient.privileges.import.replace> </strings> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ GeoNetwork-commit mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-commit |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |