← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16660: minor fixes

 

------------------------------------------------------------
revno: 16660
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-09 11:32:07 +0700
message:
  minor fixes
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/acl/AccessStringHelper.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/AccessStringHelperTest.java
  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-api/src/main/java/org/hisp/dhis/acl/AccessStringHelper.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/acl/AccessStringHelper.java	2014-03-27 04:44:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/acl/AccessStringHelper.java	2014-09-09 04:32:07 +0000
@@ -35,8 +35,6 @@
  */
 public class AccessStringHelper
 {
-    public static final String DEFAULT_ACCESS = "--------";
-
     public static enum Permission
     {
         READ( 'r', 0 ), WRITE( 'w', 1 );
@@ -62,7 +60,22 @@
         }
     }
 
-    private char[] access = DEFAULT_ACCESS.toCharArray();
+    private char[] access = DEFAULT.toCharArray();
+
+    public static final String DEFAULT = "--------";
+
+    public static final String READ = AccessStringHelper.newInstance()
+        .enable( Permission.READ )
+        .build();
+
+    public static final String WRITE = AccessStringHelper.newInstance()
+        .enable( Permission.WRITE )
+        .build();
+
+    public static final String READ_WRITE = AccessStringHelper.newInstance()
+        .enable( Permission.READ )
+        .enable( Permission.WRITE )
+        .build();
 
     public AccessStringHelper()
     {

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/AccessStringHelperTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/AccessStringHelperTest.java	2014-03-27 04:44:41 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/AccessStringHelperTest.java	2014-09-09 04:32:07 +0000
@@ -29,9 +29,11 @@
  */
 
 import org.hisp.dhis.acl.AccessStringHelper;
-import org.junit.Assert;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -43,8 +45,8 @@
         String access = "r-------";
         String access_will_fail = "--------";
 
-        Assert.assertTrue( AccessStringHelper.canRead( access ) );
-        Assert.assertFalse( AccessStringHelper.canRead( access_will_fail ) );
+        assertTrue( AccessStringHelper.canRead( access ) );
+        assertFalse( AccessStringHelper.canRead( access_will_fail ) );
     }
 
     @Test
@@ -54,8 +56,29 @@
         String access2 = "-w------";
         String access_will_fail = "--------";
 
-        Assert.assertTrue( AccessStringHelper.canWrite( access1 ) );
-        Assert.assertTrue( AccessStringHelper.canWrite( access2 ) );
-        Assert.assertFalse( AccessStringHelper.canWrite( access_will_fail ) );
+        assertTrue( AccessStringHelper.canWrite( access1 ) );
+        assertTrue( AccessStringHelper.canWrite( access2 ) );
+        assertFalse( AccessStringHelper.canWrite( access_will_fail ) );
+    }
+
+    @Test
+    public void staticRead()
+    {
+        assertTrue( AccessStringHelper.canRead( AccessStringHelper.READ ) );
+        assertFalse( AccessStringHelper.canWrite( AccessStringHelper.READ ) );
+    }
+
+    @Test
+    public void staticWrite()
+    {
+        assertFalse( AccessStringHelper.canRead( AccessStringHelper.WRITE ) );
+        assertTrue( AccessStringHelper.canWrite( AccessStringHelper.WRITE ) );
+    }
+
+    @Test
+    public void staticReadWrite()
+    {
+        assertTrue( AccessStringHelper.canRead( AccessStringHelper.READ_WRITE ) );
+        assertTrue( AccessStringHelper.canWrite( AccessStringHelper.READ_WRITE ) );
     }
 }

=== 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	2014-09-08 13:02:43 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2014-09-09 04:32:07 +0000
@@ -278,35 +278,29 @@
     @Override
     public int save( T object )
     {
+        User currentUser = currentUserService.getCurrentUser();
+
         if ( IdentifiableObject.class.isAssignableFrom( object.getClass() ) )
         {
-            ((BaseIdentifiableObject) object).setPublicAccess( AccessStringHelper.newInstance().build() );
-            ((BaseIdentifiableObject) object).setUserGroupAccesses( new HashSet<UserGroupAccess>() );
-        }
-
-        User currentUser = currentUserService.getCurrentUser();
-
-        if ( !Interpretation.class.isAssignableFrom( clazz ) && currentUser != null && aclService.isShareable( clazz ) )
-        {
             BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
-
-            // TODO we might want to allow setting sharing props on save, but for now we null them out
+            identifiableObject.setPublicAccess( AccessStringHelper.newInstance().build() );
+            identifiableObject.setUserGroupAccesses( new HashSet<UserGroupAccess>() );
 
             if ( identifiableObject.getUser() == null )
             {
                 identifiableObject.setUser( currentUser );
             }
+        }
+
+        if ( !Interpretation.class.isAssignableFrom( clazz ) && currentUser != null && aclService.isShareable( clazz ) )
+        {
+            BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
 
             if ( aclService.canCreatePublic( currentUser, identifiableObject.getClass() ) )
             {
                 if ( aclService.defaultPublic( identifiableObject.getClass() ) )
                 {
-                    String build = AccessStringHelper.newInstance()
-                        .enable( AccessStringHelper.Permission.READ )
-                        .enable( AccessStringHelper.Permission.WRITE )
-                        .build();
-
-                    identifiableObject.setPublicAccess( build );
+                    identifiableObject.setPublicAccess( AccessStringHelper.READ_WRITE );
                 }
             }
             else if ( aclService.canCreatePrivate( currentUser, identifiableObject.getClass() ) )