Search in sources :

Example 1 with PermissionTeam

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";
}
Also used : PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) User(com.xiaomi.shepher.model.User) Team(com.xiaomi.shepher.model.Team) PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) UserTeam(com.xiaomi.shepher.model.UserTeam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PermissionTeam

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;
}
Also used : UserTeam(com.xiaomi.shepher.model.UserTeam) PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) ArrayList(java.util.ArrayList) PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) Team(com.xiaomi.shepher.model.Team) UserTeam(com.xiaomi.shepher.model.UserTeam)

Example 3 with PermissionTeam

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());
}
Also used : PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) BaseTest(com.xiaomi.shepher.BaseTest) Test(org.junit.Test)

Example 4 with PermissionTeam

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;
}
Also used : PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) ShepherException(com.xiaomi.shepher.exception.ShepherException)

Example 5 with 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());
}
Also used : Status(com.xiaomi.shepher.common.Status) PermissionTeam(com.xiaomi.shepher.model.PermissionTeam) BaseTest(com.xiaomi.shepher.BaseTest) Test(org.junit.Test)

Aggregations

PermissionTeam (com.xiaomi.shepher.model.PermissionTeam)6 BaseTest (com.xiaomi.shepher.BaseTest)3 Test (org.junit.Test)3 Team (com.xiaomi.shepher.model.Team)2 UserTeam (com.xiaomi.shepher.model.UserTeam)2 Status (com.xiaomi.shepher.common.Status)1 ShepherException (com.xiaomi.shepher.exception.ShepherException)1 User (com.xiaomi.shepher.model.User)1 ArrayList (java.util.ArrayList)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1