Commit 02232d3a authored by Elias Englmeier's avatar Elias Englmeier
Browse files

added permissions for disucssions to the Ideas model and the comments portlet

parent c9df0150
......@@ -13,6 +13,6 @@
##
build.namespace=ANALYSIS
build.number=83
build.date=1522056491388
build.number=88
build.date=1525249567016
build.auto.upgrade=true
\ No newline at end of file
package comment.portlet;
import java.io.IOException;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
......@@ -12,8 +11,6 @@ import javax.portlet.RenderResponse;
import org.osgi.service.component.annotations.Component;
import com.liferay.message.boards.kernel.model.MBMessage;
import com.liferay.message.boards.kernel.service.MBMessageLocalServiceUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.theme.ThemeDisplay;
......@@ -36,7 +33,7 @@ import ideaService.service.IdeasLocalServiceUtil;
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + commentPortletKeys.comment,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
"javax.portlet.security-role-ref=power-user"
},
service = Portlet.class
)
......@@ -49,7 +46,7 @@ public class commentPortlet extends MVCPortlet {
long layoutRef = (themeDisplay.getLayout().getPrimaryKey());
Ideas idea = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(layoutRef);
//This is the code we need for fetching all the messages - if ever we need to put it in the UI
/*List<MBMessage> msgs = MBMessageLocalServiceUtil.getMessages(Ideas.class.getName(), idea.getIdeasId(), 0);
for(int i = 0; i < msgs.size(); i++){
......@@ -57,14 +54,14 @@ public class commentPortlet extends MVCPortlet {
System.out.println(msgs.get(i).getSubject());
}
}*/
renderRequest.setAttribute("classPK", idea.getIdeasId());
renderRequest.setAttribute("userID", themeDisplay.getUserId());
renderRequest.setAttribute("classPK", idea.getPrimaryKey());
renderRequest.setAttribute("userId", themeDisplay.getUserId());
renderRequest.setAttribute("currentURL", themeDisplay.getURLCurrent());
renderRequest.setAttribute("className", Ideas.class.getName());
}catch(Exception ex){
System.out.println(ex);
ex.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
......
<?xml version="1.0"?>
<!DOCTYPE resource-action-mapping PUBLIC "-//Liferay//DTD Resource Action
Mapping 7.0.0//EN" "http://www.liferay.com/dtd/liferay-resource-action-mapping_7_0_0.dtd">
<resource-action-mapping>
<portlet-resource>
<portlet-name>comment_portlet</portlet-name>
<permissions>
<supports>
<action-key>ADD_DISCUSSION</action-key>
<action-key>DELETE</action-key>
<action-key>DELETE_DISCUSSION</action-key>
<action-key>EXPIRE</action-key>
<action-key>PERMISSIONS</action-key>
<action-key>UPDATE</action-key>
<action-key>UPDATE_DISCUSSION</action-key>
<action-key>VIEW</action-key>
</supports>
<site-member-defaults>
<action-key>ADD_DISCUSSION</action-key>
<action-key>UPDATE_DISCUSSION</action-key>
<action-key>VIEW</action-key>
</site-member-defaults>
<guest-defaults>
<action-key>ADD_DISCUSSION</action-key>
<action-key>VIEW</action-key>
</guest-defaults>
<guest-unsupported />
</permissions>
</portlet-resource>
</resource-action-mapping>
\ No newline at end of file
<%@ include file="/init.jsp" %>
<%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
<%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0" %>
<c:set var="currentUrl" value="${currentURL}"/>
<c:set var="class" value="${className}"/>
<portlet:actionURL name="commentTestSubmit" var="discussionURL" />
<!-- Uncomment this to add a rating system to the comment portlet, can serve as the voting for the module
<liferay-ui:ratings
<!-- Uncomment this to add a rating system to the comment portlet, can serve as the voting for the module
<liferay-ui:ratings
className= "${class}"
classPK= "${classPK}"
type="stars"
classPK= "${classPK}"
type="stars"
/>
-->
<liferay-ui:discussion
classPK="${classPK}"
userId="${userID}"
className="${class}"
formAction="<%= discussionURL%>"
<liferay-ui:discussion
classPK="${classPK}"
userId="${userId}"
className="${class}"
formAction="<%= discussionURL%>"
ratingsEnabled="<%=true%>"
formName="fm2"
formName="fm2"
redirect="${currentUrl}"
/>
\ No newline at end of file
/>
\ No newline at end of file
resource.actions.configs=META-INF/resource-actions/default.xml
\ No newline at end of file
......@@ -13,6 +13,6 @@
##
build.namespace=GB
build.number=104
build.date=1522056496060
build.number=109
build.date=1525249571373
build.auto.upgrade=true
\ No newline at end of file
......@@ -663,6 +663,64 @@ public interface IdeasPersistence extends BasePersistence<Ideas> {
com.liferay.portal.kernel.util.OrderByComparator<Ideas> orderByComparator)
throws NoSuchIdeasException;
/**
* Returns all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param groupId the group ID
* @param status the status
* @return the matching ideases that the user has permission to view
*/
public java.util.List<Ideas> filterFindByG_S(long groupId, int status);
/**
* Returns a range of all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @return the range of matching ideases that the user has permission to view
*/
public java.util.List<Ideas> filterFindByG_S(long groupId, int status,
int start, int end);
/**
* Returns an ordered range of all the ideases that the user has permissions to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching ideases that the user has permission to view
*/
public java.util.List<Ideas> filterFindByG_S(long groupId, int status,
int start, int end,
com.liferay.portal.kernel.util.OrderByComparator<Ideas> orderByComparator);
/**
* Returns the ideases before and after the current ideas in the ordered set of ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param ideasId the primary key of the current ideas
* @param groupId the group ID
* @param status the status
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next ideas
* @throws NoSuchIdeasException if a ideas with the primary key could not be found
*/
public Ideas[] filterFindByG_S_PrevAndNext(long ideasId, long groupId,
int status,
com.liferay.portal.kernel.util.OrderByComparator<Ideas> orderByComparator)
throws NoSuchIdeasException;
/**
* Removes all the ideases where groupId = &#63; and status = &#63; from the database.
*
......@@ -680,6 +738,15 @@ public interface IdeasPersistence extends BasePersistence<Ideas> {
*/
public int countByG_S(long groupId, int status);
/**
* Returns the number of ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param groupId the group ID
* @param status the status
* @return the number of matching ideases that the user has permission to view
*/
public int filterCountByG_S(long groupId, int status);
/**
* Caches the ideas in the entity cache if it is enabled.
*
......
......@@ -853,6 +853,74 @@ public class IdeasUtil {
orderByComparator);
}
/**
* Returns all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param groupId the group ID
* @param status the status
* @return the matching ideases that the user has permission to view
*/
public static List<Ideas> filterFindByG_S(long groupId, int status) {
return getPersistence().filterFindByG_S(groupId, status);
}
/**
* Returns a range of all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @return the range of matching ideases that the user has permission to view
*/
public static List<Ideas> filterFindByG_S(long groupId, int status,
int start, int end) {
return getPersistence().filterFindByG_S(groupId, status, start, end);
}
/**
* Returns an ordered range of all the ideases that the user has permissions to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching ideases that the user has permission to view
*/
public static List<Ideas> filterFindByG_S(long groupId, int status,
int start, int end, OrderByComparator<Ideas> orderByComparator) {
return getPersistence()
.filterFindByG_S(groupId, status, start, end,
orderByComparator);
}
/**
* Returns the ideases before and after the current ideas in the ordered set of ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param ideasId the primary key of the current ideas
* @param groupId the group ID
* @param status the status
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next ideas
* @throws NoSuchIdeasException if a ideas with the primary key could not be found
*/
public static Ideas[] filterFindByG_S_PrevAndNext(long ideasId,
long groupId, int status, OrderByComparator<Ideas> orderByComparator)
throws ideaService.exception.NoSuchIdeasException {
return getPersistence()
.filterFindByG_S_PrevAndNext(ideasId, groupId, status,
orderByComparator);
}
/**
* Removes all the ideases where groupId = &#63; and status = &#63; from the database.
*
......@@ -874,6 +942,17 @@ public class IdeasUtil {
return getPersistence().countByG_S(groupId, status);
}
/**
* Returns the number of ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param groupId the group ID
* @param status the status
* @return the number of matching ideases that the user has permission to view
*/
public static int filterCountByG_S(long groupId, int status) {
return getPersistence().filterCountByG_S(groupId, status);
}
/**
* Caches the ideas in the entity cache if it is enabled.
*
......
......@@ -28,6 +28,7 @@ import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManagerUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutFriendlyURL;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.search.Document;
......@@ -257,6 +258,10 @@ public class IdeasLocalServiceImpl extends IdeasLocalServiceBaseImpl {
DLAppLocalServiceUtil.deleteFileEntry(idea.getVideoFileRef());
}
resourceLocalService.deleteResource(idea.getCompanyId(),
Ideas.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
idea.getPrimaryKey());
return idea;
} catch (PortalException e) {
e.printStackTrace();
......@@ -294,10 +299,13 @@ public class IdeasLocalServiceImpl extends IdeasLocalServiceBaseImpl {
try {
User user = UserLocalServiceUtil.getUser(userId);
nextIdea.setUserName(user.getScreenName());
resourceLocalService.addResources(user.getCompanyId(), groupId, userId, Ideas.class.getName(), nextDbId, false, true, true);
} catch (PortalException e) {
e.printStackTrace();
}
return nextIdea;
}
......@@ -334,6 +342,7 @@ public class IdeasLocalServiceImpl extends IdeasLocalServiceBaseImpl {
try {
User user = UserLocalServiceUtil.getUser(userId);
nextIdea.setUserName(user.getScreenName());
resourceLocalService.addResources(user.getCompanyId(), groupId, userId, Ideas.class.getName(), nextDbId, false, true, true);
} catch (PortalException e) {
e.printStackTrace();
}
......
......@@ -22,9 +22,11 @@ import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
import com.liferay.portal.kernel.service.persistence.CompanyProvider;
......@@ -2637,6 +2639,328 @@ public class IdeasPersistenceImpl extends BasePersistenceImpl<Ideas>
}
}
/**
* Returns all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param groupId the group ID
* @param status the status
* @return the matching ideases that the user has permission to view
*/
@Override
public List<Ideas> filterFindByG_S(long groupId, int status) {
return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @return the range of matching ideases that the user has permission to view
*/
@Override
public List<Ideas> filterFindByG_S(long groupId, int status, int start,
int end) {
return filterFindByG_S(groupId, status, start, end, null);
}
/**
* Returns an ordered range of all the ideases that the user has permissions to view where groupId = &#63; and status = &#63;.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link IdeasModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param groupId the group ID
* @param status the status
* @param start the lower bound of the range of ideases
* @param end the upper bound of the range of ideases (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching ideases that the user has permission to view
*/
@Override
public List<Ideas> filterFindByG_S(long groupId, int status, int start,
int end, OrderByComparator<Ideas> orderByComparator) {
if (!InlineSQLHelperUtil.isEnabled(groupId)) {
return findByG_S(groupId, status, start, end, orderByComparator);
}
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByFields().length * 2));
}
else {
query = new StringBundler(5);
}
if (getDB().isSupportsInlineDistinct()) {
query.append(_FILTER_SQL_SELECT_IDEAS_WHERE);
}
else {
query.append(_FILTER_SQL_SELECT_IDEAS_NO_INLINE_DISTINCT_WHERE_1);
}
query.append(_FINDER_COLUMN_G_S_GROUPID_2);
query.append(_FINDER_COLUMN_G_S_STATUS_2);
if (!getDB().isSupportsInlineDistinct()) {
query.append(_FILTER_SQL_SELECT_IDEAS_NO_INLINE_DISTINCT_WHERE_2);
}
if (orderByComparator != null) {
if (getDB().isSupportsInlineDistinct()) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator, true);
}
else {
appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
orderByComparator, true);
}
}
else {
if (getDB().isSupportsInlineDistinct()) {
query.append(IdeasModelImpl.ORDER_BY_JPQL);
}
else {
query.append(IdeasModelImpl.ORDER_BY_SQL);
}
}
String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
Ideas.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
groupId);
Session session = null;
try {
session = openSession();
SQLQuery q = session.createSynchronizedSQLQuery(sql);
if (getDB().isSupportsInlineDistinct()) {
q.addEntity(_FILTER_ENTITY_ALIAS, IdeasImpl.class);
}
else {
q.addEntity(_FILTER_ENTITY_TABLE, IdeasImpl.class);
}
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(groupId);
qPos.add(status);
return (List<Ideas>)QueryUtil.list(q, getDialect(), start, end);
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
/**
* Returns the ideases before and after the current ideas in the ordered set of ideases that the user has permission to view where groupId = &#63; and status = &#63;.
*
* @param ideasId the primary key of the current ideas
* @param groupId the group ID
* @param status the status
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next ideas
* @throws NoSuchIdeasException if a ideas with the primary key could not be found
*/
@Override
public Ideas[] filterFindByG_S_PrevAndNext(long ideasId, long groupId,
int status, OrderByComparator<Ideas> orderByComparator)
throws NoSuchIdeasException {
if (!InlineSQLHelperUtil.isEnabled(groupId)) {
return findByG_S_PrevAndNext(ideasId, groupId, status,
orderByComparator);
}
Ideas ideas = findByPrimaryKey(ideasId);
Session session = null;
try {
session = openSession();
Ideas[] array = new IdeasImpl[3];
array[0] = filterGetByG_S_PrevAndNext(session, ideas, groupId,
status, orderByComparator, true);
array[1] = ideas;
array[2] = filterGetByG_S_PrevAndNext(session, ideas, groupId,
status, orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);