Beispiel #1
0
        public void ShapeTableCreated(ShapeTable shapeTable)
        {
            var typeDefinitions = _contentDefinitionManager.Value.ListTypeDefinitions();
            var allPlacements   = typeDefinitions.SelectMany(td => td.GetPlacement(PlacementType.Editor).Select(p => new TypePlacement {
                Placement = p, ContentType = td.Name
            }));

            // group all placement settings by shape type
            var shapePlacements = allPlacements.GroupBy(x => x.Placement.ShapeType).ToDictionary(x => x.Key, y => y.ToList(), StringComparer.OrdinalIgnoreCase);

            // create a new predicate in a ShapeTableDescriptor has a custom placement
            foreach (var shapeType in shapeTable.Descriptors.Keys)
            {
                List <TypePlacement> customPlacements;
                if (shapePlacements.TryGetValue(shapeType, out customPlacements))
                {
                    var descriptor = shapeTable.Descriptors[shapeType];
                    // there are some custom placements, build a predicate
                    var placement = descriptor.Placement;

                    if (!customPlacements.Any())
                    {
                        continue;
                    }

                    descriptor.Placement = ctx => {
                        var workContext = _workContextAccessor.GetContext();
                        if (ctx.DisplayType == null &&
                            AdminFilter.IsApplied(workContext.HttpContext.Request.RequestContext))   // Tests if it's executing in admin in order to override placement.info for editors in back-end only

                        {
                            foreach (var customPlacement in customPlacements)
                            {
                                var type           = customPlacement.ContentType;
                                var differentiator = customPlacement.Placement.Differentiator;

                                if (((ctx.Differentiator ?? String.Empty) == (differentiator ?? String.Empty)) && ctx.ContentType == type)
                                {
                                    var location = customPlacement.Placement.Zone;
                                    if (!String.IsNullOrEmpty(customPlacement.Placement.Position))
                                    {
                                        location = String.Concat(location, ":", customPlacement.Placement.Position);
                                    }
                                    // clone the identified Placement.info into a new one in order to keep original informations like Wrappers and Alternates
                                    var originalPlacementInfo = placement(ctx);
                                    return(new PlacementInfo {
                                        Location = location,
                                        Alternates = originalPlacementInfo.Alternates,
                                        ShapeType = originalPlacementInfo.ShapeType,
                                        Wrappers = originalPlacementInfo.Wrappers
                                    });
                                }
                            }
                        }

                        return(placement(ctx));
                    };
                }
            }
        }
        public ActionResult Create(ReservationsCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Reservation reservation = new Reservation();

            reservation.ID = model.ID;
            if (AdminFilter.IsAdmin())
            {
                reservation.UserId = model.UserId;
            }
            else
            {
                reservation.UserId = AdminFilter.GetUserId();
            }
            reservation.RestaurantId    = model.RestaurantId;
            reservation.PeopleCount     = model.PeopleCount;
            reservation.ReservationTime = model.ReservationTime.Date;
            reservation.Comment         = model.Comment;

            var repository = new ReservationRepository();

            repository.Insert(reservation);

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // display our stuff if we are going to display a view
            if (!(filterContext.Result is ViewResultBase))
            {
                return;
            }

            if (!AdminFilter.IsApplied(_workContext.GetContext().HttpContext.Request.RequestContext))
            {
                object fromTmp           = filterContext.HttpContext.Items[TempDataKey];
                bool?  isNewSubscription = fromTmp == null ? (bool?)null : (bool?)fromTmp;
                if (isNewSubscription.HasValue && isNewSubscription.Value)
                {
                    // add our scripts to the page's footer
                    StringBuilder script = new StringBuilder();
                    script.Append("<script type=\"text/javascript\">");
                    script.Append("window.dataLayer = window.dataLayer || [];");
                    script.Append("window.dataLayer.push({");
                    script.Append("'event': 'newsletterSubscription'");
                    script.Append("});");
                    script.Append("</script>");
                    _resourceManager.RegisterFootScript(script.ToString());
                }
            }
        }
