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()));
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations