← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9555: removed old meta-data based sharing detection, uses static lookup in SharingUtils instead

 

------------------------------------------------------------
revno: 9555
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-01-18 14:04:27 +0100
message:
  removed old meta-data based sharing detection, uses static lookup in SharingUtils instead
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.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/common/SharingUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java	2013-01-18 12:58:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java	2013-01-18 13:04:27 +0000
@@ -72,7 +72,12 @@
 
     public static boolean isSupported( IdentifiableObject identifiableObject )
     {
-        return SUPPORTED_TYPES.containsValue( identifiableObject.getClass() );
+        return isSupported( identifiableObject.getClass() );
+    }
+
+    public static boolean isSupported( Class<?> clazz )
+    {
+        return SUPPORTED_TYPES.containsValue( clazz );
     }
 
     public static Class<? extends IdentifiableObject> classForType( String type )

=== 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	2013-01-18 12:58:45 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-01-18 13:04:27 +0000
@@ -30,7 +30,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.SQLQuery;
 import org.hibernate.SessionFactory;
@@ -806,25 +805,10 @@
 
     private boolean sharingEnabled()
     {
-        return hasShareProperties() && !(currentUserService.getCurrentUser() == null ||
+        return SharingUtils.isSupported( clazz ) && !(currentUserService.getCurrentUser() == null ||
             currentUserService.getCurrentUser().getUserCredentials().getAllAuthorities().contains( SharingUtils.SHARING_OVERRIDE_AUTHORITY ));
     }
 
-    private boolean hasShareProperties()
-    {
-        try
-        {
-            // for now we need to have this test, since not all idObjectClasses are converted
-            sessionFactory.getClassMetadata( clazz ).getPropertyType( "publicAccess" );
-        }
-        catch ( HibernateException ignored )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
     private boolean isReadAllowed( T object )
     {
         if ( IdentifiableObject.class.isInstance( object ) )
@@ -861,7 +845,7 @@
         {
             IdentifiableObject idObject = (IdentifiableObject) object;
 
-            if ( hasShareProperties() )
+            if ( SharingUtils.isSupported( clazz ) )
             {
                 return SharingUtils.canUpdate( currentUserService.getCurrentUser(), idObject );
             }
@@ -876,7 +860,7 @@
         {
             IdentifiableObject idObject = (IdentifiableObject) object;
 
-            if ( hasShareProperties() )
+            if ( SharingUtils.isSupported( clazz ) )
             {
                 return SharingUtils.canDelete( currentUserService.getCurrentUser(), idObject );
             }