コード例 #1
0
        public ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context)
        {
            var item = input.ToObjectValue() as ContentItem;

            if (item == null)
            {
                throw new ArgumentException("ContentItem missing while calling 'user_can_view' filter");
            }

            if (_contentPermissionsService.CanAccess(item))
            {
                return(new ValueTask <FluidValue>(BooleanValue.True));
            }

            return(new ValueTask <FluidValue>(BooleanValue.False));
        }
コード例 #2
0
        public override IDisplayResult Display(ContentPermissionsPart part, BuildPartDisplayContext context)
        {
            var settings = _contentPermissionsService.GetSettings(part);

            if (context.DisplayType != "Detail" || !settings.HasRedirectUrl || _contentPermissionsService.CanAccess(part))
            {
                return(null);
            }

            var redirectUrl = settings.RedirectUrl;

            if (!settings.RedirectUrl.StartsWith("/"))
            {
                redirectUrl = $"/{redirectUrl}";
            }

            _httpContextAccessor.HttpContext.Response.StatusCode = 403;
            _httpContextAccessor.HttpContext.Response.Redirect($"{_httpContextAccessor.HttpContext.Request.PathBase}{redirectUrl}", false);
            return(null);
        }
コード例 #3
0
 public bool CanAccess(ContentItem contentItem)
 {
     return(_contentPermissionsService.CanAccess(contentItem));
 }
コード例 #4
0
        public async Task <IActionResult> Submit(string formId)
        {
            var canView = ContentTypePermissionsHelper.CreateDynamicPermission(ContentTypePermissionsHelper.PermissionTemplates[CommonPermissions.ViewContent.Name], "VueForm");

            if (!await _authorizationService.AuthorizeAsync(User, canView))
            {
                return(NotFound());
            }

            var form = await _contentManager.GetAsync(formId, VersionOptions.Published);

            if (form == null)
            {
                return(NotFound());
            }

            var formPart = form.As <VueForm>();

            if (formPart.Disabled.Value)
            {
                return(NotFound());
            }

            if (!_contentPermissionsService.CanAccess(form))
            {
                return(NotFound());
            }

            var scriptingProvider = new VueFormMethodsProvider(form);

            var script = form.As <VueFormScripts>();

            // This object holds the return value of the script
            object serverScriptResult = EvaluateScript(script?.OnValidation?.Text, scriptingProvider, formPart, "OnValidation");

            // Return if any errors are returned in the OnValidation script
            if (ModelState.ErrorCount > 0)
            {
                return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart))));
            }

            serverScriptResult = EvaluateScript(script?.OnSubmitted?.Text, scriptingProvider, formPart, "OnSubmitted");

            // Return if any errors are returned from the OnSubmitted script
            if (ModelState.ErrorCount > 0)
            {
                return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart))));
            }

            // _workflow manager is null if workflow feature is not enabled
            if (_workflowManager != null)
            {
                await _workflowManager.TriggerEventAsync(nameof(VueFormSubmittedEvent),
                                                         input : new { VueForm = form },
                                                         correlationId : form.ContentItemId
                                                         );
            }

            // Return if any errors are returned from the Workflow
            if (ModelState.ErrorCount > 0)
            {
                return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart))));
            }

            // Handle the redirects with ajax requests.
            // 302 are equivalent to 301 in this case. No permanent redirect.
            // This can come from a scripting method or the HttpRedirect Workflow Task
            if (HttpContext.Response.StatusCode == 301 || HttpContext.Response.StatusCode == 302)
            {
                var returnValue = new { redirect = WebUtility.UrlDecode(HttpContext.Response.Headers["Location"]) };
                HttpContext.Response.Clear();
                return(Json(returnValue));
            }

            // This get's set by either the workflow's HttpRedirectTask or HttpResponseTask
            if (HttpContext.Items[WorkflowHttpResult.Instance] != null)
            {
                // Let the HttpResponseTask control the response. This will fail on the client if it's anything other than json
                return(new EmptyResult());
            }

            //try to get the message from the http context as set by the addSuccessMessage() scripting function
            var successMessage = string.Empty;

            if (HttpContext.Items[Constants.VueFormSuccessMessage] != null)
            {
                successMessage = (string)HttpContext.Items[Constants.VueFormSuccessMessage];
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(formPart.SuccessMessage?.Text))
                {
                    var formSuccessMessage = await _liquidTemplateManager.RenderStringAsync(formPart.SuccessMessage.Text, _htmlEncoder);

                    successMessage = await _shortcodeService.ProcessAsync(formSuccessMessage);
                }
            }

            return(Json(new VueFormSubmitResult(successMessage, serverScriptResult, GetDebugLogs(formPart))));
        }