From cd55a0dd560e01026b991561379cb477e508b529 Mon Sep 17 00:00:00 2001 From: lepdou Date: Tue, 28 Feb 2017 17:44:44 +0800 Subject: [PATCH] app's admin can create private namespace. & default create namespace when create public appnamespace --- .../controller/ClusterController.java | 4 +- .../repository/AppNamespaceRepository.java | 2 + .../apollo/biz/service/AdminService.java | 2 +- .../biz/service/AppNamespaceService.java | 17 ++++---- .../apollo/biz/service/ClusterService.java | 18 ++++---- .../biz/service/NamespaceBranchService.java | 2 +- .../apollo/biz/service/NamespaceService.java | 9 ++-- .../portal/component/PermissionValidator.java | 41 ++++++++++-------- .../portal/component/config/PortalConfig.java | 8 ++++ .../controller/NamespaceController.java | 28 +++++++++---- .../controller/PageSettingController.java | 27 ++++++++++++ .../apollo/portal/entity/vo/PageSetting.java | 24 +++++++++++ .../portal/service/AppNamespaceService.java | 5 +-- .../src/main/resources/static/app.html | 1 + .../main/resources/static/app/setting.html | 1 + .../src/main/resources/static/cluster.html | 1 + .../src/main/resources/static/config.html | 1 + .../main/resources/static/config/history.html | 1 + .../main/resources/static/config/sync.html | 1 + .../src/main/resources/static/index.html | 1 + .../src/main/resources/static/namespace.html | 42 ++++++++++++------- .../main/resources/static/namespace/role.html | 1 + .../main/resources/static/open/manage.html | 1 + .../scripts/controller/NamespaceController.js | 22 +++++----- .../static/scripts/directive/directive.js | 6 ++- .../static/scripts/services/CommonService.js | 17 ++++++++ .../main/resources/static/server_config.html | 1 + .../resources/static/views/common/nav.html | 2 +- 28 files changed, 204 insertions(+), 82 deletions(-) create mode 100644 apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PageSettingController.java create mode 100644 apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/PageSetting.java create mode 100644 apollo-portal/src/main/resources/static/scripts/services/CommonService.js diff --git a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java index 08f864564..775c88cfa 100644 --- a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java +++ b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java @@ -39,9 +39,9 @@ public class ClusterController { } if (autoCreatePrivateNamespace) { - entity = clusterService.saveWithCreatePrivateNamespace(entity); + entity = clusterService.saveWithInstanceOfAppNamespaces(entity); } else { - entity = clusterService.saveWithoutCreatePrivateNamespace(entity); + entity = clusterService.saveWithoutInstanceOfAppNamespaces(entity); } dto = BeanUtils.transfrom(ClusterDTO.class, entity); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java index 9e0cf8aac..99510958c 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java @@ -20,6 +20,8 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository findByAppIdAndIsPublic(String appId, boolean isPublic); + List findByAppId(String appId); + List findFirst500ByIdGreaterThanOrderByIdAsc(long id); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java index bcf4133b1..63ea9af68 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java @@ -30,7 +30,7 @@ public class AdminService { clusterService.createDefaultCluster(appId, createBy); - namespaceService.createPrivateNamespace(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, createBy); + namespaceService.instanceOfAppNamespaces(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, createBy); return app; } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java index 0c663f036..92d3701f3 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java @@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository; import com.ctrip.framework.apollo.common.entity.AppNamespace; -import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.ServiceException; import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.core.ConfigConsts; @@ -47,6 +46,10 @@ public class AppNamespaceService { return appNamespaceRepository.findByNameAndIsPublicTrue(namespaceName); } + public List findByAppId(String appId) { + return appNamespaceRepository.findByAppId(appId); + } + public List findPublicNamespacesByNames(Set namespaceNames) { if (namespaceNames == null || namespaceNames.isEmpty()) { return Collections.emptyList(); @@ -100,14 +103,12 @@ public class AppNamespaceService { appNamespace.setId(0);//protection appNamespace.setDataChangeCreatedBy(createBy); appNamespace.setDataChangeLastModifiedBy(createBy); + appNamespace = appNamespaceRepository.save(appNamespace); - if (!appNamespace.isPublic()) { - linkPrivateAppNamespaceInAllCluster(appNamespace.getAppId(), appNamespace.getName(), createBy); - } + instanceOfAppNamespaceInAllCluster(appNamespace.getAppId(), appNamespace.getName(), createBy); - auditService.audit(AppNamespace.class.getSimpleName(), appNamespace.getId(), Audit.OP.INSERT, - createBy); + auditService.audit(AppNamespace.class.getSimpleName(), appNamespace.getId(), Audit.OP.INSERT, createBy); return appNamespace; } @@ -122,8 +123,9 @@ public class AppNamespaceService { return managedNs; } - private void linkPrivateAppNamespaceInAllCluster(String appId, String namespaceName, String createBy) { + private void instanceOfAppNamespaceInAllCluster(String appId, String namespaceName, String createBy) { List clusters = clusterService.findParentClusters(appId); + for (Cluster cluster : clusters) { Namespace namespace = new Namespace(); namespace.setClusterName(cluster.getName()); @@ -131,6 +133,7 @@ public class AppNamespaceService { namespace.setNamespaceName(namespaceName); namespace.setDataChangeCreatedBy(createBy); namespace.setDataChangeLastModifiedBy(createBy); + namespaceService.save(namespace); } } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java index d1b9179b8..f2f396630 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java @@ -39,7 +39,7 @@ public class ClusterService { return clusterRepository.findByAppIdAndName(appId, name); } - public Cluster findOne(long clusterId){ + public Cluster findOne(long clusterId) { return clusterRepository.findOne(clusterId); } @@ -59,18 +59,18 @@ public class ClusterService { } @Transactional - public Cluster saveWithCreatePrivateNamespace(Cluster entity) { + public Cluster saveWithInstanceOfAppNamespaces(Cluster entity) { - Cluster savedCluster = saveWithoutCreatePrivateNamespace(entity); + Cluster savedCluster = saveWithoutInstanceOfAppNamespaces(entity); - namespaceService.createPrivateNamespace(savedCluster.getAppId(), savedCluster.getName(), - savedCluster.getDataChangeCreatedBy()); + namespaceService.instanceOfAppNamespaces(savedCluster.getAppId(), savedCluster.getName(), + savedCluster.getDataChangeCreatedBy()); return savedCluster; } @Transactional - public Cluster saveWithoutCreatePrivateNamespace(Cluster entity){ + public Cluster saveWithoutInstanceOfAppNamespaces(Cluster entity) { if (!isClusterNameUnique(entity.getAppId(), entity.getName())) { throw new BadRequestException("cluster not unique"); } @@ -108,7 +108,7 @@ public class ClusterService { managedCluster = clusterRepository.save(managedCluster); auditService.audit(Cluster.class.getSimpleName(), managedCluster.getId(), Audit.OP.UPDATE, - managedCluster.getDataChangeLastModifiedBy()); + managedCluster.getDataChangeLastModifiedBy()); return managedCluster; } @@ -128,9 +128,9 @@ public class ClusterService { auditService.audit(Cluster.class.getSimpleName(), cluster.getId(), Audit.OP.INSERT, createBy); } - public List findChildClusters(String appId, String parentClusterName){ + public List findChildClusters(String appId, String parentClusterName) { Cluster parentCluster = findOne(appId, parentClusterName); - if (parentCluster == null){ + if (parentCluster == null) { throw new BadRequestException("parent cluster not exist"); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java index 27daf7c8e..758267a86 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java @@ -52,7 +52,7 @@ public class NamespaceBranchService { //create child cluster Cluster childCluster = createChildCluster(appId, parentCluster, namespaceName, operator); - Cluster createdChildCluster = clusterService.saveWithoutCreatePrivateNamespace(childCluster); + Cluster createdChildCluster = clusterService.saveWithoutInstanceOfAppNamespaces(childCluster); //create child namespace childNamespace = createNamespaceBranch(appId, createdChildCluster.getName(), diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java index 59a502d24..44b7d2d58 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java @@ -313,12 +313,11 @@ public class NamespaceService { } @Transactional - public void createPrivateNamespace(String appId, String clusterName, String createBy) { + public void instanceOfAppNamespaces(String appId, String clusterName, String createBy) { - //load all private app namespace - List privateAppNamespaces = appNamespaceService.findPrivateAppNamespace(appId); - //create all private namespace - for (AppNamespace appNamespace : privateAppNamespaces) { + List appNamespaces = appNamespaceService.findByAppId(appId); + + for (AppNamespace appNamespace : appNamespaces) { Namespace ns = new Namespace(); ns.setAppId(appId); ns.setClusterName(clusterName); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/PermissionValidator.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/PermissionValidator.java index 86a0892f8..6a2fa26a6 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/PermissionValidator.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/PermissionValidator.java @@ -1,6 +1,7 @@ package com.ctrip.framework.apollo.portal.component; import com.ctrip.framework.apollo.common.entity.AppNamespace; +import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.constant.PermissionType; import com.ctrip.framework.apollo.portal.service.RolePermissionService; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; @@ -16,53 +17,57 @@ public class PermissionValidator { private UserInfoHolder userInfoHolder; @Autowired private RolePermissionService rolePermissionService; + @Autowired + private PortalConfig portalConfig; public boolean hasModifyNamespacePermission(String appId, String namespaceName) { return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), - PermissionType.MODIFY_NAMESPACE, - RoleUtils.buildNamespaceTargetId(appId, namespaceName)); + PermissionType.MODIFY_NAMESPACE, + RoleUtils.buildNamespaceTargetId(appId, namespaceName)); } public boolean hasReleaseNamespacePermission(String appId, String namespaceName) { return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), - PermissionType.RELEASE_NAMESPACE, - RoleUtils.buildNamespaceTargetId(appId, namespaceName)); + PermissionType.RELEASE_NAMESPACE, + RoleUtils.buildNamespaceTargetId(appId, namespaceName)); } public boolean hasDeleteNamespacePermission(String appId) { return hasAssignRolePermission(appId) || isSuperAdmin(); } - public boolean hasOperateNamespacePermission(String appId, String namespaceName){ + public boolean hasOperateNamespacePermission(String appId, String namespaceName) { return hasModifyNamespacePermission(appId, namespaceName) || hasReleaseNamespacePermission(appId, namespaceName); } public boolean hasAssignRolePermission(String appId) { return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), - PermissionType.ASSIGN_ROLE, - appId); + PermissionType.ASSIGN_ROLE, + appId); } public boolean hasCreateNamespacePermission(String appId) { - return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), - PermissionType.CREATE_NAMESPACE, - appId); - } - - public boolean hasCreateClusterPermission(String appId) { return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), - PermissionType.CREATE_CLUSTER, - appId); + PermissionType.CREATE_NAMESPACE, + appId); } public boolean hasCreateAppNamespacePermission(String appId, AppNamespace appNamespace) { + boolean isPublicAppNamespace = appNamespace.isPublic(); - if (isPublicAppNamespace) { + + if (portalConfig.canAppAdminCreatePrivateNamespace() || isPublicAppNamespace) { return hasCreateNamespacePermission(appId); - } else { - return rolePermissionService.isSuperAdmin(userInfoHolder.getUser().getUserId()); } + + return isSuperAdmin(); + } + + public boolean hasCreateClusterPermission(String appId) { + return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), + PermissionType.CREATE_CLUSTER, + appId); } public boolean isAppAdmin(String appId) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index 76a6f018f..c34b04f8c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -153,6 +153,14 @@ public class PortalConfig extends RefreshableConfig { return getValue("email.template.release.module.rules", ""); } + public String wikiAddress() { + return getValue("wiki.address", "https://github.com/ctripcorp/apollo/wiki"); + } + + public boolean canAppAdminCreatePrivateNamespace() { + return getBooleanProperty("admin.createPrivateNamespace.switch", true); + } + /*** * The following configurations are used in ctrip profile **/ diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java index eef50e220..baa3f0c3c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java @@ -11,6 +11,7 @@ import com.ctrip.framework.apollo.common.utils.RequestPrecondition; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.utils.StringUtils; +import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.constant.RoleType; import com.ctrip.framework.apollo.portal.entity.model.NamespaceCreationModel; import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO; @@ -62,6 +63,9 @@ public class NamespaceController { private RoleInitializationService roleInitializationService; @Autowired private RolePermissionService rolePermissionService; + @Autowired + private PortalConfig portalConfig; + @RequestMapping(value = "/appnamespaces/public", method = RequestMethod.GET) public List findPublicAppNamespaces() { @@ -119,14 +123,7 @@ public class NamespaceController { } } - //default assign modify、release namespace role to namespace creator - String loginUser = userInfoHolder.getUser().getUserId(); - rolePermissionService - .assignRoleToUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.MODIFY_NAMESPACE), - Sets.newHashSet(loginUser), loginUser); - rolePermissionService - .assignRoleToUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.RELEASE_NAMESPACE), - Sets.newHashSet(loginUser), loginUser); + assignNamespaceRoleToOperator(appId, namespaceName); return ResponseEntity.ok().build(); } @@ -169,6 +166,10 @@ public class NamespaceController { appNamespace.setDataChangeLastModifiedBy(operator); AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace); + if (portalConfig.canAppAdminCreatePrivateNamespace() || createdAppNamespace.isPublic()) { + assignNamespaceRoleToOperator(appId, appNamespace.getName()); + } + publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace)); return createdAppNamespace; @@ -196,4 +197,15 @@ public class NamespaceController { } + private void assignNamespaceRoleToOperator(String appId, String namespaceName) { + //default assign modify、release namespace role to namespace creator + String operator = userInfoHolder.getUser().getUserId(); + + rolePermissionService + .assignRoleToUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.MODIFY_NAMESPACE), + Sets.newHashSet(operator), operator); + rolePermissionService + .assignRoleToUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.RELEASE_NAMESPACE), + Sets.newHashSet(operator), operator); + } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PageSettingController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PageSettingController.java new file mode 100644 index 000000000..a4b3eacbf --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PageSettingController.java @@ -0,0 +1,27 @@ +package com.ctrip.framework.apollo.portal.controller; + +import com.ctrip.framework.apollo.portal.component.config.PortalConfig; +import com.ctrip.framework.apollo.portal.entity.vo.PageSetting; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PageSettingController { + + @Autowired + private PortalConfig portalConfig; + + @RequestMapping(value = "/page-settings", method = RequestMethod.GET) + public PageSetting getPageSetting() { + PageSetting setting = new PageSetting(); + + setting.setWikiAddress(portalConfig.wikiAddress()); + setting.setCanAppAdminCreatePrivateNamespace(portalConfig.canAppAdminCreatePrivateNamespace()); + + return setting; + } + +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/PageSetting.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/PageSetting.java new file mode 100644 index 000000000..8acbd1aa8 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/PageSetting.java @@ -0,0 +1,24 @@ +package com.ctrip.framework.apollo.portal.entity.vo; + +public class PageSetting { + + private String wikiAddress; + + private boolean canAppAdminCreatePrivateNamespace; + + public String getWikiAddress() { + return wikiAddress; + } + + public void setWikiAddress(String wikiAddress) { + this.wikiAddress = wikiAddress; + } + + public boolean isCanAppAdminCreatePrivateNamespace() { + return canAppAdminCreatePrivateNamespace; + } + + public void setCanAppAdminCreatePrivateNamespace(boolean canAppAdminCreatePrivateNamespace) { + this.canAppAdminCreatePrivateNamespace = canAppAdminCreatePrivateNamespace; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java index fbba8e557..a94c02f03 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java @@ -77,10 +77,7 @@ public class AppNamespaceService { AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace); - //如果是私有的app namespace 要默认初始化权限,如果是公共的,则在关联此namespace的时候初始化权限 - if (!createdAppNamespace.isPublic()) { - roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName()); - } + roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName()); return createdAppNamespace; } diff --git a/apollo-portal/src/main/resources/static/app.html b/apollo-portal/src/main/resources/static/app.html index 221e85427..b48e68aea 100644 --- a/apollo-portal/src/main/resources/static/app.html +++ b/apollo-portal/src/main/resources/static/app.html @@ -118,6 +118,7 @@ + diff --git a/apollo-portal/src/main/resources/static/app/setting.html b/apollo-portal/src/main/resources/static/app/setting.html index 040d7b15d..e7b191112 100644 --- a/apollo-portal/src/main/resources/static/app/setting.html +++ b/apollo-portal/src/main/resources/static/app/setting.html @@ -186,6 +186,7 @@ + diff --git a/apollo-portal/src/main/resources/static/cluster.html b/apollo-portal/src/main/resources/static/cluster.html index ff7a54120..6db6bf13d 100644 --- a/apollo-portal/src/main/resources/static/cluster.html +++ b/apollo-portal/src/main/resources/static/cluster.html @@ -127,6 +127,7 @@ + diff --git a/apollo-portal/src/main/resources/static/config.html b/apollo-portal/src/main/resources/static/config.html index f786aee4a..a26c036b5 100644 --- a/apollo-portal/src/main/resources/static/config.html +++ b/apollo-portal/src/main/resources/static/config.html @@ -389,6 +389,7 @@ + diff --git a/apollo-portal/src/main/resources/static/config/history.html b/apollo-portal/src/main/resources/static/config/history.html index c5b3b850d..6ecc561d2 100644 --- a/apollo-portal/src/main/resources/static/config/history.html +++ b/apollo-portal/src/main/resources/static/config/history.html @@ -267,6 +267,7 @@ + diff --git a/apollo-portal/src/main/resources/static/config/sync.html b/apollo-portal/src/main/resources/static/config/sync.html index af6709f0d..56323cf6b 100644 --- a/apollo-portal/src/main/resources/static/config/sync.html +++ b/apollo-portal/src/main/resources/static/config/sync.html @@ -234,6 +234,7 @@ + diff --git a/apollo-portal/src/main/resources/static/index.html b/apollo-portal/src/main/resources/static/index.html index 1c12a2ed4..a0dbddbf6 100644 --- a/apollo-portal/src/main/resources/static/index.html +++ b/apollo-portal/src/main/resources/static/index.html @@ -125,6 +125,7 @@ + diff --git a/apollo-portal/src/main/resources/static/namespace.html b/apollo-portal/src/main/resources/static/namespace.html index ce21b1639..4e6c3275e 100644 --- a/apollo-portal/src/main/resources/static/namespace.html +++ b/apollo-portal/src/main/resources/static/namespace.html @@ -23,7 +23,11 @@
-
新建Namespace
+
@@ -37,26 +41,32 @@
Tips:
    -
  • 公共namespace所属的应用通过关联公共namespace来配置公共部分的配置
  • -
  • 其它应用可以通过关联公共namespace来覆盖公共部分的配置
  • -
  • 如果其它应用不需要覆盖公共部分的配置,那么无需关联公共namespace
  • +
  • 应用可以通过关联公共namespace来覆盖公共Namespace的配置
  • +
  • 如果应用不需要覆盖公共Namespace的配置,那么无需关联公共Namespace
