issue #24104: npm extension bugfixes
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Thu, 17 Jul 2014 03:01:52 +0000 (23:01 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Thu, 17 Jul 2014 03:01:52 +0000 (23:01 -0400)
enyo-client/application/source/en/strings.js
enyo-client/application/source/views/workspace.js
enyo-client/database/orm/models/sys.json
node-datasource/routes/install_extension.js

index 182629f..6f0c635 100644 (file)
     "_subtotal": "Subtotal",
     "_suffix": "Suffix",
     "_summary": "Summary",
+    "_success!": "Success!",
     "_successors": "Successors",
     "_symbol": "Symbol",
     "_system": "System",
index 98860f5..b5a1632 100644 (file)
@@ -463,7 +463,7 @@ strict: false*/
             },
             {
               success: function (message) {
-                that.doNotify({message: message});
+                that.doNotify({message: message.loc()});
               },
               error: function (error) {
                 that.doNotify({message: error.message ? error.message() : error});
index 22e20d7..69b2d2c 100644 (file)
           "column": "grp_descrip"
         }
       },
+      {
+        "name": "grantedPrivileges",
+        "toMany": {
+          "type": "UserAccountRolePrivilegeAssignment",
+          "column": "grp_id",
+          "inverse": "userAccountRole",
+          "isNested": true
+        }
+      },
       {
         "name": "grantedExtensions",
         "toMany": {
     ],
     "isSystem": true
   },
+  {
+    "context": "xtuple",
+    "nameSpace": "SYS",
+    "type": "UserAccountRolePrivilegeAssignment",
+    "table": "grppriv",
+    "idSequenceName": "grppriv_grppriv_id_seq",
+    "comment": "User Account Role Privilege Assignment Map",
+    "privileges": {
+      "all": {
+        "create": true,
+        "read": true,
+        "update": false,
+        "delete": true
+      }
+    },
+    "properties": [
+      {
+        "name": "id",
+        "attr": {
+          "type": "Number",
+          "column": "grppriv_id",
+          "isPrimaryKey": true
+        }
+      },
+      {
+        "name": "uuid",
+        "attr": {
+          "type": "String",
+          "column": "obj_uuid",
+          "isNaturalKey": true
+        }
+      },
+      {
+        "name": "userAccountRole",
+        "attr": {
+          "type": "Number",
+          "column": "grppriv_grp_id"
+        }
+      },
+      {
+        "name": "privilege",
+        "toOne": {
+          "type": "Privilege",
+          "column": "grppriv_priv_id"
+        }
+      }
+    ],
+    "isNestedOnly": true,
+    "isSystem": true
+  },
   {
     "context": "xtuple",
     "nameSpace": "SYS",
index 5dafe61..5e0d67a 100644 (file)
@@ -32,11 +32,40 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
             var privCheck = _.find(model.get("grantedPrivileges"), function (model) {
               return model.privilege === "InstallExtension";
             });
-            if (!privCheck) {
-              callback({message: "_insufficientPrivileges"});
+            if (privCheck) {
+              callback(); // the user has this privilege!
               return;
             }
-            callback(); // success!
+            // this gets a little dicey: check all the user's roles for the priv, which
+            // requires async.map
+            var roles = _.map(model.get("grantedUserAccountRoles"), function (grantedRole) {
+              return grantedRole.userAccountRole;
+            });
+            var checkRole = function (roleName, next) {
+              var role = new SYS.UserAccountRole();
+              role.fetch({
+                id: roleName,
+                username: X.options.databaseServer.user,
+                database: database,
+                success: function (roleModel, results) {
+                  var rolePriv = _.find(roleModel.get("grantedPrivileges"), function (grantedPriv) {
+                    return grantedPriv.privilege === "InstallExtension";
+                  });
+                  next(null, rolePriv);
+                }
+              });
+            };
+            async.map(roles, checkRole, function (err, results) {
+              // if any of the roles give the priv, then the user has the priv
+              var result = _.reduce(results, function (memo, priv) {
+                return priv || memo;
+              }, false);
+              if (err || !result) {
+                callback({message: "_insufficientPrivileges"});
+                return;
+              }
+              callback(); // success!
+            });
           },
           error: function () {
             callback({message: "_restoreError"});
@@ -75,7 +104,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
         return;
       }
       console.log("all done");
-      res.send({data: "_success"});
+      res.send({data: "_success!"});
     });
   };
 }());