private static IEnumerable <ListItem> LoadEntityTypeList() { IEnumerable <EntityType> entityTypes = EntityTypeRepository.GetList() .Where(t => !t.Code.Equals(EntityTypeCode.CustomAction, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(n => n.Id) .ToArray(); var siteDescendants = new HashSet <int>(GetDescendantEntityTypes(EntityTypeCode.Site, entityTypes).Select(t => t.Id)); var contentDescendants = new HashSet <int>( GetDescendantEntityTypes(EntityTypeCode.Content, entityTypes).Select(t => t.Id).Union( GetDescendantEntityTypes(EntityTypeCode.VirtualContent, entityTypes).Select(t => t.Id) ) ); Func <int, string[]> getListItemDependentIds = etId => { if (siteDescendants.Contains(etId)) { return(contentDescendants.Contains(etId) ? new[] { SiteSelectionModePanelName, ContentSelectionModePanelName } : new[] { SiteSelectionModePanelName }); } return(null); }; return(entityTypes.Select(n => new ListItem(n.Id.ToString(), n.Name, getListItemDependentIds(n.Id))).ToArray()); }
public void Test_GetEntityTypes_TypelessEntity() { IDictionary <long, ISet <EntityRef> > result; List <EntityRef> testEntityRefs; // Sanity Check Assert.That(new EntityRef(EntityId.Max).HasEntity, Is.False, "EntityId.Max.HasEntity"); testEntityRefs = new List <EntityRef>() { new EntityRef(EntityTemporaryIdAllocator.AcquireId()) }; try { result = new EntityTypeRepository(x => new HashSet <long>()).GetEntityTypes(testEntityRefs); Assert.That(result, Has.Count.EqualTo(1)); Assert.That(result, Has.Exactly(1) .Property("Key") .EqualTo(EntityTypeRepository.TypelessId) .And.Property("Value") .EquivalentTo(testEntityRefs) .Using(EntityRefComparer.Instance), "Relationship entity IDs missing"); } finally { EntityTemporaryIdAllocator.RelinquishId(testEntityRefs[0].Id); } }
public void Test_GetEntityTypes_TwoSameOneDifferentEntities() { IDictionary <long, ISet <EntityRef> > result; List <EntityRef> testEntityRefs; // Relation and a type testEntityRefs = new List <EntityRef>() { new EntityRef("core", "read"), new EntityRef("core", "modify"), new EntityRef("core", "securableEntity") }; result = new EntityTypeRepository().GetEntityTypes(testEntityRefs); Assert.That( result.Keys, Is.EquivalentTo(testEntityRefs.SelectMany(er => er.Entity.GetAllTypes().Select(x => x.Id)).Distinct())); Assert.That( result.Values, Has.None.Not.SubsetOf(testEntityRefs)); foreach (EntityRef entityRef in testEntityRefs) { foreach (long entityTypeId in entityRef.Entity.GetAllTypes().Select(et => et.Id)) { Assert.That(result.Keys, Contains.Item(entityTypeId)); Assert.That(result[entityTypeId], Contains.Item(entityRef)); } } }
public void Test_GetEntityTypes_EntityRefWithNoEntity() { IDictionary <long, ISet <EntityRef> > result; List <EntityRef> testEntityRefs; EntityRef entityRef; entityRef = new EntityRef(EntityTemporaryIdAllocator.AcquireId()); try { // Sanity Check Assert.That(entityRef.Entity, Is.Null, "entityRef.Entity not null"); testEntityRefs = new List <EntityRef> { entityRef }; result = new EntityTypeRepository().GetEntityTypes(testEntityRefs); Assert.That(result, Has.Count.EqualTo(1)); Assert.That(result, Has.Exactly(1) .Property("Key") .EqualTo(EntityTypeRepository.TypelessId) .And.Property("Value") .EquivalentTo(testEntityRefs) .Using(EntityRefComparer.Instance), "Relationship entity IDs missing"); } finally { EntityTemporaryIdAllocator.RelinquishId(entityRef.Id); } }
public ImportDataService() { _exportDataService = new ExportDataService(); _crmRepository = new CRMRepository(); _eventRepository = new EventRepository(); _configurationRespository = new ConfigurationRepository(); _hostedControlRepository = new HostedControlRepository(); _entityTypeRepository = new EntityTypeRepository(); _scriptletRepository = new ScriptletRepository(); _importResults = new List <ImportResult>(); _entitySearchRepository = new EntitySearchRepository(); _sessionLineRepository = new SessionLineRepository(); _optionRepository = new OptionRepository(); _actionRepository = new ActionRepository(); _actionCallrepository = new ActionCallRepository(); _subActionCallsRepository = new SubActionCallsRepository(); _eventActionCallRepository = new EventActionCallRepository(); _toolbarRepository = new ToolbarRepository(); _toolbarButtonRepository = new ToolbarButtonRepository(); _toolbarButtonActionCallRepository = new ToolbarButtonActionCallRepository(); _toolbarHostedControlRepository = new ToolbarHostedControlRepository(); _wnrRepository = new WNRRepository(); _wnrActionCallrepository = new WNRActionCallRepository(); _agentScriptTaskRepository = new AgentScriptTaskRepository(); _taskActionCallRepository = new TaskActionCallRepository(); _taskAnswerRepository = new TaskAnswerRepository(); _agentScriptAnswerRepository = new AgentScriptAnswerRepository(); _answerActionCallRepository = new AnswerActionCallrepository(); }
/// <summary> /// Проверить возможность восстановления а втосохраненных сущностей /// </summary> /// <param name="recordHeaders"></param> /// <returns></returns> public static IEnumerable <long> AutosaveRestoringCheck(IList <AutosavedEntityRecordHeader> recordHeaders) { if (recordHeaders != null && recordHeaders.Any()) { // Проверка для существующих сущностей var approvedExisted = recordHeaders .Where(h => !h.IsNew && h.Modified.HasValue) .GroupBy(h => h.EntityTypeCode, StringComparer.InvariantCultureIgnoreCase) .Select(g => new EntityObjectRepository.VariousTypeEntityQueryParam { EntityTypeCode = g.Key, EntityIDs = g.Select(h2 => h2.EntityId).Distinct() }) .GetVariousTypeList() .Where(e => { // проверка на возможность восстановить сущность var rh = recordHeaders.First(h => h.EntityId == e.Id && h.EntityTypeCode.Equals(e.EntityTypeCode, StringComparison.InvariantCultureIgnoreCase)); return(rh.Modified.Value <= e.Modified && ( // проверка на lock e is LockableEntityObject && !((LockableEntityObject)e).LockedByAnyoneElse || !(e is LockableEntityObject) ) && !e.IsReadOnly); }).Select(e => recordHeaders .First(h => !h.IsNew && h.EntityId == e.Id && h.EntityTypeCode.Equals(e.EntityTypeCode, StringComparison.InvariantCultureIgnoreCase)) .RecordId ); // Проверка для новых сущностей (существует ли parent) var code2ParentCode = EntityTypeRepository.GetList().ToDictionary(t => t.Code, t => t.ParentCode, StringComparer.InvariantCultureIgnoreCase); foreach (var h in recordHeaders) { h.ParentEntityTypeCode = code2ParentCode[h.EntityTypeCode]; } var approvedNew = recordHeaders .Where(h => h.IsNew) .GroupBy(h => h.ParentEntityTypeCode, StringComparer.InvariantCultureIgnoreCase) .Select(g => new EntityObjectRepository.VariousTypeEntityQueryParam { EntityTypeCode = g.Key, EntityIDs = g.Select(h2 => h2.ParentEntityId).Distinct() }) .GetVariousTypeList() .SelectMany(e => recordHeaders .Where(h => h.IsNew && h.ParentEntityId == e.Id && h.ParentEntityTypeCode.Equals(e.EntityTypeCode, StringComparison.InvariantCultureIgnoreCase) ) .Select(h => h.RecordId) ); return(approvedExisted.Concat(approvedNew).ToArray()); } return(Enumerable.Empty <long>()); }
public UnitOfWork(XdContext context) { _context = context; AddressInformations = new AddressInformationRepository(_context); AppUsers = new AppUserRepository(_context); AppUserRoles = new AppUserRoleRepository(_context); Contacts = new ContactRepository(_context); Credentials = new CredentialsRepository(_context); DbTypes = new DbTypeRepository(_context); Entities = new EntityRepository(_context); EntityTypes = new EntityTypeRepository(_context); Fields = new FieldRepository(_context); FieldRequirementLevels = new FieldRequirementLevelRepository(_context); FieldTypes = new FieldTypeRepository(_context); Forms = new FormRepository(_context); FormTypes = new FormTypeRepository(_context); Genders = new GenderRepository(_context); MaritalStatuses = new MaritalStatusRepository(_context); MenuItems = new MenuItemRepository(_context); Roles = new RoleRepository(_context); Tabs = new TabRepository(_context); Titles = new TitleRepository(_context); Views = new ViewRepository(_context); ViewTypes = new ViewTypeRepository(_context); }
public void Test_GetEntityTypes_SingleEntity() { IDictionary <long, ISet <EntityRef> > result; EntityRef testEntityRef; testEntityRef = new EntityRef("core", "allowAccess"); // Sanity tests Assert.That(testEntityRef, Has.Property("Entity").Not.Null); Assert.That(testEntityRef.Entity.GetAllTypes().ToList( ), Has.Count.Positive); result = new EntityTypeRepository().GetEntityTypes(new[] { testEntityRef }); Assert.That( result.Keys, Is.EquivalentTo(testEntityRef.Entity.GetAllTypes().Select(x => x.Id))); Assert.That( result.Values, Is.All.EquivalentTo(new[] { testEntityRef }) .Using(EntityRefComparer.Instance)); }
public void Test_GetEntityTypes_TwoIdenticalEntities() { IDictionary <long, ISet <EntityRef> > result; List <EntityRef> testEntityRefs; // Two different relations testEntityRefs = new List <EntityRef>() { Permissions.Read, Permissions.Modify }; result = new EntityTypeRepository().GetEntityTypes(testEntityRefs); Assert.That( result.Keys, Is.EquivalentTo(testEntityRefs.SelectMany(er => er.Entity.GetAllTypes().Select(x => x.Id)).Distinct())); Assert.That( result.Values, Is.All.EquivalentTo(testEntityRefs) .Using(EntityRefComparer.Instance)); }
public void CheckAutomaticAccess_GrantType(string permissionEntityRef, string testEntityRef, bool expectedResult) { Permission permission; Dictionary <long, IDictionary <long, bool> > permissionToAccess; IDictionary <long, ISet <EntityRef> > entityTypes; EntityRef testType; EntityAccessControlChecker entityAccessControlChecker; permission = Entity.Get <Permission>(permissionEntityRef); Assert.That(permission, Is.Not.Null, "Unknown permission."); permissionToAccess = new Dictionary <long, IDictionary <long, bool> >(); permissionToAccess[permission.Id] = new Dictionary <long, bool>(); testType = new EntityRef(testEntityRef); entityTypes = new EntityTypeRepository().GetEntityTypes(new [] { testType }); entityAccessControlChecker = new EntityAccessControlChecker(); foreach (KeyValuePair <long, ISet <EntityRef> > entityType in entityTypes) { entityAccessControlChecker.CheckAutomaticAccess( permission, entityType, permissionToAccess); } if (expectedResult) { Assert.That( permissionToAccess[permission.Id], Has.Some.Property("Key").EqualTo(testType.Id) .And.Property("Value").EqualTo(expectedResult)); } else { Assert.That( permissionToAccess[permission.Id], Has.None.Property("Key").EqualTo(testType.Id)); } }
private static CustomAction Normalize(CustomAction customAction, int[] selectedActionsIds) { if (customAction.IsNew) { customAction.Action.ControllerActionUrl = ControllerActionUrl; customAction.Action.Code = !string.IsNullOrEmpty(customAction.ForceActionCode) ? customAction.ForceActionCode : $"custom_{DateTime.Now.Ticks}"; } var entityType = EntityTypeRepository.GetById(customAction.Action.EntityTypeId); if (entityType.ContextMenu == null) { entityType.ContextMenu = ContextMenuRepository.GetByCode(entityType.Code); } customAction.Action.EntityType = entityType; customAction.Action.Name = customAction.Name; customAction.Action.TabId = entityType.TabId; customAction.CalculateOrder(entityType.Id); if (!customAction.ShowInToolbar) { customAction.ParentActions = null; customAction.Action.ToolbarButtons = Enumerable.Empty <ToolbarButton>(); } else if (selectedActionsIds != null) { var result = new List <ToolbarButton>(); foreach (var id in selectedActionsIds) { var button = customAction.Action.ToolbarButtons?.FirstOrDefault(n => n.ParentActionId == id) ?? new ToolbarButton(); button.ActionId = customAction.Action.Id; button.ParentActionId = id; button.Name = customAction.Name; button.Icon = !string.IsNullOrWhiteSpace(customAction.IconUrl) ? customAction.IconUrl : ToolbarButtonDefaultIconUrl; button.Order = customAction.Order + 1000; result.Add(button); } customAction.Action.ToolbarButtons = result; } BackendActionTypeRepository.GetById(customAction.Action.TypeId); if (customAction.ShowInMenu) { if (entityType.ContextMenu == null) { throw new ApplicationException(string.Format(CustomActionStrings.ThereIsNoContextMenuForEntityType, entityType.Name)); } ContextMenuItem contentMenuItem; if (customAction.Action.ContextMenuItems != null && customAction.Action.ContextMenuItems.Any()) { contentMenuItem = customAction.Action.ContextMenuItems.First(); } else { contentMenuItem = new ContextMenuItem(); } contentMenuItem.ContextMenuId = entityType.ContextMenu.Id; contentMenuItem.ActionId = customAction.Action.Id; contentMenuItem.Name = customAction.Name; contentMenuItem.Icon = !string.IsNullOrWhiteSpace(customAction.IconUrl) ? customAction.IconUrl : ToolbarButtonDefaultIconUrl; contentMenuItem.Order = customAction.Order + 1000; customAction.Action.ContextMenuItems = new[] { contentMenuItem }; } else { customAction.Action.ContextMenuItems = Enumerable.Empty <ContextMenuItem>(); } if (!customAction.Action.IsInterface) { customAction.Action.IsWindow = false; } else { customAction.Action.ConfirmPhrase = null; customAction.Action.HasPreAction = false; } if (!customAction.Action.IsWindow) { customAction.Action.WindowHeight = null; customAction.Action.WindowWidth = null; } if (!IsEntityTypeSiteDescendants(entityType.Id)) { customAction.SiteIds = new int[] {}; customAction.SiteExcluded = false; } if (!IsEntityTypeContentDescendants(entityType.Id)) { customAction.ContentIds = new int[] {}; customAction.ContentExcluded = false; } return(customAction); }
/// <summary> /// Возвращает код действия по умолчанию для указанного типа сущности /// </summary> /// <param name="entityTypeCode">код типа сущности</param> /// <returns>код действия по умолчанию</returns> public static string GetDefaultActionCodeByEntityTypeCode(string entityTypeCode) => string.IsNullOrWhiteSpace(entityTypeCode) ? null : EntityTypeRepository.GetDefaultActionCodeByEntityTypeCode(entityTypeCode);
/// <summary> /// Возвращает код типа родительской сущности /// </summary> /// <param name="entityTypeCode">код типа сущности</param> /// <returns>код типа родительской сущности</returns> public static string GetParentCodeByCode(string entityTypeCode) => string.IsNullOrWhiteSpace(entityTypeCode) ? null : EntityTypeRepository.GetParentCodeByCode(entityTypeCode);
/// <summary> /// Возвращает тип сущности по ее идентификатору /// </summary> /// <param name="entityTypeId">идентификатор типа сущности</param> /// <returns>информация о типе сущности</returns> public static EntityType GetById(int entityTypeId) => EntityTypeRepository.GetById(entityTypeId);