public IHtmlString With(AclEditModel model, string fieldName) { return(Html.Partial <Views.AccessControlList.Acl>().WithModel( new AccessControlListModel { Parameters = new AccessControlListParameters { Html = Html, FieldName = fieldName, SubjectSelector = model.SubjectSelector(Html) }, InitialEntries = (from t in model.Entries let target = t.Key from e in t.Where(FilterNullSubjects) group new { target, e } by e.Entry.Subject into subj let es = subj.Select(e => new { tp = TargetPrivilege.Pair(e.target, e.e.Entry.Privilege.SID, null), e = e.e }) select new PrivilegesListModel { Subject = subj.Key, OwnEntries = es.Where(e => e.e.InheritedFrom == null).Select(e => Pair.Create(e.tp, e.e.Entry.Kind)), InheritedEntries = es.Where(e => e.e.InheritedFrom != null).Select(e => Pair.Create(e.tp, new InheritedPrivilegeModel { Kind = e.e.Entry.Kind, InheritedFrom = e.e.InheritedFrom })) } ).ToList(), PrivilegeEditors = model.PrivilegeEditors })); }
public static IEnumerable <TargetPrivilegePair> GetApplicablePrivilegesForEditor <TDomain>(this ISecurityService <TDomain> sec, IEnumerable <SecurityTarget> targets, Func <HtmlHelper, SecurityTarget, SecurityPrivilege, IHtmlString> renderPrivilege = null) { //Contract.Requires( sec != null ); //Contract.Requires( targets != null && targets.Any() ); //Contract.Ensures( //Contract.Result<IEnumerable<TargetPrivilegePair>>() != null ); renderPrivilege = renderPrivilege ?? ((_, __, p) => new MvcHtmlString(p.Name)); var allKinds = targets.SelectMany(t => sec.KindsFor(t).Select(k => new { t, tid = t.Id(), k })); return(from p in sec.AllPrivileges.Values from tk in allKinds where tk.k.ApplicablePrivilegeSets.Any(p.BelongsTo) select TargetPrivilege.Pair(tk.tid, p.SID, html => renderPrivilege(html, tk.t, p))); }
public DefaultPrivilegesEditor(IEnumerable <TargetPrivilegePair> allPrivileges, Func <HtmlHelper, TargetPrivilegePair, IHtmlString> renderPrivilege) : this(allPrivileges.Select(tp => TargetPrivilege.Pair(tp.TargetId, tp.PrivilegeId, html => renderPrivilege(html, tp)))) { //Contract.Requires( allPrivileges != null ); //Contract.Requires( renderPrivilege != null ); }