cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/rbac to 67b9753
Date Thu, 12 Dec 2013 01:41:37 GMT
Updated Branches:
  refs/heads/rbac 8f21eca92 -> 67b97539a


Separate ListTemplatePermissions and ListIsoPermissions commands to use
two different views.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/67b97539
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/67b97539
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/67b97539

Branch: refs/heads/rbac
Commit: 67b97539acc058539ed556178decc8e8ba161dd4
Parents: 8f21eca
Author: Min Chen <min.chen@citrix.com>
Authored: Wed Dec 11 17:41:10 2013 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Wed Dec 11 17:41:10 2013 -0800

----------------------------------------------------------------------
 .../BaseListTemplateOrIsoPermissionsCmd.java    | 20 ++++++------
 .../cloudstack/api/ResponseGenerator.java       |  2 +-
 .../admin/iso/ListIsoPermissionsCmdByAdmin.java | 31 +++++++++++++++++++
 .../ListTemplatePermissionsCmdByAdmin.java      | 32 ++++++++++++++++++++
 .../command/user/iso/ListIsoPermissionsCmd.java | 12 ++++++--
 .../template/ListTemplatePermissionsCmd.java    | 13 ++++++--
 server/src/com/cloud/api/ApiResponseHelper.java |  6 ++--
 7 files changed, 97 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
index caac284..06039b4 100644
--- a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
@@ -18,15 +18,15 @@ package org.apache.cloudstack.api;
 
 import java.util.List;
 
-import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
-import org.apache.cloudstack.context.CallContext;
-
 import org.apache.log4j.Logger;
 
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
+
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
 
-public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
+public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
     public Logger s_logger = getLogger();
     protected String s_name = "listtemplatepermissionsresponse";
 
@@ -76,15 +76,13 @@ public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
         return Logger.getLogger(BaseUpdateTemplateOrIsoPermissionsCmd.class.getName());
     }
 
-    @Override
-    public void execute(){
+    protected void executeWithView(ResponseView view) {
         List<String> accountNames = _templateService.listTemplatePermissions(this);
 
-        Account account = CallContext.current().getCallingAccount();
-        boolean isAdmin = (_accountService.isAdmin(account.getType()));
-
-        TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames,
id, isAdmin);
+        TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(view,
accountNames, id);
         response.setResponseName(getCommandName());
-        this.setResponseObject(response);
+        setResponseObject(response);
     }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index 730f6fd..6c2e1a8 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -307,7 +307,7 @@ public interface ResponseGenerator {
 
     List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result,
DecimalFormat format);
 
-    TemplatePermissionsResponse createTemplatePermissionsResponse(List<String> accountNames,
Long id, boolean isAdmin);
+    TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String>
accountNames, Long id);
 
     AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
b/api/src/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
new file mode 100644
index 0000000..613a4a7
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
@@ -0,0 +1,31 @@
+// Licensedname = "listIsoPermissions",  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
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.iso;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.iso.ListIsoPermissionsCmd;
+import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
+
+@APICommand(name = "listIsoPermissions", description = "List iso visibility and all accounts
that have permissions to view this iso.", responseObject = TemplatePermissionsResponse.class,
responseView = ResponseView.Full)
+public class ListIsoPermissionsCmdByAdmin extends ListIsoPermissionsCmd {
+
+    @Override
+    public void execute() {
+        executeWithView(ResponseView.Full);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
b/api/src/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
new file mode 100644
index 0000000..1b6fbab
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
@@ -0,0 +1,32 @@
+// Licensedname = "listTemplatePermissions",  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
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.template;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.template.ListTemplatePermissionsCmd;
+import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
+
+@APICommand(name = "listTemplatePermissions", description = "List template visibility and
all accounts that have permissions to view this template.", responseObject = TemplatePermissionsResponse.class,
responseView = ResponseView.Full)
+public class ListTemplatePermissionsCmdByAdmin extends ListTemplatePermissionsCmd {
+
+    @Override
+    public void execute() {
+        executeWithView(ResponseView.Full);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
index faa4f60..2f2c216 100644
--- a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
@@ -16,15 +16,17 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.iso;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.template.VirtualMachineTemplate;
 
-@APICommand(name="listIsoPermissions", description="List iso visibility and all accounts
that have permissions to view this iso.", responseObject=TemplatePermissionsResponse.class)
+@APICommand(name = "listIsoPermissions", description = "List iso visibility and all accounts
that have permissions to view this iso.", responseObject = TemplatePermissionsResponse.class,
responseView = ResponseView.Restricted)
 public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd {
     protected String getResponseName() {
         return "listisopermissionsresponse";
@@ -40,7 +42,13 @@ public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd
{
         return Logger.getLogger(ListIsoPermissionsCmd.class.getName());
     }
 
+    @Override
     protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
         return template.getFormat().equals(ImageFormat.ISO);
     }
+
+    @Override
+    public void execute() {
+        executeWithView(ResponseView.Restricted);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
index d727a33..76204bc 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
@@ -16,15 +16,17 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.template;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.template.VirtualMachineTemplate;
 
-@APICommand(name = "listTemplatePermissions", description="List template visibility and all
accounts that have permissions to view this template.", responseObject=TemplatePermissionsResponse.class)
+@APICommand(name = "listTemplatePermissions", description = "List template visibility and
all accounts that have permissions to view this template.", responseObject = TemplatePermissionsResponse.class,
responseView = ResponseView.Restricted)
 public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd {
     protected String getResponseName() {
         return "listtemplatepermissionsresponse";
@@ -40,7 +42,14 @@ public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissions
         return Logger.getLogger(ListTemplatePermissionsCmd.class.getName());
     }
 
+    @Override
     protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
         return !template.getFormat().equals(ImageFormat.ISO);
     }
+
+    @Override
+    public void execute() {
+        executeWithView(ResponseView.Restricted);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67b97539/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index bd4598c..d91ed38 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -1877,11 +1877,11 @@ public class ApiResponseHelper implements ResponseGenerator {
     }
 
     @Override
-    public TemplatePermissionsResponse createTemplatePermissionsResponse(List<String>
accountNames, Long id, boolean isAdmin) {
+    public TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view,
List<String> accountNames, Long id) {
         Long templateOwnerDomain = null;
         VirtualMachineTemplate template = ApiDBUtils.findTemplateById(id);
         Account templateOwner = ApiDBUtils.findAccountById(template.getAccountId());
-        if (isAdmin) {
+        if (view == ResponseView.Full) {
             // FIXME: we have just template id and need to get template owner
             // from that
             if (templateOwner != null) {
@@ -1892,7 +1892,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         TemplatePermissionsResponse response = new TemplatePermissionsResponse();
         response.setId(template.getUuid());
         response.setPublicTemplate(template.isPublicTemplate());
-        if (isAdmin && (templateOwnerDomain != null)) {
+        if ((view == ResponseView.Full) && (templateOwnerDomain != null)) {
             Domain domain = ApiDBUtils.findDomainById(templateOwnerDomain);
             if (domain != null) {
                 response.setDomainId(domain.getUuid());


Mime
View raw message