← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14460: fixes for sharing schema

 

------------------------------------------------------------
revno: 14460
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-03-27 02:16:51 +0100
message:
  fixes for sharing schema
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ReportTableSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sharing/DefaultSharingService.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/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-03-26 15:24:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-03-27 01:16:51 +0000
@@ -61,12 +61,6 @@
 
     private List<Authority> authorities = Lists.newArrayList();
 
-    private List<String> publicAuthorities = Lists.newArrayList();
-
-    private List<String> privateAuthorities = Lists.newArrayList();
-
-    private List<String> externalAuthorities = Lists.newArrayList();
-
     private List<Property> properties = Lists.newArrayList();
 
     public Schema( Class<?> klass, String singular, String plural )
@@ -154,45 +148,6 @@
     }
 
     @JsonProperty
-    @JacksonXmlElementWrapper( localName = "publicAuthorities", namespace = DxfNamespaces.DXF_2_0 )
-    @JacksonXmlProperty( localName = "publicAuthority", namespace = DxfNamespaces.DXF_2_0 )
-    public List<String> getPublicAuthorities()
-    {
-        return publicAuthorities;
-    }
-
-    public void setPublicAuthorities( List<String> publicAuthorities )
-    {
-        this.publicAuthorities = publicAuthorities;
-    }
-
-    @JsonProperty
-    @JacksonXmlElementWrapper( localName = "privateAuthorities", namespace = DxfNamespaces.DXF_2_0 )
-    @JacksonXmlProperty( localName = "privateAuthority", namespace = DxfNamespaces.DXF_2_0 )
-    public List<String> getPrivateAuthorities()
-    {
-        return privateAuthorities;
-    }
-
-    public void setPrivateAuthorities( List<String> privateAuthorities )
-    {
-        this.privateAuthorities = privateAuthorities;
-    }
-
-    @JsonProperty
-    @JacksonXmlElementWrapper( localName = "externalAuthorities", namespace = DxfNamespaces.DXF_2_0 )
-    @JacksonXmlProperty( localName = "externalAuthority", namespace = DxfNamespaces.DXF_2_0 )
-    public List<String> getExternalAuthorities()
-    {
-        return externalAuthorities;
-    }
-
-    public void setExternalAuthorities( List<String> externalAuthorities )
-    {
-        this.externalAuthorities = externalAuthorities;
-    }
-
-    @JsonProperty
     @JacksonXmlElementWrapper( localName = "properties", namespace = DxfNamespaces.DXF_2_0 )
     @JacksonXmlProperty( localName = "property", namespace = DxfNamespaces.DXF_2_0 )
     public List<Property> getProperties()
@@ -205,7 +160,27 @@
         this.properties = properties;
     }
 
-    private Map<String, Property> propertyMap = Maps.newHashMap();
+    private Map<AuthorityType, List<Authority>> authorityMap = Maps.newHashMap();
+
+    public List<Authority> getAuthorityByType( AuthorityType type )
+    {
+        if ( !authorityMap.containsKey( type ) )
+        {
+            List<Authority> authorityList = Lists.newArrayList();
+
+            for ( Authority authority : authorities )
+            {
+                if ( type.equals( authority.getType() ) )
+                {
+                    authorityList.add( authority );
+                }
+            }
+
+            authorityMap.put( type, authorityList );
+        }
+
+        return authorityMap.get( type );
+    }
 
     @Override
     public String toString()
@@ -217,9 +192,7 @@
             ", singular='" + singular + '\'' +
             ", plural='" + plural + '\'' +
             ", shareable=" + shareable +
-            ", publicAuthorities=" + publicAuthorities +
-            ", privateAuthorities=" + privateAuthorities +
-            ", externalAuthorities=" + externalAuthorities +
+            ", authorities=" + authorities +
             ", properties=" + properties +
             '}';
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ReportTableSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ReportTableSchemaDescriptor.java	2014-03-26 09:23:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ReportTableSchemaDescriptor.java	2014-03-27 01:16:51 +0000
@@ -30,6 +30,8 @@
 
 import com.google.common.collect.Lists;
 import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaDescriptor;
 import org.springframework.stereotype.Component;
@@ -46,8 +48,9 @@
         Schema schema = new Schema( ReportTable.class, "reportTable", "reportTables" );
 
         schema.setShareable( true );
-        schema.setPublicAuthorities( Lists.newArrayList( "F_REPORTTABLE_PUBLIC_ADD" ) );
-        schema.setExternalAuthorities( Lists.newArrayList( "F_REPORTTABLE_EXTERNAL" ) );
+
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_REPORTTABLE_PUBLIC_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.EXTERNALIZE, Lists.newArrayList( "F_REPORTTABLE_EXTERNAL" ) ) );
 
         return schema;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sharing/DefaultSharingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sharing/DefaultSharingService.java	2014-03-21 11:57:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sharing/DefaultSharingService.java	2014-03-27 01:16:51 +0000
@@ -30,6 +30,7 @@
 
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dashboard.Dashboard;
+import org.hisp.dhis.schema.AuthorityType;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.user.User;
@@ -37,9 +38,7 @@
 import org.hisp.dhis.user.UserGroupAccess;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.Arrays;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import static org.springframework.util.CollectionUtils.containsAny;
@@ -78,7 +77,7 @@
 
         //TODO ( (object instanceof User) && canCreatePrivate( user, object ) ): review possible security breaches and best way to give update access upon user import
         if ( haveOverrideAuthority( user )
-            || (object.getUser() == null && canCreatePublic( user, object.getClass() ) && !schema.getPrivateAuthorities().isEmpty())
+            || (object.getUser() == null && canCreatePublic( user, object.getClass() ) && !schema.getAuthorityByType( AuthorityType.CREATE_PRIVATE ).isEmpty())
             || (user != null && user.equals( object.getUser() ))
             //|| authorities.contains( PRIVATE_AUTHORITIES.get( object.getClass() ) )
             || ((object instanceof User) && canCreatePrivate( user, object.getClass() ))
@@ -153,7 +152,7 @@
         }
 
         if ( haveOverrideAuthority( user )
-            || (object.getUser() == null && canCreatePublic( user, object.getClass() ) && !schema.getPrivateAuthorities().isEmpty())
+            || (object.getUser() == null && canCreatePublic( user, object.getClass() ) && !schema.getAuthorityByType( AuthorityType.CREATE_PRIVATE ).isEmpty())
             || user.equals( object.getUser() )
             || AccessStringHelper.canWrite( object.getPublicAccess() ) )
         {
@@ -184,7 +183,7 @@
             return false;
         }
 
-        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getPublicAuthorities() );
+        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getAuthorityByType( AuthorityType.CREATE_PUBLIC ) );
     }
 
     @Override
@@ -199,7 +198,7 @@
             return false;
         }
 
-        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getPrivateAuthorities() );
+        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getAuthorityByType( AuthorityType.CREATE_PRIVATE ) );
     }
 
     @Override
@@ -214,7 +213,7 @@
             return false;
         }
 
-        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getExternalAuthorities() );
+        return containsAny( authorities, SHARING_OVERRIDE_AUTHORITIES ) || containsAny( authorities, schema.getAuthorityByType( AuthorityType.EXTERNALIZE ) );
     }
 
     @Override