Search in sources :

Example 16 with User

use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.

the class TeamController method getMembers.

@GetMapping("team-members")
public List<Object[]> getMembers(@IdParam(name = "team") ID teamId) {
    Team team = Application.getUserStore().getTeam(teamId);
    List<Object[]> members = new ArrayList<>();
    for (Principal p : team.getMembers()) {
        User user = (User) p;
        members.add(new Object[] { user.getId(), user.getFullName(), user.getOwningDept() != null ? user.getOwningDept().getName() : null });
    }
    return members;
}
Also used : User(com.rebuild.core.privileges.bizz.User) ArrayList(java.util.ArrayList) Team(cn.devezhao.bizz.security.member.Team) Principal(java.security.Principal) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 17 with User

use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.

the class UserController method checkUserStatus.

@RequestMapping("check-user-status")
public RespBody checkUserStatus(@IdParam ID userId) {
    if (!Application.getUserStore().existsUser(userId)) {
        return RespBody.error();
    }
    User checkedUser = Application.getUserStore().getUser(userId);
    Map<String, Object> ret = new HashMap<>();
    ret.put("active", checkedUser.isActive());
    ret.put("system", "system".equals(checkedUser.getName()) || "admin".equals(checkedUser.getName()));
    ret.put("disabled", checkedUser.isDisabled());
    if (checkedUser.getOwningRole() != null) {
        ret.put("role", checkedUser.getOwningRole().getIdentity());
        ret.put("roleDisabled", checkedUser.getOwningRole().isDisabled());
        // 附加角色
        ret.put("roleAppends", UserHelper.getRoleAppends(userId));
    }
    if (checkedUser.getOwningDept() != null) {
        ret.put("dept", checkedUser.getOwningDept().getIdentity());
        ret.put("deptDisabled", checkedUser.getOwningDept().isDisabled());
    }
    return RespBody.ok(ret);
}
Also used : User(com.rebuild.core.privileges.bizz.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject)

Example 18 with User

use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.

the class UserController method enableUser.

@PostMapping("enable-user")
public RespBody enableUser(@RequestBody JSONObject data) {
    final ID userId = ID.valueOf(data.getString("user"));
    User enUser = Application.getUserStore().getUser(userId);
    ID deptNew = null;
    ID roleNew = null;
    ID[] roleAppends = null;
    if (data.containsKey("dept")) {
        deptNew = ID.valueOf(data.getString("dept"));
        if (enUser.getOwningDept() != null && enUser.getOwningDept().getIdentity().equals(deptNew)) {
            deptNew = null;
        }
    }
    if (data.containsKey("role")) {
        roleNew = ID.valueOf(data.getString("role"));
        if (enUser.getOwningRole() != null && enUser.getOwningRole().getIdentity().equals(roleNew)) {
            roleNew = null;
        }
    }
    if (data.containsKey("roleAppends")) {
        String appends = data.getString("roleAppends");
        Set<ID> set = new HashSet<>();
        for (String s : appends.split(",")) {
            if (ID.isId(s))
                set.add(ID.valueOf(s));
        }
        if (roleNew != null) {
            set.remove(deptNew);
        } else if (enUser.getOwningRole() != null) {
            // noinspection SuspiciousMethodCalls
            set.remove(enUser.getOwningRole().getIdentity());
        }
        if (!set.isEmpty()) {
            roleAppends = set.toArray(new ID[0]);
        }
    }
    Boolean enableNew = null;
    if (data.containsKey("enable")) {
        enableNew = data.getBoolean("enable");
    }
    Application.getBean(UserService.class).updateEnableUser(userId, deptNew, roleNew, roleAppends, enableNew);
    // 禁用后马上销毁会话
    if (!enUser.isActive()) {
        HttpSession s = Application.getSessionStore().getSession(enUser.getId());
        if (s != null) {
            log.warn("FORCE DESTROY USER SESSION : {} < {}", enUser.getId(), s.getId());
            s.invalidate();
        }
    }
    return RespBody.ok();
}
Also used : User(com.rebuild.core.privileges.bizz.User) UserService(com.rebuild.core.privileges.UserService) HttpSession(javax.servlet.http.HttpSession) ID(cn.devezhao.persist4j.engine.ID) HashSet(java.util.HashSet)

Example 19 with User

use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.

the class UsersGetting method loadUsers.

