← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10273: check for create access when doing dxf2 imports

 

------------------------------------------------------------
revno: 10273
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-03-17 15:56:52 +0700
message:
  check for create access when doing dxf2 imports
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-03-16 14:59:29 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-03-17 08:56:52 +0000
@@ -382,11 +382,20 @@
     /**
      * Called every time a new idObject is to be imported.
      *
+     * @param user   User to check
      * @param object Object to import
      * @return An ImportConflict instance if there was a conflict, otherwise null
      */
-    protected boolean newObject( T object )
+    protected boolean newObject( User user, T object )
     {
+        if ( !SharingUtils.canCreatePublic( user, object ) || !SharingUtils.canCreatePrivate( user, object ) )
+        {
+            summaryType.getImportConflicts().add(
+                new ImportConflict( ImportUtils.getDisplayName( object ), "You do not have create access to class type." ) );
+
+            return false;
+        }
+
         // make sure that the internalId is 0, so that the system will generate a ID
         object.setId( 0 );
 
@@ -419,7 +428,7 @@
     /**
      * Update idObject from old => new.
      *
-     * @param user
+     * @param user            User to check for access.
      * @param object          Object to import
      * @param persistedObject The current version of the idObject
      * @return An ImportConflict instance if there was a conflict, otherwise null
@@ -546,7 +555,7 @@
 
         if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
         {
-            if ( newObject( object ) )
+            if ( newObject( user, object ) )
             {
                 summaryType.incrementImported();
             }
@@ -577,7 +586,7 @@
             }
             else
             {
-                if ( newObject( object ) )
+                if ( newObject( user, object ) )
                 {
                     summaryType.incrementImported();
                 }
@@ -697,9 +706,7 @@
             return period;
         }
 
-        IdentifiableObject reference = objectBridge.getObject( identifiableObject );
-
-        return reference;
+        return objectBridge.getObject( identifiableObject );
     }
 
     private Map<Field, Object> detachFields( final Object object )