use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.
the class GeneralEntityService method assign.
@Override
public int assign(ID record, ID to, String[] cascades) {
final User toUser = Application.getUserStore().getUser(to);
final Record assignAfter = EntityHelper.forUpdate(record, (ID) toUser.getIdentity(), false);
assignAfter.setID(EntityHelper.OwningUser, (ID) toUser.getIdentity());
assignAfter.setID(EntityHelper.OwningDept, (ID) toUser.getOwningDept().getIdentity());
// 分配前数据
Record assignBefore = null;
int affected = 0;
if (to.equals(Application.getRecordOwningCache().getOwningUser(record))) {
// No need to change
if (log.isDebugEnabled()) {
log.debug("The record owner has not changed, ignore : {}", record);
}
} else {
assignBefore = countObservers() > 0 ? record(assignAfter) : null;
delegateService.update(assignAfter);
Application.getRecordOwningCache().cleanOwningUser(record);
affected = 1;
}
Map<String, Set<ID>> cass = getCascadedRecords(record, cascades, BizzPermission.ASSIGN);
for (Map.Entry<String, Set<ID>> e : cass.entrySet()) {
if (log.isDebugEnabled()) {
log.debug("Cascading assign - {} > {}", e.getKey(), e.getValue());
}
for (ID casid : e.getValue()) {
affected += assign(casid, to, null);
}
}
if (countObservers() > 0 && assignBefore != null) {
setChanged();
notifyObservers(OperatingContext.create(UserContextHolder.getUser(), BizzPermission.ASSIGN, assignBefore, assignAfter));
}
return affected;
}
use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.
the class UserSettingsController method pageUser.
@GetMapping("/user")
public ModelAndView pageUser(HttpServletRequest request) {
ModelAndView mv = createModelAndView("/settings/user-settings");
User user = Application.getUserStore().getUser(getRequestUser(request));
mv.getModelMap().put("user", user);
String dingtalkCorpid = RebuildConfiguration.get(ConfigurationItem.DingtalkCorpid);
if (dingtalkCorpid != null) {
Object[] dingtalkUser = Application.createQueryNoFilter("select appUser from ExternalUser where bindUser = ? and appId = ?").setParameter(1, user.getId()).setParameter(2, dingtalkCorpid).unique();
if (dingtalkUser != null)
mv.getModelMap().put("dingtalkUser", dingtalkUser[0]);
}
String wxworkCorpid = RebuildConfiguration.get(ConfigurationItem.WxworkCorpid);
if (wxworkCorpid != null) {
Object[] wxworkUser = Application.createQueryNoFilter("select appUser from ExternalUser where bindUser = ? and appId = ?").setParameter(1, user.getId()).setParameter(2, wxworkCorpid).unique();
if (wxworkUser != null)
mv.getModelMap().put("wxworkUser", wxworkUser[0]);
}
return mv;
}
use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.
the class LoginController method userConfirmPasswd.
@PostMapping("user-confirm-passwd")
public RespBody userConfirmPasswd(HttpServletRequest request) {
JSONObject data = (JSONObject) ServletUtils.getRequestJson(request);
String newpwd = data.getString("newpwd");
String email = data.getString("email");
String vcode = data.getString("vcode");
if (!VerfiyCode.verfiy(email, vcode, true)) {
return RespBody.errorl("无效验证码");
}
User user = Application.getUserStore().getUserByEmail(email);
Record record = EntityHelper.forUpdate(user.getId(), user.getId());
record.setString("password", newpwd);
try {
UserContextHolder.setUser(user.getId());
Application.getBean(UserService.class).update(record);
VerfiyCode.clean(email);
return RespBody.ok();
} catch (DataSpecificationException ex) {
return RespBody.error(ex.getLocalizedMessage());
} finally {
UserContextHolder.clear();
}
}
use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.
the class UserStoreTest method testMemberToTeam.
@Test
public void testMemberToTeam() {
UserContextHolder.setUser(UserService.SYSTEM_USER);
ID teamUser = UserService.ADMIN_USER;
try {
Application.getBean(TeamService.class).createMembers(SIMPLE_TEAM, Collections.singletonList(teamUser));
User user = Application.getUserStore().getUser(teamUser);
System.out.println(user.getOwningTeams());
Assertions.assertFalse(user.getOwningTeams().isEmpty());
Assertions.assertTrue(Application.getUserStore().getTeam(SIMPLE_TEAM).isMember(teamUser));
Application.getBean(TeamService.class).deleteMembers(SIMPLE_TEAM, Collections.singletonList(teamUser));
System.out.println(user.getOwningTeams());
} finally {
UserContextHolder.clear();
}
}
use of com.rebuild.core.privileges.bizz.User in project rebuild by getrebuild.
the class PageTokenVerify method execute.
@Override
public JSON execute(ApiContext context) throws ApiInvokeException {
String token = context.getParameterNotBlank("token");
ID tokenUser = verify(token);
if (tokenUser == null) {
throw new ApiInvokeException("Invalid token : " + token);
}
User user = Application.getUserStore().getUser(tokenUser);
JSON ret = JSONUtils.toJSONObject(new String[] { "user_id", "login_name", "full_name" }, new Object[] { user.getId(), user.getName(), user.getFullName() });
return formatSuccess(ret);
}
Aggregations