Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-54837 some porltet actions need to be executed in live too (such as subscribe in some situations) #25543

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -71,7 +71,7 @@ Group scopeGroup = themeDisplay.getScopeGroup();
</c:if>

<div class="subscribe-action">
<c:if test="<%= !portletName.equals(AssetPublisherPortletKeys.HIGHEST_RATED_ASSETS) && !portletName.equals(AssetPublisherPortletKeys.MOST_VIEWED_ASSETS) && !portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT) && !portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS) && PortletPermissionUtil.contains(permissionChecker, plid, portletDisplay.getId(), ActionKeys.SUBSCRIBE) && AssetPublisherUtil.getEmailAssetEntryAddedEnabled(portletPreferences) %>">
<c:if test="<%= !portletName.equals(AssetPublisherPortletKeys.HIGHEST_RATED_ASSETS) && !portletName.equals(AssetPublisherPortletKeys.MOST_VIEWED_ASSETS) && !portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT) && !portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS) && PortletPermissionUtil.contains(permissionChecker, 0, layout, portletDisplay.getId(), ActionKeys.SUBSCRIBE, false, false) && AssetPublisherUtil.getEmailAssetEntryAddedEnabled(portletPreferences) %>">
<c:choose>
<c:when test="<%= AssetPublisherUtil.isSubscribed(themeDisplay.getCompanyId(), user.getUserId(), themeDisplay.getPlid(), portletDisplay.getId()) %>">
<portlet:actionURL name="unsubscribe" var="unsubscribeURL">
Expand Down
Expand Up @@ -1235,8 +1235,11 @@ public static void subscribe(
String portletId)
throws PortalException {

Layout layout = LayoutLocalServiceUtil.fetchLayout(plid);

PortletPermissionUtil.check(
permissionChecker, plid, portletId, ActionKeys.SUBSCRIBE);
permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE,
false, false);

SubscriptionLocalServiceUtil.addSubscription(
permissionChecker.getUserId(), groupId,
Expand All @@ -1256,8 +1259,11 @@ public static void unsubscribe(
PermissionChecker permissionChecker, long plid, String portletId)
throws PortalException {

Layout layout = LayoutLocalServiceUtil.fetchLayout(plid);

PortletPermissionUtil.check(
permissionChecker, plid, portletId, ActionKeys.SUBSCRIBE);
permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE,
false, false);

SubscriptionLocalServiceUtil.deleteSubscription(
permissionChecker.getUserId(),
Expand Down
Expand Up @@ -47,6 +47,8 @@
*/
public class PortletPermissionImpl implements PortletPermission {

public static final boolean DEFAULT_CHECK_STAGING_PERMISSION = true;

public static final boolean DEFAULT_STRICT = false;

@Override
Expand Down Expand Up @@ -96,9 +98,21 @@ public void check(
String portletId, String actionId, boolean strict)
throws PortalException {

check(
permissionChecker, groupId, layout, portletId, actionId, strict,
DEFAULT_CHECK_STAGING_PERMISSION);
}

@Override
public void check(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException {

if (!contains(
permissionChecker, groupId, layout, portletId, actionId,
strict)) {
permissionChecker, groupId, layout, portletId, actionId, strict,
checkStagingPermission)) {

throw new PrincipalException();
}
Expand Down Expand Up @@ -243,6 +257,18 @@ public boolean contains(
String portletId, String actionId, boolean strict)
throws PortalException {

return contains(
permissionChecker, groupId, layout, portletId, actionId, strict,
DEFAULT_CHECK_STAGING_PERMISSION);
}

@Override
public boolean contains(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException {

String name = null;
String primKey = null;

Expand Down Expand Up @@ -274,11 +300,13 @@ public boolean contains(

name = PortletConstants.getRootPortletId(portletId);

Boolean hasPermission = StagingPermissionUtil.hasPermission(
permissionChecker, groupId, name, groupId, name, actionId);
if (checkStagingPermission) {
Boolean hasPermission = StagingPermissionUtil.hasPermission(
permissionChecker, groupId, name, groupId, name, actionId);

if (hasPermission != null) {
return hasPermission.booleanValue();
if (hasPermission != null) {
return hasPermission.booleanValue();
}
}

if (group.isControlPanel() && actionId.equals(ActionKeys.VIEW)) {
Expand Down
Expand Up @@ -49,6 +49,12 @@ public void check(
String portletId, String actionId, boolean strict)
throws PortalException;

public void check(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException;

public void check(
PermissionChecker permissionChecker, long groupId, long plid,
String portletId, String actionId)
Expand Down Expand Up @@ -114,6 +120,12 @@ public boolean contains(
String portletId, String actionId, boolean strict)
throws PortalException;

public boolean contains(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException;

public boolean contains(
PermissionChecker permissionChecker, long groupId, long plid,
Portlet portlet, String actionId, boolean strict)
Expand Down
Expand Up @@ -68,6 +68,17 @@ public static void check(
permissionChecker, groupId, layout, portletId, actionId, strict);
}

public static void check(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException {

getPortletPermission().check(
permissionChecker, groupId, layout, portletId, actionId, strict,
checkStagingPermission);
}

public static void check(
PermissionChecker permissionChecker, long groupId, long plid,
String portletId, String actionId)
Expand Down Expand Up @@ -184,6 +195,17 @@ public static boolean contains(
permissionChecker, groupId, layout, portletId, actionId, strict);
}

public static boolean contains(
PermissionChecker permissionChecker, long groupId, Layout layout,
String portletId, String actionId, boolean strict,
boolean checkStagingPermission)
throws PortalException {

return getPortletPermission().contains(
permissionChecker, groupId, layout, portletId, actionId, strict,
checkStagingPermission);
}

/**
* @deprecated As of 6.2.0, replaced by {@link
* #hasControlPanelAccessPermission(PermissionChecker, long,
Expand Down