Commit 5359d441 by Jason Song Committed by GitHub

Merge pull request #280 from lepdou/0620_27

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