public PropertySetResult ValidateReuseSettings( int propertyTypeId, ItemTypeReuseTemplate reuseTemplateSettings) { if (reuseTemplateSettings == null) { return(null); } if (reuseTemplateSettings.ReadOnlySettings.HasFlag(ItemTypeReuseTemplateSetting.Name) && propertyTypeId == WorkflowConstants.PropertyTypeFakeIdName) { return(new PropertySetResult(propertyTypeId, ErrorCodes.InvalidArtifactProperty, "Cannot modify name from workflow event action. Property is readonly.")); } if (reuseTemplateSettings.ReadOnlySettings.HasFlag(ItemTypeReuseTemplateSetting.Description) && propertyTypeId == WorkflowConstants.PropertyTypeFakeIdDescription) { return(new PropertySetResult(propertyTypeId, ErrorCodes.InvalidArtifactProperty, "Cannot modify description from workflow event action. Property is readonly.")); } var customProperty = reuseTemplateSettings.PropertyTypeReuseTemplates[propertyTypeId]; var propertyReusetemplate = reuseTemplateSettings.PropertyTypeReuseTemplates[customProperty.PropertyTypeId]; if (propertyReusetemplate.Settings == PropertyTypeReuseTemplateSettings.ReadOnly) { return(new PropertySetResult(propertyTypeId, ErrorCodes.InvalidArtifactProperty, "Cannot modify property from workflow event action. Property is readonly.")); } return(null); }
public ExecutionParameters( int userId, VersionControlArtifactInfo artifactInfo, ItemTypeReuseTemplate reuseTemplate, List <WorkflowPropertyType> customPropertyTypes, ISaveArtifactRepository saveArtifactRepository, IDbTransaction transaction, IValidationContext validationContext) : this( userId, artifactInfo, reuseTemplate, customPropertyTypes, saveArtifactRepository, transaction, validationContext, new List <IPropertyValidator>() { new TextPropertyValidator(), new NumberPropertyValidator(), new DatePropertyValidator(), new UserPropertyValidator(), new ChoicePropertyValidator() }, new ReusePropertyValidator()) { }
public void ValidateReuseSettings_ValidateReadonlyDescriptionNameUpdating_Fails() { var namePropertyId = WorkflowConstants.PropertyTypeFakeIdDescription; var fakeItemTypeReuseTempalate = new ItemTypeReuseTemplate { ReadOnlySettings = ItemTypeReuseTemplateSetting.Description }; var result = _reusePropertyValidator.ValidateReuseSettings(namePropertyId, fakeItemTypeReuseTempalate); Assert.IsNotNull(result); }
public void ValidateReuseSettings_ValidateReadonlyCustomPropertyUpdating_Fails() { var fakePropertyId = 123; var fakeItemTypeReuseTempalate = new ItemTypeReuseTemplate(); var propertyTypeReuseTemplate = new PropertyTypeReuseTemplate { PropertyTypeId = fakePropertyId, Settings = PropertyTypeReuseTemplateSettings.ReadOnly }; fakeItemTypeReuseTempalate.PropertyTypeReuseTemplates.Add(fakePropertyId, propertyTypeReuseTemplate); var result = _reusePropertyValidator.ValidateReuseSettings(fakePropertyId, fakeItemTypeReuseTempalate); Assert.IsNotNull(result); }
public async Task <ExecutionParameters> BuildTriggerExecutionParameters( int userId, VersionControlArtifactInfo artifactInfo, WorkflowEventTriggers triggers, IDbTransaction transaction = null) { if (triggers.IsEmpty()) { return(null); } var artifactId = artifactInfo.Id; var isArtifactReadOnlyReuse = await _stateChangeExecutorRepositories.ReuseRepository.DoItemsContainReadonlyReuse(new[] { artifactId }, transaction); ItemTypeReuseTemplate reuseTemplate = null; var artifactId2StandardTypeId = await _stateChangeExecutorRepositories.ReuseRepository.GetStandardTypeIdsForArtifactsIdsAsync(new HashSet <int> { artifactId }); var instanceItemTypeId = artifactId2StandardTypeId[artifactId].InstanceTypeId; if (instanceItemTypeId == null) { throw new BadRequestException("Artifact is not a standard artifact type"); } if (isArtifactReadOnlyReuse.ContainsKey(artifactId) && isArtifactReadOnlyReuse[artifactId]) { reuseTemplate = await LoadReuseSettings(instanceItemTypeId.Value); } var customItemTypeToPropertiesMap = await LoadCustomPropertyInformation(new[] { instanceItemTypeId.Value }, triggers, artifactInfo.ProjectId, userId, artifactId); var propertyTypes = new List <WorkflowPropertyType>(); if (customItemTypeToPropertiesMap.ContainsKey(artifactInfo.ItemTypeId)) { propertyTypes = customItemTypeToPropertiesMap[artifactInfo.ItemTypeId]; } var usersAndGroups = await LoadUsersAndGroups(triggers); return(new ExecutionParameters( userId, artifactInfo, reuseTemplate, propertyTypes, _stateChangeExecutorRepositories.SaveArtifactRepository, transaction, new ValidationContext(usersAndGroups.Item1, usersAndGroups.Item2))); }
public ExecutionParameters( int userId, VersionControlArtifactInfo artifactInfo, ItemTypeReuseTemplate reuseTemplate, List <WorkflowPropertyType> customPropertyTypes, ISaveArtifactRepository saveArtifactRepository, IDbTransaction transaction, IValidationContext validationContext, IReadOnlyList <IPropertyValidator> validators, IReusePropertyValidator reuseValidator) { UserId = userId; ArtifactInfo = artifactInfo; ReuseItemTemplate = reuseTemplate; CustomPropertyTypes = customPropertyTypes; SaveRepository = saveArtifactRepository; Transaction = transaction; Validators = validators; ReuseValidator = reuseValidator; ValidationContext = validationContext; }
private async Task <bool> HasSensitiveModifiedProperty( ReuseSensitivityCollector.ArtifactModification modification, ItemTypeReuseTemplate itemTypeReuseTemplate, ItemTypePredefined artifacTypePredefined, IReuseRepository reuseRepository) { HashSet <int> modifiedPropertyTypes = new HashSet <int>(); foreach (var modifiedPropertyType in modification.ModifiedPropertyTypes) { modifiedPropertyTypes.Add(modifiedPropertyType.Item1); } var propertyTypesToStandardPropertyTypeDict = await reuseRepository.GetStandardPropertyTypeIdsForPropertyIdsAsync(modifiedPropertyTypes); foreach (var modifiedPropertyType in modification.ModifiedPropertyTypes) { var propertyTypePredefined = modifiedPropertyType.Item2; if (propertyTypePredefined.IsCustom()) { SqlPropertyTypeInfo propInfo; if ( !propertyTypesToStandardPropertyTypeDict.TryGetValue(modifiedPropertyType.Item1, out propInfo) || !propInfo.InstancePropertyTypeId.HasValue) { continue; } PropertyTypeReuseTemplate propertyTemplate; // Get corresponding property type template for standard property if ( !itemTypeReuseTemplate.PropertyTypeReuseTemplates.TryGetValue( propInfo.InstancePropertyTypeId.Value, out propertyTemplate)) { continue; } if (!propertyTemplate.Settings.HasFlag(PropertyTypeReuseTemplateSettings.ChangesIgnored)) { return(true); } } else if (!propertyTypePredefined.IsFake()) { ItemTypeReuseTemplateSetting correspondingReuseTemplateSetting; if (propertyTypePredefined == PropertyTypePredefined.Description) { correspondingReuseTemplateSetting = ItemTypeReuseTemplateSetting.Description; } else { var reconcileProperty = ReuseSystemPropertiesMap.Instance.GetCorrespondingReconcileProperty(propertyTypePredefined, artifacTypePredefined); correspondingReuseTemplateSetting = ReuseTemplateSettingsMap.GetCorrespondingReuseTemplateSetting(reconcileProperty); } if ((correspondingReuseTemplateSetting & ~itemTypeReuseTemplate.SensitivitySettings) != ItemTypeReuseTemplateSetting.None) { return(true); } } } return(false); }