Search in sources :

Example 21 with User

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;
}
Also used : User(com.rebuild.core.privileges.bizz.User) DeleteRecord(com.rebuild.core.metadata.DeleteRecord) ID(cn.devezhao.persist4j.engine.ID)

Example 22 with User

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;
}
Also used : User(com.rebuild.core.privileges.bizz.User) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONObject(com.alibaba.fastjson.JSONObject)

Example 23 with User

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();
    }
}
Also used : User(com.rebuild.core.privileges.bizz.User) JSONObject(com.alibaba.fastjson.JSONObject) UserService(com.rebuild.core.privileges.UserService) Record(cn.devezhao.persist4j.Record) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 24 with User

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();
    }
}
Also used : User(com.rebuild.core.privileges.bizz.User) ID(cn.devezhao.persist4j.engine.ID) Test(org.junit.jupiter.api.Test)

Example 25 with User

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);
}
Also used : User(com.rebuild.core.privileges.bizz.User) ApiInvokeException(com.rebuild.api.ApiInvokeException) JSON(com.alibaba.fastjson.JSON) ID(cn.devezhao.persist4j.engine.ID) UUID(java.util.UUID)

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