Skip to content

Commit a4b7770

Browse files
author
Sina Kashipazha
committed
Move settings to domain.
1 parent 0223c6f commit a4b7770

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
*/
8989
public interface QueryService {
9090

91+
static final String RestrictPublicTemplateAccessToDomainCK = "restrict.public.template.access.to.domain";
92+
9193
// Config keys
9294
ConfigKey<Boolean> AllowUserViewDestroyedVM = new ConfigKey<>("Advanced", Boolean.class, "allow.user.view.destroyed.vm", "false",
9395
"Determines whether users can view their destroyed or expunging vm ", true, ConfigKey.Scope.Account);
@@ -109,6 +111,9 @@ public interface QueryService {
109111
"allow.user.view.all.domain.accounts", "false",
110112
"Determines whether users can view all user accounts within the same domain", true, ConfigKey.Scope.Domain);
111113

114+
static final ConfigKey<Boolean> RestrictPublicTemplateAccessToDomain = new ConfigKey<>("Advanced", Boolean.class, RestrictPublicTemplateAccessToDomainCK, "false",
115+
"If true, other domains public templates will not visible in this domain.", true, ConfigKey.Scope.Domain);
116+
112117
ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
113118

114119
ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursive) throws PermissionDeniedException;

engine/components-api/src/main/java/com/cloud/template/TemplateManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@
4242
public interface TemplateManager {
4343
static final String AllowPublicUserTemplatesCK = "allow.public.user.templates";
4444
static final String TemplatePreloaderPoolSizeCK = "template.preloader.pool.size";
45-
static final String RestrictPublicTemplateAccessToDomainCK = "restrict.public.template.access.to.domain";
4645

4746
static final ConfigKey<Boolean> AllowPublicUserTemplates = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowPublicUserTemplatesCK, "true",
4847
"If false, users will not be able to create public templates.", true, ConfigKey.Scope.Account);
4948

5049
static final ConfigKey<Integer> TemplatePreloaderPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, TemplatePreloaderPoolSizeCK, "8",
5150
"Size of the TemplateManager threadpool", false, ConfigKey.Scope.Global);
5251

53-
static final ConfigKey<Boolean> RestrictPublicTemplateAccessToDomain = new ConfigKey<>("Advanced", Boolean.class, RestrictPublicTemplateAccessToDomainCK, "false",
54-
"If true, the public template wouldn't share between domains", true, ConfigKey.Scope.Global);
52+
5553

5654
/**
5755
* Prepares a template for vm creation for a certain storage pool.

server/src/main/java/com/cloud/acl/DomainChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.cloudstack.acl.SecurityChecker;
2929
import org.apache.cloudstack.affinity.AffinityGroup;
3030
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.cloudstack.query.QueryService;
3132
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
3233
import org.apache.log4j.Logger;
3334
import org.springframework.stereotype.Component;
@@ -55,7 +56,6 @@
5556
import com.cloud.service.dao.ServiceOfferingDetailsDao;
5657
import com.cloud.storage.LaunchPermissionVO;
5758
import com.cloud.storage.dao.LaunchPermissionDao;
58-
import com.cloud.template.TemplateManager;
5959
import com.cloud.template.VirtualMachineTemplate;
6060
import com.cloud.user.Account;
6161
import com.cloud.user.AccountService;
@@ -167,7 +167,7 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
167167
throw new PermissionDeniedException("Domain Admin and regular users can modify only their own Public templates");
168168
}
169169
}
170-
} else if (TemplateManager.RestrictPublicTemplateAccessToDomain.value() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { // public template can be used by other accounts in the same domain or in sub-domains, and domain admin of parent domains
170+
} else if (QueryService.RestrictPublicTemplateAccessToDomain.valueIn(caller.getDomainId()) && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { // public template can be used by other accounts in the same domain or in sub-domains, and domain admin of parent domains
171171
if (caller.getDomainId() != owner.getDomainId() && !_domainDao.isChildDomain(owner.getDomainId(), caller.getDomainId())) {
172172
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_PROJECT) {
173173
throw new PermissionDeniedException(caller + "is not allowed to access the template " + template);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@
218218
import com.cloud.storage.dao.VMTemplateDao;
219219
import com.cloud.tags.ResourceTagVO;
220220
import com.cloud.tags.dao.ResourceTagDao;
221-
import com.cloud.template.TemplateManager;
222221
import com.cloud.template.VirtualMachineTemplate.State;
223222
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
224223
import com.cloud.user.Account;
@@ -3435,7 +3434,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
34353434
}
34363435
SearchCriteria<TemplateJoinVO> sc = sb.create();
34373436

3438-
boolean restrictPublicTemplatesToDomain = TemplateManager.RestrictPublicTemplateAccessToDomain.value();
3437+
boolean restrictPublicTemplatesToDomain = QueryService.RestrictPublicTemplateAccessToDomain.valueIn(caller.getDomainId());
34393438

34403439
// verify templateId parameter and specially handle it
34413440
if (templateId != null) {
@@ -4201,6 +4200,7 @@ public String getConfigComponentName() {
42014200

42024201
@Override
42034202
public ConfigKey<?>[] getConfigKeys() {
4204-
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMBlacklistedDetails, UserVMReadOnlyUIDetails, SortKeyAscending, AllowUserViewAllDomainAccounts};
4203+
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMBlacklistedDetails, UserVMReadOnlyUIDetails, SortKeyAscending,
4204+
AllowUserViewAllDomainAccounts, RestrictPublicTemplateAccessToDomain};
42054205
}
42064206
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ public String getConfigComponentName() {
22432243

22442244
@Override
22452245
public ConfigKey<?>[] getConfigKeys() {
2246-
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize, RestrictPublicTemplateAccessToDomain};
2246+
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize};
22472247
}
22482248

22492249
public List<TemplateAdapter> getTemplateAdapters() {

0 commit comments

Comments
 (0)