GetUserBlogs() public method

Get all blogs the user has write access to from the content database
public GetUserBlogs ( string username ) : Sitecore.Modules.WeBlog.Data.Items.BlogHomeItem[]
username string The name of the user requiring write access to the blog
return Sitecore.Modules.WeBlog.Data.Items.BlogHomeItem[]
示例#1
0
        public void GetUserBlogs_NoBlogs()
        {
            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID }
            );

            var manager = new BlogManager(settings);

            var membershipProvider = Mock.Of<MembershipProvider>(x =>
                x.GetUser(_validUsername, true) == new FakeMembershipUser()
            );

            using (var db = new Db())
            {
                var item = db.GetItem("/sitecore/content");

                using (new MembershipSwitcher(membershipProvider))
                {
                    var blogs = manager.GetUserBlogs(_validUsername);

                    Assert.That(blogs, Is.Empty);
                }
            }
        }
示例#2
0
        public void GetUserBlogs_NoAccess()
        {
            var blogTemplateId = ID.NewID;
            var blog2Id = ID.NewID;
            var blog3Id = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId }
            );

            var manager = new BlogManager(settings);

            var membershipProvider = Mock.Of<MembershipProvider>(x =>
                x.GetUser(_validUsername, true) == new FakeMembershipUser()
            );

            using (var db = new Db
            {
                new DbItem("blog1", ID.NewID, blogTemplateId),
                new DbItem("blog2", blog2Id, blogTemplateId)
                {
                    Access =
                    {
                        CanWrite = true
                    }
                },
                new DbItem("blog3", blog3Id, blogTemplateId)
                {
                    Access =
                    {
                        CanWrite = true
                    }
                }
            })
            {
                var blog1 = db.GetItem("/sitecore/content/blog1");
                var blog2 = db.GetItem("/sitecore/content/blog2");
                var blog3 = db.GetItem("/sitecore/content/blog3");

                using (new MembershipSwitcher(membershipProvider))
                {
                    var user = Sitecore.Security.Accounts.User.FromName(_validUsername, true);

                    var authorizationProvider = Mock.Of<AuthorizationProvider>(x =>
                        x.GetAccess(blog1, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult() &&
                        x.GetAccess(blog2, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult() &&
                        x.GetAccess(blog3, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult()
                    );

                    using (new AuthorizationSwitcher(authorizationProvider))
                    {
                        var blogTemplate = blog1.Database.GetTemplate(blogTemplateId);

                        var linkDb = Mock.Of<LinkDatabase>(x =>
                        x.GetReferrers(blogTemplate) == new[]
                        {
                            new ItemLink("master", blog2Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString()),
                            new ItemLink("master", blog3Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString())
                        });

                        using (new LinkDatabaseSwitcher(linkDb))
                        {
                            var blogs = manager.GetUserBlogs(_validUsername);
                            var ids = from blog in blogs select blog.ID;

                            Assert.That(ids, Is.EquivalentTo(new[] { blog2Id, blog3Id }));
                        }
                    }
                }
            }
        }