Skip to content

Commit 8072e50

Browse files
committed
Fixed a bug for listTemplates with TemplateFilter=shared.
1 parent 5bfc75c commit 8072e50

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.log4j.Logger;
2020

21+
import org.apache.cloudstack.acl.AclEntityType;
2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd;
2324
import org.apache.cloudstack.api.response.SuccessResponse;
@@ -27,7 +28,7 @@
2728

2829
@APICommand(name = "updateTemplatePermissions", responseObject = SuccessResponse.class, description = "Updates a template visibility permissions. "
2930
+ "A public template is visible to all accounts within the same domain. " + "A private template is visible only to the owner of the template. "
30-
+ "A priviledged template is a private template with account permissions added. " + "Only accounts specified under the template permissions are visible to them.")
31+
+ "A priviledged template is a private template with account permissions added. " + "Only accounts specified under the template permissions are visible to them.", entityType = {AclEntityType.VirtualMachineTemplate})
3132
public class UpdateTemplatePermissionsCmd extends BaseUpdateTemplateOrIsoPermissionsCmd {
3233
@Override
3334
protected String getResponseName() {

‎server/src/com/cloud/api/query/QueryManagerImpl.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,13 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
29022902
// exclude the caller, only include those granted and not owned by self
29032903
permittedDomains.remove(caller.getDomainId());
29042904
permittedAccounts.remove(caller.getAccountId());
2905+
for (Long tid : permittedResources) {
2906+
// remove it if it is owned by the caller
2907+
VMTemplateVO tmpl = _templateDao.findById(tid);
2908+
if (tmpl != null && tmpl.getAccountId() == caller.getAccountId()) {
2909+
permittedResources.remove(tid);
2910+
}
2911+
}
29052912
// building ACL search criteria
29062913
SearchCriteria<TemplateJoinVO> aclSc = _templateJoinDao.createSearchCriteria();
29072914
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,8 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
11741174
}
11751175
}
11761176

1177-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
1177+
//_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
1178+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template); //TODO: should we replace all ModifyEntry as OperateEntry?
11781179

11791180
// If the template is removed throw an error.
11801181
if (template.getRemoved() != null) {

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
import javax.inject.Inject;
3939
import javax.naming.ConfigurationException;
4040

41+
import org.apache.commons.codec.binary.Base64;
42+
import org.apache.log4j.Logger;
43+
4144
import org.apache.cloudstack.acl.ControlledEntity;
4245
import org.apache.cloudstack.acl.QuerySelector;
4346
import org.apache.cloudstack.acl.RoleType;
@@ -57,8 +60,6 @@
5760
import org.apache.cloudstack.framework.messagebus.PublishScope;
5861
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5962
import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
60-
import org.apache.commons.codec.binary.Base64;
61-
import org.apache.log4j.Logger;
6263

6364
import com.cloud.api.ApiDBUtils;
6465
import com.cloud.configuration.Config;
@@ -2228,12 +2229,6 @@ public void buildACLSearchParameters(Account caller, Long id, String accountName
22282229
checkAccess(caller, domain);
22292230
}
22302231

2231-
if (id != null) {
2232-
// look for an individual entity, no other permission criteria are needed
2233-
permittedResources.add(id);
2234-
return;
2235-
}
2236-
22372232
if (accountName != null) {
22382233
if (projectId != null) {
22392234
throw new InvalidParameterValueException("Account and projectId can't be specified together");

0 commit comments

Comments
 (0)