Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Using my own membership and role provider

$
0
0
If anyone is still interested in this, I did get it working properly. Burningice provided all the code required, however filling in the holes was a bit daunting. This still isn't ready for production, but it produces a working implementation. Getting from here to whatever your production needs are should be a matter of technique. For myself, I'll be implementing this same system for media files. I'll also hook the roles up to an external IMS.

Composite.config

The response handler:
<Composite.Core.WebClient.Renderings.Plugins.RenderingResponseHandlerConfiguration><RenderingResponseHandlerPlugins><addname="PagePermissions"type="Composite.Membership.PagePermissions.ResponseHandler, Composite.Membership.PagePermissions"/></RenderingResponseHandlerPlugins></Composite.Core.WebClient.Renderings.Plugins.RenderingResponseHandlerConfiguration>
The action provider. This takes the place of a Tree Definition file:
<Composite.C1Console.Elements.Plugins.ElementActionProviderConfiguration><ElementActionProviderPlugins><addname="PagePermissionsActionProvider"type="Composite.Membership.PagePermissions.PagePermissionsActionProvider, Composite.Membership.PagePermissions"/></ElementActionProviderPlugins></Composite.C1Console.Elements.Plugins.ElementActionProviderConfiguration>
And this guy. It tells Composite where to look for Form Definition XML files. Your workflow will not function without this entry:
<Composite.Data.Plugins.DataProviderConfiguration><DataProviderPlugins><addrootDirectory="~/App_Data/Composite/Forms"fileSearchPattern="*.xml"topDirectoryOnly="false"fileInterfaceType="Composite.C1Console.Forms.DataServices.IFormDefinitionFile, Composite"type="Composite.Plugins.Data.DataProviders.FileSystemDataProvider.FileSystemDataProvider, Composite"name="NonCoreFormFileProvider"/></DataProviderPlugins></Composite.Data.Plugins.DataProviderConfiguration>

Form Definition

You need to create an XML Form Definition for IPagePermissions. Mine looks like this:
<?xmlversion="1.0"encoding="utf-8"?><cms:formdefinitionxmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0"xmlns="http://www.composite.net/ns/management/bindingforms/std.ui.controls.lib/1.0"xmlns:f="http://www.composite.net/ns/management/bindingforms/std.function.lib/1.0"><cms:bindings><cms:bindingname="PagePermissions"type="Composite.Membership.PagePermissions.IPagePermissions"/></cms:bindings><cms:layouticonhandle="page-edit-page"label="Page Permissions"><FieldGroup><MultiKeySelectorLabel="Allowed Roles"OptionsKeyField="Key"OptionsLabelField="Value"Required="false"><MultiKeySelector.SelectedAsString><cms:bindsource="PagePermissions.AllowedRoles"/></MultiKeySelector.SelectedAsString><MultiKeySelector.Options><functionname="Composite.Membership.PagePermissions.GetRoles"xmlns="http://www.composite.net/ns/function/1.0"/></MultiKeySelector.Options></MultiKeySelector><MultiKeySelectorLabel="Denied Roles"OptionsKeyField="Key"OptionsLabelField="Value"Required="false"><MultiKeySelector.SelectedAsString><cms:bindsource="PagePermissions.DeniedRoles"/></MultiKeySelector.SelectedAsString><MultiKeySelector.Options><functionname="Composite.Membership.PagePermissions.GetRoles"xmlns="http://www.composite.net/ns/function/1.0"/></MultiKeySelector.Options></MultiKeySelector></FieldGroup></cms:layout></cms:formdefinition>
Composite.Membership.PagePermissions.GetRoles() is just a simple Composite inline function I created that returns a dictionary of roles. Also, the key to making the MultiKeySelector work properly is to use MultiKeySelector.SelectedAsString instead of MultiKeySelector.Selected. SelectedAsString is what will translate between a string collection and the comma separated string IPagePermissions expects.

Workflow

This was what turned my brain into mush for awhile. Burningice provided the real meat of the workflow, but there's a lot of overhead that you have to create in order for it to function. Create a new State Machine Workflow in your project. This will create a layout and a code-behind file. Replace the guts of the code-behind file with Burningice's code. These functions will be hooked up in specific places to what you're about to create in the layout.

I'm only going to give a broad overview of what you need to do. I would highly recommend downloading and having a look at this example workflow project, specifcally at EditProductWorkflow. It's almost identical to what's needed here.

You'll need to use some of Composite's workflow activities, and you won't have any way to access them by default. Follow the instructions on this page under "Getting access to custom Composite C1 activities" to add them to your toolbar.
  • You're creating a state machine with four states: Initial, Edit, Save, and Final. Each state follows a logical flow starting with initialization and ending with a move to another (or to the top of the current) state.
  • If you look at Burningice's functions, it should be clear what function goes where. Use a CodeActivity to hook them up to the workflow.
  • You'll need a few Composite workflow actions, DocumentFormActivity, SaveHandleExternalEventActivity, and CancelHandleExternalEventActivity. The latter two need no configuration, but the DocumentFormActivity needs a form location to open. This is where the DataProviderPlugin Composite.config entry comes into play. If you use an ActionProvider to attach your action to the tree, the root form location is ~/App_Data/Composite/Forms/. If you use a Tree Definition XML file, the root form location is ~/App_Data/Composite/DynamicTypeForms. FormDefinitionFileName simply wants the name of the form if it's directly under one of those roots. If you put it in a folder under one of the roots, tack on that folder name too.
  • A nice little gotcha that bit me... if you don't include the global cancel and the final state, your workflow will have no save button!
I hope I said everything that's needed. Keep in mind that I'm definitely NOT a Composite C1 expert, so while this works for me, I can't guarantee that it will work for you. That said, I'll try to answer any questions to the best of my knowledge.

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>