Tuesday, January 31, 2017

How to Change the Alfresco Share Landing Page for all Users

In Alfresco 5.1.x, it’s easy for users to change their own home page. The Use Current Page option in the user menu can be used to change the logged in user’s home page to the current page. And, the home page can also be reset back to the user’s dashboard with the selection of the Use My Dashboard option.

But, what if you want all of your Alfresco users to use the same landing page when they log in to Alfresco Share? Perhaps you’d like it to be your corporate site dashboard or a heavily-used site folder? Instead of having your users individually change their home page, an admin user can easily make a global change for all users like this:
1.      Open the TOMCAT/webapps/share/site-index.jsp file for editing.

a.       Look for the following lines at the bottom of the file:

    // redirect to site or user dashboard as appropriate
     String siteName = request.getParameter("site");
        if (siteName == null || siteName.length() == 0)
        // Get and forward to user's home page
        SlingshotUserFactory slingshotUserFactory =
                (SlingshotUserFactory) FrameworkUtil.getServiceRegistry().getUserFactory();
        String userHomePage = slingshotUserFactory.getUserHomePage(context, userid);
        response.sendRedirect(request.getContextPath() + userHomePage);
        // forward to site specific dashboard page
        response.sendRedirect(request.getContextPath() + "/page/site/" + URLEncoder.encode(siteName) +  "/dashboard");

b.      Set the "siteName" variable to your preferred landing page site name, for example:

  String siteName = request.getParameter("site");
     siteName = "formtek";

      c.       If you want your site dashboard to be the new landing page, you’re done editing the file.                        However, if you want your new landing page to be a folder in your site, you’ll need to make                  one more change to replace “dashboard” in the following line with the document library                        folder of  your choice:

 response.sendRedirect(request.getContextPath() + "/page/site/" +    URLEncoder.encode(siteName) + "/dashboard");

In this example, I’m using the “Policies and Procedures” folder in the site’s document library:

 response.sendRedirect(request.getContextPath() + "/page/site/" +  URLEncoder.encode(siteName) +  "/documentlibrary#filter=path%7C%2FPolicies%2520and%2520Procedures%7C&page=1");

NOTE: To get the correct folder syntax, you can navigate to the folder in Alfresco Share and copy the folder syntax from the browser address bar.

d.      Save your changes and close the file.

2.      Restart Alfresco for the changes to take effect.

Now, when a user logs in to Alfresco Share, the user will be redirected to your newly configured landing page. Here are two different results for the above examples:

The configured site dashboard is the new landing page:

The configured site folder is the new landing page:

It is important to note that if your new landing page restricts site membership (as in the case of the “private” example site above), non-members would see the following upon login:

Clicking the “Back to My Dashboard” button redirects unprivileged users to their own home page. To eliminate this scenario, changes would need to be made to verify site membership and only redirect site members to the new landing page. (Perhaps the discussion of a future post.)

Wednesday, January 25, 2017

Restricting Availability of Alfresco Dashlets by Group

There are two kinds of dashboards in Alfresco Share: User and Site dashboards.  By default, after logging into Share, the user is presented with a customizable dashboard page.  The dashboard page is made up of dashlets that can be arranged using the Customize User Dashboard page, as shown here. Site dashboard pages can be similarly arranged and customized by the site managers.

Developers are able to create new dashlets that can be added to the list of available dashlets. A dashlet is composed of a number of files, one of which is called the descriptor file.  The descriptor file is a brief XML document that describes the name, description and availability information about the dashlet.

Alfresco documentation describes how the <family> tag can be used in the descriptor to specify which of the two dashboards the dashlet can appear: on the user, site, or both of the dashboards.

The family tag can take the following values:
  • user-dashlet - for use on the User Dashboard
  • site-dashlet - for use on the Site Dashboard
  • dashlet - for use on either User or Site Dashboards
But, there is another use for the family tag which isn't well documented.  The family tag can also be used to restrict availability of a dashlet by group. In that case, the name of the group is included in the family tag, like this:


Here we refer to the Alfresco administrators group called ALFRESCO_ADMINISTRATORS.  Note that the group name used within Alfresco code prefixes all names with GROUP_. We see the group is referenced here as GROUP_ALFRESCO_ADMINISTRATORS, even though it is displayed as ALFRESCO_ADMINISTRATORS in the Group Browser of the Share UI.

Now, let's consider a specific case. When developing the Formtek Peer Association Extension, we had the need for a dashlet to be available only to administrators from their user dashboards. To enforce both restrictions, we used the following dashlet descriptor file with two family tag elements:

   <shortname>Remove Peer Association</shortname>  
   <description>Removes Formtek Peer Association Metadata</description>