Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
b80ac465
Commit
b80ac465
authored
Oct 03, 2018
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize my-projects view to show projets which the user has admin permissions
parent
e8b82d13
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
5 deletions
+78
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+14
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppRepository.java
...rip/framework/apollo/portal/repository/AppRepository.java
+2
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
...com/ctrip/framework/apollo/portal/service/AppService.java
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
...ramework/apollo/portal/service/RolePermissionService.java
+6
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
.../portal/spi/defaultimpl/DefaultRolePermissionService.java
+19
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
...ava/com/ctrip/framework/apollo/portal/util/RoleUtils.java
+16
-2
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java
...com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java
+17
-0
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
View file @
b80ac465
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.controller;
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.controller;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
com.ctrip.framework.apollo.portal.service.RoleInitializationService
;
import
com.ctrip.framework.apollo.portal.service.RoleInitializationService
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.entity.App
;
...
@@ -71,7 +72,19 @@ public class AppController {
...
@@ -71,7 +72,19 @@ public class AppController {
@RequestMapping
(
value
=
"/by-owner"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/by-owner"
,
method
=
RequestMethod
.
GET
)
public
List
<
App
>
findAppsByOwner
(
@RequestParam
(
"owner"
)
String
owner
,
Pageable
page
)
{
public
List
<
App
>
findAppsByOwner
(
@RequestParam
(
"owner"
)
String
owner
,
Pageable
page
)
{
return
appService
.
findByOwnerName
(
owner
,
page
);
Set
<
String
>
appIds
=
Sets
.
newHashSet
();
List
<
Role
>
userRoles
=
rolePermissionService
.
findUserRoles
(
owner
);
for
(
Role
role
:
userRoles
)
{
String
appId
=
RoleUtils
.
extractAppIdFromMasterRoleName
(
role
.
getRoleName
());
if
(
appId
!=
null
)
{
appIds
.
add
(
appId
);
}
}
return
appService
.
findByAppIds
(
appIds
,
page
);
}
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppRepository.java
View file @
b80ac465
...
@@ -19,6 +19,8 @@ public interface AppRepository extends PagingAndSortingRepository<App, Long> {
...
@@ -19,6 +19,8 @@ public interface AppRepository extends PagingAndSortingRepository<App, Long> {
List
<
App
>
findByAppIdIn
(
Set
<
String
>
appIds
);
List
<
App
>
findByAppIdIn
(
Set
<
String
>
appIds
);
List
<
App
>
findByAppIdIn
(
Set
<
String
>
appIds
,
Pageable
pageable
);
@Modifying
@Modifying
@Query
(
"UPDATE App SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1"
)
@Query
(
"UPDATE App SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1"
)
int
deleteApp
(
String
appId
,
String
operator
);
int
deleteApp
(
String
appId
,
String
operator
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
View file @
b80ac465
...
@@ -60,6 +60,10 @@ public class AppService {
...
@@ -60,6 +60,10 @@ public class AppService {
return
appRepository
.
findByAppIdIn
(
appIds
);
return
appRepository
.
findByAppIdIn
(
appIds
);
}
}
public
List
<
App
>
findByAppIds
(
Set
<
String
>
appIds
,
Pageable
pageable
)
{
return
appRepository
.
findByAppIdIn
(
appIds
,
pageable
);
}
public
List
<
App
>
findByOwnerName
(
String
ownerName
,
Pageable
page
)
{
public
List
<
App
>
findByOwnerName
(
String
ownerName
,
Pageable
page
)
{
return
appRepository
.
findByOwnerName
(
ownerName
,
page
);
return
appRepository
.
findByOwnerName
(
ownerName
,
page
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
View file @
b80ac465
...
@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
...
@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
...
@@ -44,6 +45,11 @@ public interface RolePermissionService {
...
@@ -44,6 +45,11 @@ public interface RolePermissionService {
*/
*/
public
boolean
userHasPermission
(
String
userId
,
String
permissionType
,
String
targetId
);
public
boolean
userHasPermission
(
String
userId
,
String
permissionType
,
String
targetId
);
/**
* Find the user's roles
*/
public
List
<
Role
>
findUserRoles
(
String
userId
);
public
boolean
isSuperAdmin
(
String
userId
);
public
boolean
isSuperAdmin
(
String
userId
);
/**
/**
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
View file @
b80ac465
...
@@ -15,14 +15,19 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService;
...
@@ -15,14 +15,19 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
/**
/**
* Created by timothy on 2017/4/26.
* Created by timothy on 2017/4/26.
*/
*/
...
@@ -180,6 +185,18 @@ public class DefaultRolePermissionService implements RolePermissionService {
...
@@ -180,6 +185,18 @@ public class DefaultRolePermissionService implements RolePermissionService {
return
false
;
return
false
;
}
}
@Override
public
List
<
Role
>
findUserRoles
(
String
userId
)
{
List
<
UserRole
>
userRoles
=
userRoleRepository
.
findByUserId
(
userId
);
if
(
CollectionUtils
.
isEmpty
(
userRoles
))
{
return
Collections
.
emptyList
();
}
Set
<
Long
>
roleIds
=
userRoles
.
stream
().
map
(
UserRole:
:
getRoleId
).
collect
(
Collectors
.
toSet
());
return
Lists
.
newLinkedList
(
roleRepository
.
findAllById
(
roleIds
));
}
public
boolean
isSuperAdmin
(
String
userId
)
{
public
boolean
isSuperAdmin
(
String
userId
)
{
return
portalConfig
.
superAdmins
().
contains
(
userId
);
return
portalConfig
.
superAdmins
().
contains
(
userId
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
View file @
b80ac465
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
;
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
;
import
com.google.common.base.Joiner
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.portal.constant.RoleType
;
import
com.ctrip.framework.apollo.portal.constant.RoleType
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Splitter
;
import
java.util.Iterator
;
public
class
RoleUtils
{
public
class
RoleUtils
{
private
static
final
Joiner
STRING_JOINER
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
).
skipNulls
();
private
static
final
Joiner
STRING_JOINER
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
).
skipNulls
();
private
static
final
Splitter
STRING_SPLITTER
=
Splitter
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
omitEmptyStrings
().
trimResults
();
public
static
String
buildAppMasterRoleName
(
String
appId
)
{
public
static
String
buildAppMasterRoleName
(
String
appId
)
{
return
STRING_JOINER
.
join
(
RoleType
.
MASTER
,
appId
);
return
STRING_JOINER
.
join
(
RoleType
.
MASTER
,
appId
);
}
}
public
static
String
extractAppIdFromMasterRoleName
(
String
masterRoleName
)
{
Iterator
<
String
>
parts
=
STRING_SPLITTER
.
split
(
masterRoleName
).
iterator
();
// skip role type
if
(
parts
.
hasNext
()
&&
parts
.
next
().
equals
(
RoleType
.
MASTER
)
&&
parts
.
hasNext
())
{
return
parts
.
next
();
}
return
null
;
}
public
static
String
buildAppRoleName
(
String
appId
,
String
roleType
)
{
public
static
String
buildAppRoleName
(
String
appId
,
String
roleType
)
{
return
STRING_JOINER
.
join
(
roleType
,
appId
);
return
STRING_JOINER
.
join
(
roleType
,
appId
);
}
}
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java
0 → 100644
View file @
b80ac465
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
public
class
RoleUtilsTest
{
@Test
public
void
testExtractAppIdFromMasterRoleName
()
throws
Exception
{
assertEquals
(
"someApp"
,
RoleUtils
.
extractAppIdFromMasterRoleName
(
"Master+someApp"
));
assertEquals
(
"someApp"
,
RoleUtils
.
extractAppIdFromMasterRoleName
(
"Master+someApp+xx"
));
assertNull
(
RoleUtils
.
extractAppIdFromMasterRoleName
(
"ReleaseNamespace+app1+application"
));
}
}
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