Search in sources :

Example 1 with AdminUserFactory

use of org.javlo.user.AdminUserFactory in project javlo by Javlo.

the class Edit method performNeedValidation.

public static String performNeedValidation(ContentContext ctx, MenuElement currentPage, I18nAccess i18nAccess) throws Exception {
    AdminUserSecurity userSecurity = AdminUserSecurity.getInstance();
    if (userSecurity.canRole(ctx.getCurrentEditUser(), AdminUserSecurity.CONTENT_ROLE)) {
        currentPage.setNeedValidation(true);
        PersistenceService.getInstance(ctx.getGlobalContext()).setAskStore(true);
        AdminUserFactory userFact = AdminUserFactory.createAdminUserFactory(ctx.getGlobalContext(), ctx.getRequest().getSession());
        TicketBean ticket = new TicketBean();
        ticket.setAuthors(ctx.getCurrentEditUser().getLogin());
        ticket.setTitle(i18nAccess.getText("flow.ticket.title") + " : " + currentPage.getTitle(ctx));
        ticket.setCategory("validation");
        ticket.setContext(ctx.getGlobalContext().getContextKey());
        ticket.setCreationDate(new Date());
        ticket.setUrl(URLHelper.createURL(ctx));
        List<String> users = new LinkedList<String>();
        for (IUserInfo userInfo : userFact.getUserInfoList()) {
            if (userSecurity.haveRole(userInfo, AdminUserSecurity.VALIDATION_ROLE)) {
                users.add(userInfo.getLogin());
            }
        }
        ticket.setUsers(users);
        TicketService.getInstance(ctx.getGlobalContext()).updateTicket(ctx, ticket, false);
    } else {
        return "Security error !";
    }
    return null;
}
Also used : IUserInfo(org.javlo.user.IUserInfo) AdminUserFactory(org.javlo.user.AdminUserFactory) TicketBean(org.javlo.module.ticket.TicketBean) AdminUserSecurity(org.javlo.user.AdminUserSecurity) Date(java.util.Date) LinkedList(java.util.LinkedList)

Example 2 with AdminUserFactory

use of org.javlo.user.AdminUserFactory in project javlo by Javlo.

the class UserInterfaceContext method getInstance.

public static final UserInterfaceContext getInstance(HttpSession session, GlobalContext globalContext) {
    UserInterfaceContext instance = (UserInterfaceContext) session.getAttribute(KEY);
    AdminUserFactory userFact = AdminUserFactory.createUserFactory(globalContext, session);
    User user = userFact.getCurrentUser(session);
    String login = null;
    if (user != null) {
        login = user.getLogin();
    }
    if (instance == null || instance.globalContext != globalContext || !instance.login.equals(login)) {
        if (userFact == null || user == null) {
            return FAKE_INSTACE;
        }
        instance = new UserInterfaceContext();
        instance.login = user.getLogin();
        instance.session = session;
        instance.globalContext = globalContext;
        MailConfig config = new MailConfig(globalContext, globalContext.getStaticConfig(), null);
        if ((StringHelper.isEmpty(config.getSMTPHost()) || config.getSMTPPort() == null || config.getSMTPPort().equals("0")) && StringHelper.isEmpty(globalContext.getDMZServerIntra())) {
            instance.sendMailing = false;
        }
        if (globalContext.getModules().contains(IMainModuleName.MAILING) && AdminUserSecurity.getInstance().canRole(user, AdminUserSecurity.MAILING_ROLE)) {
            instance.mailing = true;
        } else {
            instance.mailing = false;
        }
        if (AdminUserSecurity.getInstance().canRole(user, AdminUserSecurity.NAVIGATION_ROLE) || AdminUserSecurity.getInstance().isAdmin(user)) {
            instance.navigation = true;
        } else {
            instance.navigation = false;
        }
        if (globalContext.getModules().contains(IMainModuleName.TICKET)) {
            instance.setTicket(true);
        } else {
            instance.setTicket(false);
        }
        if (globalContext.getModules().contains(IMainModuleName.SEARCH)) {
            instance.setSearch(true);
        } else {
            instance.setSearch(false);
        }
        instance.fromString(user.getUserInfo().getInfo());
        session.setAttribute(KEY, instance);
    }
    StaticConfig stConf = globalContext.getStaticConfig();
    instance.lightInterface = AdminUserSecurity.getInstance().haveRole(user, AdminUserSecurity.LIGHT_INTERFACE_ROLE);
    instance.setMinimalInterface(instance.lightInterface && AdminUserSecurity.getInstance().haveRole(user, AdminUserSecurity.ADD_ONLY) && stConf.isAddButton());
    instance.contributor = AdminUserSecurity.getInstance().haveRole(user, AdminUserSecurity.CONTRIBUTOR_ROLE);
    instance.setModel(AdminUserSecurity.getInstance().canRole(user, AdminUserSecurity.MODEL_ROLE));
    instance.setAdmin(AdminUserSecurity.getInstance().isAdmin(user));
    return instance;
}
Also used : User(org.javlo.user.User) AdminUserFactory(org.javlo.user.AdminUserFactory) StaticConfig(org.javlo.config.StaticConfig) MailConfig(org.javlo.mailing.MailConfig)

