Truly dynamic role assignment
I am trying to hijack the role assignment for watch, todo, forms and actions.
For watch and todo, this is relatively easy. I assign my dynamic role to the stage which then calls a server side script. This script knows the current process context so we can tell what stage we are at to dynamically assign a user to a stage whether that be in the watch or todo list.
However, in the case of forms or actions, as far as I can tell, there is no way to determine what form or action is checking its role within the server script.
Is there something in the metastorm object model that will allow me to do this?
My example is for a user stage with two forms and two actions:
- To do list = dyTodoList
- Watch list = dyWatchList
- Form 1 (restrict viewing to) = dyFormView
- Form 2 (restrict viewing to) = dyFormView
- Action 1 (available to roles) = dyActionUser
- Action 2 (available to roles) = dyActionUser
Role formulas:
- dyTodoList = Metastorm.Runtime.Models.MyProject.RoleAssignment.Assign(Metastorm.Runtime.Models.MyProject.RoleAssignment.RoleType.TodoList)
- dyWatchList = Metastorm.Runtime.Models.MyProject.RoleAssignment.Assign(Metastorm.Runtime.Models.MyProject.RoleAssignment.RoleType.WatchList)
- dyFormView = Metastorm.Runtime.Models.MyProject.RoleAssignment.Assign(Metastorm.Runtime.Models.MyProject.RoleAssignment.RoleType.FormView)
- dyActionUser = Metastorm.Runtime.Models.MyProject.RoleAssignment.Assign(Metastorm.Runtime.Models.MyProject.RoleAssignment.RoleType.ActionUser)
Rule formula script:
... public class RoleAssignment { public enum RoleType { ActionUser = 1, FormView = 2, TodoList = 4, WatchList = 8 }; public static List Assign(RoleType roleType) { List users = new List(); ProcessContext processContext = new ProcessContext(); // Todo list or watch list items, determine the stage and return users relevant to that stage if ((roleType == RoleType.TodoList) || (roleType == RoleType.WatchList)) { if (processContext.StageName == "Stage1") { users.Append(new string[] { "User1", "User2" } ); } if (processContext.StageName == "Stage2") { users.Append(new string[] { "User3", "User4" } ); } } // List of users available to the action that is being checked if (roleType == RoleType.ActionUser) { // ? What action is currently checking its role ? if (action.actionname == "action1") { users.Append(new string[] { "User5", "User6" } ); } if (action.actionname == "action2") { users.Append(new string[] { "User7", "User8" } ); } } // List of users able to see the form that is being checked if (roleType == RoleType.FormView) { // ? What action is currently checking its role ? if (form.formname == "form1") { users.Append(new string[] { "User9", "UserA" } ); } if (form.formname == "form2") { users.Append(new string[] { "UserB", "UserC" } ); } } return users; } } ...
If I were able to determine the form or action name within this server script, I can then create a script that can dynamically assign users to specific stages, forms and actions without having to make changes to a project or having to deploy a new solution.
Adding some logging code to the above does indeed show that the script is called a total of 6 times when entering a stage. So that kind of confirms the process that is taking place.
I could leave the forms and actions available to 'everyone' and enter some specific code in the 'restrict viewing to' / 'only show action if' that sends through the action / form name with each call. However, this would be a bit clunky and mean development overhead.
Ultimately, I am hoping that someone out there knows where in the object model I can get the information I need to move forward.
Any suggestions gratefully accepted.
Nils.
Comments
-
Are ProcessContext.ActionName and ProcessContext.FormName NULL in the context of the role?
0 -
Yes. If I use a loopback to refresh the folder, both of these would be null. I don't believe any of the ProcessContext object is relevant for what I am trying to do here.
I'm hoping that there is another object in the model that shows me what form / action is looking up the role assignment.
If I extend the function above to output the stack trace to the database / log, I can see the source of the call but it is not in an easily manageable form. e.g.
at Metastorm.Runtime.Models.MyProject.RoleAssignment.Assign(RoleType roleType) at Metastorm.Runtime.Models.MyProject.dyActionUser.InternalUserAccess() at Metastorm.Runtime.Core.Roles.Role.UserAccess() at Metastorm.Runtime.Core.Roles.Role.IsMember(String userName) at Metastorm.Runtime.Models.MyProject.MyProcess.Declarations.MyProcessActions.Declarations.SendEmailAction.get_HasAccess() at Metastorm.Engine.Evaluation.FolderEvaluation.ActionList() at Metastorm.Engine.Operations.OpenFolderHandler.Process(String sessionId, String callerId, CultureInfo culture, String clientData, DateTimeOffset requestTimeStamp, String folderId, String requestedForm, Boolean noLayout, Boolean noData, Int32 version, String clientType ...
0 -
Using the stack trace example above, this is the way I am currently getting around this problem.
... using System.Diagnostics; using System.Reflection; ... string source = ""; // Find the source of the call to this function StackTrace trace = new StackTrace(); foreach (StackFrame stackFrame in trace.GetFrames()) { MethodBase stackMethod = stackFrame.GetMethod(); if ((stackMethod.Name == "get_HasAccess") || (stackMethod.Name == "get_InternalToDoList") || (stackMethod.Name == "get_InternalWatchList")) { source = stackMethod.ReflectedType.Name; } } ...
This retrieves the form name, action name or stage name that is calling the method underlying the dynamic role. Not elegant, but it works.
If anyone has an alternative method (or if there is a static property somewhere in the object model), please let me know!
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 152 General Questions
- 148 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 32 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 10 XM Fax
- Follow Categories