cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olgasmola <olya.sm...@gmail.com>
Subject [PATCH] CS-15349: UI fix for Make owner action in Project wizard/New
Date Thu, 01 Jan 1970 00:00:00 GMT
project/Add account.

---
 ui/scripts/projects.js             |   23 +++++++++++++++++++++--
 ui/scripts/ui/widgets/multiEdit.js |    6 ++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/ui/scripts/projects.js b/ui/scripts/projects.js
index 6a99939..d1ace28 100644
--- a/ui/scripts/projects.js
+++ b/ui/scripts/projects.js
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation (ASF) under one
+// Licensed to the Apache Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file
 // distributed with this work for additional information
 // regarding copyright ownership.  The ASF licenses this file
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 (function(cloudStack) {
+  var getProjectAdmin;
   cloudStack.projects = {
     requireInvitation: function(args) {
       return g_capabilities.projectinviterequired;
@@ -447,12 +448,28 @@
             return ['destroy'];
         }
 
-        if (args.context.multiRule[0].role != 'Admin') {
+        if (args.context.multiRule[0].role != 'Admin' &&
+            (cloudStack.context.users[0].account == getProjectAdmin || isAdmin() || isDomainAdmin()))
{ // This is for the new project wizard: check if current logged in User is the Project Owner
           return args.context.actions;
         }
 
         return [];
       },
+      allowOwnerActions: function(args) { // check if current logged in User is the Project
Owner
+        if (isAdmin() || isDomainAdmin())
+            return true;
+
+        var projectOwner, currentUser = cloudStack.context.users[0].account;
+        $(args.data).each(function() {
+            var data = this;
+            if (data.role == 'Admin')
+                projectOwner = data.username;
+        });
+        if (projectOwner == currentUser)
+            return true;
+
+        return false;
+      },
       actions: {
         destroy: {
           label: 'label.remove.project.account',
@@ -522,6 +539,8 @@
           success: function(data) {
             args.response.success({
               data: $.map(data.listprojectaccountsresponse.projectaccount, function(elem)
{
+                if (elem.role == 'Owner' || elem.role == 'Admin')
+                    getProjectAdmin = elem.account;
                 return {
                   id: elem.accountid,
                   role: elem.role,
diff --git a/ui/scripts/ui/widgets/multiEdit.js b/ui/scripts/ui/widgets/multiEdit.js
index 0481dda..33439f5 100644
--- a/ui/scripts/ui/widgets/multiEdit.js
+++ b/ui/scripts/ui/widgets/multiEdit.js
@@ -659,6 +659,7 @@
     var context = args.context;
     var ignoreEmptyFields = args.ignoreEmptyFields;
     var actionPreFilter = args.actionPreFilter;
+    var allowOwnerActions = args.allowOwnerActions;
 
     var $thead = $('<tr>').appendTo(
       $('<thead>').appendTo($inputTable)
@@ -898,6 +899,11 @@
               ).appendTo($dataBody);
             });
 
+            if (allowOwnerActions && !allowOwnerActions(args)) {
+                $multi.find('th.add-user, td.add-user').detach();
+                $multiForm.find('tbody').detach();
+            }
+
             _medit.refreshItemWidths($multi);
           },
           error: cloudStack.dialog.error
-- 
1.7.10.msysgit.1




Mime
View raw message