Beispiel #4
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var user = _wca.GetContext().CurrentUser;

            // Not doing anything on the admin or for anonymous users, and also
            if (AdminFilter.IsApplied(filterContext.RequestContext) || user == null)
            {
                return;
            }

            var notificationsUserPart = user.As <NotificationsUserPart>();

            // Not checking if CheckIntervalMinutes hasn't passed yet since the last update.
            if (notificationsUserPart.LastCheckedUtc >= _clock.UtcNow.AddMinutes(-1 * Constants.NewNotificationCheckIntervalMinutes))
            {
                return;
            }

            notificationsUserPart.LastCheckedUtc = _clock.UtcNow;

            // Using the processing engine to do the update after the request has executed so the user experience is not impacted.
            var shellDescriptor = _shellDescriptorManager.GetShellDescriptor();

            _processingEngine.AddTask(
                _shellSettings,
                shellDescriptor,
                "IUserNotificationsUpdaterEventHandler.UpdateNotificationsForUser",
                new Dictionary <string, object> {
                { "userId", user.ContentItem.Id }
            }
                );
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // ignore tracker on admin pages
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            var script = _cacheManager.Get("GoogleAnalytics.Settings",
                                           ctx => {
                ctx.Monitor(_signals.When("GoogleAnalytics.SettingsChanged"));
                var settings = _settingsService.Get();
                return(!settings.Enable ? null : settings.Script);
            });

            if (String.IsNullOrEmpty(script))
            {
                return;
            }

            var context = _workContextAccessor.GetContext();
            var tail    = context.Layout.Tail;

            tail.Add(new MvcHtmlString(script));
        }
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("HeadScripts")
            .OnDisplaying(shapeDisplayingContext =>
            {
                if (!_imagesLoadedService.GetAutoEnable())
                {
                    return;
                }
                if (!_imagesLoadedService.GetAutoEnableAdmin())
                {
                    var request = _workContext.Value.HttpContext.Request;
                    if (AdminFilter.IsApplied(request.RequestContext))
                    {
                        return;
                    }
                }

                var resourceManager = _workContext.Value.Resolve <IResourceManager>();
                var scripts         = resourceManager.GetRequiredResources("script");


                string includejs     = "imagesLoaded";
                var currentHighlight = scripts
                                       .Where(l => l.Name == includejs)
                                       .FirstOrDefault();

                if (currentHighlight == null)
                {
                    resourceManager.Require("script", includejs).AtFoot();
                }
            });
        }
Beispiel #7
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Content")
            .OnDisplaying(displaying =>
            {
                if (AdminFilter.IsApplied(new RequestContext(_workContext.GetContext().HttpContext, new RouteData())))
                {
                    return;
                }

                if (displaying.ShapeMetadata.DisplayType != "Detail")
                {
                    return;
                }

                ContentItem contentItem = displaying.Shape.ContentItem;
                if (contentItem != null)
                {
                    var wavePart = contentItem.As <WavePart>();

                    if (wavePart == null)
                    {
                        return;
                    }

                    displaying.ShapeMetadata.Wrappers.Add("Wave_Wrapper");
                }
            });
        }
