private async Task SyncRoles(User user) { var adminRole = await SecurityRole.SelectByCode("Admins"); var dwUserToRole = await SecurityUserToSecurityRole.SelectByUser(user.WorkflowUserId.Value); if (user.HasRole(RoleName.SuperAdmin)) { // Make sure User is in "Admins" Role if (!dwUserToRole.Any(utr => utr.SecurityRoleId == adminRole.Id)) { var newAdmin = new SecurityUserToSecurityRole { Id = Guid.NewGuid(), SecurityRoleId = adminRole.Id, SecurityUserId = user.WorkflowUserId.Value }; await SecurityUserToSecurityRole.ApplyAsync(newAdmin); } } else { // Make sure User is not "Admins" Role var userAdminRole = dwUserToRole.FirstOrDefault(dtr => dtr.SecurityRoleId == adminRole.Id); if (userAdminRole != null) { await SecurityUserToSecurityRole.DeleteAsync(userAdminRole.Id); } } }
private Dictionary <Guid, SecurityUserToSecurityRole> GetHashDwAdmins(List <Guid> userids) { var adminRole = SecurityRole.SelectByCode("Admins").Result; var usersToAdminRoles = SecurityUserToSecurityRole.SelectByRole(adminRole.Id).Result; var hash = usersToAdminRoles .Where(ur => ur.SecurityRoleId == adminRole.Id && userids.Any(uid => uid == ur.SecurityUserId)) .ToDictionary(ur => ur.SecurityUserId, ur => ur); return(hash); }
public bool RoleCheck(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string parameter) { var role = SecurityRole.SelectByCode(parameter).Result; if (role == null) { return(false); } var roleUserModel = SecurityUserToSecurityRole.Model; return(roleUserModel.GetCountAsync(Filter.And.Equal(role.Id, "RoleId").Equal(Guid.Parse(identityId), "UserId")).Result > 0); }
public IEnumerable <string> RoleGet(ProcessInstance processInstance, WorkflowRuntime runtime, string parameter) { var role = SecurityRole.SelectByCode(parameter).Result; if (role == null) { return(new List <string>()); } var roleUserModel = SecurityUserToSecurityRole.SelectByRole(role.Id).Result; return(roleUserModel.Select(r => r.SecurityUserId.ToString()).Distinct()); }
public static async Task CheckDefaultRole(Guid userId, string roleCode) { if (await SecurityUserToSecurityRole.HasUserRole(userId, roleCode)) { return; } var role = await SecurityRole.SelectByCode(roleCode); if (role != null) { var suroles = new SecurityUserToSecurityRole() { Id = Guid.NewGuid(), SecurityRoleId = role.Id, SecurityUserId = userId }; await suroles.ApplyAsync(); } }