private static IEnumerable <ISecurityGroup> GetRoles(IHasRoles target) { foreach (ISecurityGroup r in target.Roles) { yield return(r); } }
private static IEnumerable <Guid> GetRoleGuids(IHasRoles target) { foreach (IRole r in target.Roles) { yield return(r.Guid); } }
/// <summary> /// Checks the target role list to see if a role exists /// </summary> /// <param name="target">The target to check</param> /// <param name="thisRole">The role to check for</param> /// <returns>If the target has the role in its role list</returns> public static bool HasRole(this IHasRoles target, IRole thisRole) { if (thisRole is null) { throw new ArgumentNullException(nameof(thisRole)); } return(target.HasRole(thisRole.ExternalId)); }
/// <summary> /// Checks the target role list to see if a role exists /// </summary> /// <param name="target">The target to check</param> /// <param name="roleName">The name of the role to check for</param> /// <returns>If the target has the role in its role list</returns> public static bool HasRole(this IHasRoles target, string roleName) { if (target is null) { throw new ArgumentNullException(nameof(target)); } ICollection <IRole> userRoles = target.Roles.ToList() ?? new List <IRole>(); return(userRoles.Any(r => string.Equals(r.ExternalId, roleName, StringComparison.InvariantCultureIgnoreCase))); }
private void RefreshRoles(IHasRoles target) { foreach (Role r in target.Roles.ToList()) { if (this.RoleRepository.Find(r) is Role nr) { (target.Roles as IList <Role>)?.Remove(r); (target.Roles as IList <Role>)?.Add(nr); } } }
/// <summary> /// Returns a list of Guids representing ONLY the roles (not groups) that an object belongs to /// </summary> /// <param name="target">The target to check</param> /// <returns>A list of Guids representing ONLY the roles (not groups) that an object belongs to</returns> public static IEnumerable <Guid> SecurityGroups(this IHasRoles target) { if (target is null) { throw new ArgumentNullException(nameof(target)); } if (target is ISecurityGroup te) { yield return(te.Guid); } foreach (Guid g in GetRoleGuids(target)) { yield return(g); } }