-
    +
      +
    • 公共的Namespace的配置能被任何项目读取
    • - 通过创建一个公共的namespace可以实现公共组件的配置,或多个应用共享同一份配置的需求 + 通过创建公共Namespace可以实现公共组件的配置,或多个应用共享同一份配置的需求
    • -
    • 创建完公共的namespace且关联到当前应用后,就可以配置公共部分的配置了
    • -
    • 如果其它应用需要覆盖公共部分的配置,可以在其它应用那里关联公共的namespace,然后在关联的namespace里面配置需要覆盖的配置即可
    • -
    • 如果其它应用不需要覆盖公共部分的配置,那么就不需要在其它应用那里关联公共的namespace
    • +
    • 如果其它应用需要覆盖公共部分的配置,可以在其它应用那里关联公共Namespace,然后在关联的Namespace里面配置需要覆盖的配置即可
    • +
    • 如果其它应用不需要覆盖公共部分的配置,那么就不需要在其它应用那里关联公共Namespace
    • +
    +
      +
    • 私有Namespace的配置只能被所属的应用获取到
    • +
    • + 通过创建一个私有的Namespace可以实现分组管理配置 +
    • +
    • 私有Namespace的格式可以是xml、yml、yaml、json. 您可以通过Apollo-client中ConfigFile接口来获取非properties格式Namespace的内容
