use of com.xiaomi.shepher.model.PermissionTeam in project shepher by XiaoMi.
the class TeamController method permission.
/**
* Lists permission of the team.
*
* @param teamId
* @param model
* @return
* @throws ShepherException
*/
@RequestMapping(value = "/{team}/permission", method = RequestMethod.GET)
public String permission(@PathVariable("team") long teamId, Model model) throws ShepherException {
User user = userHolder.getUser();
Team team = teamService.get(teamId);
List<PermissionTeam> authorizedPermissions = permissionService.listPermissionTeamsByTeam(teamId, Status.AGREE);
List<PermissionTeam> pendingPermissions = permissionService.listPermissionTeamsByTeam(teamId, Status.PENDING);
boolean isMaster = teamService.isMaster(user.getId(), teamId) || teamService.isOwner(user.getId(), teamId);
model.addAttribute("user", user);
model.addAttribute("currentTeam", team);
model.addAttribute("authorizedPermissions", authorizedPermissions);
model.addAttribute("pendingPermissions", pendingPermissions);
model.addAttribute("isMaster", isMaster);
return "/team/permission";
}
use of com.xiaomi.shepher.model.PermissionTeam in project shepher by XiaoMi.
the class TeamBiz method listTeamsByPathAndUser.
public List<Team> listTeamsByPathAndUser(long userId, String cluster, String path, boolean joined) {
List<String> parentPaths = ParentPathParser.parse(path);
List<PermissionTeam> permissionTeams = Collections.emptyList();
if (parentPaths != null && !parentPaths.isEmpty()) {
permissionTeams = permissionTeamMapper.listByPaths(cluster, parentPaths, Status.AGREE.getValue());
}
List<UserTeam> userTeams = userTeamMapper.listByUser(userId, Status.AGREE.getValue());
Set<Long> teamIds = this.parseTeamIdsFromUserTeams(userTeams);
List<Team> results = new ArrayList<>();
for (PermissionTeam permissionTeam : permissionTeams) {
if (joined == teamIds.contains(permissionTeam.getTeamId())) {
Team team = new Team();
team.setId(permissionTeam.getTeamId());
team.setName(permissionTeam.getTeamName());
results.add(team);
}
}
return results;
}
use of com.xiaomi.shepher.model.PermissionTeam in project shepher by XiaoMi.
the class PermissionTeamMapperTest method testGetByTeamIdAndNode.
@Test
public void testGetByTeamIdAndNode() {
int status = Status.AGREE.getValue();
int teamId = 5;
String cluster = "local_test";
String path = "/test/sub1";
int expectedId = 2;
PermissionTeam permissionTeam = permissionTeamMapper.get(teamId, cluster, path, status);
Assert.assertEquals(expectedId, permissionTeam.getId());
}
use of com.xiaomi.shepher.model.PermissionTeam in project shepher by XiaoMi.
the class PermissionTeamBiz method create.
public PermissionTeam create(long permissionId, long teamId, Status status) throws ShepherException {
if (status == null) {
throw ShepherException.createIllegalParameterException();
}
PermissionTeam permissionTeam = new PermissionTeam(permissionId, teamId, status.getValue());
int count;
try {
count = permissionTeamMapper.create(permissionTeam);
} catch (DuplicateKeyException e) {
throw ShepherException.createDuplicateKeyException();
} catch (Exception e) {
throw ShepherException.createDBCreateErrorException();
}
DaoValidator.checkSqlReturn(count, ShepherConstants.DB_OPERATE_CREATE);
return permissionTeam;
}
use of com.xiaomi.shepher.model.PermissionTeam in project shepher by XiaoMi.
the class PermissionServiceTest method testAddForPermissionIdTeamIdStatus.
/**
* Method: add(long permissionId, long teamId, Status status)
*/
@Test
public void testAddForPermissionIdTeamIdStatus() throws Exception {
long permissionId = 3;
long teamId = 5;
Status status = Status.AGREE;
PermissionTeam permissionTeam = permissionService.add(permissionId, teamId, status);
Assert.assertNotNull(permissionTeam);
Assert.assertEquals(4, permissionTeam.getId());
}
Aggregations