public async Task <List <UserGroupAssignment> > ListLocationApprovalPermissionAsssignments(string buyerID, string locationID, VerifiedUserContext verifiedUser) { await EnsureUserIsLocationAdmin(locationID, verifiedUser); var locationUserTypes = HSUserTypes.BuyerLocation().Where(s => s.UserGroupIDSuffix == UserGroupSuffix.NeedsApproval.ToString() || s.UserGroupIDSuffix == UserGroupSuffix.OrderApprover.ToString()); var userGroupAssignmentResponses = await Throttler.RunAsync(locationUserTypes, 100, 5, locationUserType => { return(_oc.UserGroups.ListUserAssignmentsAsync(buyerID, userGroupID: $"{locationID}-{locationUserType.UserGroupIDSuffix}", pageSize: 100)); }); return(userGroupAssignmentResponses .Select(userGroupAssignmentResponse => userGroupAssignmentResponse.Items) .SelectMany(l => l) .ToList()); }
public async Task CreateLocationUserGroupsAndApprovalRule(string buyerLocationID, string locationName, string token) { var buyerID = buyerLocationID.Split('-').First(); var AddUserTypeRequests = HSUserTypes.BuyerLocation().Select(userType => AddUserTypeToLocation(token, buyerLocationID, userType)); await Task.WhenAll(AddUserTypeRequests); var approvingGroupID = $"{buyerLocationID}-{UserGroupSuffix.OrderApprover.ToString()}"; await _oc.ApprovalRules.CreateAsync(buyerID, new ApprovalRule() { ID = buyerLocationID, ApprovingGroupID = approvingGroupID, Description = "General Approval Rule for Location. Every Order Over a Certain Limit will Require Approval for the designated group of users.", Name = $"{locationName} General Location Approval Rule", RuleExpression = $"order.xp.ApprovalNeeded = '{buyerLocationID}' & order.Total > 0" }); }
public async Task CreateUserTypeUserGroupsAndSecurityProfileAssignments(User user, string token, string supplierID) { // Assign supplier to HSMeAdmin security profile await _oc.SecurityProfiles.SaveAssignmentAsync(new SecurityProfileAssignment() { SupplierID = supplierID, SecurityProfileID = "HSMeAdmin" }, token); foreach (var userType in HSUserTypes.Supplier()) { var userGroupID = $"{supplierID}{userType.UserGroupIDSuffix}"; await _oc.SupplierUserGroups.CreateAsync(supplierID, new UserGroup() { ID = userGroupID, Name = userType.UserGroupName, xp = { Type = "UserPermissions", } }, token); await _oc.SupplierUserGroups.SaveUserAssignmentAsync(supplierID, new UserGroupAssignment() { UserID = user.ID, UserGroupID = userGroupID }, token); foreach (var customRole in userType.CustomRoles) { await _oc.SecurityProfiles.SaveAssignmentAsync(new SecurityProfileAssignment() { SupplierID = supplierID, UserGroupID = userGroupID, SecurityProfileID = customRole.ToString() }, token); } } }
public async Task CreateSinglePermissionGroup(string buyerLocationID, string permissionGroupID) { var permissionGroup = HSUserTypes.BuyerLocation().Find(userType => permissionGroupID.Contains(userType.UserGroupIDSuffix)); await AddUserTypeToLocation(buyerLocationID, permissionGroup); }