Skip to content

Commit fdb8599

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-3347: fixed project deletion for project's owned template
Conflicts: server/src/com/cloud/template/TemplateAdapterBase.java
1 parent 0e27357 commit fdb8599

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎server/src/com/cloud/template/TemplateAdapterBase.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
2626
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
2727
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
28-
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
2928
import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
29+
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
3030
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3131
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3232
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
@@ -46,6 +46,7 @@
4646
import com.cloud.host.dao.HostDao;
4747
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4848
import com.cloud.org.Grouping;
49+
import com.cloud.projects.ProjectManager;
4950
import com.cloud.server.ConfigurationServer;
5051
import com.cloud.storage.GuestOS;
5152
import com.cloud.storage.Storage.ImageFormat;
@@ -86,8 +87,9 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
8687
protected @Inject ResourceLimitService _resourceLimitMgr;
8788
protected @Inject DataStoreManager storeMgr;
8889
@Inject TemplateManager templateMgr;
89-
@Inject ConfigurationServer _configServer;
90-
90+
@Inject ConfigurationServer _configServer;
91+
@Inject ProjectManager _projectMgr;
92+
9193
@Override
9294
public boolean stop() {
9395
return true;
@@ -289,9 +291,16 @@ private Long accountAndUserValidation(Account account, long userId, UserVmVO vmI
289291

290292
if ((template != null)
291293
&& (!template.isPublicTemplate() && (account.getId() != template.getAccountId()) && (template.getTemplateType() != TemplateType.PERHOST))) {
292-
throw new PermissionDeniedException(msg + ". Permission denied.");
294+
//special handling for the project case
295+
Account owner = _accountMgr.getAccount(template.getAccountId());
296+
if (owner.getType() == Account.ACCOUNT_TYPE_PROJECT) {
297+
if (!_projectMgr.canAccessProjectAccount(account, owner.getId())) {
298+
throw new PermissionDeniedException(msg + ". Permission denied. The caller can't access project's template");
299+
}
300+
} else {
301+
throw new PermissionDeniedException(msg + ". Permission denied.");
302+
}
293303
}
294-
295304
} else {
296305
if ((vmInstanceCheck != null) && !_domainDao.isChildDomain(account.getDomainId(), vmInstanceCheck.getDomainId())) {
297306
throw new PermissionDeniedException(msg + ". Permission denied.");

0 commit comments

Comments
 (0)