/// <summary> /// Make a ProjectFirmaMenuItem from a route. A feature is required on the Route and will be used to check access for the menu item. /// If menu item is not accessible, it will not be shown. /// </summary> public static LtInfoMenuItem MakeItem <T>(SitkaRoute <T> route, Person currentPerson, string menuItemName, string menuGroupName) where T : Controller { var urlString = route.BuildUrlFromExpression(); var shouldShow = FirmaBaseFeature.IsAllowed(route, currentPerson); return(new LtInfoMenuItem(urlString, menuItemName, shouldShow, false, menuGroupName)); }
/// <summary> /// Throws an exception if the <see cref="Person"/> associated with this <see cref="WebServiceToken"/> does not have access to <see cref="FirmaBaseFeature" /> /// In a unit test using <see cref="WebServiceTokenGuidForUnitTests"/> this will always pass, and <see cref="Person"/> will return Stewart Gordon's person ID for now /// Might want to introduce a system person at some point. /// </summary> /// <param name="feature"></param> public void DemandHasPermission(FirmaBaseFeature feature) { if (IsValidAsUnitTestToken(_tokenGuid, false)) { // We consider the Unit Test one good if it's in the right environment return; } Check.RequireNotNull(_person, string.Format("The provided token {0} = \"{1}\" is not associated with a person. Cannot check for access to feature \"{2}\"", WebServiceTokenModelBinder.WebServiceTokenParameterName, _tokenGuid, feature.FeatureName)); var hasPermission = feature.HasPermissionByPerson(_person); Check.Require(hasPermission, string.Format("Web service token \"{0}\" is for person \"{1}\" PersonID={2}, but that person does not have access to feature \"{3}\"" , _tokenGuid, _person.GetFullNameFirstLast(), _person.PersonID , feature.FeatureName)); }