@@ -65,7 +75,7 @@
- +
@@ -93,7 +103,9 @@ ng-model="appNamespace.name">
-
+ + +
+   
-
+
@@ -184,6 +197,7 @@ + diff --git a/apollo-portal/src/main/resources/static/namespace/role.html b/apollo-portal/src/main/resources/static/namespace/role.html index 4c52dc32d..59d40ddb9 100644 --- a/apollo-portal/src/main/resources/static/namespace/role.html +++ b/apollo-portal/src/main/resources/static/namespace/role.html @@ -126,6 +126,7 @@ + diff --git a/apollo-portal/src/main/resources/static/open/manage.html b/apollo-portal/src/main/resources/static/open/manage.html index 37f3685bc..698432064 100644 --- a/apollo-portal/src/main/resources/static/open/manage.html +++ b/apollo-portal/src/main/resources/static/open/manage.html @@ -172,6 +172,7 @@ + diff --git a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js index 6beb13c17..92397508a 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js @@ -1,8 +1,8 @@ namespace_module.controller("LinkNamespaceController", ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'NamespaceService', - 'PermissionService', + 'PermissionService', 'CommonService', function ($scope, $location, $window, toastr, AppService, AppUtil, NamespaceService, - PermissionService) { + PermissionService, CommonService) { var params = AppUtil.parseParams($location.$$url); $scope.appId = params.appid; @@ -16,6 +16,10 @@ namespace_module.controller("LinkNamespaceController", $scope.hasRootPermission = result.hasPermission; }); + CommonService.getPageSetting().then(function (setting) { + $scope.pageSetting = setting; + }); + NamespaceService.find_public_namespaces().then(function (result) { var publicNamespaces = []; result.forEach(function (item) { @@ -112,27 +116,23 @@ namespace_module.controller("LinkNamespaceController", } else { var namespaceNameLength = $scope.concatNamespace().length; - if (namespaceNameLength > 32){ + if (namespaceNameLength > 32) { toastr.error("namespace名称不能大于32个字符. 部门前缀" + (namespaceNameLength - $scope.appNamespace.name.length) + "个字符, 名称" + $scope.appNamespace.name.length + "个字符" ); return; } - + $scope.submitBtnDisabled = true; NamespaceService.createAppNamespace($scope.appId, $scope.appNamespace).then( function (result) { $scope.step = 2; setTimeout(function () { $scope.submitBtnDisabled = false; - if ($scope.appNamespace.isPublic) { - $window.location.reload(); - } else {//private的直接link并且跳转到授权页面 - $window.location.href = - "/namespace/role.html?#/appid=" + $scope.appId - + "&namespaceName=" + result.name; - } + $window.location.href = + "/namespace/role.html?#/appid=" + $scope.appId + + "&namespaceName=" + result.name; }, 1000); }, function (result) { $scope.submitBtnDisabled = false; diff --git a/apollo-portal/src/main/resources/static/scripts/directive/directive.js b/apollo-portal/src/main/resources/static/scripts/directive/directive.js index 01b002317..8494514db 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive/directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive/directive.js @@ -1,6 +1,6 @@ /** navbar */ directive_module.directive('apollonav', - function ($compile, $window, toastr, AppUtil, AppService, EnvService, UserService) { + function ($compile, $window, toastr, AppUtil, AppService, EnvService, UserService, CommonService) { return { restrict: 'E', templateUrl: '../../views/common/nav.html', @@ -8,6 +8,10 @@ directive_module.directive('apollonav', replace: true, link: function (scope, element, attrs) { + CommonService.getPageSetting().then(function (setting) { + scope.pageSetting = setting; + }); + scope.sourceApps = []; scope.copyedApps = []; diff --git a/apollo-portal/src/main/resources/static/scripts/services/CommonService.js b/apollo-portal/src/main/resources/static/scripts/services/CommonService.js new file mode 100644 index 000000000..263a6fe54 --- /dev/null +++ b/apollo-portal/src/main/resources/static/scripts/services/CommonService.js @@ -0,0 +1,17 @@ +appService.service('CommonService', ['$resource', '$q', 'AppUtil', + function ($resource, $q, AppUtil) { + var resource = $resource('', {}, { + page_setting: { + method: 'GET', + isArray: false, + url: '/page-settings' + } + }); + + + return { + getPageSetting: function () { + return AppUtil.ajax(resource.page_setting, {}); + } + } +}]); diff --git a/apollo-portal/src/main/resources/static/server_config.html b/apollo-portal/src/main/resources/static/server_config.html index 9efbf40a3..64b279268 100644 --- a/apollo-portal/src/main/resources/static/server_config.html +++ b/apollo-portal/src/main/resources/static/server_config.html @@ -84,6 +84,7 @@ + diff --git a/apollo-portal/src/main/resources/static/views/common/nav.html b/apollo-portal/src/main/resources/static/views/common/nav.html index 5e30e7b4b..3f65a8544 100644 --- a/apollo-portal/src/main/resources/static/views/common/nav.html +++ b/apollo-portal/src/main/resources/static/views/common/nav.html @@ -21,7 +21,7 @@