diff --git a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java index caac2844850..06039b4a2f2 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 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); } + + } diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index 730f6fd8ebf..6c2e1a8ae32 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 createCapacityResponse(List result, DecimalFormat format); - TemplatePermissionsResponse createTemplatePermissionsResponse(List accountNames, Long id, boolean isAdmin); + TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List accountNames, Long id); AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd); 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 00000000000..613a4a7942c --- /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); + } +} 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 00000000000..1b6fbab3605 --- /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); + } + +} 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 faa4f607edc..2f2c21663dc 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); + } } 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 d727a334c82..76204bced9a 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); + } + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index bd4598c8e38..d91ed3866df 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 accountNames, Long id, boolean isAdmin) { + public TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List 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());