Search in sources :

Example 21 with Sysprop

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;
    }
}
Also used : Sysprop(com.erudika.para.core.Sysprop) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 22 with Sysprop

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";
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Pager(com.erudika.para.core.utils.Pager) Sysprop(com.erudika.para.core.Sysprop) ParaObject(com.erudika.para.core.ParaObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 23 with Sysprop

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);
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 24 with Sysprop

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 "";
}
Also used : Sysprop(com.erudika.para.core.Sysprop) ServletException(javax.servlet.ServletException) JOSEException(com.nimbusds.jose.JOSEException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 25 with Sysprop

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);
        }
    }
}
Also used : Sysprop(com.erudika.para.core.Sysprop) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Sysprop (com.erudika.para.core.Sysprop)32 HashMap (java.util.HashMap)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Map (java.util.Map)6 ParaObject (com.erudika.para.core.ParaObject)5 Profile (com.erudika.scoold.core.Profile)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 Pager (com.erudika.para.core.utils.Pager)3 TreeMap (java.util.TreeMap)3 User (com.erudika.para.core.User)2 ConfigValue (com.typesafe.config.ConfigValue)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ParaClient (com.erudika.para.client.ParaClient)1 App (com.erudika.para.core.App)1 Tag (com.erudika.para.core.Tag)1 Webhook (com.erudika.para.core.Webhook)1 Config (com.erudika.para.core.utils.Config)1