Flagging Inappropriate Asset Content

As you’re undoubtedly aware, users can sometimes cross the line with what they post. When users are able to report inappropriate content, a greater sense of community and collaboration develops as users establish what kinds of things will and won’t be tolerated by the community. This also takes much of the monitoring work off the backs of administrators. Liferay’s asset framework fortunately has you covered–you can leverage it to let users report inappropriate content posted by others. Users can click a flag which opens a small form they can fill out, letting administrators know why they find the content objectionable. You’ve probably seen this flag in Liferay’s built in portlets. For example, each blog in the Blogs portlet can be flagged as inappropriate by users.

Figure 1: Flags for letting users mark objectionable content are enabled in the built in Blogs portlet

Figure 1: Flags for letting users mark objectionable content are enabled in the built in Blogs portlet

This tutorial shows you how to enable flagging of content in a portlet. As a prerequisite, you must have assets enabled for your portlet’s custom entity before you can enable content flagging. This tutorial demonstrates implementing this feature in a custom Insults portlet. Coming up with great insults is a natural part of comedy, but sometimes things can go too far. It’s for these situations that flagging inappropriate content is useful. You can find the Insults portlet complete with the flagging feature enabled on Github.

Now it’s time to get on with the flagging!

If you’ve implemented asset rendering for your entity, you can use flags in the full content view of an Asset Publisher portlet. You can also use flags in any view JSP you create for viewing the entity.

As an example, the Insult portlet’s view JSP file view_insult.jsp shows an insult entity and the flagging component. This tutorial shows you how to associate the flagging component with your custom entity.

In your view JSP, you can use ParamUtil to get the ID of the entity from the render request. Then you can create an entity object using your -LocalServiceUtil class.

long insultId = ParamUtil.getLong(renderRequest, "insultId");
Insult ins = InsultLocalServiceUtil.getInsult(insultId);

Now you just need to implement the flagging itself. This is done with the liferay-ui:flags tag. Here’s the liferay-ui:flags tag for the Insults portlet:

    className="<%= Insult.class.getName() %>"
    classPK="<%= ins.getInsultId() %>"
    contentTitle="<%= ins.getInsultString() %>"
    reportedUserId="<%= ins.getUserId() %>"

Awesome! Now you have a JSP that lets your users flag inappropriate content in your portlet.

If you haven’t already connected your portlet’s view to the JSP for your entity, you can refer here to see how to connect your portlet’s main view JSP to your entity’s view JSP.

Now redeploy your portlet and refresh the page so that the your plugin’s UI reloads. The flag icon appears at the bottom of the page.

Figure 2: Users can now flag content in your portlet as inappropriate.

Figure 2: Users can now flag content in your portlet as inappropriate.

Great! Now you know how to let users flag inappropriate content in your asset enabled portlets.

Another thing you might want to do is perform permissions checks to control who can flag content. For example, the Add Insult and Permissions buttons of the Insults portlet are wrapped in a permissions check in the view.jsp. For more information on this, see the Learning Path Checking for Permissions in the UI.

Related Topics

Customizing Liferay Portal

Liferay UI Taglibs

User Interfaces with AlloyUI

Service Builder and Services

« Apply Social BookmarksIntroduction to Recycle Bin »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0