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-153687 Add fetchSharingCollaborators to the Info display Context #2636

Closed
wants to merge 7 commits into from
Closed
@@ -1,6 +1,6 @@
Bundle-Name: Liferay Content Dashboard API
Bundle-SymbolicName: com.liferay.content.dashboard.api
Bundle-Version: 2.2.1
Bundle-Version: 2.3.0
Export-Package:\
com.liferay.content.dashboard.item.action,\
com.liferay.content.dashboard.item.action.exception,\
Expand Down
Expand Up @@ -35,8 +35,8 @@ public interface ContentDashboardItemAction {

public enum Type {

DELETE, DOWNLOAD, EDIT, PREVIEW, PREVIEW_IMAGE, SHARING_BUTTON, VIEW,
VIEW_IN_PANEL
DELETE, DOWNLOAD, EDIT, PREVIEW, PREVIEW_IMAGE, SHARING_BUTTON,
SHARING_COLLABORATORS, VIEW, VIEW_IN_PANEL

}

Expand Down
@@ -1 +1 @@
version 1.2.0
version 1.3.0
@@ -0,0 +1,111 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.content.dashboard.blogs.internal.item.action;

import com.liferay.blogs.model.BlogsEntry;
import com.liferay.content.dashboard.item.action.ContentDashboardItemAction;
import com.liferay.petra.portlet.url.builder.PortletURLBuilder;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.LiferayWindowState;
import com.liferay.portal.kernel.util.JavaConstants;
import com.liferay.portal.kernel.util.Portal;

import java.util.Locale;

import javax.portlet.PortletResponse;

import javax.servlet.http.HttpServletRequest;

/**
* @author Cristina González
*/
public class SharingCollaboratorsBlogsEntryContentDashboardItemAction
implements ContentDashboardItemAction {

public SharingCollaboratorsBlogsEntryContentDashboardItemAction(
BlogsEntry blogsEntry, HttpServletRequest httpServletRequest,
Language language, Portal portal) {

_blogsEntry = blogsEntry;
_httpServletRequest = httpServletRequest;
_language = language;
_portal = portal;
}

@Override
public String getIcon() {
return "share";
}

@Override
public String getLabel(Locale locale) {
return _language.get(locale, "share");
}

@Override
public String getName() {
return "share";
}

@Override
public Type getType() {
return Type.SHARING_COLLABORATORS;
}

@Override
public String getURL() {
try {
PortletResponse portletResponse =
(PortletResponse)_httpServletRequest.getAttribute(
JavaConstants.JAVAX_PORTLET_RESPONSE);

return PortletURLBuilder.createRenderURL(
_portal.getLiferayPortletResponse(portletResponse),
"com_liferay_content_dashboard_web_portlet_" +
"ContentDashboardAdminPortlet"
).setMVCPath(
"/sharing_collaborators.jsp"
).setParameter(
"className", BlogsEntry.class.getName()
).setParameter(
"classPK", _blogsEntry.getEntryId()
).setWindowState(
LiferayWindowState.EXCLUSIVE
).buildString();
}
catch (Exception exception) {
_log.error(exception);

return StringPool.BLANK;
}
}

@Override
public String getURL(Locale locale) {
return getURL();
}

private static final Log _log = LogFactoryUtil.getLog(
SharingCollaboratorsBlogsEntryContentDashboardItemAction.class);

private final BlogsEntry _blogsEntry;
private final HttpServletRequest _httpServletRequest;
private final Language _language;
private final Portal _portal;

}
@@ -0,0 +1,129 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.content.dashboard.blogs.internal.item.action.provider;

import com.liferay.blogs.model.BlogsEntry;
import com.liferay.content.dashboard.blogs.internal.item.action.SharingCollaboratorsBlogsEntryContentDashboardItemAction;
import com.liferay.content.dashboard.item.action.ContentDashboardItemAction;
import com.liferay.content.dashboard.item.action.provider.ContentDashboardItemActionProvider;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import com.liferay.portal.kernel.service.ClassNameLocalService;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.sharing.configuration.SharingConfiguration;
import com.liferay.sharing.configuration.SharingConfigurationFactory;
import com.liferay.sharing.security.permission.SharingPermission;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Cristina González
*/
@Component(service = ContentDashboardItemActionProvider.class)
public class SharingCollaboratorsBlogsEntryContentDashboardItemActionProvider
implements ContentDashboardItemActionProvider<BlogsEntry> {

@Override
public ContentDashboardItemAction getContentDashboardItemAction(
BlogsEntry blogsEntry, HttpServletRequest httpServletRequest) {

if (!isShow(blogsEntry, httpServletRequest)) {
return null;
}

return new SharingCollaboratorsBlogsEntryContentDashboardItemAction(
blogsEntry, httpServletRequest, _language, _portal);
}

@Override
public String getKey() {
return "share";
}

@Override
public ContentDashboardItemAction.Type getType() {
return ContentDashboardItemAction.Type.SHARING_COLLABORATORS;
}

@Override
public boolean isShow(
BlogsEntry blogsEntry, HttpServletRequest httpServletRequest) {

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

try {
if (_isSharingEnabled(themeDisplay.getScopeGroupId()) &&
_sharingPermission.containsSharePermission(
themeDisplay.getPermissionChecker(),
_classNameLocalService.getClassNameId(
BlogsEntry.class.getName()),
blogsEntry.getEntryId(), themeDisplay.getScopeGroupId())) {

return true;
}
}
catch (PortalException portalException) {
_log.error(portalException);

return false;
}

return false;
}

private boolean _isSharingEnabled(long groupId) throws PortalException {
SharingConfiguration sharingConfiguration =
_sharingConfigurationFactory.getGroupSharingConfiguration(
_groupLocalService.getGroup(groupId));

return sharingConfiguration.isEnabled();
}

private static final Log _log = LogFactoryUtil.getLog(
SharingCollaboratorsBlogsEntryContentDashboardItemActionProvider.class);

@Reference
private ClassNameLocalService _classNameLocalService;

@Reference
private GroupLocalService _groupLocalService;

@Reference
private Language _language;

@Reference(target = "(model.class.name=com.liferay.blogs.model.BlogsEntry)")
private ModelResourcePermission<BlogsEntry> _modelResourcePermission;

@Reference
private Portal _portal;

@Reference
private SharingConfigurationFactory _sharingConfigurationFactory;

@Reference
private SharingPermission _sharingPermission;

}
@@ -0,0 +1,111 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.content.dashboard.document.library.internal.item.action;

import com.liferay.content.dashboard.item.action.ContentDashboardItemAction;
import com.liferay.petra.portlet.url.builder.PortletURLBuilder;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.LiferayWindowState;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.util.JavaConstants;
import com.liferay.portal.kernel.util.Portal;

import java.util.Locale;

import javax.portlet.PortletResponse;

import javax.servlet.http.HttpServletRequest;

/**
* @author Cristina González
*/
public class SharingCollaboratorsFileEntryContentDashboardItemAction
implements ContentDashboardItemAction {

public SharingCollaboratorsFileEntryContentDashboardItemAction(
FileEntry fileEntry, HttpServletRequest httpServletRequest,
Language language, Portal portal) {

_fileEntry = fileEntry;
_httpServletRequest = httpServletRequest;
_language = language;
_portal = portal;
}

@Override
public String getIcon() {
return "share";
}

@Override
public String getLabel(Locale locale) {
return _language.get(locale, "share");
}

@Override
public String getName() {
return "share";
}

@Override
public Type getType() {
return Type.SHARING_COLLABORATORS;
}

@Override
public String getURL() {
try {
PortletResponse portletResponse =
(PortletResponse)_httpServletRequest.getAttribute(
JavaConstants.JAVAX_PORTLET_RESPONSE);

return PortletURLBuilder.createRenderURL(
_portal.getLiferayPortletResponse(portletResponse),
"com_liferay_content_dashboard_web_portlet_" +
"ContentDashboardAdminPortlet"
).setMVCPath(
"/sharing_collaborators_button.jsp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgoncas maybe we missed to rename this path to "/sharing_collaborators.jsp"
i'm getting an error I did not realized before:

javax.portlet.PortletException: Path /sharing_collaborators_button.jsp is not accessible by portlet com_liferay_content_dashboard_web_portlet_ContentDashboardAdminPortlet

thxs!

).setParameter(
"className", FileEntry.class.getName()
).setParameter(
"classPK", _fileEntry.getFileEntryId()
).setWindowState(
LiferayWindowState.EXCLUSIVE
).buildString();
}
catch (Exception exception) {
_log.error(exception);

return StringPool.BLANK;
}
}

@Override
public String getURL(Locale locale) {
return getURL();
}

private static final Log _log = LogFactoryUtil.getLog(
SharingCollaboratorsFileEntryContentDashboardItemAction.class);

private final FileEntry _fileEntry;
private final HttpServletRequest _httpServletRequest;
private final Language _language;
private final Portal _portal;

}