Пример #1
0
        private static void EnsureItems()
        {
            using (new SecurityDisabler())
            {
                var database  = Factory.GetDatabase("master");
                var blogsItem = database.GetItem(BlogsRoot);
                if (blogsItem == null)
                {
                    var content = database.GetItem(ItemIDs.ContentRoot);
                    Assert.IsNotNull(content, "/sitecore/content item is missing");

                    blogsItem = content.Add("Blogs", new TemplateID(TemplateIDs.Node));
                    Assert.IsNotNull(blogsItem, "/sitecore/content/blogs item wasn't created");
                }

                var blogItems = blogsItem.Children;
                Assert.IsNotNull(blogItems, "blogItems");

                foreach (var blogName in BloggrFactory.GetBlogNames())
                {
                    var blogItem = blogItems[blogName];
                    if (blogItem == null)
                    {
                        blogItem = blogsItem.Add(blogName, new BranchId(ID.Parse("{15FA2775-5BFA-43C5-91E7-A3581448D0B2}")));
                        Assert.IsNotNull(blogItem, "/sitecore/content/blogs/$name item wasn't created");
                    }

                    if (!string.IsNullOrEmpty(blogItem[FieldIDs.Security]))
                    {
                        continue;
                    }

                    using (new EditContext(blogItem))
                    {
                        blogItem[FieldIDs.Security] = DefaultBlogSecurity.Replace("$name", blogName);
                    }
                }
            }
        }
Пример #2
0
        private static void EnsureRoles()
        {
            // ensure "sitecore\Bloggr All Users" -> "sitecore\Authors"
            var allUsersRole = EnsureAllUsersRole();

            // ensure "sitecore\Bloggr Global Administrators" -> "sitecore\Bloggr All Users" -> "sitecore\Author"
            Role globalAdminsRole;
            var  globalAdmins       = "sitecore\\Bloggr Global Administrators";
            var  globalAdminsExists = Role.Exists(globalAdmins);

            if (!globalAdminsExists)
            {
                Log.Info("Creating role: " + globalAdmins, typeof(BloggrInstallHook));
                Roles.CreateRole(globalAdmins);
            }

            globalAdminsRole = Role.FromName(globalAdmins);
            Assert.IsNotNull(globalAdminsRole, "Role does not exist: " + globalAdmins);

            if (!globalAdminsExists)
            {
                RolesInRolesManager.AddRoleToRole(globalAdminsRole, allUsersRole);
            }

            var blogNames = BloggrFactory.GetBlogNames();

            foreach (var roleKind in RoleKinds)
            {
                EnsureAllRole(roleKind);
            }

            foreach (var blogName in blogNames)
            {
                EnsureBlogRoles(blogName);
            }
        }