Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
f763525b
Commit
f763525b
authored
Jun 28, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
已授权校验 & 创建app 用户模糊搜索
parent
a474d5ca
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
21 deletions
+42
-21
AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+10
-1
PermissionController.java
...mework/apollo/portal/controller/PermissionController.java
+9
-2
app.html
apollo-portal/src/main/resources/static/app.html
+1
-4
role.html
apollo-portal/src/main/resources/static/namespace/role.html
+2
-2
AppController.js
...main/resources/static/scripts/controller/AppController.js
+9
-2
AppRoleController.js
...urces/static/scripts/controller/role/AppRoleController.js
+1
-0
NamespaceRoleController.js
...static/scripts/controller/role/NamespaceRoleController.js
+6
-6
ServiceExceptionTest.java
...m/ctrip/framework/apollo/portal/ServiceExceptionTest.java
+4
-4
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
View file @
f763525b
...
@@ -8,9 +8,11 @@ import com.ctrip.framework.apollo.common.utils.InputValidator;
...
@@ -8,9 +8,11 @@ import com.ctrip.framework.apollo.common.utils.InputValidator;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
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.listener.AppCreationEvent
;
import
com.ctrip.framework.apollo.portal.service.AppService
;
import
com.ctrip.framework.apollo.portal.service.AppService
;
import
com.ctrip.framework.apollo.portal.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisher
;
...
@@ -40,6 +42,8 @@ public class AppController {
...
@@ -40,6 +42,8 @@ public class AppController {
@Autowired
@Autowired
private
ApplicationEventPublisher
publisher
;
private
ApplicationEventPublisher
publisher
;
@Autowired
private
UserService
userService
;
@RequestMapping
(
""
)
@RequestMapping
(
""
)
public
List
<
App
>
findAllApp
()
{
public
List
<
App
>
findAllApp
()
{
...
@@ -71,12 +75,17 @@ public class AppController {
...
@@ -71,12 +75,17 @@ public class AppController {
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@RequestBody
App
app
)
{
public
ResponseEntity
<
Void
>
create
(
@RequestBody
App
app
)
{
checkArgument
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwner
Email
(),
app
.
getOwner
Name
(),
checkArgument
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerName
(),
app
.
getOrgId
(),
app
.
getOrgName
());
app
.
getOrgId
(),
app
.
getOrgName
());
if
(!
InputValidator
.
isValidClusterNamespace
(
app
.
getAppId
()))
{
if
(!
InputValidator
.
isValidClusterNamespace
(
app
.
getAppId
()))
{
throw
new
BadRequestException
(
String
.
format
(
"AppId格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
throw
new
BadRequestException
(
String
.
format
(
"AppId格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
}
}
UserInfo
userInfo
=
userService
.
findByUserId
(
app
.
getOwnerName
());
if
(
userInfo
==
null
){
throw
new
BadRequestException
(
"应用负责人不存在"
);
}
app
.
setOwnerEmail
(
userInfo
.
getEmail
());
appService
.
enrichUserInfo
(
app
);
appService
.
enrichUserInfo
(
app
);
App
createdApp
=
appService
.
create
(
app
);
App
createdApp
=
appService
.
create
(
app
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java
View file @
f763525b
...
@@ -16,6 +16,7 @@ import com.ctrip.framework.apollo.portal.util.RoleUtils;
...
@@ -16,6 +16,7 @@ import com.ctrip.framework.apollo.portal.util.RoleUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -89,8 +90,11 @@ public class PermissionController {
...
@@ -89,8 +90,11 @@ public class PermissionController {
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
throw
new
BadRequestException
(
"role type is illegal"
);
throw
new
BadRequestException
(
"role type is illegal"
);
}
}
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
roleType
),
Set
<
String
>
assignedUser
=
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUser
)){
throw
new
BadRequestException
(
user
+
"已授权"
);
}
return
ResponseEntity
.
ok
().
build
();
return
ResponseEntity
.
ok
().
build
();
}
}
...
@@ -130,8 +134,11 @@ public class PermissionController {
...
@@ -130,8 +134,11 @@ public class PermissionController {
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
throw
new
BadRequestException
(
"role type is illegal"
);
throw
new
BadRequestException
(
"role type is illegal"
);
}
}
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppRoleName
(
appId
,
roleType
),
Set
<
String
>
assignedUsers
=
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppRoleName
(
appId
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUsers
)){
throw
new
BadRequestException
(
user
+
"已授权"
);
}
return
ResponseEntity
.
ok
().
build
();
return
ResponseEntity
.
ok
().
build
();
}
}
...
...
apollo-portal/src/main/resources/static/app.html
View file @
f763525b
...
@@ -48,10 +48,7 @@
...
@@ -48,10 +48,7 @@
<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-6"
>
<div
class=
"col-sm-6"
>
<div
class=
"input-group"
>
<apollouserselector
apollo-id=
"userSelectWidgetId"
></apollouserselector>
<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>
<small>
(负责人具有项目管理的最高权限,比如分配配置的修改权,发布权等)
</small>
</div>
</div>
</div>
</div>
...
...
apollo-portal/src/main/resources/static/namespace/role.html
View file @
f763525b
...
@@ -73,8 +73,8 @@
...
@@ -73,8 +73,8 @@
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
>
添加
</button>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
>
添加
</button>
</form>
</form>
<!-- Split button -->
<!-- Split button -->
<div
style=
"margin-top: 15px;
"
>
<div
class=
"user-container
"
>
<div
class=
"btn-group"
ng-repeat=
"user in rolesAssignedUsers.releaseRoleUsers"
>
<div
class=
"btn-group
user-info
"
ng-repeat=
"user in rolesAssignedUsers.releaseRoleUsers"
>
<button
type=
"button"
class=
"btn btn-default"
ng-bind=
"user.userId"
></button>
<button
type=
"button"
class=
"btn btn-default"
ng-bind=
"user.userId"
></button>
<button
type=
"button"
class=
"btn btn-default dropdown-toggle"
data-toggle=
"dropdown"
<button
type=
"button"
class=
"btn btn-default dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
ng-click=
"removeUserRole('ReleaseNamespace', user.userId)"
>
aria-haspopup=
"true"
aria-expanded=
"false"
ng-click=
"removeUserRole('ReleaseNamespace', user.userId)"
>
...
...
apollo-portal/src/main/resources/static/scripts/controller/AppController.js
View file @
f763525b
...
@@ -26,7 +26,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
...
@@ -26,7 +26,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
});
});
$scope
.
emailPostfix
=
"@ctrip.com
"
;
$scope
.
userSelectWidgetId
=
"userSelectWidgetId
"
;
$scope
.
create
=
function
()
{
$scope
.
create
=
function
()
{
var
selectedOrg
=
$
(
'#organization'
).
select2
(
'data'
)[
0
];
var
selectedOrg
=
$
(
'#organization'
).
select2
(
'data'
)[
0
];
...
@@ -38,7 +38,14 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
...
@@ -38,7 +38,14 @@ 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
;
// ownerName
var
user
=
$
(
'.'
+
$scope
.
userSelectWidgetId
).
select2
(
'data'
)[
0
];
if
(
!
user
){
toastr
.
warning
(
"请输入应用负责人"
);
return
;
}
$scope
.
app
.
ownerName
=
user
.
id
;
AppService
.
create
(
$scope
.
app
).
then
(
function
(
result
)
{
AppService
.
create
(
$scope
.
app
).
then
(
function
(
result
)
{
toastr
.
success
(
'添加成功!'
);
toastr
.
success
(
'添加成功!'
);
...
...
apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js
View file @
f763525b
...
@@ -36,6 +36,7 @@ role_module.controller('AppRoleController',
...
@@ -36,6 +36,7 @@ role_module.controller('AppRoleController',
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
toastr
.
success
(
"添加成功"
);
toastr
.
success
(
"添加成功"
);
$scope
.
appRoleUsers
.
masterUsers
.
push
({
userId
:
toAssignMasterRoleUser
});
$scope
.
appRoleUsers
.
masterUsers
.
push
({
userId
:
toAssignMasterRoleUser
});
$
(
'.'
+
$scope
.
userSelectWidgetId
).
select2
(
"val"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
});
});
...
...
apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js
View file @
f763525b
...
@@ -9,7 +9,7 @@ role_module.controller('NamespaceRoleController',
...
@@ -9,7 +9,7 @@ role_module.controller('NamespaceRoleController',
appId
:
params
.
appid
,
appId
:
params
.
appid
,
namespaceName
:
params
.
namespaceName
namespaceName
:
params
.
namespaceName
};
};
$scope
.
releaseRoleWidgetId
=
'releaseRoleWidgetId'
;
$scope
.
releaseRoleWidgetId
=
'releaseRoleWidgetId'
;
$scope
.
modifyRoleWidgetId
=
'modifyRoleWidgetId'
;
$scope
.
modifyRoleWidgetId
=
'modifyRoleWidgetId'
;
...
@@ -24,16 +24,14 @@ role_module.controller('NamespaceRoleController',
...
@@ -24,16 +24,14 @@ role_module.controller('NamespaceRoleController',
$scope
.
pageContext
.
namespaceName
)
$scope
.
pageContext
.
namespaceName
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
$scope
.
rolesAssignedUsers
=
result
;
$scope
.
rolesAssignedUsers
=
result
;
console
.
log
(
result
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"加载授权用户出错"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"加载授权用户出错"
);
});
});
$scope
.
assignRoleToUser
=
function
(
roleType
)
{
$scope
.
assignRoleToUser
=
function
(
roleType
)
{
if
(
'ReleaseNamespace'
==
roleType
)
{
if
(
'ReleaseNamespace'
==
roleType
)
{
var
user
=
$
(
'.'
+
$scope
.
releaseRoleWidgetId
).
select2
(
'data'
)[
0
];
var
user
=
$
(
'.'
+
$scope
.
releaseRoleWidgetId
).
select2
(
'data'
)[
0
];
if
(
!
user
){
if
(
!
user
)
{
toastr
.
warning
(
"请选择用户"
);
toastr
.
warning
(
"请选择用户"
);
return
;
return
;
}
}
...
@@ -45,12 +43,13 @@ role_module.controller('NamespaceRoleController',
...
@@ -45,12 +43,13 @@ role_module.controller('NamespaceRoleController',
toastr
.
success
(
"添加成功"
);
toastr
.
success
(
"添加成功"
);
$scope
.
rolesAssignedUsers
.
releaseRoleUsers
.
push
(
$scope
.
rolesAssignedUsers
.
releaseRoleUsers
.
push
(
{
userId
:
toAssignReleaseNamespaceRoleUser
});
{
userId
:
toAssignReleaseNamespaceRoleUser
});
$
(
'.'
+
$scope
.
releaseRoleWidgetId
).
select2
(
"val"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
});
});
}
else
{
}
else
{
var
user
=
$
(
'.'
+
$scope
.
modifyRoleWidgetId
).
select2
(
'data'
)[
0
];
var
user
=
$
(
'.'
+
$scope
.
modifyRoleWidgetId
).
select2
(
'data'
)[
0
];
if
(
!
user
){
if
(
!
user
)
{
toastr
.
warning
(
"请选择用户"
);
toastr
.
warning
(
"请选择用户"
);
return
;
return
;
}
}
...
@@ -62,6 +61,7 @@ role_module.controller('NamespaceRoleController',
...
@@ -62,6 +61,7 @@ role_module.controller('NamespaceRoleController',
toastr
.
success
(
"添加成功"
);
toastr
.
success
(
"添加成功"
);
$scope
.
rolesAssignedUsers
.
modifyRoleUsers
.
push
(
$scope
.
rolesAssignedUsers
.
modifyRoleUsers
.
push
(
{
userId
:
toAssignModifyNamespaceRoleUser
});
{
userId
:
toAssignModifyNamespaceRoleUser
});
$
(
'.'
+
$scope
.
modifyRoleWidgetId
).
select2
(
"val"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"添加失败"
);
});
});
...
@@ -102,5 +102,5 @@ role_module.controller('NamespaceRoleController',
...
@@ -102,5 +102,5 @@ role_module.controller('NamespaceRoleController',
}
}
list
.
splice
(
index
,
1
);
list
.
splice
(
index
,
1
);
}
}
}]);
}]);
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/ServiceExceptionTest.java
View file @
f763525b
...
@@ -26,7 +26,7 @@ import com.ctrip.framework.apollo.common.utils.ExceptionUtils;
...
@@ -26,7 +26,7 @@ import com.ctrip.framework.apollo.common.utils.ExceptionUtils;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.portal.controller.AppController
;
import
com.ctrip.framework.apollo.portal.controller.AppController
;
import
com.ctrip.framework.apollo.portal.service.
App
Service
;
import
com.ctrip.framework.apollo.portal.service.
User
Service
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
...
@@ -35,12 +35,12 @@ public class ServiceExceptionTest extends AbstractPortalTest {
...
@@ -35,12 +35,12 @@ public class ServiceExceptionTest extends AbstractPortalTest {
@Autowired
@Autowired
private
AppController
appController
;
private
AppController
appController
;
@Mock
@Mock
private
AppService
app
Service
;
private
UserService
user
Service
;
@Before
@Before
public
void
setUp
()
{
public
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
ReflectionTestUtils
.
setField
(
appController
,
"
appService"
,
app
Service
);
ReflectionTestUtils
.
setField
(
appController
,
"
userService"
,
user
Service
);
}
}
private
String
getBaseAppUrl
()
{
private
String
getBaseAppUrl
()
{
...
@@ -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
.
create
(
any
(
App
.
class
))).
thenThrow
(
adminException
);
when
(
userService
.
findByUserId
(
any
(
String
.
class
))).
thenThrow
(
adminException
);
App
app
=
generateSampleApp
();
App
app
=
generateSampleApp
();
try
{
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment