mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Separate ListTemplatePermissions and ListIsoPermissions commands to use
two different views.
This commit is contained in:
parent
8f21eca922
commit
67b97539ac
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user