Completely hide and restric access to control panel

General Blogs May 27, 2014 By Tauseef Ahmed

By using
#if (($is_signed_in) && $permissionChecker.isCompanyAdmin($company_id))
 dockbar()
#end
in portal_normal.vm we can hide access to control panel but any user can access by using http://localhost:8080/group/control_panel url

To avoid it we can restrict access to control panel by using hook.
  1) Into liferay-hook.xml add:
<portal-properties>portal.properties</portal-properties>

Add portal.properties file to hook's src folder and add this line to it:

servlet.service.events.pre=my.event.portal.ControlPanelAccessPreAction

Create ControlPanelAccessPreAction.java into appropriate package and add next code it:

package my.event.portal;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.RoleServiceUtil;
import com.liferay.portal.service.UserServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
 
/**
 * The ControlPanelAccessPreAction restricts access to Control panel of simple
 * users.
 */
public class ControlPanelAccessPreAction extends Action {
 
  /**
   * Instantiates a new control panel access pre action.
   */
  public ControlPanelAccessPreAction() {
 super();
  }
 
  /*
   * @see com.liferay.portal.kernel.events.Action#run(javax.servlet.http. HttpServletRequest,
   * javax.servlet.http.HttpServletResponse)
   */
  public void run(HttpServletRequest request,
      HttpServletResponse response) throws ActionException {
 try {
 
   ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
   if (GroupLocalServiceUtil.getGroup(themeDisplay.getLayout().getGroupId()).isControlPanel()) {
 
  User currentUser = UserServiceUtil.getUserById(themeDisplay.getUserId());
  if (!RoleServiceUtil.hasUserRole(currentUser.getUserId(),
           currentUser.getCompanyId(),
           "administrator",
           true)) {
    throw new PrincipalException("User " + request.getRemoteUser()
     + " can't access the control panel.");
  }
   
   }
 } catch (Exception ex) {
   throw new ActionException(ex);
 }
  }
}

Liferay - Facebook SSO

General Blogs May 22, 2014 By Tauseef Ahmed

Liferay Single Sign-On using Facebook-SSO

  • First, Log into http://developers.facebook.com with your Facebook credentials
  • Then go to Apps -> Register as a Developer
  • Then Click on -> Apps -> Create a New App

  • Here we have to give the “Display Name” for our application. Also, choose the Category as “Local”.

  • After submitting that, you will get some Client Id and Client Secret Code.
  • Now, Go to our Liferay Control Panel -> Portal Settings -> Authentication -> Facebook

  • Now, Enable the “Enabled” and “Verified Account Required” checkboxes.
  • And also give your client id and client secret code in the given boxes and save your changes.
  • And now sign out and again click the sign in button. There you can find out the facebook link. Click on that link and give your facebook credentials to login to the localhost.

Hope it Helps...!!

Liferay Alloy Popup

General Blogs May 20, 2014 By Tauseef Ahmed


To Display some Html content in Alloy Popup:


< aui:script >
function callPopup(){
AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain', function(A) {
var dialog = new A.Dialog({
title: 'DISPLAY CONTENT',
centered: true,
modal: true,
width: 500,
height: 400,
bodyContent: "This is testing content inside the popup"
}).render();
});

}

</aui:script >

How to put your document library folder under workflow control programmatically

General Blogs May 19, 2014 By Tauseef Ahmed

If you want to create document library folders (dlfolder) programmatically, you can do this very easy by calling


DLFolderLocalServiceUtil.addFolder(userId, groupId, groupId, false0"Folder title""Folder description",falsenew ServiceContext()); 
 
That´s just one line of code and you´re done. But what if you want to put your folder under workflow control? Liferay offers the possibility to connect assets in your folders to specific workflows. So as soon as you upload a basic document for example, the workflow will be started.First, set the file entry types override:
dlFolder.setOverrideFileEntryTypes(true); dlFolder = DLFolderLocalServiceUtil.updateDLFolder(dlFolder);
Then you need to query the DLFileEntryType table for the FileEntryType you want to set up a workflow for. Next, you need to set the DlFileEntries for the folder:
long[] fileEntryTypeIds = new long[] { basicDocumentType.getFileEntryTypeId() };  DLFileEntryTypeLocalServiceUtil.setDLFolderDLFileEntryTypes(dlFolder.getFolderId(), fileEntryTypeIds); 
 
Next is a query to get the process definitions you want your folder and the fileEntryType to connect with:
List<WorkflowDefinition> activeWorkflowDefinitions = WorkflowDefinitionManagerUtil.getActiveWorkflowDefinitions(companyId, "Your Process Name"0100null);
you need to add a workflow definition link:
 
WorkflowDefinitionLinkLocalServiceUtil.addWorkflowDefinitionLink(userId, companyId, groupId, 
DLFolderConstants.getClassName(), dlFolder.getFolderId(), basicDocumentType.getFileEntryTypeId(),  name, version);
 
 

Hide control panel after acccess to liferay 6.1

General Blogs May 13, 2014 By Tauseef Ahmed

-Into portal_normal.vm  change this code:

#if ($is_signed_in)
 #dockbar()
#end
 
with this one

#if (($is_signed_in) && $permissionChecker.isCompanyAdmin($company_id))
 #dockbar()
#end

it will hide dockbar for users except admin

jQuery ajax with liferay

General Blogs May 9, 2014 By Tauseef Ahmed

On click on confirm ajax submit this form, and wherever your redirect in your class the ajax will redirect just the portlet.

<portlet:actionURL var="ajaxURL" name="atsglobaltechsoft" windowState="< %= LiferayWindowState.EXCLUSIVE.toString()%>" />

<script type="text/javascript" >
    function submitForm(){
        jQuery.ajax({
          type: 'POST',
          url: '<%= ajaxURL % >',
          success: function(data){
              jQuery('#p_p_id<portlet:namespace/ > .portlet-content').html(data);
          }
        });
    }
</script >


<form action="" name="fm" id="fm" method="post">
    <a href="#" onclick="submitForm();">confirm < /a>
</form>


 

AUI Script - To Retrieve Selected Check Box Value in Liferay

General Blogs May 7, 2014 By Tauseef Ahmed

          Everything inside of an aui:script block that contains a “use” attribute is called asynchronously, so it could fire right away (if the resources are on the page) or if the network resolution is taking a long time, it could execute later on.

Bellow is an example:

alert('not "using" any modules, Im fired right away');
alert('"using" aui-io, Im fired when its ready');

So we make sure never to define a function inside of an aui-script block that has a “use” attribute, unless we’re creating another module to be used.

But then how do you define a function that uses a module?
Luckily, we can use Liferay.provide.

For simplicity here I have used two field which will indicated the checked and unchecked value of checkboks and can easily get this value on action class, like bellow:

<aui:input name="addCommIds" type="hidden" value="" />
<aui:input name="removeCommIds" type="hidden" value="" />

Bellow given the aui:script code:


Liferay.provide(
window,
'saveEntry',
function() {
document.fm.addCommIds.value = Liferay.Util.listCheckedExcept(document.fm, "allRowIds");
document.fm.removeCommIds.value = Liferay.Util.listUncheckedExcept(document.fm, "allRowIds");
submitForm(document.fm);
},
['liferay-util-list-fields']
);

NB: listCheckedExcept is a javascript function
we can simply call this function as bellow:

<aui:button onClick="<%= renderResponse.getNamespace() + "saveEntry();"%>"value="save" />

 

Hope it helps..!!

Deploying EXT in LR

General Blogs May 2, 2014 By Tauseef Ahmed

My Portlet name is Sample-ext so I am referring with this name in the below steps :-

1) Stop the Server
2) put ext-redeploy-6.0.5.jar in tomcat-6.0.29/Webapps/ROOT/WEB-INF/lib/
3) Delete the Sample-ext portlet from the webapps folder if in case you are redeploying
4) Remove ext-Sample-ext-service.jar from the tomcat-6.0.29\lib\ext
5) Remove all the *-ext.xml from the path tomcat-6.0.29\webapps\ROOT\WEB-INF except struts-config-ext.xml
6) Remove all the jar file related to ext from the tomcat-6.0.29\webapps\ROOT\WEB-INF\lib except ext-redeploy-6.0.5.jar
7) Start the Server
8) Deploy the EXT Portlet
9) After that it will ask for rebooting the server once the EXT portlet is successfully deployed.
10) Now once again start the server.

Your EXT portlet will re-deployed successfully and all the changes will get Executed.

Hope it helps !!!

Steps to add search portlet in theme and customize that portlet:

General Blogs April 30, 2014 By Tauseef Ahmed

1. Open file [LIFRAY_SDK]/themes/{theme-name}/docroot/_diffs/templates/portal_normal.vm

2. Add $theme.search() at your desired location.

3. Build and deploy the theme.

4. A search text box will appear where the code was placed

Steps to customize the search:

In case you need to customize the search functionality to search only specific content types, follow the steps below.

1. Open file [LIFERAY_HOME]/tomcat-6.1/webapps/ROOT/WEB-INF/classes/portal-ext.properties

2. Add following lines:

com.liferay.portlet.blogs.util.BlogsOpenSearchImpl=true

com.liferay.portlet.bookmarks.util.BookmarksOpenSearchImpl=true

com.liferay.portlet.calendar.util.CalendarOpenSearchImpl=true

com.liferay.portlet.directory.util.DirectoryOpenSearchImpl=true

com.liferay.portlet.documentlibrary.util.DLOpenSearchImpl=true

com.liferay.portlet.imagegallery.util.IGOpenSearchImpl=true

com.liferay.portlet.journal.util.JournalOpenSearchImpl=true

com.liferay.portlet.messageboards.util.MBOpenSearchImpl=true

com.liferay.portlet.wiki.util.WikiOpenSearchImpl=true

3. Change values to “false” for those you do not want to include in search result.

For example, to search only “Web Content”, leave “com.liferay.portlet.journal.util.JournalOpenSearchImpl” to “true” and make other values to false.

Showing 9 results.
Items 20
of 1