예제 #1
0
        private Page CreateNestedPage()
        {
            PageController pc       = new PageController();
            var            page     = pc.Create("page", testContext.users[0]);
            var            pageSub1 = pc.AddSubPage("sub page 1", page.Id, testContext.users[0]);
            var            pageSub2 = pc.AddSubPage("sub page 2", page.Id, testContext.users[0]);

            var p = pc.AddSubPage("sub 1 sub page 1", pageSub1.Id, testContext.users[0]);

            pc.ChangeOwner(p.Id, testContext.users[17].Id, testContext.users[0]);

            pc.AddSubPage("sub 2 sub page 1", pageSub2.Id, testContext.users[0]);

            var t = pc.AddAttachment("sub 1 attachment 1", pageSub1.Id, testContext.users[0]);
            AttachmentController ac = new AttachmentController();

            ac.ChangeOwner(t.Id, testContext.users[25].Id, testContext.users[0]);

            pc.AddAttachment("page attachment", page.Id, testContext.users[0]);

            var teams = CreateTeams();

            pc.AddAdmin(page.Id, teams[0].Id, testContext.users[0]);
            pc.AddReader(page.Id, teams[1].Id, testContext.users[0]);

            pc.AddAdmin(page.Id, testContext.users[10].Id, testContext.users[0]);
            pc.AddReader(page.Id, testContext.users[11].Id, testContext.users[0]);

            return(page);
        }
예제 #2
0
        public void ChangeOwner()
        {
            testContext.CreateAdminTeam();
            var            page      = CreateNestedPage();
            PageController pc        = new PageController();
            var            children  = pc.GetChildren(page.Id, testContext.adminUsers[0]);
            var            subPage   = children.Item1[0];
            var            children2 = pc.GetChildren(subPage.Id, testContext.adminUsers[0]);
            var            att       = children2.Item2[0];

            controller.ChangeOwner(att.Id, testContext.users[14].Id, testContext.adminUsers[0]);
            var fetchedPage = controller.Get(att.Id, testContext.adminUsers[0]);

            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Admin Team Writer
            controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.adminUsers[1]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[1]);
            Assert.Equal(testContext.users[15].Id, fetchedPage.Acl.ownerId);

            // Admin Team Nested reader team writer
            controller.ChangeOwner(att.Id, testContext.users[14].Id, testContext.adminUsers[2]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[2]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Admin Team Writer
            controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.adminUsers[3]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[3]);
            Assert.Equal(testContext.users[15].Id, fetchedPage.Acl.ownerId);

            // Admin Team Nested reader team writer
            controller.ChangeOwner(att.Id, testContext.users[14].Id, testContext.adminUsers[4]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[4]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Team Owner reader team writer
            controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.users[0]);
            fetchedPage = controller.Get(att.Id, testContext.users[0]);
            Assert.Equal(testContext.users[15].Id, fetchedPage.Acl.ownerId);

            // Team Writer
            controller.ChangeOwner(att.Id, testContext.users[14].Id, testContext.users[10]);
            fetchedPage = controller.Get(att.Id, testContext.users[10]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Team Reader
            Assert.Throws <NotAuthorized>(() => controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.users[11]));
            fetchedPage = controller.Get(att.Id, testContext.users[11]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Nested Team Writer writer
            controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.users[3]);
            fetchedPage = controller.Get(att.Id, testContext.users[3]);
            Assert.Equal(testContext.users[15].Id, fetchedPage.Acl.ownerId);

            // Nested Team Writer reader
            controller.ChangeOwner(att.Id, testContext.users[14].Id, testContext.users[4]);
            fetchedPage = controller.Get(att.Id, testContext.users[4]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Nested Team Reader writerter");
            Assert.Throws <NotAuthorized>(() => controller.ChangeOwner(att.Id, testContext.users[15].Id, testContext.users[5]));
            fetchedPage = controller.Get(att.Id, testContext.users[5]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            // Nested Team reader readerder");
            Assert.Throws <NotAuthorized>(() => controller.ChangeOwner(att.Id, testContext.users[16].Id, testContext.users[6]));
            fetchedPage = controller.Get(att.Id, testContext.users[6]);
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);

            Assert.Throws <NotAuthorized>(() => controller.ChangeOwner(att.Id, testContext.users[17].Id, testContext.users[7]));
            Assert.Throws <NotAuthorized>(() => fetchedPage = controller.Get(att.Id, testContext.users[7]));
            Assert.Equal(testContext.users[14].Id, fetchedPage.Acl.ownerId);
        }