← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18815: minor fix, if user is null on update, set it to current user

 

------------------------------------------------------------
revno: 18815
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-04-07 14:56:59 +0700
message:
  minor fix, if user is null on update, set it to current user
modified:
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.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-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2015-03-27 17:33:25 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2015-04-07 07:56:59 +0000
@@ -28,9 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.collect.Lists;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Criteria;
@@ -65,7 +63,8 @@
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.util.Assert;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -194,7 +193,7 @@
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( getClazz(), "c" ).setCacheable( cacheable );
 
         User user = currentUserService.getCurrentUser();
-        
+
         if ( !sharingEnabled( user ) || user == null )
         {
             return criteria;
@@ -372,8 +371,8 @@
     private boolean checkPublicAccess( User user, IdentifiableObject identifiableObject )
     {
         return aclService.canCreatePublic( user, identifiableObject.getClass() ) ||
-            ( aclService.canCreatePrivate( user, identifiableObject.getClass() ) &&
-                !AccessStringHelper.canReadOrWrite( identifiableObject.getPublicAccess() ) );
+            (aclService.canCreatePrivate( user, identifiableObject.getClass() ) &&
+                !AccessStringHelper.canReadOrWrite( identifiableObject.getPublicAccess() ));
     }
 
     @Override
@@ -381,7 +380,13 @@
     {
         if ( IdentifiableObject.class.isInstance( object ) )
         {
-            ((BaseIdentifiableObject) object).setAutoFields();
+            BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
+            identifiableObject.setAutoFields();
+
+            if ( identifiableObject.getUser() == null )
+            {
+                identifiableObject.setUser( currentUserService.getCurrentUser() );
+            }
         }
 
         if ( !Interpretation.class.isAssignableFrom( clazz ) && !isUpdateAllowed( object ) )
@@ -419,7 +424,7 @@
     {
         return (T) sessionFactory.getCurrentSession().get( getClazz(), id );
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public final T load( int id )
@@ -558,7 +563,7 @@
 
     protected boolean sharingEnabled( User currentUser )
     {
-        return forceAcl() || ( aclService.isShareable( clazz ) && !( currentUser == null || currentUser.isSuper() ) );
+        return forceAcl() || (aclService.isShareable( clazz ) && !(currentUser == null || currentUser.isSuper()));
     }
 
     protected boolean isReadAllowed( T object )
@@ -568,7 +573,7 @@
             IdentifiableObject idObject = (IdentifiableObject) object;
 
             User currentUser = currentUserService.getCurrentUser();
-            
+
             if ( sharingEnabled( currentUser ) )
             {
                 return aclService.canRead( currentUser, idObject );
@@ -585,7 +590,7 @@
             IdentifiableObject idObject = (IdentifiableObject) object;
 
             User currentUser = currentUserService.getCurrentUser();
-            
+
             if ( sharingEnabled( currentUser ) )
             {
                 return aclService.canWrite( currentUser, idObject );