Add a new context path for users' rights


Add a new button

The purpose of this button is to open the tool for rights assignment (uitool-rights-assignment) and initialize it with your own context.

Declaration

<extension id="org.ametys.web.rights.assignment.tool.Sitemap"
	point="org.ametys.cms.workspace.ribbon.RibbonControlsManager"
	class="org.ametys.runtime.ui.impl.StaticContextualClientSideElement">
	<action class="org.ametys.cms.tool.right.control.RightsAssignmentToolButton">
		<param name="role">uitool-rights-assignment</param>
		<param name="initialize-tool">org.ametys.web.tool.right.context.SitemapContextIniialize</param>
    		<param name="selection-listener">org.ametys.web.tool.right.context.SitemapContextSelectionListener</param>
    		<param name="context">/sitemap</param>
		<param name="label" i18n="true">PLUGINS_WEB_RIGHTS_ASSIGNMENT_RESOURCES_CONTEXT</param>
		<param name="default-description" i18n="true">PLUGINS_WEB_RIGHTS_ASSIGNMENT_RESOURCES_CONTEXT_DESC</param>
		<param name="footer"></param>
		<param name="icon-small" file="true">img/rights/resources_16.png</param>
		<param name="icon-medium" file="true">img/rights/resources_32.png</param>
		<param name="icon-large" file="true">img/rights/resources_48.png</param>
	</action>
	<scripts>
		<file plugin="cms">js/org/ametys/cms/tool/right/control/RightsAssignmentToolButton.js</file>
		<file>js/org/ametys/web/tool/right/context/ResourcesContext.i18n.js</file>
	</scripts>
</extension>
  • role : role of the tool to open
  • initialize-tool : function to call to initialize the tool (when the button is pressed)
  • selection-listener : function to call on a vent of selection
  • context : the right's context

Sample of init function for the sitemap context

This function opens the sitemap tool and init the context according to the current selection (the selected page context or the root sitemap context if no page is selected)

org.ametys.web.tool.right.context.SitemapContextIniialize = function(tool, context)
{
	// Open sitemap
	org.ametys.uitool.ToolsManager.getInstance().openTool('uitool-sitemap', {});

	var targets = org.ametys.ribbon.RibbonManager.getInstance().getCurrentSelectionTargets();
	var target = org.ametys.messagebus.message.MessageTargetHelper.findFirst(targets, function(target) { return target.getType() == "page" || target.getType() == "sitemap";});

	if (target == null)
	{
		tool.updateContext (null, true);
		tool.updateContextHelperText ("<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_NO_SELECTION"/>");
	}
	else
	{
		if (target.getType() == "page")
		{
			var ctx = '/' + target.getParameters().siteName + '/pages/'
					+ target.getParameters().lang
					+ (target.getType() == "page" ? '/' + target.getParameters().path : "");

			var text = "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_PAGE_1"/>";
			text += '&lt;b&gt;' + target.getParameters().title + '&lt;/b&gt;'
			text += "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_PAGE_2"/>";

			tool.updateContext (ctx, true);
			tool.updateContextHelperText (text);
		}
		else
		{
			var ctx = '/' + target.getParameters().siteName + '/pages/' + target.getParameters().lang;
			var text = "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_SITEMAP"/>";
			tool.updateContext (ctx, true);
			tool.updateContextHelperText (text);
		}
	}

}

Sample of selection function for the sitemap context

This function update the context of the tool when a new page is selected.

org.ametys.web.tool.right.context.SitemapContextSelectionListener = function(tool, targets)
{
var target = org.ametys.messagebus.message.MessageTargetHelper.findFirst(targets, function(target) { return target.getType() == "page" || target.getType() == "sitemap";});
if (target != null)
{
	if (target.getType() == "page")
	{
		var ctx = '/' + target.getParameters().siteName + '/pages/'
			+ target.getParameters().lang
			+ (target.getType() == "page" ? '/' + target.getParameters().path : "");

		var text = "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_PAGE_1"/>";
		text += '&lt;b&gt;' + target.getParameters().title + '&lt;/b&gt;'
		text += "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_PAGE_2"/>";

		tool.updateContext (ctx);
		tool.updateContextHelperText (text);
	}
	else
	{
		var ctx = '/' + target.getParameters().siteName + '/pages/' + target.getParameters().lang;
		var text = "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_SITEMAP"/>";

		tool.updateContext (ctx);
		tool.updateContextHelperText (text);
	}
	return;
}

var target = org.ametys.messagebus.message.MessageTargetHelper.findFirst(targets, function(target) { return target.getType() == "profile";})
if (target == null)
{
	var text = "<i18n:text i18n:key="PLUGINS_WEB_RIGHTS_ASSIGNMENT_SITEMAP_CONTEXT_NO_SELECTION"/>";
	tool.updateContext (null);
	tool.updateContextHelperText (text);
}
}

Add a new item menu

You must declare a new org.ametys.cms.rights.RightsContextExtensionPoint. This extension point adds automatically a new item in the rights assignment menu. This item has the same purpose of the button (see up).

Declaration

 <extension id="org.ametys.web.rights.assignment.Sitemap"
	point="org.ametys.cms.rights.RightsContextExtensionPoint"
    	class="org.ametys.runtime.ui.impl.StaticClientSideElement">
    	<action class="org.ametys.cms.tool.right.Open">
    		<param name="role">uitool-rights-assignment</param>
    		<param name="controlId">org.ametys.web.rights.assignment.tool.Sitemap</param>
    		<param name="initialize-tool"org.ametys.web.tool.right.context.SitemapContextIniialize</param>
    		<param name="selection-listener">org.ametys.web.tool.right.context.SitemapContextSelectionListener</param>
    		<param name="label" i18n="true">PLUGINS_WEB_RIGHTS_ASSIGNMENT_RESOURCES_CONTEXT</param>
		<param name="description" i18n="true">PLUGINS_WEB_RIGHTS_ASSIGNMENT_RESOURCES_CONTEXT_DESC</param>
		<param name="icon-small" file="true">img/rights/resources_16.png</param>
		<param name="icon-medium" file="true">img/rights/resources_32.png</param>
		<param name="context">/sitemap</param>
    	</action>
    	<scripts>
    		<file plugin="cms">js/org/ametys/cms/tool/right/Actions.i18n.js</file>
		<file>js/org/ametys/web/tool/right/context/ResourcesContext.i18n.js</file>
	</scripts>

</extension>role : role of tool to open

* role : role of the tool to open

  • initialize-tool : function to call to initialize the tool (when the button is pressed) (same as button)
  • selection-listener : function to call on a vent of selection (same as button)
  • context : the right's context (same as button)
  • controlId : the id of the declared button
Back to top