Search in sources :

Example 1 with Auth

use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.

the class TeamController method updateRole.

/**
 * Updates role of a team member.
 * Needs role master.
 *
 * @param teamId
 * @param id
 * @param roleValue
 * @return
 * @throws ShepherException
 */
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/role", method = RequestMethod.POST)
public String updateRole(@PathVariable("team") long teamId, @RequestParam("id") long id, @RequestParam("role") int roleValue) throws ShepherException {
    Role role = Role.get(roleValue);
    if (role == null) {
        throw ShepherException.createNoSuchRoleException();
    }
    teamService.updateRole(id, role);
    return "redirect:/teams/" + teamId + "/manage";
}
Also used : Role(com.xiaomi.shepher.common.Role) Auth(com.xiaomi.shepher.common.Auth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Auth

use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.

the class TeamController method agree.

/**
 * Agrees a user to join a team.
 * Needs role master.
 *
 * @param teamId
 * @param id
 * @return
 * @throws ShepherException
 */
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/agree", method = RequestMethod.POST)
public String agree(@PathVariable("team") long teamId, @RequestParam("id") long id) throws ShepherException {
    User user = userHolder.getUser();
    teamService.agreeJoin(user, id, teamId);
    return "redirect:/teams/" + teamId + "/manage";
}
Also used : User(com.xiaomi.shepher.model.User) Auth(com.xiaomi.shepher.common.Auth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Auth

use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.

the class TeamController method addMember.

/**
 * Adds a user to a team.
 * Needs role master.
 *
 * @param teamId
 * @param userName
 * @param roleValue
 * @return
 * @throws ShepherException
 */
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/members/add", method = RequestMethod.POST)
public String addMember(@PathVariable("team") long teamId, @RequestParam("user") String userName, @RequestParam("role") int roleValue) throws ShepherException {
    User member = userService.get(userName);
    User user = userHolder.getUser();
    Role role = Role.get(roleValue);
    if (member == null) {
        throw ShepherException.createNoSuchUserException();
    } else if (role == null) {
        throw ShepherException.createNoSuchRoleException();
    }
    teamService.addMember(member, teamId, role, user);
    return "redirect:/teams/" + teamId + "/manage";
}
Also used : Role(com.xiaomi.shepher.common.Role) User(com.xiaomi.shepher.model.User) Auth(com.xiaomi.shepher.common.Auth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Auth

use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.

the class AuthorizationInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Auth annotation = getAnnotation(handlerMethod);
        if (annotation != null && !authStrategy.validate(request, annotation.value())) {
            throw ShepherException.createNoAuthorizationException();
        }
    }
    return true;
}
Also used : Auth(com.xiaomi.shepher.common.Auth) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 5 with Auth

use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.

the class TeamController method refuse.

/**
 * Refuses a user to join a team.
 * Needs role master.
 *
 * @param teamId
 * @param id
 * @return
 * @throws ShepherException
 */
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/refuse", method = RequestMethod.POST)
public String refuse(@PathVariable("team") long teamId, @RequestParam("id") long id) throws ShepherException {
    User user = userHolder.getUser();
    teamService.refuseJoin(user, id, teamId);
    return "redirect:/teams/" + teamId + "/manage";
}
Also used : User(com.xiaomi.shepher.model.User) Auth(com.xiaomi.shepher.common.Auth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Auth (com.xiaomi.shepher.common.Auth)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 User (com.xiaomi.shepher.model.User)6 Role (com.xiaomi.shepher.common.Role)3 PermissionTeam (com.xiaomi.shepher.model.PermissionTeam)1 Team (com.xiaomi.shepher.model.Team)1 UserTeam (com.xiaomi.shepher.model.UserTeam)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1