GUACAMOLE-292: Restrict attributes on object management pages to those 
explicitly present on the object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/22cce485
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/22cce485
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/22cce485

Branch: refs/heads/master
Commit: 22cce485585c0dce3d615ae3accc7e3930b97f7d
Parents: 07fb473
Author: Michael Jumper <mjum...@apache.org>
Authored: Tue Feb 21 23:32:38 2017 -0800
Committer: Michael Jumper <mjum...@apache.org>
Committed: Fri May 26 20:15:02 2017 -0700

----------------------------------------------------------------------
 .../src/main/webapp/app/form/directives/form.js | 60 +++++++++++++++++++-
 .../main/webapp/app/form/templates/form.html    |  4 +-
 .../app/manage/templates/manageConnection.html  |  3 +-
 .../manage/templates/manageConnectionGroup.html |  3 +-
 .../manage/templates/manageSharingProfile.html  |  2 +-
 .../webapp/app/manage/templates/manageUser.html |  3 +-
 6 files changed, 69 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/form/directives/form.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/form/directives/form.js 
b/guacamole/src/main/webapp/app/form/directives/form.js
index f659899..518db7d 100644
--- a/guacamole/src/main/webapp/app/form/directives/form.js
+++ b/guacamole/src/main/webapp/app/form/directives/form.js
@@ -55,7 +55,16 @@ angular.module('form').directive('guacForm', [function 
form() {
              *
              * @type Object.<String, String>
              */
-            model : '='
+            model : '=',
+
+            /**
+             * Whether the contents of the form should be restricted to those
+             * fields/forms which match properties defined within the given
+             * model object. By default, all fields will be shown.
+             *
+             * @type Boolean
+             */
+            modelOnly : '='
 
         },
         templateUrl: 'app/form/templates/form.html',
@@ -163,6 +172,55 @@ angular.module('form').directive('guacForm', [function 
form() {
 
             });
 
+            /**
+             * Returns whether the given field should be displayed to the
+             * current user.
+             *
+             * @param {Field} field
+             *     The field to check.
+             *
+             * @returns {Boolean}
+             *     true if the given field should be visible, false otherwise.
+             */
+            $scope.isVisible = function isVisible(field) {
+
+                // All fields are visible if contents are not restricted to
+                // model properties only
+                if (!$scope.modelOnly)
+                    return true;
+
+                // Otherwise, fields are only visible if they are present
+                // within the model
+                return field && (field.name in $scope.values);
+
+            };
+
+            /**
+             * Returns whether at least one of the given fields should be
+             * displayed to the current user.
+             *
+             * @param {Field[]} fields
+             *     The array of fields to check.
+             *
+             * @returns {Boolean}
+             *     true if at least one field within the given array should be
+             *     visible, false otherwise.
+             */
+            $scope.containsVisible = function containsVisible(fields) {
+
+                // If fields are defined, check whether at least one is visible
+                if (fields) {
+                    for (var i = 0; i < fields.length; i++) {
+                        if ($scope.isVisible(fields[i]))
+                            return true;
+                    }
+                }
+
+                // Otherwise, there are no visible fields
+                return false;
+
+            };
+
         }] // end controller
     };
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/form/templates/form.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/form/templates/form.html 
b/guacamole/src/main/webapp/app/form/templates/form.html
index 6013543..e4564e8 100644
--- a/guacamole/src/main/webapp/app/form/templates/form.html
+++ b/guacamole/src/main/webapp/app/form/templates/form.html
@@ -1,5 +1,6 @@
 <div class="form-group">
-    <div ng-repeat="form in forms" class="form">
+    <div ng-repeat="form in forms" class="form"
+         ng-show="containsVisible(form.fields)">
 
         <!-- Form name -->
         <h3 ng-show="form.name">{{getSectionHeader(form) | translate}}</h3>
@@ -7,6 +8,7 @@
         <!-- All fields in form -->
         <div class="fields">
             <guac-form-field ng-repeat="field in form.fields" 
