Example usage for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker.

Prototype

@JSON(include = false)
public PermissionChecker getPermissionChecker() 

Source Link

Document

Returns the permission checker, which is used to ensure users making resource requests have the necessary access permissions.

Usage

From source file:com.liferay.message.boards.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static MBMessageDisplay getMessageDisplay(HttpServletRequest request) throws PortalException {

    long messageId = ParamUtil.getLong(request, "messageId");

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    int status = WorkflowConstants.STATUS_APPROVED;

    if (permissionChecker.isContentReviewer(themeDisplay.getUserId(), themeDisplay.getScopeGroupId())) {

        status = WorkflowConstants.STATUS_ANY;
    }//  w  w  w . j av  a2s.c  om

    MBMessageDisplay messageDisplay = MBMessageServiceUtil.getMessageDisplay(messageId, status);

    if (messageDisplay != null) {
        MBMessage message = messageDisplay.getMessage();

        if ((message != null) && message.isInTrash()) {
            throw new NoSuchMessageException("{messageId=" + messageId + "}");
        }
    }

    return messageDisplay;
}

From source file:com.liferay.message.boards.web.internal.portlet.action.EditMessageMVCActionCommand.java

License:Open Source License

protected MBMessage updateMessage(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long messageId = ParamUtil.getLong(actionRequest, "messageId");

    long groupId = themeDisplay.getScopeGroupId();
    long categoryId = ParamUtil.getLong(actionRequest, "mbCategoryId");
    long threadId = ParamUtil.getLong(actionRequest, "threadId");
    long parentMessageId = ParamUtil.getLong(actionRequest, "parentMessageId");
    String subject = ParamUtil.getString(actionRequest, "subject");
    String body = ParamUtil.getString(actionRequest, "body");

    MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings.getInstance(groupId);

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<>(5);

    try {/*from  w w  w  .j  a v a 2 s  . c  o  m*/
        UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

        for (int i = 1; i <= 5; i++) {
            String fileName = uploadPortletRequest.getFileName("msgFile" + i);
            InputStream inputStream = uploadPortletRequest.getFileAsStream("msgFile" + i);

            if ((inputStream == null) || Validator.isNull(fileName)) {
                continue;
            }

            ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<>(fileName, inputStream);

            inputStreamOVPs.add(inputStreamOVP);
        }

        boolean question = ParamUtil.getBoolean(actionRequest, "question");
        boolean anonymous = ParamUtil.getBoolean(actionRequest, "anonymous");
        double priority = ParamUtil.getDouble(actionRequest, "priority");
        boolean allowPingbacks = ParamUtil.getBoolean(actionRequest, "allowPingbacks");

        ServiceContext serviceContext = ServiceContextFactory.getInstance(MBMessage.class.getName(),
                actionRequest);

        boolean preview = ParamUtil.getBoolean(actionRequest, "preview");

        serviceContext.setAttribute("preview", preview);

        MBMessage message = null;

        if (messageId <= 0) {
            if (PropsValues.CAPTCHA_CHECK_PORTLET_MESSAGE_BOARDS_EDIT_MESSAGE) {

                CaptchaUtil.check(actionRequest);
            }

            if (threadId <= 0) {

                // Post new thread

                message = _mbMessageService.addMessage(groupId, categoryId, subject, body,
                        mbGroupServiceSettings.getMessageFormat(), inputStreamOVPs, anonymous, priority,
                        allowPingbacks, serviceContext);

                if (question) {
                    _mbThreadLocalService.updateQuestion(message.getThreadId(), true);
                }
            } else {

                // Post reply

                message = _mbMessageService.addMessage(parentMessageId, subject, body,
                        mbGroupServiceSettings.getMessageFormat(), inputStreamOVPs, anonymous, priority,
                        allowPingbacks, serviceContext);
            }
        } else {
            List<String> existingFiles = new ArrayList<>();

            for (int i = 1; i <= 5; i++) {
                String path = ParamUtil.getString(actionRequest, "existingPath" + i);

                if (Validator.isNotNull(path)) {
                    existingFiles.add(path);
                }
            }

            // Update message

            message = _mbMessageService.updateMessage(messageId, subject, body, inputStreamOVPs, existingFiles,
                    priority, allowPingbacks, serviceContext);

            if (message.isRoot()) {
                _mbThreadLocalService.updateQuestion(message.getThreadId(), question);
            }
        }

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        boolean subscribe = ParamUtil.getBoolean(actionRequest, "subscribe");

        if (!preview && subscribe
                && MBMessagePermission.contains(permissionChecker, message, ActionKeys.SUBSCRIBE)) {

            _mbMessageService.subscribeMessage(message.getMessageId());
        }

        return message;
    } finally {
        for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {

            InputStream inputStream = inputStreamOVP.getValue();

            StreamUtil.cleanUp(inputStream);
        }
    }
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.CategoryPermissionsPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();/*from ww w  . j  a  v  a2 s.  co m*/

    if (user.isDefaultUser()) {
        return false;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    try {
        MBCategory category = ActionUtil.getCategory(portletRequest);

        if (!MBCategoryPermission.contains(permissionChecker, category, ActionKeys.PERMISSIONS)) {

            return false;
        }
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.CategorySubscriptionPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    try {//from  w w  w.j  ava  2s .  co m
        MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings
                .getInstance(themeDisplay.getScopeGroupId());

        if (!mbGroupServiceSettings.isEmailMessageAddedEnabled()
                && !mbGroupServiceSettings.isEmailMessageUpdatedEnabled()) {

            return false;
        }

        MBCategory category = ActionUtil.getCategory(portletRequest);

        return MBCategoryPermission.contains(themeDisplay.getPermissionChecker(), category,
                ActionKeys.SUBSCRIBE);
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.DeleteCategoryPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {//from www.  java  2 s .co m
        MBCategory category = ActionUtil.getCategory(portletRequest);

        if (category == null) {
            return false;
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (MBCategoryPermission.contains(themeDisplay.getPermissionChecker(), category, ActionKeys.DELETE)) {

            return true;
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.DeleteThreadPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {/*from w  ww .  jav  a 2s.  c  om*/
        MBMessage message = ActionUtil.getMessage(portletRequest);

        MBThread thread = message.getThread();

        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (MBMessagePermission.contains(themeDisplay.getPermissionChecker(), message, ActionKeys.DELETE)
                && !thread.isLocked()) {

            return true;
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.EditCategoryPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {//  w  w w . ja va2  s  .  c  om
        MBCategory category = ActionUtil.getCategory(portletRequest);

        if (category.getCategoryId() == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

            return false;
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (MBCategoryPermission.contains(themeDisplay.getPermissionChecker(), category, ActionKeys.UPDATE)) {

            return true;
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.MoveThreadPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {/*from   w w  w. j  a v a2 s.  c o m*/
        MBCategory category = ActionUtil.getCategory(portletRequest);

        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (MBCategoryPermission.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(),
                getCategoryId(category), ActionKeys.MOVE_THREAD)) {

            return true;
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.PermissionsPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();/*from www. j  a v  a 2 s.  c om*/

    if (user.isDefaultUser()) {
        return false;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!MBPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), ActionKeys.PERMISSIONS)) {

        return false;
    }

    return true;
}

From source file:com.liferay.message.boards.web.internal.portlet.configuration.icon.ThreadLockPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    try {//from   w  ww . j  a  va 2 s  . c  o m
        MBMessage message = ActionUtil.getMessage(portletRequest);

        return MBCategoryPermission.contains(themeDisplay.getPermissionChecker(),
                themeDisplay.getScopeGroupId(), message.getCategoryId(), ActionKeys.LOCK_THREAD);
    } catch (Exception e) {
    }

    return false;
}