pull/3/head
liuhuan 9 years ago
parent 4c7e131e65
commit d2743c0539

@ -1,6 +1,7 @@
package com.rekoe.module.admin;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -13,18 +14,24 @@ import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Attr;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import com.rekoe.annotation.PermissionTag;
import com.rekoe.common.Message;
import com.rekoe.common.page.Pagination;
import com.rekoe.domain.Pj;
import com.rekoe.domain.ProjectConfig;
import com.rekoe.domain.Usr;
import com.rekoe.module.BaseAction;
import com.rekoe.service.EmailService;
import com.rekoe.service.ProjectConfigService;
import com.rekoe.service.ProjectService;
import com.rekoe.service.SvnService;
import com.rekoe.service.SvnUserService;
import com.rekoe.utils.EncryptUtil;
@ -32,6 +39,8 @@ import com.rekoe.utils.EncryptUtil;
@At("/admin/svn/user")
public class AdminSvnUserAct extends BaseAction {
private final static Log log = Logs.get();
private static final char[] RANDOM_ARRY_CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
@Inject
@ -73,6 +82,12 @@ public class AdminSvnUserAct extends BaseAction {
@Inject
private ProjectConfigService projectConfigService;
@Inject
private SvnService svnService;
@Inject
private ProjectService projectService;
/**
*
*
@ -84,15 +99,27 @@ public class AdminSvnUserAct extends BaseAction {
@Ok("json")
@RequiresPermissions("svn.user:add")
@PermissionTag(name = "SVN添加账号", tag = "SVN账号管理", enable = false)
public Message restpwd(@Param("usr") String usr, HttpServletRequest req) {
public Message restpwd(@Param("usr") String usr, @Attr("usr") Usr manager, HttpServletRequest req) {
Usr user = svnUserService.fetch(Cnd.where("usr", "=", usr));
if (user == null) {
return Message.error("error.account.empty", req);
}
String code = RandomStringUtils.random(7, RANDOM_ARRY_CHAR);
svnUserService.update(Chain.make("psw", EncryptUtil.encrypt(code)), Cnd.where("usr", "=", usr));
ProjectConfig conf = projectConfigService.get();
emailNotify(user, emailService, conf, user.getEmail(), code);
if (usr.equals(manager.getUsr())) {
req.getSession().setAttribute("usr", svnUserService.fetch(Cnd.where("usr", "=", usr)));
}
List<Pj> list = svnUserService.getPjList(usr);
if (list != null) {
for (Pj pj : list) {
try {
this.svnService.exportConfig(pj);
} catch (Exception e) {
projectService.deleteDB(pj.getPj());
log.errorf("project %s ,error %s", pj.getPj(), e.getMessage());
}
}
}
return Message.success("ok", req);
}

@ -1,11 +1,19 @@
package com.rekoe.service;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
@ -155,15 +163,53 @@ public class ProjectService extends BaseService<Pj> {
@Aop(TransAop.READ_COMMITTED)
public void delete(String pj) {
deleteDB(pj);
svnService.exportConfig(pj);
}
public void deleteDB(String pj) {
projectAuthService.deletePj(pj);
projectGroupUsrService.deletePj(pj);
projectGroupService.deletePj(pj);
projectUserService.deletePj(pj);
svnService.exportConfig(pj);
dao().clear(getEntityClass(), Cnd.where("pj", "=", pj));
}
public void update(Pj pj) {
dao().update(pj);
}
/**
* @param usr
*
* @return ()
*/
public List<Pj> getList(String usr) {
Sql sql = Sqls.create("select p.pj,p.des,p.type,pm.pj manager from ( " + " select distinct a.pj,a.des,a.type from pj a where " + " exists (select b.usr from pj_gr_usr b where a.pj=b.pj and b.usr=@usr) " + " or exists(select c.usr from pj_usr_auth c where a.pj=c.pj and c.usr=@usr) " + " ) p " + " left join ( " + " select distinct a.pj from pj a where " + " exists (select b.usr from pj_gr_usr b where a.pj=b.pj and b.usr=@usr and b.gr like @like)" + " ) pm on p.pj=pm.pj");
final List<Pj> list = new ArrayList<Pj>();
sql.setCallback(new SqlCallback() {
@Override
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
while (rs.next()) {
Pj pj = readPj(rs);
String manager = rs.getString("manager");// 是否是管理员组的用户
pj.setManager(StringUtils.isNotBlank(manager));
list.add(pj);
}
return list;
}
});
sql.setParam("usr", usr).setParam("like", "%" + Constants.GROUP_MANAGER);
dao().execute(sql);
return list;
}
public Pj readPj(ResultSet rs) throws SQLException {
Pj result = new Pj();
result.setPj(rs.getString("pj"));
result.setDes(rs.getString("des"));
result.setType(rs.getString("type"));
return result;
}
}

@ -13,9 +13,11 @@ import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import com.rekoe.domain.Pj;
import com.rekoe.domain.Usr;
/**
@ -91,4 +93,12 @@ public class SvnUserService extends BaseService<Usr> {
result.setRole(rs.getString("role"));
return result;
}
@Inject
private ProjectService projectService;
public List<Pj> getPjList(String usr) {
List<Pj> list = projectService.getList(usr);// 用户可以看到的所有项目
return list;
}
}

Loading…
Cancel
Save