namespace="namespace"
+                             ng-show="isVisible(field)"
                              field="field" 
model="values[field.name]"></guac-form-field>
         </div>
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/manage/templates/manageConnection.html
----------------------------------------------------------------------
diff --git 
a/guacamole/src/main/webapp/app/manage/templates/manageConnection.html 
b/guacamole/src/main/webapp/app/manage/templates/manageConnection.html
index 9df51a0..80796a4 100644
--- a/guacamole/src/main/webapp/app/manage/templates/manageConnection.html
+++ b/guacamole/src/main/webapp/app/manage/templates/manageConnection.html
@@ -40,7 +40,8 @@
 
     <!-- Connection attributes section -->
     <div class="attributes">
-        <guac-form namespace="'CONNECTION_ATTRIBUTES'" content="attributes" 
model="connection.attributes"></guac-form>
+        <guac-form namespace="'CONNECTION_ATTRIBUTES'" content="attributes"
+                   model="connection.attributes" model-only="true"></guac-form>
     </div>
 
     <!-- Connection parameters -->

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/manage/templates/manageConnectionGroup.html
----------------------------------------------------------------------
diff --git 
a/guacamole/src/main/webapp/app/manage/templates/manageConnectionGroup.html 
b/guacamole/src/main/webapp/app/manage/templates/manageConnectionGroup.html
index 0b95251..2d5ac58 100644
--- a/guacamole/src/main/webapp/app/manage/templates/manageConnectionGroup.html
+++ b/guacamole/src/main/webapp/app/manage/templates/manageConnectionGroup.html
@@ -40,7 +40,8 @@
 
     <!-- Connection group attributes section -->
     <div class="attributes">
-        <guac-form namespace="'CONNECTION_GROUP_ATTRIBUTES'" 
content="attributes" model="connectionGroup.attributes"></guac-form>
+        <guac-form namespace="'CONNECTION_GROUP_ATTRIBUTES'" 
content="attributes"
+                   model="connectionGroup.attributes" 
model-only="true"></guac-form>
     </div>
 
     <!-- Form action buttons -->

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/manage/templates/manageSharingProfile.html
----------------------------------------------------------------------
diff --git 
a/guacamole/src/main/webapp/app/manage/templates/manageSharingProfile.html 
b/guacamole/src/main/webapp/app/manage/templates/manageSharingProfile.html
index 4873b86..a8e6438 100644
--- a/guacamole/src/main/webapp/app/manage/templates/manageSharingProfile.html
+++ b/guacamole/src/main/webapp/app/manage/templates/manageSharingProfile.html
@@ -22,7 +22,7 @@
     <!-- Sharing profile attributes section -->
     <div class="attributes">
         <guac-form namespace="'SHARING_PROFILE_ATTRIBUTES'" 
content="attributes"
-                   model="sharingProfile.attributes"></guac-form>
+                   model="sharingProfile.attributes" 
model-only="true"></guac-form>
     </div>
 
     <!-- Sharing profile parameters -->

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/22cce485/guacamole/src/main/webapp/app/manage/templates/manageUser.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/manage/templates/manageUser.html 
b/guacamole/src/main/webapp/app/manage/templates/manageUser.html
index e32d725..dc71d27 100644
--- a/guacamole/src/main/webapp/app/manage/templates/manageUser.html
+++ b/guacamole/src/main/webapp/app/manage/templates/manageUser.html
@@ -41,7 +41,8 @@
 
         <!-- User attributes section -->
         <div class="attributes" ng-show="canChangeAttributes()">
-            <guac-form namespace="'USER_ATTRIBUTES'" content="attributes" 
model="user.attributes"></guac-form>
+            <guac-form namespace="'USER_ATTRIBUTES'" content="attributes"
+                       model="user.attributes" model-only="true"></guac-form>
         </div>
 
         <!-- System permissions section -->

Reply via email to