示例#1
0
        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);
        }
示例#2
0
文件: Endpoint.cs 项目: Agnael/Sero
        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;
        }
示例#3
0
        public static bool IsOfResource(this ActionDescriptor action, string resourceCode, EndpointScope scope)
        {
            var hateoasAttr = action.GetHateoasAttribute();

            return(hateoasAttr.ResourceCode == resourceCode &&
                   hateoasAttr.Scope == scope);
        }
示例#4
0
        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);
        }
示例#5
0
 public SafeEndpointAttribute(string resourceCode, PermissionLevel levelRequired, EndpointScope actionScope)
     : base(resourceCode, actionScope)
 {
     this.LevelRequired = levelRequired;
 }
示例#6
0
 public EndpointAttribute(string resourceCode, EndpointScope actionScope)
 {
     this.ResourceCode = resourceCode;
     this.Scope        = actionScope;
 }