Search in sources :

Example 11 with User

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

the class UserService method updateEnableUser.

/**
 * xxxNew 值为 null 表示不做修改
 *
 * @param user
 * @param deptNew     新部门
 * @param roleNew     新角色
 * @param roleAppends 附加角色
 * @param enableNew   激活状态
 */
public void updateEnableUser(ID user, ID deptNew, ID roleNew, ID[] roleAppends, Boolean enableNew) {
    User enUser = Application.getUserStore().getUser(user);
    // 当前是从未激活状态
    final boolean beforeUnEnabled = enUser.isDisabled() && (enUser.getOwningDept() == null || enUser.getOwningRole() == null);
    ID deptOld = null;
    // 检查是否需要更新部门
    if (deptNew != null) {
        deptOld = enUser.getOwningBizUnit() == null ? null : (ID) enUser.getOwningBizUnit().getIdentity();
        if (deptNew.equals(deptOld)) {
            deptNew = null;
            deptOld = null;
        }
    }
    // 检查是否需要更新角色
    if (enUser.getOwningRole() != null && enUser.getOwningRole().getIdentity().equals(roleNew)) {
        roleNew = null;
    }
    Record record = EntityHelper.forUpdate(user, UserContextHolder.getUser());
    boolean changed = false;
    if (deptNew != null) {
        record.setID("deptId", deptNew);
        changed = true;
    }
    if (roleNew != null) {
        record.setID("roleId", roleNew);
        changed = true;
    }
    if (enableNew != null) {
        record.setBoolean("isDisabled", !enableNew);
        changed = true;
    }
    if (changed) {
        super.update(record);
    }
    if (changed || updateRoleAppends(user, roleAppends)) {
        Application.getUserStore().refreshUser(user);
    }
    // 改变记录的所属部门
    if (deptOld != null) {
        TaskExecutors.submit(new ChangeOwningDeptTask(user, deptNew), UserContextHolder.getUser());
    }
    // 是否需要发送激活通知
    if (beforeUnEnabled) {
        notifyEnableUser(Application.getUserStore().getUser(enUser.getId()));
    }
}
Also used : User(com.rebuild.core.privileges.bizz.User) Record(cn.devezhao.persist4j.Record) ID(cn.devezhao.persist4j.engine.ID)

Example 12 with User

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

the class UserStore method refreshUser.

/**
 * 刷新用户
 *
 * @param userId
 */
public void refreshUser(ID userId) {
    Object[] o = aPMFactory.createQuery("select " + USER_FS + " from User where userId = ?").setParameter(1, userId).unique();
    final User newUser = new User(userId, (String) o[1], (String) o[2], (String) o[8], (String) o[3], (String) o[4], (Boolean) o[5]);
    final ID deptId = (ID) o[6];
    final ID roleId = (ID) o[7];
    final User oldUser = existsUser(userId) ? getUser(userId) : null;
    if (oldUser != null) {
        Role role = oldUser.getOwningRole();
        if (role != null) {
            role.removeMember(oldUser);
        }
        Department dept = oldUser.getOwningDept();
        if (dept != null) {
            dept.removeMember(oldUser);
        }
        for (Team team : oldUser.getOwningTeams().toArray(new Team[0])) {
            team.removeMember(oldUser);
            team.addMember(newUser);
        }
        // 邮箱可更改
        if (oldUser.getEmail() != null) {
            USERS_MAIL2ID.remove(normalIdentifier(oldUser.getEmail()));
        }
    }
    if (deptId != null) {
        getDepartment(deptId).addMember(newUser);
    }
    if (roleId != null) {
        getRole(roleId).addMember(newUser);
        refreshUserRoleAppends(newUser);
    }
    store(newUser);
}
Also used : User(com.rebuild.core.privileges.bizz.User) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID)

Example 13 with User

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

the class UserStore method removeUser.

/**
 * 移除用户
 *
 * @param userId
 */
public void removeUser(ID userId) {
    final User oldUser = getUser(userId);
    // 移除成员
    if (oldUser.getOwningDept() != null) {
        oldUser.getOwningDept().removeMember(oldUser);
    }
    if (oldUser.getOwningRole() != null) {
        oldUser.getOwningRole().removeMember(oldUser);
    }
    for (Team team : oldUser.getOwningTeams()) {
        team.removeMember(oldUser);
    }
    // 移除缓存
    for (Map.Entry<String, ID> e : USERS_NAME2ID.entrySet()) {
        if (e.getValue().equals(userId)) {
            USERS_NAME2ID.remove(e.getKey());
            break;
        }
    }
    for (Map.Entry<String, ID> e : USERS_MAIL2ID.entrySet()) {
        if (e.getValue().equals(userId)) {
            USERS_MAIL2ID.remove(e.getKey());
            break;
        }
    }
    USERS.remove(userId);
}
Also used : User(com.rebuild.core.privileges.bizz.User) ID(cn.devezhao.persist4j.engine.ID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 14 with User

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

the class FeedsGroupController method userList.

@GetMapping("user-list")
public JSON userList(HttpServletRequest request) {
    final ID user = getRequestUser(request);
    final String query = getParameter(request, "q");
    JSONArray ret = new JSONArray();
    Set<Member> stars = getStars(user, EntityHelper.User);
    Set<ID> starsId = new HashSet<>();
    for (Member m : UserHelper.sortMembers(stars.toArray(new Member[0]))) {
        User u = (User) m;
        if (StringUtils.isEmpty(query) || CommonsUtils.containsIgnoreCase(new String[] { u.getName(), u.getFullName(), u.getEmail() }, query)) {
            ret.add(JSONUtils.toJSONObject(new String[] { "id", "name", "star" }, new Object[] { u.getId(), u.getFullName(), true }));
            starsId.add(u.getId());
        }
    }
    for (User u : UserHelper.sortUsers()) {
        if (StringUtils.isBlank(query) || CommonsUtils.containsIgnoreCase(new String[] { u.getName(), u.getFullName(), u.getEmail() }, query)) {
            if (starsId.contains(u.getId()))
                continue;
            ret.add(JSONUtils.toJSONObject(new String[] { "id", "name" }, new Object[] { u.getId(), u.getFullName() }));
            if (ret.size() >= 20)
                break;
        }
    }
    return ret;
}
Also used : User(com.rebuild.core.privileges.bizz.User) JSONArray(com.alibaba.fastjson.JSONArray) ID(cn.devezhao.persist4j.engine.ID) Member(cn.devezhao.bizz.security.member.Member) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 15 with User

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

the class FeedsListController method pageIndex.

/**
 * @see FeedsType
 */
@GetMapping("/feeds/{type}")
public ModelAndView pageIndex(@PathVariable String type, HttpServletRequest request) {
    ModelAndView mv = createModelAndView("/feeds/home");
    mv.getModel().put("feedsType", type);
    User user = Application.getUserStore().getUser(getRequestUser(request));
    mv.getModel().put("UserEmail", user.getEmail());
    mv.getModel().put("UserMobile", StringUtils.defaultIfBlank(user.getWorkphone(), ""));
    return mv;
}
Also used : User(com.rebuild.core.privileges.bizz.User) ModelAndView(org.springframework.web.servlet.ModelAndView) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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