Exemplo n.º 1
0
        public MultiFileUploadViewModel Execute(GetMultiFileUploadRequest request)
        {
            var model = new MultiFileUploadViewModel();

            model.RootFolderId     = request.FolderId;
            model.RootFolderType   = request.Type;
            model.ReuploadMediaId  = request.ReuploadMediaId;
            model.SelectedFolderId = Guid.Empty;
            model.UploadedFiles    = null;

            var foldersQuery = Repository.AsQueryable <MediaFolder>().Where(f => f.Type == request.Type);

            if (request.FolderId == Guid.Empty)
            {
                foldersQuery = foldersQuery.Where(f => f.Folder == null);
            }
            else
            {
                foldersQuery = foldersQuery.Where(f => f.Folder.Id == request.FolderId);
            }

            model.Folders = foldersQuery
                            .OrderBy(f => f.Title)
                            .Select(f => new Tuple <Guid, string>(f.Id, f.Title))
                            .ToList();

            model.Folders.Insert(0, new Tuple <Guid, string>(Guid.Empty, ".."));

            if (request.Type != MediaType.Image && cmsConfiguration.Security.AccessControlEnabled)
            {
                if (!request.ReuploadMediaId.HasDefaultValue())
                {
                    var media = Repository.AsQueryable <Media>(m => m.Id == request.ReuploadMediaId).FirstOne();
                    var file  = media as MediaFile;
                    if (file != null)
                    {
                        AccessControlService.DemandAccess(file, Context.Principal, AccessLevel.ReadWrite);
                    }
                }
                else
                {
                    var principal = SecurityService.GetCurrentPrincipal();
                    model.UserAccessList       = AccessControlService.GetDefaultAccessList(principal).Cast <UserAccessViewModel>().ToList();
                    model.AccessControlEnabled = cmsConfiguration.Security.AccessControlEnabled;
                }
            }
            return(model);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the default access rules to blog post entity.
        /// </summary>
        /// <param name="blogPost">The blog post.</param>
        private void AddDefaultAccessRules(BlogPost blogPost)
        {
            // Set default access rules
            blogPost.AccessRules = new List <AccessRule>();

            var list = AccessControlService.GetDefaultAccessList(Context.Principal);

            foreach (var rule in list)
            {
                blogPost.AccessRules.Add(new AccessRule
                {
                    Identity    = rule.Identity,
                    AccessLevel = rule.AccessLevel,
                    IsForRole   = rule.IsForRole
                });
            }
        }
Exemplo n.º 3
0
        public IList <UserAccessViewModel> Execute(GetLayoutUserAccessCommandRequest request)
        {
            var principal = securityService.GetCurrentPrincipal();

            if (request.IsMasterPage)
            {
                return
                    (Repository.AsQueryable <Root.Models.Page>()
                     .Where(x => x.Id == request.Id && !x.IsDeleted)
                     .SelectMany(x => x.AccessRules)
                     .OrderBy(x => x.IsForRole)
                     .ThenBy(x => x.Identity)
                     .Select(x => new UserAccessViewModel(x))
                     .ToList());
            }

            return(AccessControlService.GetDefaultAccessList(principal).Select(f => new UserAccessViewModel(f)).ToList());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="sitemapId">The sitemap identifier.</param>
        /// <returns>
        /// Sitemap view model.
        /// </returns>
        public SitemapViewModel Execute(Guid sitemapId)
        {
            if (sitemapId.HasDefaultValue())
            {
                var langs = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues().ToList() : new List <LookupKeyValue>();
                return(new SitemapViewModel()
                {
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    UserAccessList = AccessControlService.GetDefaultAccessList(SecurityService.GetCurrentPrincipal()).Select(f => new UserAccessViewModel(f)).ToList(),
                    ShowLanguages = CmsConfiguration.EnableMultilanguage && langs.Any(),
                    Languages = langs,
                    ShowMacros = CmsConfiguration.EnableMacros
                });
            }

            IEnumerable <AccessRule> userAccessFuture;

            if (CmsConfiguration.Security.AccessControlEnabled)
            {
                userAccessFuture = Repository
                                   .AsQueryable <Models.Sitemap>()
                                   .Where(x => x.Id == sitemapId && !x.IsDeleted)
                                   .SelectMany(x => x.AccessRules)
                                   .OrderBy(x => x.Identity)
                                   .ToFuture();
            }
            else
            {
                userAccessFuture = null;
            }

            var tagsFuture      = TagService.GetSitemapTagNames(sitemapId);
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);

            IQueryable <Models.Sitemap> sitemapQuery = Repository.AsQueryable <Models.Sitemap>()
                                                       .Where(map => map.Id == sitemapId)
                                                       .FetchMany(map => map.Nodes)
                                                       .ThenFetch(node => node.Page);

            if (CmsConfiguration.EnableMultilanguage)
            {
                sitemapQuery = sitemapQuery
                               .FetchMany(map => map.Nodes)
                               .ThenFetchMany(node => node.Translations);
            }

            var sitemap   = sitemapQuery.Distinct().ToFuture().ToList().First();
            var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();
            var model     = new SitemapViewModel
            {
                Id        = sitemap.Id,
                Version   = sitemap.Version,
                Title     = sitemap.Title,
                RootNodes =
                    SitemapHelper.GetSitemapNodesInHierarchy(
                        CmsConfiguration.EnableMultilanguage,
                        sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                        sitemap.Nodes.Distinct().ToList(),
                        languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                        (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                Tags = tagsFuture.ToList(),
                AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                Languages            = languages,
                ShowMacros           = CmsConfiguration.EnableMacros
            };

            if (userAccessFuture != null)
            {
                model.UserAccessList = userAccessFuture.Select(x => new UserAccessViewModel(x)).ToList();

                var rules = model.UserAccessList.Cast <IAccessRule>().ToList();

                SetIsReadOnly(model, rules);
            }

            return(model);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>AddNewPage view model</returns>
        public AddNewPageViewModel Execute(AddNewPageCommandRequest request)
        {
            if (request.CreateMasterPage)
            {
                AccessControlService.DemandAccess(Context.Principal, RootModuleConstants.UserRoles.Administration);
            }
            else
            {
                AccessControlService.DemandAccess(Context.Principal, RootModuleConstants.UserRoles.EditContent);
            }

            var showLanguages   = cmsConfiguration.EnableMultilanguage && !request.CreateMasterPage;
            var languagesFuture = (showLanguages) ? languageService.GetLanguagesLookupValues() : null;

            var principal = securityService.GetCurrentPrincipal();
            var model     = new AddNewPageViewModel
            {
                ParentPageUrl        = request.ParentPageUrl,
                Templates            = layoutService.GetAvailableLayouts().ToList(),
                AccessControlEnabled = cmsConfiguration.Security.AccessControlEnabled,
                CreateMasterPage     = request.CreateMasterPage,
                ShowLanguages        = showLanguages
            };

            if (showLanguages)
            {
                model.Languages     = languagesFuture.ToList();
                model.ShowLanguages = model.Languages.Any();
            }

            if (model.Templates.Count > 0)
            {
                model.Templates.ToList().ForEach(x => x.IsActive = false);

                // Select current page as master
                var urlHash = request.ParentPageUrl.UrlHash();
                model.Templates.Where(t => t.IsMasterPage && t.MasterUrlHash == urlHash).ToList().ForEach(x => x.IsActive = true);

                // Select current page's layout
                if (model.Templates.Count(t => t.IsActive) != 1)
                {
                    // Try to get layout of the current page
                    var currentPageLayout = repository
                                            .AsQueryable <Root.Models.Page>(p => p.PageUrlHash == request.ParentPageUrl.UrlHash())
                                            .Select(p => new
                    {
                        MasterPageId = p.MasterPage != null ? p.MasterPage.Id : (System.Guid?)null,
                        LayoutId     = p.Layout != null ? p.Layout.Id : (System.Guid?)null
                    })
                                            .FirstOrDefault();
                    if (currentPageLayout != null)
                    {
                        if (currentPageLayout.MasterPageId.HasValue)
                        {
                            model.Templates
                            .Where(t => t.IsMasterPage && t.TemplateId == currentPageLayout.MasterPageId.Value)
                            .Take(1)
                            .ToList().ForEach(x => x.IsActive = true);
                        }
                        else if (currentPageLayout.LayoutId.HasValue)
                        {
                            model.Templates
                            .Where(t => !t.IsMasterPage && t.TemplateId == currentPageLayout.LayoutId.Value)
                            .Take(1)
                            .ToList().ForEach(x => x.IsActive = true);
                        }
                    }
                }

                // Select first layout as active
                if (model.Templates.Count(t => t.IsActive) != 1)
                {
                    model.Templates.First().IsActive = true;
                }

                var active = model.Templates.First(t => t.IsActive);
                if (active != null)
                {
                    if (active.IsMasterPage)
                    {
                        model.MasterPageId   = active.TemplateId;
                        model.UserAccessList = Repository
                                               .AsQueryable <Root.Models.Page>()
                                               .Where(x => x.Id == model.MasterPageId && !x.IsDeleted)
                                               .SelectMany(x => x.AccessRules)
                                               .OrderBy(x => x.Identity)
                                               .Select(x => new UserAccessViewModel(x)).ToList();
                    }
                    else
                    {
                        model.TemplateId     = active.TemplateId;
                        model.UserAccessList = AccessControlService.GetDefaultAccessList(principal).Select(f => new UserAccessViewModel(f)).ToList();
                    }
                }

                if (model.TemplateId.HasValue)
                {
                    model.OptionValues = layoutService.GetLayoutOptionValues(model.TemplateId.Value);
                }

                if (model.MasterPageId.HasValue)
                {
                    model.OptionValues = masterPageService.GetMasterPageOptionValues(model.MasterPageId.Value);
                }

                model.CustomOptions = optionService.GetCustomOptions();
            }

            return(model);
        }