public static ObservableCollection <AllowedRole> GetAllowedRoles(this IAccessRestrictedItem item) { var additionalPermissions = JsonConvert.DeserializeObject <ObservableCollection <AllowedRole> >(item.AllowedRolesString ?? string.Empty) ?? new ObservableCollection <AllowedRole>(); additionalPermissions.CollectionChanged += item.SaveToPremissinBackingField; return(additionalPermissions); }
private static void SaveToPremissinBackingField(this IAccessRestrictedItem item, object sender, NotifyCollectionChangedEventArgs e) { var premissions = sender as ObservableCollection <AllowedRole>; if (premissions == null) { throw new InvalidOperationException("Cant Observe Entitiy AllowedPremissions For DataPresistence"); } item.AllowedRoles = premissions; }
public bool HasAccess(IAccessRestrictedItem restricted, AccessPremission premission) { if (restricted.AccessType == AccessType.Public) { return(true); } if (_identityManager.IsCurrentIdentitySupervisor()) { return(true); } var identityRoles = _identityManager.GetCurrentIdentityRoles(); return (restricted.AllowedRoles.Any( x => x.AccessPremission == premission && identityRoles.Contains(x.RoleName))); }