Commit 5359d441 authored by Jason Song's avatar Jason Song Committed by GitHub

Merge pull request #280 from lepdou/0620_27

多处细节优化
parents b9813f17 f98b344c
...@@ -77,7 +77,7 @@ public class AppController { ...@@ -77,7 +77,7 @@ public class AppController {
} }
appService.enrichUserInfo(app); appService.enrichUserInfo(app);
App createdApp = appService.createOrUpdateAppInLocal(app); App createdApp = appService.create(app);
publisher.publishEvent(new AppCreationEvent(createdApp)); publisher.publishEvent(new AppCreationEvent(createdApp));
......
...@@ -22,7 +22,6 @@ import com.ctrip.framework.apollo.core.exception.BadRequestException; ...@@ -22,7 +22,6 @@ import com.ctrip.framework.apollo.core.exception.BadRequestException;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI; import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder; import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo; import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo;
import com.ctrip.framework.apollo.portal.listener.AppCreationEvent;
import com.ctrip.framework.apollo.portal.repository.AppRepository; import com.ctrip.framework.apollo.portal.repository.AppRepository;
@Service @Service
...@@ -45,8 +44,6 @@ public class AppService { ...@@ -45,8 +44,6 @@ public class AppService {
@Autowired @Autowired
private AppRepository appRepository; private AppRepository appRepository;
@Autowired
private ApplicationEventPublisher publisher;
public List<App> findAll() { public List<App> findAll() {
Iterable<App> apps = appRepository.findAll(); Iterable<App> apps = appRepository.findAll();
...@@ -87,13 +84,12 @@ public class AppService { ...@@ -87,13 +84,12 @@ public class AppService {
@Transactional @Transactional
public App createOrUpdateAppInLocal(App app) { public App create(App app) {
String appId = app.getAppId(); String appId = app.getAppId();
App managedApp = appRepository.findByAppId(appId); App managedApp = appRepository.findByAppId(appId);
if (managedApp != null) { if (managedApp != null) {
BeanUtils.copyEntityProperties(app, managedApp); throw new BadRequestException(String.format("app id %s already exists!", app.getAppId()));
return appRepository.save(managedApp);
} else { } else {
App createdApp = appRepository.save(app); App createdApp = appRepository.save(app);
namespaceService.createDefaultAppNamespace(appId); namespaceService.createDefaultAppNamespace(appId);
......
...@@ -35,32 +35,31 @@ ...@@ -35,32 +35,31 @@
<label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用AppId</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用AppId</label>
<div class="col-sm-3"> <div class="col-sm-3">
<input type="text" class="form-control" name="appAppId" ng-model="app.appId" <input type="text" class="form-control" name="appAppId" ng-model="app.appId"
required> required><small>(CMS上申请的App Id)</small>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用名称</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用名称</label>
<div class="col-sm-5"> <div class="col-sm-5">
<input type="text" class="form-control" name="appName" ng-model="app.name" required> <input type="text" class="form-control" name="appName" ng-model="app.name" required>
<small>(建议格式 xx-yy-zz 例:apollo-server)</small>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用负责人</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用负责人</label>
<div class="col-sm-3"> <div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required> <input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required>
<div class="input-group-addon" ng-bind="emailPostfix"></div>
</div> </div>
</div> <small>(负责人具有项目管理的最高权限,比如分配配置的修改权,发布权等)</small>
<div class="form-group">
<label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 邮箱地址</label>
<div class="col-sm-4">
<input type="email" class="form-control" ng-model="app.ownerEmail" required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10"> <div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">创建</button> <button type="submit" class="btn btn-primary">提交</button>
</div> </div>
</div> </div>
</form> </form>
......
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
<div class="row"> <div class="row">
<div class="col-md-2"><img src="img/user_manage.png" class="i-20"></div> <div class="col-md-2"><img src="img/user_manage.png" class="i-20"></div>
<div class="col-md-10 hidden-xs"> <div class="col-md-10 hidden-xs">
<p class="btn-title">项目管理员</p> <p class="btn-title">项目负责人</p>
</div> </div>
</div> </div>
</a> </a>
...@@ -365,7 +365,7 @@ ...@@ -365,7 +365,7 @@
apollo-detail="'确定要删除配置吗?'" apollo-confirm="deleteItem"></apolloconfirmdialog> apollo-detail="'确定要删除配置吗?'" apollo-confirm="deleteItem"></apolloconfirmdialog>
<apolloconfirmdialog apollo-dialog-id="'releaseNoPermissionDialog'" apollo-title="'发布'" <apolloconfirmdialog apollo-dialog-id="'releaseNoPermissionDialog'" apollo-title="'发布'"
apollo-detail="'您没有发布权限哦~'" apollo-detail="'您没有发布权限哦~ 请找 ' + masterUsers + ' 分配权限'"
apollo-show-cancel-btn="false"></apolloconfirmdialog> apollo-show-cancel-btn="false"></apolloconfirmdialog>
<!--create release modal--> <!--create release modal-->
......
create_app_module.controller('CreateAppController', ['$scope', '$window', 'toastr', 'AppService', 'AppUtil', 'OrganizationService', create_app_module.controller('CreateAppController', ['$scope', '$window', 'toastr', 'AppService', 'UserService', 'AppUtil', 'OrganizationService',
function ($scope, $window, toastr, AppService, AppUtil, OrganizationService) { function ($scope, $window, toastr, AppService, UserService, AppUtil, OrganizationService) {
OrganizationService.find_organizations().then(function (result) { OrganizationService.find_organizations().then(function (result) {
var organizations = []; var organizations = [];
...@@ -19,6 +19,15 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast ...@@ -19,6 +19,15 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
toastr.error(AppUtil.errorMsg(result), "load organizations error"); toastr.error(AppUtil.errorMsg(result), "load organizations error");
}); });
$scope.app = {};
UserService.load_user().then(function (result) {
$scope.app.ownerName = result.userId;
}, function (result) {
});
$scope.emailPostfix = "@ctrip.com";
$scope.create = function () { $scope.create = function () {
var selectedOrg = $('#organization').select2('data')[0]; var selectedOrg = $('#organization').select2('data')[0];
...@@ -29,6 +38,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast ...@@ -29,6 +38,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
$scope.app.orgId = selectedOrg.id; $scope.app.orgId = selectedOrg.id;
$scope.app.orgName = selectedOrg.name; $scope.app.orgName = selectedOrg.name;
$scope.app.ownerEmail = $scope.app.ownerName + $scope.emailPostfix;
AppService.create($scope.app).then(function (result) { AppService.create($scope.app).then(function (result) {
toastr.success('添加成功!'); toastr.success('添加成功!');
......
...@@ -66,6 +66,17 @@ application_module.controller("ConfigNamespaceController", ...@@ -66,6 +66,17 @@ application_module.controller("ConfigNamespaceController",
}); });
}; };
PermissionService.get_app_role_users($rootScope.pageContext.appId)
.then(function (result) {
var masterUsers = '';
result.masterUsers.forEach(function (user) {
masterUsers += user.userId + ',';
});
$scope.masterUsers = masterUsers.substring(0, masterUsers.length - 1);
}, function (result) {
});
$scope.switchView = function (namespace, viewType) { $scope.switchView = function (namespace, viewType) {
if (namespace_view_type.TEXT == viewType) { if (namespace_view_type.TEXT == viewType) {
namespace.text = parseModel2Text(namespace); namespace.text = parseModel2Text(namespace);
......
role_module.controller('AppRoleController', ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'PermissionService', role_module.controller('AppRoleController',
['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'PermissionService',
function ($scope, $location, $window, toastr, AppService, AppUtil, PermissionService) { function ($scope, $location, $window, toastr, AppService, AppUtil, PermissionService) {
var params = AppUtil.parseParams($location.$$url); var params = AppUtil.parseParams($location.$$url);
...@@ -13,7 +14,6 @@ role_module.controller('AppRoleController', ['$scope', '$location', '$window', ' ...@@ -13,7 +14,6 @@ role_module.controller('AppRoleController', ['$scope', '$location', '$window', '
}); });
PermissionService.get_app_role_users($scope.pageContext.appId) PermissionService.get_app_role_users($scope.pageContext.appId)
.then(function (result) { .then(function (result) {
$scope.appRoleUsers = result; $scope.appRoleUsers = result;
...@@ -28,30 +28,35 @@ role_module.controller('AppRoleController', ['$scope', '$location', '$window', ' ...@@ -28,30 +28,35 @@ role_module.controller('AppRoleController', ['$scope', '$location', '$window', '
$scope.toAssignMasterRoleUser) $scope.toAssignMasterRoleUser)
.then(function (result) { .then(function (result) {
toastr.success("添加成功"); toastr.success("添加成功");
reloadPage(); $scope.appRoleUsers.masterUsers.push({userId: $scope.toAssignMasterRoleUser});
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "添加失败"); toastr.error(AppUtil.errorMsg(result), "添加失败");
}); });
}; };
$scope.removeMasterRoleFromUser = function (user) { $scope.removeMasterRoleFromUser = function (user) {
if ($scope.appRoleUsers.masterUsers.length <= 1){ if ($scope.appRoleUsers.masterUsers.length <= 1) {
$('#warning').modal('show'); $('#warning').modal('show');
return; return;
} }
PermissionService.remove_master_role($scope.pageContext.appId, user) PermissionService.remove_master_role($scope.pageContext.appId, user)
.then(function (result) { .then(function (result) {
toastr.success("删除成功"); toastr.success("删除成功");
reloadPage(); removeUserFromList($scope.appRoleUsers.masterUsers, user);
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "删除失败"); toastr.error(AppUtil.errorMsg(result), "删除失败");
}); });
}; };
function reloadPage() { function removeUserFromList(list, user) {
setInterval(function () { var index = 0;
location.reload(true); for (var i = 0; i < list.length; i++) {
}, 1000); if (list[i].userId == user) {
index = i;
break;
}
} }
list.splice(index, 1);
}
}]); }]);
role_module.controller('NamespaceRoleController', ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'PermissionService', role_module.controller('NamespaceRoleController',
['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'PermissionService',
function ($scope, $location, $window, toastr, AppService, AppUtil, PermissionService) { function ($scope, $location, $window, toastr, AppService, AppUtil, PermissionService) {
var params = AppUtil.parseParams($location.$$url); var params = AppUtil.parseParams($location.$$url);
...@@ -32,7 +33,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind ...@@ -32,7 +33,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind
$scope.toAssignReleaseNamespaceRoleUser) $scope.toAssignReleaseNamespaceRoleUser)
.then(function (result) { .then(function (result) {
toastr.success("添加成功"); toastr.success("添加成功");
reloadPage(); $scope.rolesAssignedUsers.releaseRoleUsers.push({userId: $scope.toAssignReleaseNamespaceRoleUser});
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "添加失败"); toastr.error(AppUtil.errorMsg(result), "添加失败");
}); });
...@@ -42,7 +43,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind ...@@ -42,7 +43,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind
$scope.toAssignModifyNamespaceRoleUser) $scope.toAssignModifyNamespaceRoleUser)
.then(function (result) { .then(function (result) {
toastr.success("添加成功"); toastr.success("添加成功");
reloadPage(); $scope.rolesAssignedUsers.modifyRoleUsers.push({userId: $scope.toAssignModifyNamespaceRoleUser});
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "添加失败"); toastr.error(AppUtil.errorMsg(result), "添加失败");
}); });
...@@ -56,7 +57,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind ...@@ -56,7 +57,7 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind
user) user)
.then(function (result) { .then(function (result) {
toastr.success("删除成功"); toastr.success("删除成功");
reloadPage(); removeUserFromList($scope.rolesAssignedUsers.releaseRoleUsers, user);
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "删除失败"); toastr.error(AppUtil.errorMsg(result), "删除失败");
}); });
...@@ -66,17 +67,22 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind ...@@ -66,17 +67,22 @@ role_module.controller('NamespaceRoleController', ['$scope', '$location', '$wind
user) user)
.then(function (result) { .then(function (result) {
toastr.success("删除成功"); toastr.success("删除成功");
reloadPage(); removeUserFromList($scope.rolesAssignedUsers.modifyRoleUsers, user);
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "删除失败"); toastr.error(AppUtil.errorMsg(result), "删除失败");
}); });
} }
}; };
function reloadPage() { function removeUserFromList(list, user) {
setInterval(function () { var index = 0;
location.reload(true); for (var i = 0; i < list.length; i++) {
}, 1000); if (list[i].userId == user) {
index = i;
break;
}
} }
list.splice(index, 1);
}
}]); }]);
...@@ -127,7 +127,6 @@ table th { ...@@ -127,7 +127,6 @@ table th {
.apps .apps-description { .apps .apps-description {
color: gray; color: gray;
font-family: "Apple Color Emoji";
font-size: 16px; font-size: 16px;
} }
......
...@@ -61,7 +61,7 @@ public class ServiceExceptionTest extends AbstractPortalTest { ...@@ -61,7 +61,7 @@ public class ServiceExceptionTest extends AbstractPortalTest {
new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "admin server error", new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "admin server error",
new Gson().toJson(errorAttributes).getBytes(), Charset.defaultCharset()); new Gson().toJson(errorAttributes).getBytes(), Charset.defaultCharset());
when(appService.createOrUpdateAppInLocal(any(App.class))).thenThrow(adminException); when(appService.create(any(App.class))).thenThrow(adminException);
App app = generateSampleApp(); App app = generateSampleApp();
try { try {
......
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