← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10262: notification when you are creating a new object that has sharing properties, wip

 

------------------------------------------------------------
revno: 10262
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-03-16 12:57:01 +0700
message:
  notification when you are creating a new object that has sharing properties, wip
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataDictionaryForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupSet.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm


--
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-03-15 11:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java	2013-03-16 05:57:01 +0000
@@ -27,11 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.dataset.DataSet;
@@ -46,6 +41,11 @@
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupAccess;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -132,14 +132,24 @@
      * 1. Does user have SHARING_OVERRIDE_AUTHORITY authority?
      * 2. Does user have the authority to create public instances of that object
      *
-     * @param user   User to check against
-     * @param object Object to check
+     * @param user  User to check against
+     * @param clazz Class to check
      * @return Result of test
      */
-    public static boolean canCreatePublic( User user, IdentifiableObject object )
+    public static <T extends IdentifiableObject> boolean canCreatePublic( User user, Class<T> clazz )
     {
         Set<String> authorities = user != null ? user.getUserCredentials().getAllAuthorities() : new HashSet<String>();
-        return authorities.contains( SHARING_OVERRIDE_AUTHORITY ) || authorities.contains( PUBLIC_AUTHORITIES.get( object.getClass() ) );
+        return authorities.contains( SHARING_OVERRIDE_AUTHORITY ) || authorities.contains( PUBLIC_AUTHORITIES.get( clazz ) );
+    }
+
+    public static boolean canCreatePublic( User user, IdentifiableObject identifiableObject )
+    {
+        return canCreatePublic( user, identifiableObject.getClass() );
+    }
+
+    public static boolean canCreatePublic( User user, String type )
+    {
+        return canCreatePublic( user, SUPPORTED_TYPES.get( type ) );
     }
 
     /**
@@ -148,16 +158,26 @@
      * 1. Does user have SHARING_OVERRIDE_AUTHORITY authority?
      * 2. Does user have the authority to create private instances of that object
      *
-     * @param user   User to check against
-     * @param object Object to check
+     * @param user  User to check against
+     * @param clazz Class to check
      * @return Result of test
      */
-    public static boolean canCreatePrivate( User user, IdentifiableObject object )
+    public static <T extends IdentifiableObject> boolean canCreatePrivate( User user, Class<T> clazz )
     {
         Set<String> authorities = user != null ? user.getUserCredentials().getAllAuthorities() : new HashSet<String>();
         return authorities.contains( SHARING_OVERRIDE_AUTHORITY )
-            || PRIVATE_AUTHORITIES.get( object.getClass() ) == null
-            || authorities.contains( PRIVATE_AUTHORITIES.get( object.getClass() ) );
+            || PRIVATE_AUTHORITIES.get( clazz ) == null
+            || authorities.contains( PRIVATE_AUTHORITIES.get( clazz ) );
+    }
+
+    public static boolean canCreatePrivate( User user, IdentifiableObject identifiableObject )
+    {
+        return canCreatePrivate( user, identifiableObject.getClass() );
+    }
+
+    public static boolean canCreatePrivate( User user, String type )
+    {
+        return canCreatePrivate( user, SUPPORTED_TYPES.get( type ) );
     }
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java	2013-01-18 12:58:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java	2013-03-16 05:57:01 +0000
@@ -29,9 +29,9 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.common.SharingUtils;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.SharingUtils;
 import org.hisp.dhis.message.MessageSender;
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.setting.SystemSettingManager;
@@ -243,12 +243,24 @@
     }
 
     @Override
+    public boolean canCreatePublic( String type )
+    {
+        return SharingUtils.canCreatePublic( currentUserService.getCurrentUser(), type );
+    }
+
+    @Override
     public boolean canCreatePrivate( IdentifiableObject identifiableObject )
     {
         return SharingUtils.canCreatePrivate( currentUserService.getCurrentUser(), identifiableObject );
     }
 
     @Override
+    public boolean canCreatePrivate( String type )
+    {
+        return SharingUtils.canCreatePrivate( currentUserService.getCurrentUser(), type );
+    }
+
+    @Override
     public boolean canRead( IdentifiableObject identifiableObject )
     {
         return SharingUtils.canRead( currentUserService.getCurrentUser(), identifiableObject );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java	2013-01-18 12:58:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java	2013-03-16 05:57:01 +0000
@@ -111,6 +111,14 @@
     boolean canCreatePublic( IdentifiableObject identifiableObject );
 
     /**
+     * Checks whether current user can create public instances of the object.
+     *
+     * @param type Type to check for write access.
+     * @return true of false depending on outcome of write check
+     */
+    boolean canCreatePublic( String type );
+
+    /**
      * Checks whether current user can create private instances of the object.
      *
      * @param identifiableObject Object to check for write access.
@@ -119,6 +127,14 @@
     boolean canCreatePrivate( IdentifiableObject identifiableObject );
 
     /**
+     * Checks whether current user can create private instances of the object.
+     *
+     * @param type Type to check for write access.
+     * @return true of false depending on outcome of write check
+     */
+    boolean canCreatePrivate( String type );
+
+    /**
      * Checks whether current user has update access to object.
      *
      * @param identifiableObject Object to check for update access.

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css	2013-03-11 15:31:37 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css	2013-03-16 05:57:01 +0000
@@ -756,3 +756,20 @@
 {
   font-weight: normal !important;
 }
+
+/*----------------------------------------------------------------------------*/
+/* Messages used for sharing                                                  */
+/*----------------------------------------------------------------------------*/
+
+.message * { margin: 0; padding: 0; }
+.message {
+    border: 1px solid #002a80;
+    border-radius: 5px;
+    width: 450px;
+    padding: 5px;
+    margin-bottom: 4px;
+}
+
+.message-info {
+    background-color: #eee;
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-03-13 11:47:27 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-03-16 05:57:01 +0000
@@ -358,3 +358,13 @@
 </tr>
 </script>
 #end
+
+#macro( sharingCreateNotification $type )
+<div class="message message-info">
+    #if( $security.canCreatePublic( $type ) )
+    <p><img src="../icons/function-about-dhis2.png" width="18" height="18" style="float: left; padding-right: 3px;"/> $i18n.getString("object_will_created_public")</p>
+    #elseif( $security.canCreatePrivate( $type ) )
+    <p><img src="../icons/function-about-dhis2.png" width="18" height="18" style="float: left; padding-right: 3px;"/> $i18n.getString("object_will_created_private")</p>
+    #end
+</div>
+#end

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-03-14 19:05:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-03-16 05:57:01 +0000
@@ -635,6 +635,8 @@
 can_edit_and_view=Can edit and view
 can_view=Can view
 search_for_user_groups=Search for user groups
+object_will_created_public=This object will be created with public edit and view rights
+object_will_created_private=This object will be created private
 
 #-- Countries / flags ---------------------------------------------------------#
 

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm	2013-03-14 10:53:15 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm	2013-03-16 05:57:01 +0000
@@ -28,6 +28,8 @@
 
 <h3>$i18n.getString( "add_user_group" )</h3>
 
+#sharingCreateNotification( "userGroup" )
+
 <form id="addUserGroupForm" name="addUserGroupForm" action="addUserGroup.action" method="post" class="inputForm">
  
 <table id="detailsList">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataDictionaryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataDictionaryForm.vm	2012-10-17 11:58:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataDictionaryForm.vm	2013-03-16 05:57:01 +0000
@@ -47,6 +47,8 @@
 
 <h3>$i18n.getString( "create_new_data_dictionary" )</h3>
 
+#sharingCreateNotification( "dataDictionary" )
+
 <form id="addDataDictionaryForm" action="addDataDictionary.action" method="post" class="inputForm">
 
 <table>	

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm	2013-03-14 10:33:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm	2013-03-16 05:57:01 +0000
@@ -19,6 +19,8 @@
 
 <h3>$i18n.getString( "create_new_indicator" )</h3>
 
+#sharingCreateNotification( "indicator" )
+
 <form id="addIndicatorForm" action="addIndicator.action" method="post" class="inputForm">
 
 <input type="hidden" id="numeratorDescription" name="numeratorDescription"/>	

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupForm.vm	2013-03-14 10:33:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupForm.vm	2013-03-16 05:57:01 +0000
@@ -33,6 +33,8 @@
 
 <h3>$i18n.getString( "create_new_indicator_group" )</h3>
 
+#sharingCreateNotification( "indicatorGroup" )
+
 <form id="addIndicatorGroupForm" action="addIndicatorGroup.action" method="post" class="inputForm">
 
 <table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupSet.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupSet.vm	2013-02-04 15:02:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorGroupSet.vm	2013-03-16 05:57:01 +0000
@@ -21,6 +21,8 @@
 
 <h3>$i18n.getString( "add_indicatorgroupset" )</h3>
 
+#sharingCreateNotification( "indicatorGroupSet" )
+
 <form id="addIndicatorGroupSet" action="addIndicatorGroupSet.action" method="post" class="inputForm">
 
 <table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm	2012-12-04 15:27:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm	2013-03-16 05:57:01 +0000
@@ -49,6 +49,8 @@
 
 <h3>$i18n.getString( "add_dataset" )</h3>
 
+#sharingCreateNotification( "dataSet" )
+
 <form id="addDataSetForm" name="addDataSetForm" action="addDataSet.action" method="post" class="inputForm">
   <table id="detailsList" style="width: 540px;">
     <col/> ## Labels

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm	2013-03-14 11:00:17 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm	2013-03-16 05:57:01 +0000
@@ -15,6 +15,8 @@
 
 <h3>$i18n.getString( 'create_new_resource' )</h3>
 
+#sharingCreateNotification( "document" )
+
 <form id="documentForm" action="saveDocument.action" method="post" enctype="multipart/form-data" class="inputForm">
 <input type='hidden' id='id' name='id' value='$!document.id'/>
 <table>

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm	2013-03-14 10:27:27 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm	2013-03-16 05:57:01 +0000
@@ -9,6 +9,8 @@
 
 <h3>$i18n.getString( 'create_new_report' )</h3>
 
+#sharingCreateNotification( "report" )
+
 <form id="reportForm" action="addReport.action" method="post" enctype="multipart/form-data" class="inputForm">
 
 <input type="hidden" id="id" name="id" value="$!report.id" />

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2013-03-14 10:27:27 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2013-03-16 05:57:01 +0000
@@ -19,6 +19,8 @@
 
 <h3>$i18n.getString( "create_report_table" )</h3>
 
+#sharingCreateNotification( "reportTable" )
+
 <form id="tableForm" name="tableForm" method="post" action="saveTable.action">
 
 <input type="hidden" id="tableId" name="tableId" value="$!reportTable.id">