use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.
the class User method filter.
@Override
protected void filter(FetchCase caze, Map req) throws HongsException {
/**
* 默认情况下不包含上级部门
* 此时顶级仅需列出当前用户
*/
if (!caze.getOption("INCLUDE_PARENTS", false) && "getList".equals(caze.getOption("MODEL_START"))) {
Object id = req.get(/**
*/
"id");
Object pid = req.get("dept_id");
if (id == null && "0".equals(pid)) {
ActionHelper helper = Core.getInstance(ActionHelper.class);
String uid = (String) helper.getSessibute(Cnst.UID_SES);
if (!Cnst.ADM_UID.equals(uid)) {
Set set = AuthKit.getUserDepts(uid);
if (!set.contains(Cnst.ADM_GID)) {
req.put("id", uid);
req.remove("dept_id");
}
}
}
}
/**
* 如果有指定dept_id
* 则关联a_master_user_dept来约束范围
*/
Object deptId = req.get("dept_id");
if (null != deptId && !"".equals(deptId)) {
caze.gotJoin("depts").from("a_master_user_dept").by(FetchCase.INNER).on("`depts`.`user_id` = `user`.`id`").filter("`depts`.`dept_id` = ?", deptId);
}
super.filter(caze, req);
}
use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.
the class Form method deleteAuthRole.
protected void deleteAuthRole(String id) throws HongsException {
ActionHelper helper = Core.getInstance(ActionHelper.class);
String uid = (String) helper.getSessibute(Cnst.UID_SES);
String tan;
// 删除权限
tan = (String) table.getParams().get("role.table");
if (tan != null) {
Table tab = db.getTable(tan);
tab.remove("`role` IN (?)", Synt.setOf(prefix + "/" + id + "/search", prefix + "/" + id + "/create", prefix + "/" + id + "/update", prefix + "/" + id + "/delete", prefix + "/" + id + "/revert"));
}
// 更新缓存(通过改变权限更新时间)
tan = (String) table.getParams().get("user.table");
if (tan != null) {
Table tab = db.getTable(tan);
tab.update(Synt.mapOf("rtime", System.currentTimeMillis() / 1000), "`id` = ?", uid);
}
}
use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.
the class Unit method filter.
@Override
protected void filter(FetchCase caze, Map rd) throws HongsException {
super.filter(caze, rd);
// 超级管理员不做限制
ActionHelper helper = Core.getInstance(ActionHelper.class);
String uid = (String) helper.getSessibute(Cnst.UID_SES);
if (Cnst.ADM_UID.equals(uid)) {
return;
}
String mm = caze.getOption("MODEL_START", "");
if ("getList".equals(mm) || "getInfo".equals(mm)) {
// mm = "/search";
} else if ("update".equals(mm) || "delete".equals(mm)) {
// mm = "/" + mm ;
} else {
// 非常规动作不限制
return;
}
// 从导航表中取单元ID
NaviMap navi = NaviMap.getInstance(prefix);
Map<String, Map> ms = navi.menus;
Set<String> rs = navi.getRoleSet();
Set<String> us = /**/
new HashSet();
getSubUnits(ms, rs, us);
// 限制为有权限的单元
caze.filter("`" + table.name + "`.`id` IN (?)", us);
}
use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.
the class ConfAction method service.
/**
* 服务方法
* 判断配置和消息有没有生成, 如果没有则生成; 消息按客户语言存放
* @param req
* @param rsp
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
Core core = ActionDriver.getActualCore(req);
ActionHelper helper = core.get(ActionHelper.class);
String name = req.getPathInfo();
if (name == null || name.length() == 0) {
helper.error400("Path info required");
return;
}
int p = name.lastIndexOf('.');
if (p < 0) {
helper.error400("File type required");
return;
}
String type = name.substring(1 + p);
name = name.substring(1, p);
if (!"js".equals(type) && !"json".equals(type)) {
helper.error400("Wrong file type: " + type);
return;
}
/**
* 如果指定配置的数据并没有改变
* 则直接返回 304 Not modified
*/
String m;
m = helper.getRequest().getHeader("If-Modified-Since");
if (m != null && m.equals(ConfAction.MTIMES.get(name))) {
helper.getResponse().setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
/**
* 如果没有配置
* 则调用工厂方法构造 JS 代码
*/
String s;
if (!ConfAction.CACHES.containsKey(name)) {
try {
s = this.makeConf(name);
} catch (HongsError ex) {
helper.error500(ex.getMessage());
return;
}
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
m = sdf.format(new Date());
ConfAction.CACHES.put(name, s);
ConfAction.MTIMES.put(name, m);
} else {
s = ConfAction.CACHES.get(name);
m = ConfAction.MTIMES.get(name);
}
// 标明修改时间
helper.getResponse().setHeader("Last-Modified", m);
// 输出配置信息
if ("json".equals(type)) {
helper.print(s, "application/json");
} else {
String c = req.getParameter("callback");
if (c != null && c.length() != 0) {
if (!c.matches("^[a-zA-Z_\\$][a-zA-Z0-9_]*$")) {
helper.error400("Illegal callback function name!");
return;
}
helper.print("function " + c + "() { return " + s + "; }", "text/javascript");
} else {
helper.print("if(!self.HsCONF)self.HsCONF={};Object.assign(self.HsCONF," + s + ");", "text/javascript");
}
}
}
use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.
the class LangAction method service.
/**
* 服务方法
* 判断配置和消息有没有生成, 如果没有则生成; 消息按客户语言存放
* @param req
* @param rsp
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException {
Core core = ActionDriver.getActualCore(req);
ActionHelper helper = core.get(ActionHelper.class);
String name = req.getPathInfo();
if (name == null || name.length() == 0) {
helper.error400("Path info required");
return;
}
int p = name.lastIndexOf('.');
if (p < 0) {
helper.error400("File type required");
return;
}
String type = name.substring(1 + p);
name = name.substring(1, p);
if (!"js".equals(type) && !"json".equals(type)) {
helper.error400("Wrong file type: " + type);
return;
}
/**
* 如果指定语言的数据并没有改变
* 则直接返回 304 Not modified
*/
String m;
m = helper.getRequest().getHeader("If-Modified-Since");
if (m != null && m.equals(LangAction.MTIMES.get(name))) {
helper.getResponse().setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
/**
* 如果没有语言
* 则调用工厂方法构造 JS 代码
*/
String s;
if (!LangAction.CACHES.containsKey(name)) {
try {
s = this.makeLang(name);
} catch (HongsError ex) {
helper.error500(ex.getMessage());
return;
}
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
m = sdf.format(new Date());
LangAction.CACHES.put(name, s);
LangAction.MTIMES.put(name, m);
} else {
s = LangAction.CACHES.get(name);
m = LangAction.MTIMES.get(name);
}
// 标明修改时间
helper.getResponse().setHeader("Last-Modified", m);
// 输出语言信息
if ("json".equals(type)) {
helper.print(s, "application/json");
} else {
String c = req.getParameter("callback");
if (c != null && c.length() != 0) {
if (!c.matches("^[a-zA-Z_\\$][a-zA-Z0-9_]*$")) {
helper.error400("Illegal callback function name!");
return;
}
helper.print("function " + c + "() { return " + s + "; }", "text/javascript");
} else {
helper.print("if(!self.HsLANG)self.HsLANG={};Object.assign(self.HsLANG," + s + ");", "text/javascript");
}
}
}
Aggregations