Exemplo n.º 1
0
        /// <summary>
        /// Updates a Collection in the database with the the values provided. A new Collection is created if one does not already exist.
        /// </summary>
        /// <param name="changedCollection">The collection content to be modified.</param>
        /// <returns>The modified database collection.</returns>
        public CFCollection UpdateStoredCollection(CFCollection changedCollection)
        {
            CFCollection dbModel = new CFCollection();

            if (changedCollection.Id > 0)
            {
                dbModel = GetCollection(changedCollection.Id);
            }
            else
            {
                dbModel = CreateEntity <CFCollection>(changedCollection.EntityTypeId.Value);
            }

            //updating the "value" text elements
            dbModel.UpdateValues(changedCollection);
            dbModel.Serialize();

            if (changedCollection.Id > 0) //update Item
            {
                Db.Entry(dbModel).State = EntityState.Modified;
            }
            else
            {
                dbModel = Db.Collections.Add(dbModel);
            }

            return(dbModel);
        }
Exemplo n.º 2
0
        public void CreateCollections()
        {
            int COUNT = 20;

            CatfishDbContext    db = new CatfishDbContext();
            List <CFEntityType> collectionTypes = db.EntityTypes.Where(t => t.TargetTypes.Contains(CFEntityType.eTarget.Collections.ToString())).ToList();//db.EntityTypes.Where(t => t.TargetType == EntityType.eTarget.Collections).ToList();

            if (collectionTypes.Count == 0)
            {
                throw new Exception("No entity types have been defined for collections.");
            }
            var rand = new Random();
            CollectionService srv = new CollectionService(db);

            for (int i = 0; i < COUNT; ++i)
            {
                CFEntityType cType = collectionTypes[rand.Next(0, collectionTypes.Count)];
                CFCollection c     = srv.CreateEntity <CFCollection>(cType.Id);
                string       name  = TestData.LoremIpsum(5, 10);
                c.SetName("Collection: " + name);
                c.SetDescription(TestData.LoremIpsum(20, 100, 1, 10));
                c.Serialize();
                db.Collections.Add(c);
            }
            db.SaveChanges();
        }
Exemplo n.º 3
0
        public ActionResult AccessGroup(int id, EntityAccessDefinitionsViewModel entityAccessVM)
        {
            SecurityService.CreateAccessContext();
            CFCollection collection = CollectionService.GetCollection(entityAccessVM.Id, AccessMode.Control);

            if (collection != null)
            {
                AccessGroupService accessGroupService = new AccessGroupService(Db);
                collection = accessGroupService.UpdateEntityAccessGroups(collection, entityAccessVM) as CFCollection;
                collection = EntityService.UpdateEntity(collection) as CFCollection;

                collection.Serialize();
                Db.SaveChanges();
            }

            collection.Serialize();
            Db.SaveChanges();

            SuccessMessage(Catfish.Resources.Views.Shared.EntityAccessGroup.SaveSuccess);

            return(AccessGroup(entityAccessVM.Id));
        }
Exemplo n.º 4
0
        public void TestNoAccessDefinitionNoParents()
        {
            SecurityServiceBase srv = new TestSecurityService(Db);

            string collectionName       = "TestUserIsAdminCollection";
            string collectionDesciption = "Test collection description";
            string itemName             = "TestUserIsAdminItem";
            string itemDesciption       = "Test item description";

            AccessMode defaultAccess = GetDefaultPermissions();
            AccessMode modes;

            int          entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Collections).FirstOrDefault().Id;
            CFCollection c1         = mDh.CreateCollection(mDh.Cs, entityType, collectionName, collectionDesciption, true);

            entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i1 = mDh.CreateItem(mDh.Is, entityType, itemName + "1", itemDesciption, true);
            CFItem i2 = mDh.CreateItem(mDh.Is, entityType, itemName + "2", itemDesciption, true);

            Db.SaveChanges();

            c1.ChildMembers.Add(i1);
            c1.Serialize();
            Db.Entry(c1).State = System.Data.Entity.EntityState.Modified;

            i2.ChildMembers.Add(i1);
            i2.Serialize();
            Db.Entry(i2).State = System.Data.Entity.EntityState.Modified;

            Db.SaveChanges();

            foreach (TestUser user in Users)
            {
                modes = srv.GetPermissions(user.Guid, c1);

                Assert.AreEqual(defaultAccess, modes);
                Assert.AreNotEqual(AccessMode.All, modes);

                modes = srv.GetPermissions(user.Guid, i2);

                Assert.AreEqual(defaultAccess, modes);
                Assert.AreNotEqual(AccessMode.All, modes);

                modes = srv.GetPermissions(user.Guid, i1);

                Assert.AreEqual(defaultAccess, modes);
                Assert.AreNotEqual(AccessMode.All, modes);
            }
        }
