Exemplo n.º 1
0
        public CFEntity UpdateEntityAccessGroups(CFEntity entity, EntityAccessDefinitionsViewModel entityAccessVM)
        {
            List <CFAccessGroup> accessGroups = new List <CFAccessGroup>();

            foreach (var ag in entityAccessVM.SelectedAccessGroups)
            {
                CFAccessGroup group = new CFAccessGroup();
                group.AccessGuids = new List <Guid>()
                {
                    Guid.Parse(ag.userId)
                };
                group.AccessDefinition.AccessModes = (AccessMode)ag.AccessModesNum;
                if (ag.AccessMode != null)
                {
                    group.AccessDefinition.Name = ag.AccessMode.Substring(0, ag.AccessMode.LastIndexOf("-"));
                }


                accessGroups.Add(group);
            }
            entity.AccessGroups = accessGroups;

            entity.BlockInheritance = entityAccessVM.BlockInheritance;

            return(entity);
        }
        public CFEntity UpdateEntityAccessGroups(CFEntity entity, EntityAccessDefinitionsViewModel entityAccessVM)
        {
            List <CFAccessGroup> accessGroups = new List <CFAccessGroup>();

            foreach (var ag in entityAccessVM.SelectedAccessGroups)
            {
                CFAccessGroup group = new CFAccessGroup();
                //group.AccessGuids = new List<Guid>() { Guid.Parse(ag.userId) };
                group.AccessGuid = Guid.Parse(ag.userId);
                group.AccessDefinition.AccessModes = (AccessMode)ag.AccessModesNum;
                if (ag.AccessMode != null)
                {
                    group.AccessDefinition.Name = ag.AccessMode.Substring(0, ag.AccessMode.LastIndexOf("-"));
                }
                accessGroups.Add(group);
            }

            entity.AccessGroups     = accessGroups;
            entity.BlockInheritance = entityAccessVM.BlockInheritance;

            // fetch solr entry by cfentity mapped guid
            SolrNet.SolrQueryResults <Dictionary <string, object> > mapedEntity;
            mapedEntity = SolrService.SolrOperations.Query("id:" + entity.MappedGuid);

            mapedEntity.First();
            // remove all access entries

            return(entity);
        }
        public EntityAccessDefinitionsViewModel UpdateViewModel(CFEntity entity)
        {
            UserService     us           = new UserService();
            UserListService uListService = new UserListService(Db);

            EntityAccessDefinitionsViewModel entityAccessVM = new EntityAccessDefinitionsViewModel();

            entityAccessVM.Id               = entity.Id;
            entityAccessVM.EntityName       = entity.Name;
            entityAccessVM.BlockInheritance = entity.BlockInheritance;

            entityAccessVM.AvailableUsers2 = us.GetUserIdAndLoginName();
            Dictionary <string, string> allUserLists = uListService.GetDictionaryUserLists();

            allUserLists.ToList().ForEach(x => entityAccessVM.AvailableUsers2.Add(x.Key, x.Value));

            AccessDefinitionService accessDefinitionService = new AccessDefinitionService(Db);
            SelectList accessDefs = new SelectList(accessDefinitionService.GetSelectListAccessDefinitions()
                                                   .GroupBy(a => a.Name)
                                                   .Select(a => a.FirstOrDefault())
                                                   .Select(i => new SelectListItem()
            {
                Value = ((int)i.AccessModes).ToString(),
                Text  = i.StringAccessModesList
            }), "Value", "Text");

            entityAccessVM.AvailableAccessDefinitions = accessDefs;

            entityAccessVM.AvailableAccessDefinitions2 = accessDefs.ToList();

            if (entity.AccessGroups.Count > 0)
            {
                //update SelectedAccessGroups
                foreach (CFAccessGroup gr in entity.AccessGroups)
                {
                    AccessGroup accGrp = new Models.ViewModels.AccessGroup();
                    accGrp.userId = gr.AccessGuid.ToString(); //FirstOrDefault().ToString();
                    var    user = us.GetUserById(accGrp.userId);
                    string name = string.Empty;
                    if (user == null)
                    {
                        name = uListService.GetEntityGroup(accGrp.userId).Name;
                    }
                    else
                    {
                        name = user.Login;
                    }
                    accGrp.User           = name;
                    accGrp.AccessMode     = gr.AccessDefinition.StringAccessModesList;
                    accGrp.AccessModesNum = (int)gr.AccessDefinition.AccessModes;

                    entityAccessVM.SelectedAccessGroups.Add(accGrp);
                }
            }


            return(entityAccessVM);
        }
Exemplo n.º 4
0
        public ActionResult AccessGroup(int id)
        {
            var entity = CollectionService.GetCollection(id); //ItemService.GetAnEntity(id);
            EntityAccessDefinitionsViewModel entityAccessVM = new EntityAccessDefinitionsViewModel();
            AccessGroupService accessGroupService           = new AccessGroupService(Db);

            entityAccessVM        = accessGroupService.UpdateViewModel(entity);// UpdateViewModel(entity);
            ViewBag.SugestedUsers = entityAccessVM.AvailableUsers2.ToArray();
            return(View(entityAccessVM));
        }
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 }));
        }
Exemplo n.º 6
0
        public ActionResult AddUserAccessDefinition(EntityAccessDefinitionsViewModel entityAccessVM)
        {
            CFItem item = ItemService.GetItem(entityAccessVM.Id);

            AccessGroupService accessGroupService = new AccessGroupService(Db);

            item = accessGroupService.UpdateEntityAccessGroups(item, entityAccessVM) as CFItem;
            item = EntityService.UpdateEntity(item) as CFItem;

            item.Serialize();
            Db.SaveChanges();


            return(RedirectToAction("AccessGroup", new { id = entityAccessVM.Id }));
        }
Exemplo n.º 7
0
        public ActionResult AccessGroup(int id)
        {
            SecurityService.CreateAccessContext();
            var entity = ItemService.GetAnEntity(id);
            EntityAccessDefinitionsViewModel entityAccessVM = new EntityAccessDefinitionsViewModel();
            AccessGroupService accessGroupService           = new AccessGroupService(Db);

            entityAccessVM        = accessGroupService.UpdateViewModel(entity);// UpdateViewModel(entity);
            ViewBag.SugestedUsers = entityAccessVM.AvailableUsers2.ToArray();
            var accessList = accessGroupService.GetAccessCodesList();

            accessList.Remove(accessList.First()); //remove "None"
            //accessList.Remove(accessList.Last()); //remove all
            ViewBag.AccessCodesList = accessList;
            return(View("AccessGroup", entityAccessVM));
        }
Exemplo n.º 8
0
        public ActionResult AccessGroup(int id, EntityAccessDefinitionsViewModel entityAccessVM)
        {
            SecurityService.CreateAccessContext();
            CFItem item = ItemService.GetItem(entityAccessVM.Id);

            AccessGroupService accessGroupService = new AccessGroupService(Db);

            item = accessGroupService.UpdateEntityAccessGroups(item, entityAccessVM) as CFItem;
            item = EntityService.UpdateEntity(item) as CFItem;
            item.Serialize();
            Db.SaveChanges();
            // commit changes to solr

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

            return(AccessGroup(entityAccessVM.Id));
        }
Exemplo n.º 9
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));
        }