private IEnumerable <Endpoint> GetEndpoints(IApiResource resource, EndpointScope scope, EndpointType type, IHateoasAuthorizator authorizator) { var links = Endpoints .Where(x => x.Type == type && x.Scope == scope && x.ResourceCode == resource.ApiResourceCode && authorizator.IsAuthorized(resource, x)); return(links); }
public Endpoint(ControllerActionDescriptor action) { var elementGetterAttr = action.GetElementGetterAttribute(); bool isElementGetter = false; string getterParameterName = null; string getterDisplayNameWhenLinked = null; if (elementGetterAttr != null) { isElementGetter = true; getterDisplayNameWhenLinked = elementGetterAttr.DisplayNameWhenLinked; getterParameterName = action.GetGetterParameterName(); if (string.IsNullOrEmpty(getterParameterName)) { throw new Exception("Si el endpoint es un ElementGetter, entonces es obligatorio proporcionar un GetterParameterName NO NULO."); } } string actionName = CasingUtil.UpperCamelCaseToLowerUnderscore(action.ActionName); EndpointType type = EndpointType.Action; HttpMethodAttribute httpMethodAttr = action.GetHttpMethodAttribute(); string httpMethod = action.GetHttpMethodValue(); if (httpMethod == HttpMethods.Get) { type = EndpointType.Link; } var hateoasAttr = action.GetHateoasAttribute(); this.Action = action; this.IsElementGetter = isElementGetter; this.GetterParameterName = getterParameterName; this.DisplayNameWhenLinked = getterDisplayNameWhenLinked; this.ResourceCode = hateoasAttr.ResourceCode; this.MvcActionName = action.ActionName; this.EndpointName = actionName; this.Type = type; this.Scope = hateoasAttr.Scope; this.UrlTemplate = httpMethodAttr.Template; this.HttpMethod = httpMethod; }
public static bool IsOfResource(this ActionDescriptor action, string resourceCode, EndpointScope scope) { var hateoasAttr = action.GetHateoasAttribute(); return(hateoasAttr.ResourceCode == resourceCode && hateoasAttr.Scope == scope); }
public static bool IsActionFor(this ActionDescriptor action, string resourceCode, EndpointScope scope) { bool isHttpGet = action.IsHttpGet(); if (isHttpGet) { return(false); } var hateoasAttr = action.GetHateoasAttribute(); return(hateoasAttr.ResourceCode == resourceCode && hateoasAttr.Scope == scope); }
public SafeEndpointAttribute(string resourceCode, PermissionLevel levelRequired, EndpointScope actionScope) : base(resourceCode, actionScope) { this.LevelRequired = levelRequired; }
public EndpointAttribute(string resourceCode, EndpointScope actionScope) { this.ResourceCode = resourceCode; this.Scope = actionScope; }