Skip to content

Commit

Permalink
KNL-1535 - Sites with custom title changes created from templates don…
Browse files Browse the repository at this point in the history
…'t keep change (sakaiproject#4552)

Also added new property to override the 3 hardcoded tools
  • Loading branch information
jonespm authored Jul 11, 2017
1 parent 40dfc8d commit e1ed84a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3470,6 +3470,9 @@
# DEFAULT: elfinder
# wysiwyg.editor.ckeditor.browser=fckeditor

# KNL-1535 - List of tool registration ids that a custom title will always be applied to
# DEFAULT: sakai.iframe,sakai.rutgers.linktool,sakai.news
# site.tool.custom.titles = sakai.iframe,sakai.rutgers.linktool,sakai.news

# ########################################################################
# UPGRADE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,12 @@ public void setupPageCategory(String toolId) {
}
throw new UnsupportedOperationException();
}
@Override
public boolean isTitleToolException(String toolId) {
if (sitePage != null) {
return sitePage.isTitleToolException(toolId);
}
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,10 @@ public interface SitePage extends Edit, Serializable
public int getPosition();

public void setupPageCategory(String toolId);

/**
* Is this an exception to the tool titles (Based on a default value)
*/
public boolean isTitleToolException(String toolId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,22 @@ public class BaseSitePage implements SitePage, Identifiable
protected String m_skin = null;

private BaseSiteService siteService;

protected String[] SAKAI_DEFAULT_EXCEPTION_IDS = {"sakai.iframe","sakai.rutgers.linktool","sakai.news"};
/** String array of default exception ids to not override the title */
protected String[] m_titleExceptionIds;

/**
* Private constructor to setup some defaults
*/
private BaseSitePage (BaseSiteService siteService) {
this.siteService = siteService;
m_titleExceptionIds = siteService.serverConfigurationService().getStrings("site.tool.custom.titles");
if (m_titleExceptionIds == null) {
m_titleExceptionIds = SAKAI_DEFAULT_EXCEPTION_IDS;
}
}

/**
* Construct. Auto-generate the id.
*
Expand All @@ -95,7 +110,7 @@ public class BaseSitePage implements SitePage, Identifiable
*/
protected BaseSitePage(BaseSiteService siteService, Site site)
{
this.siteService = siteService;
this(siteService);
m_site = site;
m_id = siteService.idManager().createUuid();
m_properties = new BaseResourcePropertiesEdit();
Expand All @@ -119,7 +134,7 @@ protected BaseSitePage(BaseSiteService siteService, Site site)
protected BaseSitePage(BaseSiteService siteService, Site site, String id, String title, String layout,
boolean popup)
{
this.siteService = siteService;
this(siteService);
m_site = site;
m_id = id;

Expand Down Expand Up @@ -163,7 +178,7 @@ else if (layout.equals(String.valueOf(LAYOUT_DOUBLE_COL)))
protected BaseSitePage(BaseSiteService siteService, String pageId, String title, String layout, boolean popup,
String siteId, String skin)
{
this.siteService = siteService;
this(siteService);

m_site = null;
m_id = pageId;
Expand Down Expand Up @@ -205,7 +220,7 @@ else if (layout.equals(String.valueOf(LAYOUT_DOUBLE_COL)))
*/
protected BaseSitePage(BaseSiteService siteService, SitePage other, Site site, boolean exact)
{
this.siteService = siteService;
this(siteService);

BaseSitePage bOther = (BaseSitePage) other;

Expand Down Expand Up @@ -276,7 +291,7 @@ protected BaseSitePage(BaseSiteService siteService, SitePage other, Site site, b
*/
protected BaseSitePage(BaseSiteService siteService, Element el, Site site)
{
this.siteService = siteService;
this(siteService);

m_site = site;

Expand Down Expand Up @@ -378,6 +393,25 @@ public String getTitle()

return m_title;
}

/**
* Checks to see if this is a title exception
* @param toolId
* @return
*/
public boolean isTitleToolException(String toolId) {
if (toolId == null) {
return false;
}

for (String titleExceptionId : m_titleExceptionIds) {
if (titleExceptionId.equals(toolId) || toolId.startsWith(titleExceptionId)) {
return true;
}

}
return false;
}

/**
* @inheritDoc
Expand Down Expand Up @@ -553,7 +587,7 @@ private boolean getTitleCustomLegacy()
if (getTools().size() > 0 && getProperties().getProperty(IS_HOME_PAGE) == null)
{
String toolId = ( (BaseToolConfiguration) (getTools().get(0))).getToolId();
return "sakai.iframe".equals(toolId) || "sakai.news".equals(toolId) || "sakai.rutgers.linktool".equals(toolId);
return isTitleToolException(toolId);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class BaseToolConfiguration extends org.sakaiproject.util.Placement imple

/** The site skin, in case I have no m_page. */
protected String m_skin = null;

/** True if the placement conf has not been read yet. */
protected boolean m_configLazy = false;

Expand Down Expand Up @@ -109,9 +109,11 @@ protected BaseToolConfiguration(BaseSiteService siteService, SitePage page, Stri
m_custom_title = getTitleCustom(page);

m_configLazy = true;

setPageCategory();
}


/**
** Checks if the tool's page has set the custom_title property (for custom page or tool titles),
** or alternately checks if this tool should be cosidered a "legacy" custom tool title
Expand All @@ -123,16 +125,14 @@ private boolean getTitleCustom(SitePage page)
{
if (page.isHomePage())
{
return page.getHomeToolsTitleCustom(getId());
return page.getHomeToolsTitleCustom(m_id) || page.isTitleToolException(m_toolId);
}
else
{
String custom = (String)page.getProperties().get(SitePage.PAGE_CUSTOM_TITLE_PROP);
if ( custom != null )
return Boolean.parseBoolean(custom);
else if ( "sakai.iframe".equals(m_toolId) || "sakai.news".equals(m_toolId) || "sakai.rutgers.linktool".equals(m_toolId) )
return true;
else if (m_toolId != null && m_toolId.startsWith("sakai.iframe"))
else if (page.isTitleToolException(m_toolId))
return true;
else
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public void setUp() {

ignoring(storage).readPageProperties(with(any(SitePage.class)), with(any(ResourcePropertiesEdit.class)));
ignoring(storage).readPageTools(with(any(SitePage.class)), with(any(ResourceVector.class)));

oneOf(serverConfigurationService).getStrings("site.tool.custom.titles");
will(returnValue(null));
}
});
page = new BaseSitePage(service, "pageId", "Page Title", "0,0", false, "siteId", "skin");
Expand Down

0 comments on commit e1ed84a

Please sign in to comment.