public MemberTypeDisplay PostSave(MemberTypeSave contentTypeSave) { //get the persisted member type var ctId = Convert.ToInt32(contentTypeSave.Id); var ct = ctId > 0 ? Services.MemberTypeService.Get(ctId) : null; if (UmbracoContext.Security.CurrentUser.HasAccessToSensitiveData() == false) { //We need to validate if any properties on the contentTypeSave have had their IsSensitiveValue changed, //and if so, we need to check if the current user has access to sensitive values. If not, we have to return an error var props = contentTypeSave.Groups.SelectMany(x => x.Properties); if (ct != null) { foreach (var prop in props) { // Id 0 means the property was just added, no need to look it up if (prop.Id == 0) { continue; } var foundOnContentType = ct.PropertyTypes.FirstOrDefault(x => x.Id == prop.Id); if (foundOnContentType == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No property type with id " + prop.Id + " found on the content type")); } if (ct.IsSensitiveProperty(foundOnContentType.Alias) && prop.IsSensitiveData == false) { //if these don't match, then we cannot continue, this user is not allowed to change this value throw new HttpResponseException(HttpStatusCode.Forbidden); } } } else { //if it is new, then we can just verify if any property has sensitive data turned on which is not allowed if (props.Any(prop => prop.IsSensitiveData)) { throw new HttpResponseException(HttpStatusCode.Forbidden); } } } var savedCt = PerformPostSave <MemberTypeDisplay, MemberTypeSave, MemberPropertyTypeBasic>( contentTypeSave: contentTypeSave, getContentType: i => ct, saveContentType: type => Services.MemberTypeService.Save(type)); var display = Mapper.Map <MemberTypeDisplay>(savedCt); display.AddSuccessNotification( Services.TextService.Localize("speechBubbles", "memberTypeSavedHeader"), string.Empty); return(display); }
public MemberTypeDisplay PostSave(MemberTypeSave contentTypeSave) { var savedCt = PerformPostSave <IMemberType, MemberTypeDisplay, MemberTypeSave, MemberPropertyTypeBasic>( contentTypeSave: contentTypeSave, getContentType: i => Services.MemberTypeService.Get(i), saveContentType: type => Services.MemberTypeService.Save(type)); var display = Mapper.Map <MemberTypeDisplay>(savedCt); display.AddSuccessNotification( Services.TextService.Localize("speechBubbles/memberTypeSavedHeader"), string.Empty); return(display); }
// no MapAll - take care private void Map(MemberTypeSave source, IMemberType target, MapperContext context) { MapSaveToTypeBase <MemberTypeSave, MemberPropertyTypeBasic>(source, target, context); MapComposition(source, target, alias => _memberTypeService.Get(alias)); foreach (var propertyType in source.Groups.SelectMany(x => x.Properties)) { var localCopy = propertyType; var destProp = target.PropertyTypes.SingleOrDefault(x => x.Alias.InvariantEquals(localCopy.Alias)); if (destProp == null) { continue; } target.SetMemberCanEditProperty(localCopy.Alias, localCopy.MemberCanEditProperty); target.SetMemberCanViewProperty(localCopy.Alias, localCopy.MemberCanViewProperty); target.SetIsSensitiveProperty(localCopy.Alias, localCopy.IsSensitiveData); } }
public ActionResult <MemberTypeDisplay?> PostSave(MemberTypeSave contentTypeSave) { //get the persisted member type var ctId = Convert.ToInt32(contentTypeSave.Id); var ct = ctId > 0 ? _memberTypeService.Get(ctId) : null; if (_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasAccessToSensitiveData() == false) { //We need to validate if any properties on the contentTypeSave have had their IsSensitiveValue changed, //and if so, we need to check if the current user has access to sensitive values. If not, we have to return an error var props = contentTypeSave.Groups.SelectMany(x => x.Properties); if (ct != null) { foreach (var prop in props) { // Id 0 means the property was just added, no need to look it up if (prop.Id == 0) { continue; } var foundOnContentType = ct.PropertyTypes.FirstOrDefault(x => x.Id == prop.Id); if (foundOnContentType == null) { return(NotFound(new { Message = "No property type with id " + prop.Id + " found on the content type" })); } if (ct.IsSensitiveProperty(foundOnContentType.Alias) && prop.IsSensitiveData == false) { //if these don't match, then we cannot continue, this user is not allowed to change this value return(Forbid()); } } } else { //if it is new, then we can just verify if any property has sensitive data turned on which is not allowed if (props.Any(prop => prop.IsSensitiveData)) { return(Forbid()); } } } var savedCt = PerformPostSave <MemberTypeDisplay, MemberTypeSave, MemberPropertyTypeBasic>( contentTypeSave: contentTypeSave, getContentType: i => ct, saveContentType: type => _memberTypeService.Save(type)); if (!(savedCt.Result is null)) { return(savedCt.Result); } var display = _umbracoMapper.Map <MemberTypeDisplay>(savedCt.Value); display?.AddSuccessNotification( _localizedTextService.Localize("speechBubbles", "memberTypeSavedHeader"), string.Empty); return(display); }
// no MapAll - take care private void Map(MemberTypeSave source, MemberTypeDisplay target, MapperContext context) => MapTypeToDisplayBase <MemberTypeSave, MemberPropertyTypeBasic, MemberTypeDisplay, MemberPropertyTypeDisplay>( source, target, context);
public void MemberPropertyGroupBasic_To_MemberPropertyGroup() { // TODO use builder var dataType = new DataType(Services.GetRequiredService <LabelPropertyEditor>(), _serializer) { Name = "TODO" }; _dataTypeService.Save(dataType); var basic = new PropertyGroupBasic <MemberPropertyTypeBasic> { Id = 222, Alias = "group1", Name = "Group 1", SortOrder = 1, Properties = new[] { new MemberPropertyTypeBasic { MemberCanEditProperty = true, MemberCanViewProperty = true, IsSensitiveData = true, Id = 33, SortOrder = 1, Alias = "prop1", Description = "property 1", DataTypeId = dataType.Id, GroupId = 222, Label = "Prop 1", Validation = new PropertyTypeValidation { Mandatory = true, Pattern = null } }, new MemberPropertyTypeBasic { MemberCanViewProperty = false, MemberCanEditProperty = false, IsSensitiveData = false, Id = 34, SortOrder = 2, Alias = "prop2", Description = "property 2", DataTypeId = dataType.Id, GroupId = 222, Label = "Prop 2", Validation = new PropertyTypeValidation { Mandatory = false, Pattern = null } } } }; var contentType = new MemberTypeSave { Id = 0, ParentId = -1, Alias = "alias", Groups = new[] { basic } }; // proper group properties mapping takes place when mapping the content type, // not when mapping the group - because of inherited properties and such // var result = Mapper.Map<PropertyGroup>(basic); var result = _sut.Map <IMemberType>(contentType).PropertyGroups[0]; Assert.AreEqual(basic.Name, result.Name); Assert.AreEqual(basic.Id, result.Id); Assert.AreEqual(basic.SortOrder, result.SortOrder); Assert.AreEqual(basic.Properties.Count(), result.PropertyTypes.Count()); }