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