Foros de discusión

How to Enable Permissions on Discussions (Comments) in Custom Portlet

thumbnail
Randy Parsons, modificado hace 9 años.

How to Enable Permissions on Discussions (Comments) in Custom Portlet

Junior Member Mensajes: 33 Fecha de incorporación: 4/01/11 Mensajes recientes
I am attempting to add Comments (Discussions) to my custom portlet using the liferay-ui:discussion taglib in Liferay 6.1.20 After searching around I have finally got it to work using the following setup:
JSP Page
<portlet:actionurl var="discussionURL" name="addDiscussion" />
		
<liferay-ui:discussion className="<%= Announcement.class.getName() %>" classPK="<%= announcement.getPrimaryKey() %>" formAction="<%= discussionURL %>" formName="fm2" ratingsEnabled="<%= false %>" redirect="<%= currentURL %>" subject="<%= announcement.getHeadline() %>" userId="<%= themeDisplay.getUserId() %>" />

Portlet Class
public void addDiscussion(ActionRequest actionRequest,ActionResponse actionResponse){  
		try { 			
			invokeTaglibDiscussion(actionRequest, actionResponse);  
		} catch (Exception e) {  
			_log.error("There was an Error adding a comment to the Announcement");
		}  
	}

This is the first workaround I had to do, because when I followed the book Liferay In Action (which is a great source of information) I shouldn't have had to add the code to the Portlet Class since the class extends the MVCPortlet (Note: in jsp page name was changed to "invokeTaglibDiscussion") . However unless I added the above code I kept getting a NoSuchMethodException error indicating it couldn't find the invokeTaglibDiscussion method in the class even though it is part of the the MVCPortlet.
So with that resolved, I now had a working form that users could add comments and reply to other comments previously added.

Main Question
The problem is any user can edit, delete anyone's comment. Can someone please direct me to solve this last missing component for this functionality to work as expected.
Thanks
thumbnail
Rahul Pande, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
Randy Parsons:
Main Question
The problem is any user can edit, delete anyone's comment. Can someone please direct me to solve this last missing component for this functionality to work as expected.


Were you be able to figure this out ? I am also stuck on the same issue and even tried assigning various permissions to the role but none of them is working.

Can anybody post the working set of permissions that needs to assigned to make this functionality work ? emoticon

Thanks for helping.
Rahul Pande
thumbnail
Rahul Pande, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
Update : I followed the steps suggested in this forum post. Though it gives control over enabling / disabling the add / update / delete discussions, it still doesn't solve the issue.

Please give it a try and reply if it works for you. emoticon

Thanks in advance.
Rahul Pande
thumbnail
Randy Parsons, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Junior Member Mensajes: 33 Fecha de incorporación: 4/01/11 Mensajes recientes
Hi Rahul,
Thanks for the posting/link. When I saw it, I thought for sure this would be it, but unfortunately I still get the same issue - anyone can edit anyone's comments.

I tried a number of different things, including removing the original 'document' and adding a new one before any comments were added. What's interesting is that I can see the discussion being added to the 'mbmessage' table but nothing to the 'resourcepermission' table which is what I'd expect when each comment (discussion) was added - otherwise, how would the permission be checked/verified?

What did you mean by
Though it gives control over enabling / disabling the add / update / delete discussions
? Are the buttons being removed?

Let me know if you make any headway.

Thanks again,
Randy
thumbnail
Rahul Pande, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
Randy Parsons:
What did you mean by
Though it gives control over enabling / disabling the add / update / delete discussions
? Are the buttons being removed?


I am able to see the custom portlet while assigning the permissions to a role with permissions like Add Discussion / Delete Discussion etc. If I uncheck the Add Discussion for say User role, then logged in user will not be able to add comment. So this means permissions are being applied to our custom portlet. Please find the attached screen shot.

My other observation is, blogs portlet have similar permissions and comments work as expected without checking any of the permission for model class i.e BlogsEntry, but same permissions are not working for custom portlet.

I hope this will help.

Thank you,
Rahul
thumbnail
Randy Parsons, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Junior Member Mensajes: 33 Fecha de incorporación: 4/01/11 Mensajes recientes
Hi Rahul,