Example 3 with AdminUserFactory

use of org.javlo.user.AdminUserFactory in project javlo by Javlo.

the class UserInterfaceContext method store.

private void store() throws IOException {
    if (globalContext != null) {
        AdminUserFactory userFact = AdminUserFactory.createUserFactory(globalContext, session);
        User user = userFact.getCurrentUser(session);
        if (user != null) {
            // get real user
            user = userFact.getUser(user.getLogin());
            if (user != null) {
                // not god user, so storable user
                IUserInfo ui = user.getUserInfo();
                // ui.setUserInfo(toString());
                userFact.updateUserInfo(ui);
            }
        }
    }
}
Also used : User(org.javlo.user.User) IUserInfo(org.javlo.user.IUserInfo) AdminUserFactory(org.javlo.user.AdminUserFactory)

Example 4 with AdminUserFactory

use of org.javlo.user.AdminUserFactory in project javlo by Javlo.

the class CreateArticle method performCreate.

public static String performCreate(RequestService rs, EditContext editCtx, ContentContext ctx, MessageRepository messageRepository, I18nAccess i18nAccess) {
    String pageName = rs.getParameter("root", null);
    String date = rs.getParameter("date", null);
    boolean widthMonth = StringHelper.isTrue(ctx.getGlobalContext().getSpecialConfig().get("macro.create-article.month", "true"));
    boolean create = rs.getParameter("create", null) != null;
    boolean duplicate = rs.getParameter("duplicate", null) != null;
    boolean duplicateChildren = rs.getParameter("children", null) != null;
    if (duplicateChildren) {
        duplicate = true;
    }
    String message = null;
    String newURL = null;
    String newEditURL = null;
    String lang = rs.getParameter("lang", null);
    ContentContext ctxLg = ctx;
    if (lang != null) {
        ctxLg = new ContentContext(ctx);
        ctxLg.setContentLanguage(lang);
    }
    if (pageName == null) {
        return "page or date not found.";
    }
    try {
        Date articleDate;
        if (date != null && date.trim().length() > 0) {
            articleDate = StringHelper.parseDate(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(articleDate);
            Calendar now = Calendar.getInstance();
            cal.set(Calendar.HOUR, now.get(Calendar.HOUR));
            cal.set(Calendar.MINUTE, now.get(Calendar.MINUTE));
            articleDate = cal.getTime();
        } else {
            articleDate = new Date();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(articleDate);
        MenuElement rootPage = ContentService.getInstance(ctx.getRequest()).getNavigation(ctxLg).searchChildFromName(pageName);
        MenuElement newPage = null;
        if (rootPage != null) {
            List<String> roles = new LinkedList<String>();
            Set<String> roleSet = new HashSet<String>();
            for (String role : ctx.getGlobalContext().getAdminUserRoles()) {
                roleSet.clear();
                roleSet.add(role);
                if (ctx.getCurrentEditUser().validForRoles(roleSet)) {
                    roles.add(role);
                }
            }
            String yearPageName = rootPage.getName() + "-" + cal.get(Calendar.YEAR);
            MenuElement yearPage = MacroHelper.addPageIfNotExist(ctxLg, rootPage.getName(), yearPageName, true);
            MenuElement parentPage = yearPage;
            if (widthMonth) {
                MacroHelper.createMonthStructure(ctxLg, yearPage);
                String mountPageName = MacroHelper.getMonthPageName(ctxLg, yearPage.getName(), articleDate);
                parentPage = ContentService.getInstance(ctx.getRequest()).getNavigation(ctxLg).searchChildFromName(mountPageName);
            }
            if (parentPage != null) {
                newPage = MacroHelper.createArticlePageName(ctx, parentPage);
                if (newPage != null) {
                    ContentContext noAreaCtx = ctx.getContextWithArea(null);
                    if (duplicate) {
                        ContentService content = ContentService.getInstance(ctx.getRequest());
                        MenuElement page = content.getNavigation(ctx).searchChildFromName(ctx.getRequest().getParameter("page"));
                        {
                            ContentElementList contentList = page.getContent(noAreaCtx);
                            Map<String, String> parents = new HashMap<String, String>();
                            while (contentList.hasNext(noAreaCtx)) {
                                IContentVisualComponent comp = contentList.next(noAreaCtx);
                                if (!comp.isRepeat()) {
                                    ComponentBean bean = new ComponentBean(comp.getComponentBean());
                                    bean.setId(StringHelper.getRandomId());
                                    String parent = parents.get(bean.getArea());
                                    if (parent == null) {
                                        parent = "0";
                                    }
                                    parent = content.createContent(ctx, bean, parent, false);
                                    parents.put(bean.getArea(), parent);
                                }
                            }
                        }
                        if (duplicateChildren) {
                            for (MenuElement child : page.getChildMenuElements()) {
                                MenuElement newChild = ContentHelper.createChild(noAreaCtx, newPage);
                                ContentElementList contentList = child.getContent(noAreaCtx);
                                Map<String, String> parents = new HashMap<String, String>();
                                while (contentList.hasNext(noAreaCtx)) {
                                    IContentVisualComponent comp = contentList.next(noAreaCtx);
                                    if (!comp.isRepeat()) {
                                        ComponentBean bean = new ComponentBean(comp.getComponentBean());
                                        bean.setId(StringHelper.getRandomId());
                                        String parent = parents.get(bean.getArea());
                                        if (parent == null) {
                                            parent = "0";
                                        }
                                        parent = content.createContent(ctx, newChild, bean, parent, false);
                                        parents.put(bean.getArea(), parent);
                                    }
                                }
                            }
                        }
                        ctx.getCurrentPage().releaseCache();
                    } else if (create) {
                        GlobalContext globalContext = GlobalContext.getInstance(ctx.getRequest());
                        Collection<String> tags = null;
                        if (globalContext.getTags().size() > 0) {
                            tags = new LinkedList<String>();
                            for (String tag : globalContext.getTags()) {
                                if (rs.getParameter("tag-" + tag, null) != null) {
                                    tags.add(tag);
                                }
                            }
                        }
                        MacroHelper.addContentInPage(ctxLg, newPage, rootPage.getName().toLowerCase(), articleDate, tags);
                    }
                    newURL = URLHelper.createURL(ctxLg.getContextWithOtherRenderMode(ContentContext.PREVIEW_MODE), newPage);
                    newEditURL = URLHelper.createURL(ctxLg.getContextWithOtherRenderMode(ContentContext.EDIT_MODE), newPage);
                    List<String> selectedRole = new LinkedList<String>();
                    for (String role : roles) {
                        if (rs.getParameter("role-" + role, null) != null) {
                            newPage.addEditorRole(role);
                            selectedRole.add(role);
                        }
                    }
                    if (rs.getParameter("email", null) != null) {
                        GlobalContext globalContext = GlobalContext.getInstance(ctx.getRequest());
                        AdminUserFactory userFact = AdminUserFactory.createAdminUserFactory(globalContext, ctx.getRequest().getSession());
                        Set<InternetAddress> receivers = new HashSet<InternetAddress>();
                        for (IUserInfo userInfo : userFact.getUserInfoList()) {
                            Set<String> userRoles = new HashSet<String>(userInfo.getRoles());
                            userRoles.retainAll(selectedRole);
                            if (userRoles.size() > 0) {
                                try {
                                    InternetAddress address = new InternetAddress(userInfo.getEmail());
                                    if (address != null) {
                                        receivers.add(address);
                                    }
                                } catch (Exception e) {
                                    logger.warning(e.getMessage());
                                }
                            }
                        }
                        Mail mail = ctxLg.getCurrentTemplate().getMail(ctxLg, "create-article", ctxLg.getRequestContentLanguage());
                        if (mail == null) {
                            mail = new Mail("new page created.", "a new page was create on : " + URLHelper.createURL(ctxLg.getContextForAbsoluteURL().getContextWithOtherRenderMode(ContentContext.VIEW_MODE)));
                        } else {
                            ContentContext mailContext = ctxLg.getContextWithOtherRenderMode(ContentContext.VIEW_MODE);
                            mailContext.setPath(newPage.getPath());
                            mail.setContent(XHTMLHelper.replaceJSTLData(mailContext, mail.getContent()));
                            mail.setSubject(XHTMLHelper.replaceJSTLData(mailContext, mail.getSubject()));
                        }
                        Mailing m = new Mailing();
                        m.setFrom(new InternetAddress(globalContext.getAdministratorEmail()));
                        m.setReceivers(receivers);
                        m.setSubject(mail.getSubject());
                        m.setAdminEmail(globalContext.getAdministratorEmail());
                        m.setNotif(null);
                        m.setContent(mail.getContent());
                        m.setHtml(mail.isHtml());
                        Calendar calendar = Calendar.getInstance();
                        calendar.roll(Calendar.MINUTE, 5);
                        m.setSendDate(calendar.getTime());
                        m.store(ctx.getRequest().getSession().getServletContext());
                    }
                }
            } else {
                message = "parent page not found.";
            }
        } else {
            message = pageName + " not found.";
        }
        MacroModuleContext.getInstance(ctx.getRequest()).setActiveMacro(null);
        if (ctx.isEditPreview()) {
            if (newURL != null && create) {
                newEditURL = URLHelper.addParam(newEditURL, "module", "content");
                newEditURL = URLHelper.addParam(newEditURL, "webaction", "editPreview");
                newEditURL = URLHelper.addParam(newEditURL, "webaction", "edit.changeArea");
                newEditURL = URLHelper.addParam(newEditURL, ContentContext.PREVIEW_EDIT_PARAM, "true");
                newEditURL = URLHelper.addParam(newEditURL, "lightEdit", "true");
                newEditURL = URLHelper.addParam(newEditURL, "area", ComponentBean.DEFAULT_AREA);
            }
            if (create && isEditPopup()) {
                NetHelper.sendRedirectTemporarily(ctx.getResponse(), newEditURL);
            } else {
                ctx.setParentURL(newURL);
                ctx.setClosePopup(true);
            }
        // ctx.getRequest().getRequestDispatcher(editPressrealseURL).forward(ctx.getRequest(),
        // ctx.getResponse());
        /*
				 * ctx.setClosePopup(true); if (newURL != null) { ctx.setParentURL(newURL); }
				 */
        }
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
    return message;
}
Also used : GlobalContext(org.javlo.context.GlobalContext) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) AdminUserFactory(org.javlo.user.AdminUserFactory) MenuElement(org.javlo.navigation.MenuElement) HashSet(java.util.HashSet) ComponentBean(org.javlo.component.core.ComponentBean) Calendar(java.util.Calendar) ContentService(org.javlo.service.ContentService) Mailing(org.javlo.mailing.Mailing) ContentElementList(org.javlo.component.core.ContentElementList) Date(java.util.Date) LinkedList(java.util.LinkedList) Mail(org.javlo.mailing.Mail) IUserInfo(org.javlo.user.IUserInfo) IContentVisualComponent(org.javlo.component.core.IContentVisualComponent) Collection(java.util.Collection) ContentContext(org.javlo.context.ContentContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AdminUserFactory

use of org.javlo.user.AdminUserFactory in project javlo by Javlo.

the class TicketAction method sendTicketSummaryNotification.

private static void sendTicketSummaryNotification(ContentContext ctx, List<TicketBean> tickets, String subject, boolean reply) throws Exception {
    AdminUserFactory userFactory = AdminUserFactory.createUserFactory(ctx.getGlobalContext(), ctx.getRequest().getSession());
    Map<String, List<TicketBean>> ticketsByUser = new HashMap<String, List<TicketBean>>();
    for (TicketBean ticket : tickets) {
        for (String user : ticket.getUsers()) {
            List<TicketBean> list = ticketsByUser.get(user);
            if (list == null) {
                list = new LinkedList<TicketBean>();
                ticketsByUser.put(user, list);
            }
            list.add(ticket);
        }
        if (reply && StringHelper.isMail(ticket.getAuthors())) {
            List<TicketBean> list = ticketsByUser.get(ticket.getAuthors());
            if (list == null) {
                list = new LinkedList<TicketBean>();
                ticketsByUser.put(ticket.getAuthors(), list);
            }
            list.add(ticket);
        }
    }
    for (Entry<String, List<TicketBean>> entry : ticketsByUser.entrySet()) {
        sendUserTicketSummaryNotification(ctx, userFactory, entry.getKey(), entry.getValue(), subject);
    }
}
Also used : HashMap(java.util.HashMap) AdminUserFactory(org.javlo.user.AdminUserFactory) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

AdminUserFactory (org.javlo.user.AdminUserFactory)18 LinkedList (java.util.LinkedList)11 IUserInfo (org.javlo.user.IUserInfo)9 User (org.javlo.user.User)9 GlobalContext (org.javlo.context.GlobalContext)7 Date (java.util.Date)5 HashSet (java.util.HashSet)5 ContentContext (org.javlo.context.ContentContext)5 HashMap (java.util.HashMap)4 GenericMessage (org.javlo.message.GenericMessage)4 InternetAddress (javax.mail.internet.InternetAddress)3 I18nAccess (org.javlo.i18n.I18nAccess)3 MenuElement (org.javlo.navigation.MenuElement)3 ContentService (org.javlo.service.ContentService)3 IUserFactory (org.javlo.user.IUserFactory)3 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 AddressException (javax.mail.internet.AddressException)2 HttpSession (javax.servlet.http.HttpSession)2 ComponentBean (org.javlo.component.core.ComponentBean)2