Adding Permission Helper to RSF based Sakai Tools
This material based on the writeup from - https://confluence.sakaiproject.org/display/BOOT/Using+Helper+Tools+from+RSF
Overview
This guide is for laying out what you need to do in order to add the Permissions Helper to an RSF-based Sakai tool (for this example, we are looking at the Evaluation Tool). The Permissions Helper allows you to add a screen which gives the appropriate users access to quickly setting the tool specific permissions. For example, after adding this to the Evaluation Tool, we can see this:
It is essentially a shortcut for having to go into the Realms section of Sakai to configure the site permissions.
Step 1 - HTML Template
We start with the RSF HTML template. The template is basically just a stub, as the helper will be overwriting the template. The basic template format holds true for all the Sakai helpers in RSF. The basic requirement is that there are two specific inputs in the body (these don't need to actually be in a form element):
- One of type text with rsf:id helper-id
- One of type submit with rsf:id helper-binding.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns:rsf="http://ponder.org.uk/rsf" xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <h3>Evaluations Permissions Helper Stub</h3> <input type="text" rsf:id="helper-id" /> <input type="submit" rsf:id="helper-binding" /> </body> </html>
Step 2 - Producer
Next is the producer code. As usual, the ViewID should correspond with the template name (even though it is a stub template). Note that we implement uk.org.ponder.rsf.viewstate.ViewParamsReporter. In getViewParameters(), we need to return HelperViewParameters. This is what tells SakaiRSF that we are a stub for a Sakai Helper. Without this, RSF will try to render this as a normal page.
public class AssignPermissionsProducer implements ViewComponentProducer, ViewParamsReporter, NavigationCaseReporter { public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) { ToolSession session = sessionManager.getCurrentToolSession(); session.setAttribute(PermissionsHelper.TARGET_REF, site.getReference()); session.setAttribute(PermissionsHelper.PREFIX, "eval."); ResourceLoader resourceLoader = new ResourceLoader("org.sakaiproject.evaluation.tool.bundle.permissions"); HashMap<String, String> permissionsDescriptions = new HashMap<String, String>(); for (Object key : resourceLoader.keySet()) { permissionsDescriptions.put(key.toString(), (String) resourceLoader.get(key)); } session.setAttribute("permissionDescriptions", permissionsDescriptions); UIOutput.make(tofill, HelperViewParameters.HELPER_ID, "sakai.permissions.helper"); UICommand.make(tofill, HelperViewParameters.POST_HELPER_BINDING, "", null); } public static final String VIEW_ID = "assign_permissions"; public String getViewID() { return VIEW_ID; } public ViewParameters getViewParameters() { return new HelperViewParameters(); } @SuppressWarnings({ "unchecked", "rawtypes" }) public List reportNavigationCases() { ArrayList result = new ArrayList(); result.add(new NavigationCase(null, new SimpleViewParameters(SummaryProducer.VIEW_ID))); return result; } private SessionManager sessionManager; public void setSessionManager(SessionManager sessionManager) { this.sessionManager = sessionManager; } private Site site; public void setSite(Site site) { this.site = site; } }
First, in fillComponents(...), we grab the ToolSession and fill it with the initial parameters for the helper (the names and expected values will vary from Helper to Helper). We need to set the attributes for:
- PermissionsHelper.TARGET_REF - This tells the helper where we are setting the permissions.
- PermissionsHelper.PREFIX - This tells the helper what settings we want. In the below example code, we'll be getting all the permissions that have a key-prefix of "eval." (yes, including the period)
 Next, rather than showing the permission keys (as they are in the realms displays), we can show descriptive text. To do this, we create a properties file with descriptions of each key. For the properties file, the key values must be prefixed with *desc\-* and the remaining portion of the key will match the permission key like such:
desc-eval.assign.evaluation=May assign evaluations desc-eval.be.evaluated=May be evaluated desc-eval.take.evaluation=May take evaluations desc-eval.write.template=May create evaluation templates
The descriptions are loaded into a map and set into the attributes with the key permissionDescriptions.
After that, it's important to bind the two special fields from the template. The Helper ID should be the ID of the helper, in this case sakai.permissions. helper. You can find a Helper's ID in it's tool registration. For the permissions helper, the registration file is conveniently located at webapps/sakai-authz-tool/tools/sakai.permissions.helper.xml in the installed Tomcat.
The second special field is the method binding. This method binding will be called when the helper is finished. For this case, we don't want anything special to happen so we pass null in as the last parameter.
Step 3 - Wrap It Up
After that, all that's left to do is the standard hook-ups. Add the producer to the requestConext.xml and add a link to your new permissions page (be sure to only give access to the link for those users that should have it).