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 override object GetContent(object model) { //For testing -- go to the page that use this region and add ?entity=[entityId] HttpContext context = HttpContext.Current; if (context != null) { string entityId = context.Request.QueryString[EntityImagePanel.ENTITY_PARAM]; CatfishDbContext db = new CatfishDbContext(); EntityService es = new EntityService(db); if (!string.IsNullOrEmpty(entityId)) //get it from url param { Entity = es.GetAnEntity(Convert.ToInt32(entityId)); EntityId = Entity.Id; } else { if (EntityId > 0) //the default entity Id { Entity = es.GetAnEntity(Convert.ToInt32(EntityId)); } } if (Entity != null) { foreach (var f in ((CFItem)Entity).Files) { CFDataFile img = f; FileGuid = f.Guid; } } } return(base.GetContent(model)); }
private CFEntity UpdateEntityMetadataSet(CFEntity entity, CFMetadataSet metadata) { CFMetadataSet entityMetadata = entity.MetadataSets.Where(m => m.Guid == metadata.Guid).FirstOrDefault(); if (entityMetadata != null) { List <FormField> entityFields = new List <FormField>(metadata.Fields.Count); foreach (FormField field in metadata.Fields) { FormField entityField = entityMetadata.Fields.Where(f => f.Guid == field.Guid).FirstOrDefault(); if (entityField == null) { entityFields.Add(field); } else { entityField.Merge(field); entityFields.Add(entityField); } } entityMetadata.Fields = entityFields; return(entity); } return(null); }
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); }
/// <summary> /// NOTE: This only works for aggrigations at the moment. Future work will be needed for files and forms. /// </summary> /// <param name="userGuid">The guid of the user to compare the entity against</param> /// <param name="entity">The object to validate against.</param> /// <returns>The access modes given to the entity.</returns> public AccessMode GetPermissions(string userGuid, CFEntity entity) { if (typeof(CFAggregation).IsAssignableFrom(entity.GetType())) { return(GetAggregationPermissions(userGuid, (CFAggregation)entity)); } return(AccessMode.None); }
public EntityViewModel(CFEntity entity, string[] languageCodes, IDictionary <string, EntityViewModel> previousEntities = null) : this() { this.Id = entity.Id; this.Guid = entity.Guid; this.LanguageCodes = languageCodes; this.EntityTypeName = entity.EntityType.Name; this.Created = entity.Created; Type entityType = entity.GetType(); // Added to prevent circular child members. if (previousEntities == null) { previousEntities = new Dictionary <string, EntityViewModel>(); } previousEntities.Add(this.Guid, this); foreach (CFMetadataSet metadataset in entity.MetadataSets) { MetadataSets.Add(new MetadataSetViewModel(metadataset, languageCodes)); } if (typeof(CFItem).IsAssignableFrom(entityType)) { foreach (CFDataObject dataObject in ((CFItem)entity).DataObjects) { if (typeof(CFDataFile).IsAssignableFrom(dataObject.GetType())) { Files.Add(new DataFileViewModel((CFDataFile)dataObject, entity.Id)); } } } if (typeof(CFAggregation).IsAssignableFrom(entityType)) { foreach (CFEntity member in ((CFAggregation)entity).ChildMembers) { if (previousEntities.ContainsKey(member.Guid)) { Children.Add(previousEntities[member.Guid]); } else { EntityViewModel child = new EntityViewModel(member, languageCodes, previousEntities); Children.Add(child); } } } }
public override object GetContent(object model) { //For testing -- go to the page that use this region and add ?entity=[entityId] HttpContext context = HttpContext.Current; if (context != null) { string entityId = context.Request.QueryString[EntityContainer.ENTITY_PARAM]; if (!string.IsNullOrEmpty(entityId)) { CatfishDbContext db = new CatfishDbContext(); EntityService es = new EntityService(db); Entity = es.GetAnEntity(Convert.ToInt32(entityId)); } } return(base.GetContent(model)); }
public override object GetContent(object model) { if (CompiledCode != null) { HttpContext context = HttpContext.Current; Assembly assembly = Assembly.Load(CompiledCode); View = (ICatfishCompiledView)Activator.CreateInstance(assembly.GetType("Catfish.Models.Regions.CSEntityPanel." + ClassId)); string entityId = context.Request.QueryString[EntityContainer.ENTITY_PARAM]; int id = 0; if (IgnoreEntityProperty || string.IsNullOrEmpty(entityId) || !int.TryParse(entityId, out id)) { if (DefaultEntityId != null) { id = DefaultEntityId.Value; } } if (id > 0) { EntityService es = new EntityService(db); CFEntity entity = es.GetAnEntity(id); if (entity == null) { Error = Catfish.Resources.Views.Shared.DisplayTemplates.CSEntityPanel.NotFound; } else { View.SetModel(new EntityViewModel(es.GetAnEntity(id), ConfigHelper.Languages.Select(l => l.TwoLetterISOLanguageName.ToLower()).ToArray())); //TODO: Get Language codes } } } return(base.GetContent(model)); }
protected void AssertMatchesSolrInformationFromUrl() { // get id from url string url = Driver.Url; const string urlPattern = @".+\/(\d+)"; const string keyValuePattern = @"^value_.+_txts_\w{2}$"; const string associationsPattern = @"^(?:parents|related)_ss$"; Regex urlRegex = new Regex(urlPattern); Regex keyValyeRegex = new Regex(keyValuePattern); Regex associationsRegex = new Regex(associationsPattern); Match urlMatch = urlRegex.Match(url); if (urlMatch.Success && urlMatch.Groups.Count == 2) { Int64 id = Convert.ToInt64(urlMatch.Groups[1].Value); CatfishDbContext db = new CatfishDbContext(); CFEntity model = db.Entities.Find(id); Dictionary <string, object> result = model.ToSolrDictionary(); SolrQuery q = new SolrQuery($@"id:{model.MappedGuid}"); SolrQueryResults <Dictionary <string, object> > solrResults = SolrService.SolrOperations.Query(q); if (solrResults.Count == 1) { Dictionary <string, object> fromSolr = solrResults[0]; foreach (KeyValuePair <string, object> entry in result) { // first we need to make sure the entry value is not empty, // otherwise is not indexed in solr //if (entry.Value.ToString().Length > 0 && entry.Value != fromSolr[entry.Key]) //{ // return false; //} //if (entry.Value.ToString().Length > 0) //{ // // check if key has value pattern // Match keyValueMatch = keyValyeRegex.Match(entry.Key); // if (keyValueMatch.Success) // { // // compare as list of values // CollectionAssert.AreEqual((List<string>)entry.Value, // (System.Collections.ArrayList)fromSolr[entry.Key]); // } else // { // Assert.AreEqual(entry.Value, fromSolr[entry.Key]); // } //} Match keyValueMatch = keyValyeRegex.Match(entry.Key); Match associationsMatch = associationsRegex.Match(entry.Key); if (keyValueMatch.Success || associationsMatch.Success) { // treat as multi values List <string> test = (List <string>)entry.Value; if (test.Count > 0 && test[0] != "") { CollectionAssert.AreEqual(test, (System.Collections.ArrayList)fromSolr[entry.Key]); } //XXX Should it fail if the previous test is not passed? } else { // treat as regular values if (!string.IsNullOrEmpty(entry.Value.ToString())) { Assert.AreEqual(entry.Value, fromSolr[entry.Key]); } } } //return true; } } //return false; }
public CFEntity UpdateEntity(CFEntity entity) { Db.Entry(entity).State = EntityState.Modified; return(entity); }
public void UpdateModel(CFEntity entity) { Id = entity.Id; EntityName = entity.Name; }
public EntityViewModel(CFEntity src) { Id = src.Id; Label = src.GetName(); }