public RenderPartialExpression <TViewModel> RequiresAccessTo(params string[] roles) { if (_isAuthorized) { _isAuthorized = PrincipalRoles.IsInRole(roles); } return(this); }
public void authorized_link_to_positive_directly_against_endpoint_service() { execute(page => { PrincipalRoles.SetCurrentRolesForTesting("Role1"); return(page.AuthorizedLinkTo(svc => svc.EndpointFor <ConventionEndpoint>(x => x.get_authorized_data()))); }); theResult.ShouldEqual("<a href=\"/authorized/data\"></a>"); }
public void authorized_link_to_negative_directly_against_endpoint_service() { execute(page => { PrincipalRoles.SetCurrentRolesForTesting("Role2"); return(page.AuthorizedLinkTo(svc => svc.EndpointFor <ConventionEndpoint>(x => x.get_authorized_data()))); }); theResult.ShouldBe(string.Empty); }
public void read_role_off_principal() { var principal = new GenericPrincipal(new GenericIdentity("somebody"), new string[] { "a", "b" }); Thread.CurrentPrincipal = principal; PrincipalRoles.Current.ShouldBeTheSameAs(principal); PrincipalRoles.IsInRole("a").ShouldBeTrue(); PrincipalRoles.IsInRole("c").ShouldBeFalse(); }
public void link_to_by_input_model_that_passes_authorization() { execute(page => { PrincipalRoles.SetCurrentRolesForTesting("Role1"); return(page.LinkTo(new SecuredInput { Name = "Max" })); }); theResult.ShouldEqual("<a href=\"/secured/by/role/Max\"></a>"); }
public void link_to_by_input_model_that_does_not_pass_authorization() { execute(page => { PrincipalRoles.SetCurrentRolesForTesting("Role2"); return(page.LinkTo(new SecuredInput { Name = "Max" })); }); theResult.ShouldBeEmpty(); }
public FormLineExpression <T> EditableForRole(params string[] roles) { return(Editable(PrincipalRoles.IsInRole(roles))); }
public void SetUp() { PrincipalRoles.SetCurrentRolesForTesting("a", "b"); }
public void edit_if_the_user_does_not_have_a_role() { PrincipalRoles.SetCurrentRolesForTesting(); expression.EditableForRole("admin").ToString().ShouldNotContain("input"); }
// TODO -- will need something more generic later. Maybe. public ExtensionsExpression OnlyForRoles(params string[] roles) { Func <bool> filter = () => PrincipalRoles.IsInRole(roles); return(register(g => g.FilterLast(filter))); }
public static HtmlTag RequiresAccessTo(this HtmlTag tag, params string[] roleName) { return(tag.Authorized(tag.Authorized() && PrincipalRoles.IsInRole(roleName))); }
public static bool CanView(Type type) { return(PrincipalRoles.IsInRole(SecurableNameForViewing(type))); }
public static bool CanCreate(Type type) { return(PrincipalRoles.IsInRole(SecurableNameForCreation(type))); }