use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class AdminController method addSpace.
@PostMapping("/add-space")
public String addSpace(@RequestParam String space, HttpServletRequest req, HttpServletResponse res, Model model) {
Profile authUser = utils.getAuthUser(req);
if (!StringUtils.isBlank(space) && utils.isAdmin(authUser)) {
Sysprop spaceObj = utils.buildSpaceObject(space);
if (utils.isDefaultSpace(spaceObj.getId()) || pc.getCount("scooldspace") >= MAX_SPACES || pc.read(spaceObj.getId()) != null) {
if (utils.isAjaxRequest(req)) {
res.setStatus(400);
return "space";
} else {
return "redirect:" + ADMINLINK + "?code=7&error=true";
}
} else {
if (pc.create(spaceObj) != null) {
authUser.getSpaces().add(spaceObj.getId() + Config.SEPARATOR + spaceObj.getName());
authUser.update();
model.addAttribute("space", spaceObj);
utils.getAllSpaces().add(spaceObj);
} else {
model.addAttribute("error", Collections.singletonMap("name", utils.getLang(req).get("posts.error1")));
}
}
} else {
model.addAttribute("error", Collections.singletonMap("name", utils.getLang(req).get("requiredfield")));
}
if (utils.isAjaxRequest(req)) {
res.setStatus(model.containsAttribute("error") ? 400 : 200);
return "space";
} else {
return "redirect:" + ADMINLINK;
}
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class AdminController method get.
@GetMapping
public String get(HttpServletRequest req, Model model) {
if (utils.isAuthenticated(req) && !utils.isAdmin(utils.getAuthUser(req))) {
return "redirect:" + HOMEPAGE;
} else if (!utils.isAuthenticated(req)) {
return "redirect:" + SIGNINLINK + "?returnto=" + ADMINLINK;
}
Map<String, Object> configMap = new LinkedHashMap<String, Object>();
for (Map.Entry<String, ConfigValue> entry : Config.getConfig().entrySet()) {
ConfigValue value = entry.getValue();
configMap.put(entry.getKey(), value != null ? value.unwrapped() : "-");
}
Pager itemcount = utils.getPager("page", req);
Pager itemcount1 = utils.getPager("page1", req);
itemcount.setLimit(40);
model.addAttribute("path", "admin.vm");
model.addAttribute("title", utils.getLang(req).get("administration.title"));
model.addAttribute("configMap", configMap);
model.addAttribute("version", pc.getServerVersion());
model.addAttribute("endpoint", Config.getConfigParam("security.redirect_uri", pc.getEndpoint()));
model.addAttribute("paraapp", Config.getConfigParam("access_key", "x"));
model.addAttribute("spaces", pc.findQuery("scooldspace", "*", itemcount));
model.addAttribute("webhooks", pc.findQuery(Utils.type(Webhook.class), "*", itemcount1));
model.addAttribute("scooldimports", pc.findQuery("scooldimport", "*", new Pager(7)));
model.addAttribute("coreScooldTypes", utils.getCoreScooldTypes());
model.addAttribute("customHookEvents", utils.getCustomHookEvents());
model.addAttribute("apiKeys", utils.getApiKeys());
model.addAttribute("apiKeysExpirations", utils.getApiKeysExpirations());
model.addAttribute("itemcount", itemcount);
model.addAttribute("itemcount1", itemcount1);
model.addAttribute("isDefaultSpacePublic", utils.isDefaultSpacePublic());
model.addAttribute("scooldVersion", Optional.ofNullable(scooldVersion).orElse("unknown"));
String importedCount = req.getParameter("imported");
if (importedCount != null) {
if (req.getParameter("success") != null) {
model.addAttribute("infoStripMsg", "Successfully imported " + importedCount + " objects from archive.");
} else {
model.addAttribute("infoStripMsg", "Imported operation failed!" + ("0".equals(importedCount) ? "" : " Partially imported " + importedCount + " objects from archive."));
}
}
Sysprop theme = utils.getCustomTheme();
String themeCSS = (String) theme.getProperty("theme");
model.addAttribute("selectedTheme", theme.getName());
model.addAttribute("customTheme", StringUtils.isBlank(themeCSS) ? utils.getDefaultTheme() : themeCSS);
return "base";
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class ScooldUtils method saveApiKeysObject.
private void saveApiKeysObject() {
Sysprop s = new Sysprop("api_keys");
s.setProperties(API_KEYS);
pc.create(s);
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class ScooldUtils method getInlineCSS.
public String getInlineCSS() {
try {
Sysprop custom = getCustomTheme();
String themeName = custom.getName();
String inline = Config.getConfigParam("inline_css", "");
String loadedTheme;
if ("default".equalsIgnoreCase(themeName) || StringUtils.isBlank(themeName)) {
return inline;
} else if ("custom".equalsIgnoreCase(themeName)) {
loadedTheme = (String) custom.getProperty("theme");
} else {
loadedTheme = loadResource(getThemeKey(themeName));
if (StringUtils.isBlank(loadedTheme)) {
FILE_CACHE.put("theme", "default");
custom.setName("default");
customTheme = pc.update(custom);
return inline;
} else {
FILE_CACHE.put("theme", themeName);
}
}
loadedTheme = StringUtils.replaceEachRepeatedly(loadedTheme, new String[] { "<", "</", "<script", "<SCRIPT" }, new String[] { "", "", "", "" });
return loadedTheme + "\n/*** END OF THEME CSS ***/\n" + inline;
} catch (Exception e) {
logger.debug("Failed to load inline CSS.");
}
return "";
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class ScooldUtils method subscribeToNotifications.
@SuppressWarnings("unchecked")
public void subscribeToNotifications(String email, String channelId) {
if (!StringUtils.isBlank(email) && !StringUtils.isBlank(channelId)) {
Sysprop s = pc.read(channelId);
if (s == null || !s.hasProperty("emails")) {
s = new Sysprop(channelId);
s.addProperty("emails", new LinkedList<>());
}
Set<String> emails = new HashSet<>((List<String>) s.getProperty("emails"));
if (emails.add(email)) {
s.addProperty("emails", emails);
pc.create(s);
}
}
}
Aggregations