Skip to content

Commit

Permalink
SAK-32376: ensure multiple places are obeying the option to display r…
Browse files Browse the repository at this point in the history
…oster title rather than site title (sakaiproject#4152)
  • Loading branch information
bjones86 authored Mar 27, 2017
1 parent e982b18 commit cecfbbf
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

package org.sakaiproject.coursemanagement.impl;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -80,7 +82,7 @@ public void init()
/**
* {@inheritDoc}
*/
public String getUserSpecificSiteTitle( Site site, String userID )
public String getUserSpecificSiteTitle( Site site, String userID, List<String> siteProviders )
{
// Short circuit - only continue if sakai.property set to true
if( portalUseSectionTitle )
Expand Down Expand Up @@ -108,8 +110,14 @@ public String getUserSpecificSiteTitle( Site site, String userID )
// Short circuit - only continue if user is not null and user does not have the site.upd permission in the given site
if( currentUser != null && !ss.unlock( currentUser, SITE_UPDATE_PERMISSION, site.getReference() ) )
{
Collection<String> providerIDs = siteProviders;
if( providerIDs == null )
{
String realmID = site.getReference();
providerIDs = azgs.getProviderIDsForRealms( ((List<String>) Arrays.asList( new String[] {realmID} )) ).get( realmID );
}

// Short circuit - only continue if there are more than one provider ID (cross listed site)
Set<String> providerIDs = azgs.getProviderIds( site.getReference() );
if( CollectionUtils.isNotEmpty( providerIDs ) )
{
// Get the current user's section membership/role map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public interface AuthzGroupService extends EntityProducer
/** Standard role name for the auth. role. */
static final String AUTH_ROLE = ".auth";

/**
* Get all provider IDs for the realms given.
*
* @param realmIDs a List of the realms you want the provider IDs for.
* @return a Map, where the key is the realm ID, and the value is a List of Strings of provider IDs for that realm
*/
public Map<String, List<String>> getProviderIDsForRealms(List<String> realmIDs);

/**
* Access a list of AuthzGroups that meet specified criteria, naturally sorted.
* NOTE: The group objects returned will not have the associated roles loaded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,4 +1257,12 @@ public boolean isAsc()
* @return the site or section title
*/
public String getUserSpecificSiteTitle( Site site, String userID );
}

/**
* Similar to getUserSpecificSiteTitle(Site site, String userId), but consumes the specified siteProviders (for performance savings)
*
* @see getUserSpecificSiteTitle(Site site, String userId)
* @param siteProviders the site providers corresponding to the specified site; if null, they will be looked up
*/
public String getUserSpecificSiteTitle(Site site, String userID, List<String> siteProviders);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.sakaiproject.site.api;

import java.util.List;

/**
* SAK-29138 - Portal, user and site-manage tools will optionally (if an implementation is
* present) use this to conditionally display the site or section title in the UI.
Expand All @@ -29,7 +31,7 @@
*/
public interface SiteTitleAdvisor
{
/**
/**
* Given a site and a user ID, return the appropriate site or section title for the user.
*
* SAK-29138 - Takes into account 'portal.use.sectionTitle' sakai.property;
Expand All @@ -39,7 +41,8 @@ public interface SiteTitleAdvisor
*
* @param site the site in question
* @param userID the ID of the current user
* @param siteProviders the providerIDs associated with this site; they will be queried if this parameter is null
* @return the site or section title
*/
public String getUserSpecificSiteTitle( Site site, String userID );
public String getUserSpecificSiteTitle( Site site, String userID, List<String> siteProviders );
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,18 @@ public static String getUserSpecificSiteTitle( Site site, String userID )

return service.getUserSpecificSiteTitle( site, userID );
}

/**
* Similar to getUserSpecificSiteTitle(Site site, String userId), but consumes the specified siteProviders (for performance savings)
*
* @see getUserspecificSiteTitle(Site site, String userId)
* @param siteProviders the site providers corresponding to the specified site; if null, they will be looked up
*/
public static String getUserSpecificSiteTitle(Site site, String userId, List<String> siteProviders)
{
org.sakaiproject.site.api.SiteService service = getInstance();
if (service == null) return null;

return service.getUserSpecificSiteTitle(site, userId, siteProviders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ public void destroy()
* AuthzGroupService implementation
*********************************************************************************************************************************************************************************************************************************************************/

/**
* {@inheritDoc}
*/
public Map<String, List<String>> getProviderIDsForRealms(List<String> realmIDs)
{
return m_storage.getProviderIDsForRealms(realmIDs);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1365,6 +1373,14 @@ protected interface Storage
*/
void remove(AuthzGroup azGroup);

/**
* Get all provider IDs for the realms given.
*
* @param realmIDs a List of the realms you want the provider IDs for.
* @return a Map, where the key is the realm ID, and the value is a List of Strings of provider IDs for that realm
*/
public Map<String, List<String>> getProviderIDsForRealms(List<String> realmIDs);

/**
* Access a list of AuthzGroups that meet specified criteria, naturally sorted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,54 @@ public Set<String> getProviderIds(String authzGroupId)
return new HashSet<>(results);
}

/**
* {@inheritDoc}
*/
public Map<String, List<String>> getProviderIDsForRealms(List<String> realmIDs)
{
Map<String, List<String>> realmProviderMap = new HashMap<>();
if (realmIDs != null && realmIDs.size() > 0)
{
// Custom reader to get only realm_id and provider_id
SqlReader reader = (result)-> {
try
{
String realmID = result.getString(1);
String providerIDs = result.getString(2);
List<String> retVal = new ArrayList<>();
retVal.add(realmID);
retVal.add(providerIDs);
return retVal;
}
catch (SQLException ex)
{
// Avoid nulls by returning an empty Colleciton<String>
M_log.warn("getProviderIDsForRealms.readSqlResultRecord: " + ex);
return Collections.<String>emptyList();
}
};

// Execute the SQL statement
String sql = dbAuthzGroupSql.getSelectRealmsProviderIDsSql(orInClause(realmIDs.size(), "r.realm_id"));
Object[] fields = realmIDs.toArray();
List<List<String>> results = (List<List<String>>) m_sql.dbRead(sql, fields, reader);

// Build the realm-provider map
for (List<String> list : results)
{
String realmID = list.get(0);
String providerIDs = list.get(1);

if (StringUtils.isNotBlank(realmID) && StringUtils.isNotBlank(providerIDs))
{
realmProviderMap.put(realmID, Arrays.asList(providerIDs.split("\\+")));
}
}
}

return realmProviderMap;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public interface DbAuthzGroupSql

String getSelectRealmProviderId2Sql();

String getSelectRealmsProviderIDsSql(String inClause);

String getSelectRealmProviderSql(String inClause);

String getSelectRealmRoleDescriptionSql();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ public String getSelectRealmIdRoleSwapSql(Collection azGroups)
return sqlBuilder.toString();
}

public String getSelectRealmsProviderIDsSql(String inClause)
{
return "SELECT r.realm_id, r.provider_id FROM sakai_realm r WHERE " + inClause;
}

public String getSelectRealmProvider2Sql()
{
return "SELECT RR.ROLE_NAME, RRD.DESCRIPTION, RRD.PROVIDER_ONLY FROM SAKAI_REALM_ROLE_DESC RRD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3557,11 +3557,19 @@ public String getParentSite(String siteId) {
/**
* {@inheritDoc}
*/
public String getUserSpecificSiteTitle( Site site, String userID )
public String getUserSpecificSiteTitle(Site site, String userID)
{
return getUserSpecificSiteTitle(site, userID, null);
}

/**
* {@inheritDoc}
*/
public String getUserSpecificSiteTitle(Site site, String userID, List<String> siteProviders)
{
if( m_siteTitleAdvisor != null )
{
return m_siteTitleAdvisor.getUserSpecificSiteTitle( site, userID );
return m_siteTitleAdvisor.getUserSpecificSiteTitle( site, userID, siteProviders );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

public class MockAuthzGroupService implements AuthzGroupService {

public Map<String, List<String>> getProviderIDsForRealms(List<String> realmIDs) {
return null;
}

public AuthzGroup addAuthzGroup(String id) throws GroupIdInvalidException,
GroupAlreadyDefinedException, AuthzPermissionException {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.sakaiproject.portal.api;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -98,7 +99,7 @@ Map pageListToMap(HttpServletRequest req, boolean loggedIn, Site site,
Map convertSiteToMap(HttpServletRequest req, Site s, String prefix,
String currentSiteId, String myWorkspaceSiteId, boolean includeSummary,
boolean expandSite, boolean resetTools, boolean doPages,
String toolContextPath, boolean loggedIn);
String toolContextPath, boolean loggedIn, List<String> siteProviders);

/**
* SAK-29138 - Get the site or section title for the current user for the current site.
Expand All @@ -113,6 +114,23 @@ Map convertSiteToMap(HttpServletRequest req, Site s, String prefix,
*/
String getUserSpecificSiteTitle( Site site, boolean escaped );

/**
* Similar to getUserSpecificSiteTitle(Site site, boolean escaped), but also takes truncated parameter
*
* @see getUserSpecificSiteTitle(Site site, String userId)
* @param truncated true if you want long titles to be truncated with an ellipses
*/
String getUserSpecificSiteTitle(Site site, boolean truncated, boolean escaped);

/**
* Similar to getUserSpecificSiteTitle(Site site, boolean escaped), but consumes the specified siteProviders (for performance savings)
*
* @see getUserSpecificSiteTitle(Site site, String userId)
* @param truncated true if you want long titles to be truncated with an ellipses
* @param siteProviders the site providers corresponding to the specified site; if null, they will be looked up
*/
String getUserSpecificSiteTitle(Site site, boolean truncated, boolean escaped, List<String> siteProviders);

/**
* Generates a SiteView object from the current request and location
* @param view
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sakaiproject.portal.charon.handlers;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -11,6 +12,7 @@
import org.sakaiproject.portal.api.Portal;
import org.sakaiproject.portal.api.PortalHandlerException;
import org.sakaiproject.portal.api.PortalRenderContext;
import org.sakaiproject.portal.charon.site.PortalSiteHelperImpl;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.tool.api.Session;
Expand Down Expand Up @@ -133,11 +135,12 @@ protected void showJoin(String[] parts, HttpServletRequest req,
String serviceName = ServerConfigurationService.getString("ui.service", "Sakai");

// SAK-29138
String title = serviceName + " : "+ portal.getSiteHelper().getUserSpecificSiteTitle( site, false );
List<String> siteProviders = (List<String>) PortalSiteHelperImpl.getProviderIDsForSite(site);
String title = serviceName + " : " + portal.getSiteHelper().getUserSpecificSiteTitle(site, true, false, siteProviders);

String skin = site.getSkin();
PortalRenderContext context = portal.startPageContext(siteType, title, skin, req);
context.put("currentSite", portal.getSiteHelper().convertSiteToMap(req, site, null, site.getId(), null, false, false, false, false, null, true));
context.put("currentSite", portal.getSiteHelper().convertSiteToMap(req, site, null, site.getId(), null, false, false, false, false, null, true, siteProviders));
context.put("uiService", serviceName);

boolean restrictedByAccountType = !SiteService.getInstance().isAllowedToJoin(siteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Enumeration;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -57,6 +56,7 @@
import org.sakaiproject.portal.api.SiteView;
import org.sakaiproject.portal.api.StoredState;
import org.sakaiproject.portal.charon.site.AllSitesViewImpl;
import org.sakaiproject.portal.charon.site.PortalSiteHelperImpl;
import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.api.ToolSession;
import org.sakaiproject.tool.api.ToolManager;
Expand Down Expand Up @@ -406,8 +406,9 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess
session.removeAttribute(Portal.ATTR_SITE_PAGE + siteId);

// SAK-29138 - form a context sensitive title
List<String> providers = PortalSiteHelperImpl.getProviderIDsForSites(((List<Site>) Arrays.asList(new Site[] { site }))).get(site.getReference());
String title = ServerConfigurationService.getString("ui.service","Sakai") + " : "
+ portal.getSiteHelper().getUserSpecificSiteTitle( site, false );
+ portal.getSiteHelper().getUserSpecificSiteTitle(site, false, false, providers);

// Lookup the page in the site - enforcing access control
// business rules
Expand Down Expand Up @@ -535,8 +536,8 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess
rcontext.put("siteTitle", rb.getString("sit_mywor") );
rcontext.put("siteTitleTruncated", rb.getString("sit_mywor") );
}else{
rcontext.put("siteTitle", Web.escapeHtml(site.getTitle()));
rcontext.put("siteTitleTruncated", portal.getSiteHelper().getUserSpecificSiteTitle( site, false ) );
rcontext.put("siteTitle", portal.getSiteHelper().getUserSpecificSiteTitle(site, false, true, providers));
rcontext.put("siteTitleTruncated", portal.getSiteHelper().getUserSpecificSiteTitle(site, true, false, providers));
}

addLocale(rcontext, site, session.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.sakaiproject.portal.charon.site;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.sakaiproject.component.api.ServerConfigurationService;
Expand Down Expand Up @@ -95,11 +96,12 @@ private void init()
try
{
Site site = siteHelper.getSiteVisit(currentSiteId);
List<String> siteProviders = (List<String>) PortalSiteHelperImpl.getProviderIDsForSite(site);
siteMap = siteHelper
.convertSiteToMap(request, site, prefix, currentSiteId,
myWorkspaceSiteId, includeSummary,
/* expandSite */true, resetTools, doPages, toolContextPath,
loggedIn);
loggedIn, siteProviders);
}
catch (IdUnusedException e)
{
Expand Down
Loading

0 comments on commit cecfbbf

Please sign in to comment.