Beispiel #8
0
        public void OnDisplaying(ShapeDisplayingContext context)
        {
            // Check to see if the markup for this shape is already in the cache, and if so, there is no need to render it! :)
            // We can prevent the render by setting context.ChildContent to anything other than null (the default display manager checks this property before calling render).
            // In our case, we want to set this to the placeholder value, so that it can be replaced with the cached markup later on in the request pipeline.

            if (AdminFilter.IsApplied(mHttpContextAccessor.Current().Request.RequestContext))
            {
                return;
            }

            var contentItem = (IContent)context.Shape.ContentItem;

            var itemLevelTokenizationShouldBeBypassed = ItemLevelTokenizationShouldBeBypassed(context);
            var markupMustNotBeTokenized = !mItemLevelCacheService.MarkupShouldBeTokenized(contentItem, context.ShapeMetadata.DisplayType);

            if (itemLevelTokenizationShouldBeBypassed || markupMustNotBeTokenized)
            {
                return;
            }

            var placeholderText = mItemLevelCacheService.GetPlaceholderText(contentItem, context.ShapeMetadata.DisplayType);

            context.ShapeMetadata.Wrappers = new List <string>(); // TODO: add in ability to toggle debug info wrappers?
            context.ChildContent           = new HtmlString(WrapPlaceholderText(placeholderText));
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (!AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // if it's not a view result, a redirect for example
            if (!(filterContext.Result is ViewResultBase))
            {
                return;
            }

            // if it's a child action, a partial view for example
            if (filterContext.IsChildAction)
            {
                return;
            }



            var messageEntries = _notificationManager.GetNotifications().ToList();

            if (!messageEntries.Any())
            {
                return;
            }

            var messagesZone = _workContextAccessor.GetContext(filterContext).Layout.Zones["Messages"];

            foreach (var messageEntry in messageEntries)
            {
                messagesZone = messagesZone.Add(_shapeFactory.Message(messageEntry));
            }
        }
        protected override DriverResult Display(MobileContactPart part, string displayType, dynamic shapeHelper)
        {
            //Determine if we're on an admin page
            bool isAdmin = AdminFilter.IsApplied(_orchardServices.WorkContext.HttpContext.Request.RequestContext);

            if (isAdmin)
            {
                if (displayType == "Detail")
                {
                    List <PushNotificationRecord> viewModel = new List <PushNotificationRecord>();
                    if (part.MobileEntries != null && part.MobileEntries.Value != null && part.MobileEntries.Value.Count > 0)
                    {
                        viewModel = part.MobileEntries.Value.ToList();
                    }
                    return(ContentShape("Parts_MobileContact",
                                        () => shapeHelper.Parts_MobileContact(Devices: viewModel)));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #11
0
        protected override DriverResult Editor(ReCaptchaPart part, dynamic shapeHelper)
        {
            var workContext = _workContextAccessor.GetContext();

            // don't display the part in the admin
            if (AdminFilter.IsApplied(workContext.HttpContext.Request.RequestContext))
            {
                return(null);
            }

            return(ContentShape("Parts_ReCaptcha_Fields", () => {
                var settings = workContext.CurrentSite.As <ReCaptchaSettingsPart>();

                if (settings.TrustAuthenticatedUsers && workContext.CurrentUser != null)
                {
                    return null;
                }

                var viewModel = new ReCaptchaPartEditViewModel {
                    PublicKey = settings.PublicKey
                };

                return shapeHelper.EditorTemplate(TemplateName: "Parts.ReCaptcha.Fields", Model: viewModel, Prefix: Prefix);
            }));
        }
Beispiel #12
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // ignore filter on admin pages
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var themeName = _siteThemeService.GetSiteTheme();

            if (themeName.Name == Constants.ThemeName)
            {
                this.AddCss();
            }
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // Kirigami should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            // Some standard checks
            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // TODO: Build and add shape to zone.

            /*var zones = workContext.Layout.Zones;
             * foreach (var widgetPart in widgetParts)
             * {
             *  if (activeLayerIds.Contains(widgetPart.As<ICommonPart>().Container.ContentItem.Id))
             *  {
             *      var widgetShape = _contentManager.BuildDisplay(widgetPart);
             *      zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
             *  }
             * }*/
        }
Beispiel #14
0
        /// <summary>
        /// Updates the items by checking for permissions
        /// </summary>
        private IEnumerable <MenuItem> Reduce(IEnumerable <MenuItem> items)
        {
            var hasDebugShowAllMenuItems = _authorizationService.TryCheckAccess(Permission.Named("DebugShowAllMenuItems"), _orchardServices.WorkContext.CurrentUser, null);

            foreach (var item in items)
            {
                if (hasDebugShowAllMenuItems ||
                    AdminFilter.IsApplied(_urlHelper.RequestContext) ||
                    item.Permissions.Concat(new [] { Permission.Named("ViewContent") }).Any(x => _authorizationService.TryCheckAccess(x, _orchardServices.WorkContext.CurrentUser, item.Content)))
                {
                    yield return(new MenuItem {
                        Items = Reduce(item.Items),
                        Permissions = item.Permissions,
                        Position = item.Position,
                        RouteValues = item.RouteValues,
                        LocalNav = item.LocalNav,
                        Culture = item.Culture,
                        Text = item.Text,
                        IdHint = item.IdHint,
                        Classes = item.Classes,
                        Url = item.Url,
                        LinkToFirstChild = item.LinkToFirstChild,
                        Href = item.Href,
                        Content = item.Content
                    });
                }
            }
        }
        protected override DriverResult Display(SmsContactPart part, string displayType, dynamic shapeHelper)
        {
            //Determine if we're on an admin page
            bool isAdmin = AdminFilter.IsApplied(_orchardServices.WorkContext.HttpContext.Request.RequestContext);

            if (isAdmin)
            {
                if (displayType == "Detail")
                {
                    View_SmsVM         viewModel = new View_SmsVM();
                    View_SmsVM_element vm        = new View_SmsVM_element();
                    if (part.SmsEntries.Value != null)
                    {
                        List <CommunicationSmsRecord> oldviewModel = part.SmsEntries.Value.ToList();
                        foreach (CommunicationSmsRecord cm in oldviewModel)
                        {
                            vm = new View_SmsVM_element();
                            _mapper.Map <CommunicationSmsRecord, View_SmsVM_element>(cm, vm);
                            viewModel.Elenco.Add(vm);
                        }
                    }
                    return(ContentShape("Parts_SmsContact",
                                        () => shapeHelper.Parts_SmsContact(Elenco: viewModel.Elenco)));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #16
0
 public override IEnumerable <dynamic> GetAdditionalOrderMetadataShapes(OrderPart orderPart)
 {
     // I need to avoid showing these shapes if I'm in the backoffice.
     if (!AdminFilter.IsApplied(_workContextAccessor.GetContext().HttpContext.Request.RequestContext))
     {
         var transactionId = orderPart.Charge?.TransactionId;
         if (transactionId != null)
         {
             PaymentRecord payment = _paymentService.GetPaymentByTransactionId(transactionId);
             if (payment != null)
             {
                 var metaShapes = _customPosProviders
                                  .Select(cpp => cpp.GetAdditionalFrontEndMetadataShapes(payment))
                                  .ToList();
                 // metaShapes variable is a list of lists.
                 foreach (var l in metaShapes)
                 {
                     foreach (var shape in l.ToList())
                     {
                         yield return(shape);
                     }
                 }
             }
         }
     }
 }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            var script = _cacheManager.Get("Mod.CookieConsent.Script",
                                           ctx => {
                ctx.Monitor(_signals.When("Mod.CookieConsent.Changed"));
                var settings = _wca.GetContext().CurrentSite.As <CookieConsentSettingsPart>();
                return(settings.BuildScript());
            });

            if (String.IsNullOrEmpty(script))
            {
                return;
            }

            var context = _wca.GetContext();
            var tail    = context.Layout.Tail;

            tail.Add(new MvcHtmlString(script));
        }
        private CultureSelectorResult EvaluateResult(HttpContextBase context)
        {
            if (context == null || context.Request == null || context.Request.Cookies == null)
            {
                return(null);
            }
            if (AdminFilter.IsApplied(context.Request.RequestContext))   // I am in admin context so I have to use defualt site culture
            {
                return(new CultureSelectorResult {
                    Priority = SelectorPriority, CultureName = _orchardServices.WorkContext.CurrentSite.SiteCulture
                });
            }

            HttpCookie cultureCookie = context.Request.Cookies[context.Request.AnonymousID + CultureCookieName];

            if (cultureCookie == null)
            {
                return(null);
            }

            string currentCultureName = cultureCookie[CurrentCultureFieldName];

            if (String.IsNullOrEmpty(currentCultureName))
            {
                return(null);
            }
            return(new CultureSelectorResult {
                Priority = SelectorPriority, CultureName = currentCultureName
            });
        }
        public void IsAppliedShouldBeFalseByDefault()
        {
            var context   = new RequestContext(new StubHttpContext(), new RouteData());
            var isApplied = AdminFilter.IsApplied(context);

            Assert.That(isApplied, Is.False);
        }
Beispiel #20
0
 protected override DriverResult Display(CustomerPart part, string displayType, dynamic shapeHelper)
 {
     if (AdminFilter.IsApplied(Services.WorkContext.HttpContext.Request.RequestContext))
     {
         return(Combined(
                    ContentShape("Parts_Customer_Admin", () => shapeHelper.Parts_Customer_Admin(
                                     ContentPart: part)
                                 ),
                    ContentShape("Parts_Customer_Addresses_Admin", () => shapeHelper.Parts_Customer_Addresses_Admin(
                                     ContentPart: part)
                                 )
                    ));
     }
     else
     {
         return(Combined(
                    ContentShape("Parts_Customer", () => shapeHelper.Parts_Customer(
                                     ContentPart: part)
                                 ),
                    ContentShape("Parts_Customer_Addresses", () => shapeHelper.Parts_Customer_Addresses(
                                     ContentPart: part)
                                 )
                    ));
     }
 }
Beispiel #21
0
        public void ShapeTableCreated(ShapeTable shapeTable)
        {
            var typeDefinitions = _contentDefinitionManager.Value
                                  .ListTypeDefinitions()
                                  .Where(ctd => ctd.Parts.Any(ctpd => ctpd.PartDefinition.Name == "ProfilePart"));

            var allPlacements = typeDefinitions
                                .SelectMany(td => _frontEndProfileService.GetFrontEndPlacement(td)
                                            .Select(p => new TypePlacement {
                Placement = p, ContentType = td.Name
            }));

            // group all placement settings by shape type
            var shapePlacements = allPlacements
                                  .GroupBy(x => x.Placement.ShapeType)
                                  .ToDictionary(x => x.Key, y => y.ToList());

            foreach (var shapeType in shapeTable.Descriptors.Keys)
            {
                List <TypePlacement> customPlacements;
                if (shapePlacements.TryGetValue(shapeType, out customPlacements))
                {
                    if (!customPlacements.Any())
                    {
                        continue;
                    }
                    // there are some custom placements, build a predicate
                    var descriptor = shapeTable.Descriptors[shapeType];
                    var placement  = descriptor.Placement;
                    descriptor.Placement = ctx => {
                        var WorkContext = _workContextAccessor.GetContext(); //I need the context for the call using the predicates
                        if (ctx.DisplayType == null &&
                            !AdminFilter.IsApplied(WorkContext.HttpContext.Request.RequestContext))
                        {
                            foreach (var customPlacement in customPlacements)
                            {
                                var type           = customPlacement.ContentType;
                                var differentiator = customPlacement.Placement.Differentiator;

                                if (((ctx.Differentiator ?? string.Empty) == (differentiator ?? string.Empty)) && ctx.ContentType == type)
                                {
                                    var location = customPlacement.Placement.Zone;
                                    if (!string.IsNullOrEmpty(customPlacement.Placement.Position))
                                    {
                                        location = string.Concat(location, ":", customPlacement.Placement.Position);
                                    }

                                    return(new PlacementInfo {
                                        Location = location
                                    });
                                }
                            }
                        }
                        //fallback
                        return(placement(ctx));
                    };
                }
            }
        }
Beispiel #22
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // Paperclips should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            // Don't run on Admin either
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            // Some standard checks
            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            var site = workContext.CurrentSite;

            // Create a dummy sockets container which will be used to build user and site display. We don't really want to display this shape
            // (although it could possibly be useful) but we might want certain of its sockets or connectors to appear in zones, which will happen
            // during display building via socket events.
            var sockets = Shape.Sockets();

            var sitePart = site.As <SocketsPart>();

            if (sitePart != null)
            {
                // Building the display will cause any paperclips to perform push into layout
                // TODO: Probably building loads of inefficient sockets, need to check up on this and eradicate via placement.
                var model   = new SocketsModel(sitePart, "Detail", null);
                var builder = _origami.Builder(model).WithDisplayType("Detail").WithMode("Display").WithParadigms(new[] { "Paperclip" });
                _origami.Build(builder, sockets);
            }
            // Same for User
            var user = workContext.CurrentUser;

            if (user != null)
            {
                var userPart = user.As <SocketsPart>();
                if (userPart != null)
                {
                    // Building the display will cause any paperclips to perform push into layout
                    var model   = new SocketsModel(userPart, "Detail", null);
                    var builder = _origami.Builder(model).WithDisplayType("Detail").WithMode("Display").WithParadigms(new[] { "Paperclip" });
                    _origami.Build(builder, sockets);
                }
            }
        }
Beispiel #23
0
 public void OnResultExecuting(ResultExecutingContext filterContext)
 {
     // Defer to underlying menu filter if in admin (otherwise we lose whole admin menu!)
     if (AdminFilter.IsApplied(filterContext.RequestContext))
     {
         _menuFilter.OnResultExecuting(filterContext);
     }
 }
Beispiel #24
0
 public void ResourcePlaceholder(string resourceType, RequestContext requestContext, TextWriter Output)
 {
     // This check must be applied here as you can't guarantee that the filter will have been applied yet in OnResultExecuting.
     if (!AdminFilter.IsApplied(requestContext))
     {
         Output.WriteLine($"%%{{ItemLevelCacheResource::{resourceType}}}");
     }
 }
        public void IsAppliedShouldBeTrueAfterBeingApplied()
        {
            var context = new RequestContext(new StubHttpContext(), new RouteData());

            Assert.That(AdminFilter.IsApplied(context), Is.False);
            AdminFilter.Apply(context);
            Assert.That(AdminFilter.IsApplied(context), Is.True);
        }
Beispiel #26
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // ignore filter on admin pages
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            var settings = _settingsService.GetSettings();

            if (String.IsNullOrEmpty(settings.Swatch))
            {
                return;
            }

            var themeName = _siteThemeService.GetSiteTheme();

            if (themeName.Name == Constants.ThemeName)
            {
                var viewResult = filterContext.Result as ViewResult;
                if (viewResult == null)
                {
                    return;
                }

                if (settings.UseFixedNav)
                {
                    /* TODO: Replace note use Items collection */
                    System.Web.HttpContext.Current.Items[Constants.UseFixedNav] = settings.UseFixedNav.ToString();
                }
                if (settings.UseNavSearch)
                {
                    /* TODO: Replace note use Items collection */
                    System.Web.HttpContext.Current.Items[Constants.UseNavSearch] = settings.UseNavSearch.ToString();
                }
                if (settings.UseFluidLayout)
                {
                    /* TODO: Replace note use Items collection */
                    System.Web.HttpContext.Current.Items[Constants.UseFluidLayout] = settings.UseFluidLayout.ToString();
                }
                if (settings.UseInverseNav)
                {
                    /* TODO: Replace note use Items collection */
                    System.Web.HttpContext.Current.Items[Constants.UseInverseNav] = settings.UseInverseNav.ToString();
                }
                if (settings.UseStickyFooter)
                {
                    /* TODO: Replace note use Items collection */
                    System.Web.HttpContext.Current.Items[Constants.UseStickyFooter] = settings.UseStickyFooter.ToString();
                }
            }
        }
Beispiel #27
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            var accessFrontEnd = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AlwaysAccessibleAttribute), true).Any();

            if (!AdminFilter.IsApplied(filterContext.RequestContext) && !accessFrontEnd && !_authorizer.Authorize(StandardPermissions.AccessFrontEnd))
            {
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }
 protected override DriverResult Editor(CommonPart part, dynamic shapeHelper)
 {
     if (!AdminFilter.IsApplied(_orchardServices.WorkContext.HttpContext.Request.RequestContext))
     {
         return(null);
     }
     return(ContentShape("Parts_Common_SummaryInfoFor_Edit",
                         () => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.SummaryInfoFor_Edit", Model: part, Prefix: Prefix)));
 }
        internal static bool IsRequestAdmin(HttpContextBase context)
        {
            if (AdminFilter.IsApplied(context.Request.RequestContext))
            {
                return(true);
            }

            return(false);
        }
Beispiel #30
0
        protected virtual bool RequestIsCacheable(ActionExecutingContext filterContext)
        {
            // Respect OutputCacheAttribute if applied.
            var actionAttributes     = filterContext.ActionDescriptor.GetCustomAttributes(typeof(OutputCacheAttribute), true);
            var controllerAttributes = filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(OutputCacheAttribute), true);
            var outputCacheAttribute = actionAttributes.Concat(controllerAttributes).Cast <OutputCacheAttribute>().FirstOrDefault();

            if (outputCacheAttribute != null)
            {
                if (outputCacheAttribute.Duration <= 0 || outputCacheAttribute.NoStore)
                {
                    Logger.Debug("Request for item '{0}' ignored based on OutputCache attribute.", _cacheKey);
                    return(false);
                }
            }

            // Don't cache POST requests.
            if (filterContext.HttpContext.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase))
            {
                Logger.Debug("Request for item '{0}' ignored because HTTP method is POST.", _cacheKey);
                return(false);
            }

            // Don't cache admin section requests.
            if (AdminFilter.IsApplied(new RequestContext(filterContext.HttpContext, new RouteData())))
            {
                Logger.Debug("Request for item '{0}' ignored because it's in admin section.", _cacheKey);
                return(false);
            }

            // Ignore authenticated requests unless the setting to cache them is true.
            if (_workContext.CurrentUser != null && !CacheSettings.CacheAuthenticatedRequests)
            {
                Logger.Debug("Request for item '{0}' ignored because user is authenticated.", _cacheKey);
                return(false);
            }

            // Don't cache ignored URLs.
            if (IsIgnoredUrl(filterContext.RequestContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath, CacheSettings.IgnoredUrls))
            {
                Logger.Debug("Request for item '{0}' ignored because the URL is configured as ignored.", _cacheKey);
                return(false);
            }

            // Ignore requests with the refresh key on the query string.
            foreach (var key in filterContext.RequestContext.HttpContext.Request.QueryString.AllKeys)
            {
                if (String.Equals(_refreshKey, key, StringComparison.OrdinalIgnoreCase))
                {
                    Logger.Debug("Request for item '{0}' ignored because refresh key was found on query string.", _cacheKey);
                    return(false);
                }
            }

            return(true);
        }