Ejemplo n.º 1
0
        /// <summary>
        /// Adds the default access rules to blog post entity.
        /// </summary>
        /// <param name="blogPost">The blog post.</param>
        /// <param name="principal">The principal.</param>
        /// <param name="masterPage">The master page.</param>
        private void AddDefaultAccessRules(BlogPost blogPost, IPrincipal principal, Page masterPage)
        {
            // Set default access rules
            blogPost.AccessRules = new List <AccessRule>();

            if (masterPage != null)
            {
                blogPost.AccessRules = masterPage
                                       .AccessRules
                                       .Select(x => new AccessRule
                {
                    Identity    = x.Identity,
                    AccessLevel = x.AccessLevel,
                    IsForRole   = x.IsForRole
                })
                                       .ToList();
            }
            else
            {
                var list = accessControlService.GetDefaultAccessList(principal);
                foreach (var rule in list)
                {
                    blogPost.AccessRules.Add(new AccessRule
                    {
                        Identity    = rule.Identity,
                        AccessLevel = rule.AccessLevel,
                        IsForRole   = rule.IsForRole
                    });
                }
            }
        }
        /// <summary>
        /// Adds the default access rules to blog post entity.
        /// </summary>
        /// <param name="blogPost">The blog post.</param>
        /// <param name="principal">The principal.</param>
        /// <param name="masterPage">The master page.</param>
        protected void AddDefaultAccessRules(BlogPost blogPost, IPrincipal principal, Page masterPage)
        {
            IEnumerable <IAccessRule> accessRules;

            if (masterPage != null)
            {
                accessRules = masterPage.AccessRules;
            }
            else
            {
                accessRules = accessControlService.GetDefaultAccessList(principal);
            }

            accessControlService.UpdateAccessControl(blogPost, accessRules.ToList());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>AddNewPage view model</returns>
        public AddNewPageViewModel Execute(AddNewPageCommandRequest request)
        {
            var principal = securityService.GetCurrentPrincipal();
            var model     = new AddNewPageViewModel
            {
                ParentPageUrl        = request.ParentPageUrl,
                Templates            = layoutService.GetLayouts(),
                AccessControlEnabled = cmsConfiguration.AccessControlEnabled,
                UserAccessList       = accessControlService.GetDefaultAccessList(principal).Cast <UserAccessViewModel>().ToList()
            };

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

                model.OptionValues = layoutService.GetLayoutOptionValues(model.TemplateId);
            }

            return(model);
        }
        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.AccessControlEnabled && request.ReuploadMediaId.HasDefaultValue())
            {
                var principal = securityService.GetCurrentPrincipal();
                model.UserAccessList = accessControlService.GetDefaultAccessList(principal).Cast <UserAccessViewModel>().ToList();

                model.AccessControlEnabled = cmsConfiguration.AccessControlEnabled;
            }

            return(model);
        }