I also see that my custom portlet shows up under Add Permissions, however none of the added Permissions are checked by default, where if I understood you correctly - yours were. So, that brings me to the custom permission xml file. Here is mine as a comparisons. I figure if we both are trying to resolve (which I appreciate your comments) we should make sure we are comparing the same configuration settings.
default.xml File

<resource-action-mapping>
   ...
          <model-resource>
		<model-name>com.ca.dbServices.model.Announcement</model-name>
		<portlet-ref>
			<portlet-name>company-announcements</portlet-name>
		</portlet-ref>
		<permissions>
			<supports>
				<action-key>ADD_ANNOUNCEMENT</action-key>
				<action-key>UPDATE_ANNOUNCEMENT</action-key>
				<action-key>MOVE_ANNOUNCEMENT</action-key>
				<action-key>DELETE_ANNOUNCEMENT</action-key>
				<action-key>ADD_DISCUSSION</action-key>
				<action-key>DELETE_DISCUSSION</action-key>
				<action-key>UPDATE_DISCUSSION</action-key>				
			</supports>			
			<site-member-defaults>
				<action-key>ADD_DISCUSSION</action-key>
			</site-member-defaults>
			<guest-defaults />
			<guest-unsupported>
				<action-key>ADD_ANNOUNCEMENT</action-key>
				<action-key>UPDATE_ANNOUNCEMENT</action-key>
				<action-key>MOVE_ANNOUNCEMENT</action-key>
				<action-key>DELETE_ANNOUNCEMENT</action-key>
				<action-key>PERMISSIONS</action-key>
				<action-key>ADD_DISCUSSION</action-key>
				<action-key>DELETE_DISCUSSION</action-key>
				<action-key>UPDATE_DISCUSSION</action-key>
			 </guest-unsupported>
		</permissions>
	</model-resource>
</resource-action-mapping>

So, to me, based on these settings, the User role should never had been able to add comments in the first place. I'm not convinced we are going down the correct path to resolve this - especially when none of this is mentioned in the Liferay Developer section or the Liferay in Action book that I have.

Also, quick questions:
  • Does your Portlet class extend MVCPortlet?
  • Are you using the invokeTaglibDiscussion(actionRequest, actionResponse); or
    PortletActionInvoker.processAction( "com.liferay.portlet.messageboards.action.EditDiscussionAction", null, actionRequest, actionResponse); in your addDiscussion action method?
  • Can you show the code you used for your <portlet:actionURL> in your JSP


Thanks again,
Randy
thumbnail
Rahul Pande, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
however none of the added Permissions are checked by default, where if I understood you correctly - yours were.

Even for me none of added permission were checked by default. I enabled the ADD_DISCUSSION permission explicitely for User role to enable commenting for logged in user. The screen shot I attached is the permissions I tried to verify the issue .

First of all I am using Liferay 6.2 CE GA2 and it seems you are using Liferay 6.1 version.

Does your Portlet class extend MVCPortlet?

Yes. I am using Liferay MVC portlet.

Are you using the invokeTaglibDiscussion(actionRequest, actionResponse); or
PortletActionInvoker.processAction( "com.liferay.portlet.messageboards.action.EditDiscussionAction", null, actionRequest, actionResponse); in your addDiscussion action method?

I am using invokeTaglibDiscussion(actionRequest, actionResponse).

Can you show the code you used for your <portlet:actionURL> in your JSP

It is a pretty normal action call similar to other action methods.
<portlet:actionURL name="updateDiscussion" var="updateDiscussionURL" />

I could not post the code here as my machine is dead emoticon, I'll keep you posted once I get it up and running.

Thanks,
Rahul
thumbnail
Randy Parsons, modificado hace 9 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Junior Member Mensajes: 33 Fecha de incorporación: 4/01/11 Mensajes recientes
Hi Rahul,

Have you had any success with this yet? I can't believe no one is able to provide a solution. I would have thought this would have been a common component for a custom portlet.
Venkat N, modificado hace 7 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

New Member Mensajes: 11 Fecha de incorporación: 14/02/12 Mensajes recientes
Guys,

Any updates for the above issue please let me know.
Harsh Kanakhara, modificado hace 6 años.

RE: How to Enable Permissions on Discussions (Comments) in Custom Portlet

Junior Member Mensajes: 74 Fecha de incorporación: 6/04/17 Mensajes recientes
Any updates ? I am using DXP SP4.

Regards,
Harsh Kanakhara.