← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10694: re-enabled import of userRoles/userGroups. Only allow creation of NEW instances. For userGroup, n...

 

------------------------------------------------------------
revno: 10694
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-26 14:12:45 +0700
message:
  re-enabled import of userRoles/userGroups. Only allow creation of NEW instances. For userGroup, no user scanning is performed.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java
  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-api/src/main/java/org/hisp/dhis/user/UserGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java	2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java	2013-04-26 07:12:45 +0000
@@ -38,7 +38,6 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.annotation.Scanned;
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 
@@ -57,7 +56,6 @@
     /**
      * Set of related users
      */
-    @Scanned
     private Set<User> members = new HashSet<User>();
 
     /**

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2013-04-16 11:26:10 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2013-04-26 07:12:45 +0000
@@ -153,10 +153,8 @@
 
         // for now, do not allow user to be imported
         importClasses.remove( User.class );
-        importClasses.remove( UserGroup.class );
-        importClasses.remove( UserAuthorityGroup.class );
 
-        // this is considered data, and is not available for meta-data import
+        // this is considered data, and is not available for meta-data export/import
         exportClasses.remove( MessageConversation.class );
         exportClasses.remove( Interpretation.class );
         importClasses.remove( MessageConversation.class );

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java	2013-04-08 13:14:42 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java	2013-04-26 07:12:45 +0000
@@ -60,7 +60,6 @@
             {
                 return identifiableObject.getCode();
             }
-
         }
 
         return object.getClass().getName();

=== 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-04-04 18:06:19 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-04-26 07:12:45 +0000
@@ -60,6 +60,8 @@
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.system.util.functional.Function1;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserGroup;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.lang.reflect.Field;
@@ -142,7 +144,7 @@
         private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
 
         private DataEntryForm dataEntryForm;
-        
+
         public void extract( T object )
         {
             attributeValues = extractAttributeValues( object );
@@ -436,6 +438,14 @@
      */
     protected boolean updateObject( User user, T object, T persistedObject )
     {
+        if ( newOnly( object ) )
+        {
+            summaryType.getImportConflicts().add(
+                new ImportConflict( ImportUtils.getDisplayName( object ), "This object type only allows creation of new objects." ) );
+
+            return false;
+        }
+
         if ( !SharingUtils.canUpdate( user, persistedObject ) )
         {
             summaryType.getImportConflicts().add(
@@ -538,6 +548,12 @@
     // Helpers
     //-------------------------------------------------------------------------------------------------------
 
+    // until we have proper update of UserGroup/UserAuthorityGroup, only allow new instances to be created
+    private boolean newOnly( T object )
+    {
+        return UserGroup.class.isInstance( object ) || UserAuthorityGroup.class.isInstance( object );
+    }
+
     private void importObjectLocal( User user, T object )
     {
         if ( validateIdentifiableObject( object ) )