@GetMapping("users")
public JSON loadUsers(HttpServletRequest request) {
    final String type = getParameter(request, "type", "User");
    final String query = getParameter(request, "q");
    Member[] members;
    if ("User".equalsIgnoreCase(type)) {
        members = Application.getUserStore().getAllUsers();
    } else if ("Department".equalsIgnoreCase(type)) {
        members = Application.getUserStore().getAllDepartments();
    } else if ("Role".equalsIgnoreCase(type)) {
        members = Application.getUserStore().getAllRoles();
    } else if ("Team".equalsIgnoreCase(type)) {
        members = Application.getUserStore().getAllTeams();
    } else {
        throw new InvalidParameterException("Unknown type of bizz entity : " + type);
    }
    // 排序
    members = UserHelper.sortMembers(members);
    JSONArray found = new JSONArray();
    // 全部用户
    if (getBoolParameter(request, "atall") && "User".equals(type) && StringUtils.isBlank(query) && Application.getPrivilegesManager().allow(getRequestUser(request), ZeroEntry.AllowAtAllUsers)) {
        found.add(JSONUtils.toJSONObject(new String[] { "id", "text" }, new Object[] { UserService.ALLUSERS, Language.L("所有人") }));
    }
    for (Member m : members) {
        if (m.isDisabled())
            continue;
        String name = m.getName();
        final User ifUser = m instanceof User ? (User) m : null;
        if (ifUser != null) {
            if (!ifUser.isActive())
                continue;
            name = ifUser.getFullName();
        }
        if (StringUtils.isBlank(query) || StringUtils.containsIgnoreCase(name, query) || (ifUser != null && StringUtils.containsIgnoreCase(ifUser.getName(), query)) || (ifUser != null && ifUser.getEmail() != null && StringUtils.containsIgnoreCase(ifUser.getEmail(), query))) {
            found.add(JSONUtils.toJSONObject(new String[] { "id", "text" }, new Object[] { m.getIdentity(), name }));
            // 最多显示40个
            if (found.size() >= 40)
                break;
        }
    }
    return found;
}
Also used : InvalidParameterException(com.rebuild.web.InvalidParameterException) User(com.rebuild.core.privileges.bizz.User) JSONArray(com.alibaba.fastjson.JSONArray) Member(cn.devezhao.bizz.security.member.Member) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with User

use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.

the class BaseFeedsService method awareMention.

/**
 * 内容中涉及的用户要加入 FeedsMention
 *
 * @param record
 * @param isNew
 * @see #awareMentionCreate(Record)
 */
protected void awareMention(Record record, boolean isNew) {
    String content = record.getString("content");
    if (content == null || record.getID("feedsId") == null)
        return;
    // 已存在的
    Set<ID> existsAtUsers = isNew ? Collections.emptySet() : this.awareMentionDelete(record.getPrimary(), true);
    Set<ID> atUsers = this.awareMentionCreate(record);
    if (atUsers.isEmpty())
        return;
    // 发送通知
    final String msgContent = Language.L("@%s 在动态中提到了你", record.getEditor()) + " \n> " + content;
    ID related = record.getPrimary();
    if (related.getEntityCode() == EntityHelper.FeedsComment) {
        related = record.getID("feedsId");
    }
    if (atUsers.contains(UserService.ALLUSERS) && !existsAtUsers.contains(UserService.ALLUSERS)) {
        atUsers.clear();
        for (User u : Application.getUserStore().getAllUsers()) {
            if (u.isActive())
                atUsers.add(u.getId());
        }
    }
    for (ID to : atUsers) {
        if (existsAtUsers.contains(to))
            continue;
        Application.getNotifications().send(MessageBuilder.createMessage(to, msgContent, Message.TYPE_FEEDS, related));
    }
}
Also used : User(com.rebuild.core.privileges.bizz.User) ID(cn.devezhao.persist4j.engine.ID)

Aggregations

User (com.rebuild.core.privileges.bizz.User)26 ID (cn.devezhao.persist4j.engine.ID)13 JSONObject (com.alibaba.fastjson.JSONObject)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 Member (cn.devezhao.bizz.security.member.Member)3 JSONArray (com.alibaba.fastjson.JSONArray)3 Entity (cn.devezhao.persist4j.Entity)2 Record (cn.devezhao.persist4j.Record)2 JSON (com.alibaba.fastjson.JSON)2 UserService (com.rebuild.core.privileges.UserService)2 Department (com.rebuild.core.privileges.bizz.Department)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Test (org.junit.jupiter.api.Test)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 Team (cn.devezhao.bizz.security.member.Team)1 Field (cn.devezhao.persist4j.Field)1 ApiInvokeException (com.rebuild.api.ApiInvokeException)1