/// <summary> /// Builds a domain consisting of the names of the user groups /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="extraValues">An array of string values to be added to the list</param> /// <returns>A coded value domain as an IGPDomain</returns> public static IGPDomain BuildGroupsDomain(IJTXDatabase3 wmxDb, string[] extraValues) { IGPCodedValueDomain domain = new GPCodedValueDomainClass(); // Sort the types first SortedList <string, string> sortedValues = new SortedList <string, string>(); IJTXUserGroupSet groups = wmxDb.ConfigurationManager.UserGroups; for (int i = 0; i < groups.Count; i++) { IJTXUserGroup group = groups.get_Item(i); sortedValues.Add(group.Name, null); } // Add the extra values, if any if (extraValues != null) { foreach (string s in extraValues) { sortedValues.Add(s, null); } } // Add the sorted types to the domain foreach (string value in sortedValues.Keys) { IGPValue tempGpVal = new GPStringClass(); tempGpVal.SetAsText(value); domain.AddCode(tempGpVal, value); } return(domain as IGPDomain); }
/// <summary> /// Builds a domain containing the usernames of the users to whom a /// user can assign jobs. /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="username">The name of the user to be tested</param> /// <param name="extraValues">An array of string values to be added to the list</param> /// <returns>A coded value domain of strings</returns> public static IGPDomain BuildAssignableUsersDomain(IJTXDatabase3 wmxDb, string username, string[] extraValues) { IGPCodedValueDomain domain = null; // Only proceed if the user exists in the Workflow Manager database IJTXUser3 user = wmxDb.ConfigurationManager.GetUser(username) as IJTXUser3; if (user == null) { return(domain as IGPDomain); } // Case 1: If the user can assign the job to anyone, then // just use the "all users" list if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_ASSIGN_ANY_JOB)) { domain = Common.WmauGpDomainBuilder.BuildUsersDomain(wmxDb, extraValues) as IGPCodedValueDomain; } else { domain = new GPCodedValueDomainClass(); string[] eligibleUsers = null; // Case 2: The user can assign jobs to anyone within any of their groups if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_GROUP_JOB_ASSIGN)) { HashSet <string> usernames = new HashSet <string>(); IJTXUserGroupSet groups = user.Groups; for (int i = 0; i < groups.Count; i++) { IJTXUserGroup group = groups.get_Item(i); for (int j = 0; j < group.Users.Count; j++) { usernames.Add(group.Users.get_Item(j).UserName); } } eligibleUsers = usernames.ToArray(); } // Case 3: The user can assign jobs to themselves else if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_INDIVIDUAL_JOB_ASSIGN)) { eligibleUsers = new string[] { username }; } // Case 4: The user can't assign jobs to anyone else { eligibleUsers = new string[0]; } // Sort the types first SortedList <string, string> sortedValues = new SortedList <string, string>(); for (int i = 0; i < eligibleUsers.Length; i++) { sortedValues.Add(eligibleUsers[i], null); } // Add the extra values, if any if (extraValues != null) { foreach (string s in extraValues) { sortedValues.Add(s, null); } } // Add the sorted types to the domain foreach (string value in sortedValues.Keys) { IGPValue tempGpVal = new GPStringClass(); tempGpVal.SetAsText(value); domain.AddCode(tempGpVal, value); } } return(domain as IGPDomain); }