Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dc"></param>
        public static ModelFolderPermissions AddFolderPermissions(this DataContext dc)
        {
            var repo = new FolderRepository(dc);
            var res  = new ModelFolderPermissions();

            var folders = dc.Folders;

            var users = dc
                        .Users
                        .Select(x => x.ToModel())
                        .ToList();

            var teams = dc
                        .Teams
                        .Select(x => x.ToModel())
                        .ToList();

            foreach (var f in folders)
            {
                var hasAcl = TestFactory.GetRandomBoolean();

                if (hasAcl)
                {
                    var perms = TestFactory.CreateFolderPermissions(f.Uid, users, teams);

                    res.AddRange(perms);

                    repo
                    .ForActiveOrg(f.OrgId)
                    .UpdatePermissions(f.Uid, perms);
                }
            }

            return(res);
        }
Beispiel #2
0
        public void Should_UpdatePermissions()
        {
            var folders = CreateFolderPermissions();
            var users   = GetRepo <UserRepository>().All.Value;
            var teams   = GetRepo <TeamRepository>().All.Value;

            foreach (var f in folders)
            {
                var newPerms = TestFactory.CreateFolderPermissions(f.Uid, users, teams);

                if (!f.HasAcl)
                {
                    CheckDefaultPermissions(GetRepo <FolderRepository>()
                                            .ForActiveOrg(f)
                                            .GetPermissions(f.Uid)
                                            .Value);
                }

                Assert.False(GetRepo <FolderRepository>()
                             .ForActiveOrg(f)
                             .UpdatePermissions(f.Uid, newPerms)
                             .HasError);

                Assert.True(GetRepo <FolderRepository>()
                            .ForActiveOrg(f) [f.Uid]
                            .Value
                            .HasAcl);
            }

            var perms = GetAllPermissions();

            foreach (var f in folders)
            {
                var fPermsRes = GetRepo <FolderRepository>()
                                .ForActiveOrg(f)
                                .GetPermissions(f.Uid);

                Assert.False(fPermsRes.HasError);

                var fPerms = fPermsRes.Value;

                foreach (var fp in fPerms)
                {
                    var existing = perms.FirstOrDefault(x => x.Id == fp.Id);
                    Assert.True(fp.Equals(existing));
                }
            }
        }