Exemplo n.º 5
0
        public ActionResult AddUserAccessDefinition(EntityAccessDefinitionsViewModel entityAccessVM)
        {
            CFCollection collection = CollectionService.GetCollection(entityAccessVM.Id);//ItemService.GetItem(entityAccessVM.Id);

            AccessGroupService accessGroupService = new AccessGroupService(Db);

            collection = accessGroupService.UpdateEntityAccessGroups(collection, entityAccessVM) as CFCollection;
            collection = EntityService.UpdateEntity(collection) as CFCollection;

            collection.Serialize();
            Db.SaveChanges();


            return(RedirectToAction("AccessGroup", new { id = entityAccessVM.Id }));
        }
        /// <summary>
        /// Updates a Collection in the database with the the values provided. A new Collection is created if one does not already exist.
        /// </summary>
        /// <param name="changedCollection">The collection content to be modified.</param>
        /// <returns>The modified database collection.</returns>
        public CFCollection UpdateStoredCollection(CFCollection changedCollection)
        {
            CFCollection dbModel = new CFCollection();

            if (changedCollection.Id > 0)
            {
                dbModel = GetCollection(changedCollection.Id, AccessMode.Write);
            }
            else
            {
                dbModel = CreateEntity <CFCollection>(changedCollection.EntityTypeId.Value);
            }

            //updating the "value" text elements
            dbModel.UpdateValues(changedCollection);

            //update collection attribute -- issystemCollection -- Aug 21 2019
            XAttribute isSysColl = changedCollection.Data.Attribute("issystemcollection");

            if (isSysColl != null)
            {
                dbModel.Data.SetAttributeValue("issystemcollection", isSysColl.Value);
            }

            dbModel.Serialize();

            if (changedCollection.Id > 0) //update Item
            {
                Db.Entry(dbModel).State = EntityState.Modified;
            }
            else
            {
                dbModel = Db.Collections.Add(dbModel);
            }

            return(dbModel);
        }
Exemplo n.º 7
0
        public void TestCircularParents()
        {
            SecurityServiceBase srv = new TestSecurityService(Db);

            string collectionName       = "TestUserIsAdminCollection";
            string collectionDesciption = "Test collection description";
            string itemName             = "TestUserIsAdminItem";
            string itemDesciption       = "Test item description";

            AccessMode defaultAccess = GetDefaultPermissions();

            CFAccessDefinition ad1 = new CFAccessDefinition()
            {
                Name        = "Test 1",
                AccessModes = AccessMode.Write
            };

            CFAccessDefinition ad2 = new CFAccessDefinition()
            {
                Name        = "Test 2",
                AccessModes = AccessMode.Control | AccessMode.Append
            };

            CFAccessDefinition ad3 = new CFAccessDefinition()
            {
                Name        = "Test 3",
                AccessModes = AccessMode.Discover
            };

            int    entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i1         = mDh.CreateItem(mDh.Is, entityType, itemName, itemDesciption, true);

            entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Collections).FirstOrDefault().Id;
            CFCollection c1 = mDh.CreateCollection(mDh.Cs, entityType, collectionName, collectionDesciption, true);

            entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i2 = mDh.CreateItem(mDh.Is, entityType, itemName, itemDesciption, true);

            List <CFAccessGroup> groups = new List <CFAccessGroup>()
            {
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[0])
                    }, AccessDefinition = ad1
                },
            };

            c1.AccessGroups = groups;
            c1.Serialize();

            groups = new List <CFAccessGroup>()
            {
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[1])
                    }, AccessDefinition = ad2
                },
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[2])
                    }, AccessDefinition = ad3
                }
            };

            i2.AccessGroups = groups;
            i2.Serialize();

            i1.Serialize();

            c1.ChildMembers.Add(i1);
            c1.ChildMembers.Add(i2); //NOTE: Here is our circular relationship
            i2.ChildMembers.Add(i1);
            Db.SaveChanges();

            AccessMode modes1 = srv.GetPermissions(Users[0].Guid, i1);
            AccessMode modes2 = srv.GetPermissions(Users[1].Guid, i1);
            AccessMode modes3 = srv.GetPermissions(Users[2].Guid, i1);
            AccessMode modes4 = srv.GetPermissions(Users[3].Guid, i1);

            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad3.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad2.AccessModes, modes2);
            Assert.AreEqual(defaultAccess | ad2.AccessModes, modes3);
            Assert.AreEqual(defaultAccess | ad2.AccessModes | ad3.AccessModes, modes4);

            modes1 = srv.GetPermissions(Users[0].Guid, i2);
            modes2 = srv.GetPermissions(Users[1].Guid, i2);
            modes3 = srv.GetPermissions(Users[2].Guid, i2);
            modes4 = srv.GetPermissions(Users[3].Guid, i2);

            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad3.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad2.AccessModes, modes2);
            Assert.AreEqual(defaultAccess | ad2.AccessModes, modes3);
            Assert.AreEqual(defaultAccess | ad2.AccessModes | ad3.AccessModes, modes4);

            modes1 = srv.GetPermissions(Users[0].Guid, c1);
            modes2 = srv.GetPermissions(Users[1].Guid, c1);
            modes3 = srv.GetPermissions(Users[2].Guid, c1);
            modes4 = srv.GetPermissions(Users[3].Guid, c1);

            Assert.AreEqual(defaultAccess | ad1.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes, modes2);
            Assert.AreEqual(defaultAccess, modes3);
            Assert.AreEqual(defaultAccess, modes4);
        }