use of com.publiccms.entities.sys.SysRoleAuthorized in project PublicCMS-preview by sanluan.
the class SysAuthorizedDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
Integer[] roleIds = handler.getIntegerArray("roleIds");
String url = handler.getString("url");
String[] urls = handler.getStringArray("urls");
if (CommonUtils.notEmpty(roleIds)) {
if (CommonUtils.notEmpty(url) && sysRoleService.showAllModule(roleIds)) {
handler.put("object", true).render();
} else if (CommonUtils.notEmpty(url)) {
SysRoleAuthorizedId[] ids = new SysRoleAuthorizedId[roleIds.length];
for (int i = 0; i < roleIds.length; i++) {
ids[i] = new SysRoleAuthorizedId(roleIds[i], url);
}
if (CommonUtils.notEmpty(service.getEntitys(ids))) {
handler.put("object", true).render();
}
} else if (CommonUtils.notEmpty(urls)) {
Map<String, Boolean> map = new LinkedHashMap<>();
if (sysRoleService.showAllModule(roleIds)) {
for (String u : urls) {
map.put(u, true);
}
} else {
SysRoleAuthorizedId[] ids = new SysRoleAuthorizedId[urls.length * roleIds.length];
int n = 0;
for (int i = 0; i < urls.length; i++) {
map.put(urls[i], false);
for (int j = 0; j < roleIds.length; j++) {
ids[n++] = new SysRoleAuthorizedId(roleIds[j], urls[i]);
}
}
for (SysRoleAuthorized entity : service.getEntitys(ids)) {
map.put(entity.getId().getUrl(), true);
}
}
handler.put("map", map).render();
}
}
}
use of com.publiccms.entities.sys.SysRoleAuthorized in project PublicCMS-preview by sanluan.
the class SysRoleAuthorizedService method dealRoleModules.
/**
* @param roleId
* @param showAllModule
* @param modules
* @param pageUrls
*/
public void dealRoleModules(Integer roleId, boolean showAllModule, List<SysModule> modules, Set<String> pageUrls) {
if (CommonUtils.notEmpty(roleId)) {
Set<String> urls = new HashSet<>();
if (CommonUtils.notEmpty(modules)) {
for (SysModule module : modules) {
if (CommonUtils.notEmpty(module.getUrl()) && !showAllModule) {
int index = module.getUrl().indexOf("?");
urls.add(module.getUrl().substring(0, index > 0 ? index : module.getUrl().length()));
}
if (CommonUtils.notEmpty(module.getAuthorizedUrl())) {
for (String url : StringUtils.split(module.getAuthorizedUrl(), ',')) {
urls.add(url);
}
}
}
}
if (showAllModule) {
urls.addAll(pageUrls);
}
@SuppressWarnings("unchecked") List<SysRoleAuthorized> list = (List<SysRoleAuthorized>) getPage(roleId, null, null, null).getList();
for (SysRoleAuthorized roleAuthorized : list) {
if (urls.contains(roleAuthorized.getId().getUrl())) {
urls.remove(roleAuthorized.getId().getUrl());
} else {
delete(roleAuthorized.getId());
}
}
if (!urls.isEmpty()) {
for (String url : urls) {
save(new SysRoleAuthorized(new SysRoleAuthorizedId(roleId, url)));
}
}
}
}
Aggregations