Commit 922c8790 authored by Jason Song's avatar Jason Song Committed by GitHub

Merge pull request #1292 from nobodyiam/bugfix

bug fix
parents 41a32fee c4dc744b
......@@ -2,8 +2,10 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.component.PermissionValidator;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult;
......@@ -13,6 +15,7 @@ import com.ctrip.framework.apollo.portal.service.ReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -35,6 +38,8 @@ public class ReleaseController {
private ApplicationEventPublisher publisher;
@Autowired
private PortalConfig portalConfig;
@Autowired
private PermissionValidator permissionValidator;
@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName, #env)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases", method = RequestMethod.POST)
......@@ -138,16 +143,21 @@ public class ReleaseController {
}
@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName, #env)")
@RequestMapping(path = "/envs/{env}/releases/{releaseId}/rollback", method = RequestMethod.PUT)
public void rollback(@PathVariable String env,
@PathVariable long releaseId) {
releaseService.rollback(Env.valueOf(env), releaseId);
ReleaseDTO release = releaseService.findReleaseById(Env.valueOf(env), releaseId);
if (Objects.isNull(release)) {
return;
if (release == null) {
throw new NotFoundException("release not found");
}
if (!permissionValidator.hasReleaseNamespacePermission(release.getAppId(), release.getNamespaceName(), env)) {
throw new AccessDeniedException("Access is denied");
}
releaseService.rollback(Env.valueOf(env), releaseId);
ConfigPublishEvent event = ConfigPublishEvent.instance();
event.withAppId(release.getAppId())
.withCluster(release.getClusterName())
......
......@@ -104,13 +104,16 @@ public class AppNamespaceService {
appNamespace.setDataChangeLastModifiedBy(operator);
// unique check
if (appNamespace.isPublic() && findPublicAppNamespace(appNamespace.getName()) != null) {
throw new BadRequestException(appNamespace.getName() + "已存在");
if (appNamespace.isPublic()) {
AppNamespace publicAppNamespace = findPublicAppNamespace(appNamespace.getName());
if (publicAppNamespace != null) {
throw new BadRequestException("Public AppNamespace " + appNamespace.getName() + " already exists in appId: " + publicAppNamespace.getAppId() + "!");
}
}
if (!appNamespace.isPublic() &&
appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName()) != null) {
throw new BadRequestException(appNamespace.getName() + "已存在");
throw new BadRequestException("Private AppNamespace " + appNamespace.getName() + " already exists!");
}
AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace);
......
......@@ -151,7 +151,7 @@
</div>
<div class="form-group" viv clform-group>
<label class="col-sm-2 control-label">
集群信息</label>
AppNamespace信息</label>
<div class="col-sm-5">
<h5 ng-show="appNamespace.info" ng-bind="appNamespace.info"></h5>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment