public Member(string name, string email, string username, string password, IContentBase parent, IMemberType contentType) : base(name, parent, contentType, new PropertyCollection()) { Mandate.ParameterNotNull(contentType, "contentType"); _contentType = contentType; _email = email; _username = username; _password = password; }
/// <summary> /// Constructor for creating an empty Member object /// </summary> /// <param name="contentType">ContentType for the current Content object</param> public Member(IMemberType contentType) : base("", -1, contentType, new PropertyCollection()) { _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); _contentTypeAlias = contentType.Alias; IsApproved = true; //this cannot be null but can be empty _rawPasswordValue = ""; _email = ""; _username = ""; }
public void Member_Cannot_View_Property() { IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); ServiceContext.MemberTypeService.Save(memberType); //re-get memberType = ServiceContext.MemberTypeService.Get(memberType.Id); foreach (var p in memberType.PropertyTypes) { Assert.IsFalse(memberType.MemberCanViewProperty(p.Alias)); } }
/// <summary> /// Constructor for creating a Member object /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="username"></param> /// <param name="rawPasswordValue"> /// The password value passed in to this parameter should be the encoded/encrypted/hashed format of the member's password /// </param> /// <param name="contentType"></param> public Member(string name, string email, string username, string rawPasswordValue, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { Mandate.ParameterNotNull(contentType, "contentType"); _contentTypeAlias = contentType.Alias; _contentType = contentType; _email = email; _username = username; _rawPasswordValue = rawPasswordValue; IsApproved = true; }
public void Member_Cannot_Edit_Property() { IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeService.Save(memberType); // re-get memberType = MemberTypeService.Get(memberType.Id); foreach (var p in memberType.PropertyTypes) { Assert.IsFalse(memberType.MemberCanEditProperty(p.Alias)); } }
/// <summary> /// Validates the correct access to members, taking into account the information hiding level. /// </summary> /// <param name="member">The type of the member</param> /// <returns>If the access has been correct</returns> public bool validAccess(TypeExpression member) { // * Union or Intersection type IList <TypeExpression> typeSet = null; UnionType unionType = member as UnionType; if (member is UnionType) { typeSet = ((UnionType)member).TypeSet; } else if (member is IntersectionType) { typeSet = ((IntersectionType)member).TypeSet; } if (typeSet != null) { bool anyValid = false; foreach (TypeExpression type in typeSet) { if (!this.validAccess(type) && !member.IsDynamic) { return(false); } else { anyValid = true; } return(anyValid); } } // * Member type IMemberType memberType = member as IMemberType; if (memberType == null || memberType.MemberInfo == null) { return(false); } // * Public or Internal if (memberType.MemberInfo.hasModifier(Modifier.Public) || memberType.MemberInfo.hasModifier(Modifier.Internal)) { return(true); } // * Private if (memberType.MemberInfo.hasModifier(Modifier.Private)) { return((bool)this.AcceptOperation(new EquivalentOperation(memberType.MemberInfo.Class), null)); } // * Protected return((bool)this.AcceptOperation(new EquivalentOperation(memberType.MemberInfo.Class), null) || this.InheritsFrom(memberType.MemberInfo.Class)); }
public void Can_Get_Member_Type_By_Guid_Id() { var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); repository.AddOrUpdate(memberType); unitOfWork.Commit(); memberType = repository.Get(memberType.Key); Assert.That(memberType, Is.Not.Null); } }
/// <summary> /// Constructor for creating an empty Member object /// </summary> /// <param name="contentType">ContentType for the current Content object</param> public Member(IMemberType contentType) : base("", -1, contentType, new PropertyCollection()) { Mandate.ParameterNotNull(contentType, "contentType"); _contentTypeAlias = contentType.Alias; _contentType = contentType; IsApproved = true; //this cannot be null but can be empty _rawPasswordValue = ""; _email = ""; _username = ""; }
/// <summary> /// Private method to create a member object from a MemberDto /// </summary> /// <param name="dto"></param> /// <param name="contentType"></param> /// <param name="propCollection"></param> /// <returns></returns> private IMember CreateMemberFromDto(MemberDto dto, IMemberType contentType, PropertyCollection propCollection) { var factory = new MemberFactory(contentType, NodeObjectTypeId, dto.ContentVersionDto.NodeId); var member = factory.BuildEntity(dto); member.Properties = propCollection; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((Entity)member).ResetDirtyProperties(false); return(member); }
/// <summary> /// Constructor for creating a Member object /// </summary> /// <param name="name">Name of the content</param> /// <param name="contentType">ContentType for the current Content object</param> public Member(string name, IMemberType contentType) : this(contentType) { Mandate.ParameterNotNull(contentType, "contentType"); Mandate.ParameterNotNullOrEmpty(name, "name"); _contentTypeAlias = contentType.Alias; _contentType = contentType; IsApproved = true; //this cannot be null but can be empty _rawPasswordValue = ""; _email = ""; _username = ""; }
public void Can_Get_Member_Type_By_Guid_Id() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MemberTypeRepository repository = CreateRepository(provider); IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); repository.Save(memberType); memberType = repository.Get(memberType.Key); Assert.That(memberType, Is.Not.Null); } }
public void Can_Get_Member_Type_By_Guid_Id() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); repository.Save(memberType); memberType = repository.Get(memberType.Key); Assert.That(memberType, Is.Not.Null); } }
/// <summary> /// Constructor for creating a Member object /// </summary> /// <param name="name">Name of the content</param> /// <param name="contentType">ContentType for the current Content object</param> public Member(string name, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullOrEmptyException(nameof(name)); } IsApproved = true; //this cannot be null but can be empty _rawPasswordValue = ""; _email = ""; _username = ""; }
public ContentTypeDto BuildDto(IMemberType entity) { var contentTypeDto = new ContentTypeDto { Alias = entity.Alias, Description = entity.Description, Icon = entity.Icon, Thumbnail = entity.Thumbnail, NodeId = entity.Id, AllowAtRoot = entity.AllowedAsRoot, IsContainer = entity.IsContainer, NodeDto = BuildNodeDto(entity) }; return(contentTypeDto); }
public string MemberTypes() { AddDictionaryItems(); var newaccountType = _localizationService.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType"); IMemberType memberContentType = _memberTypeService.Get(newaccountType.GetDefaultValue()); var test = memberContentType.PropertyTypes.Where(p => p.Alias == MediaWizards.Forums.Models.ForumAuthConstants.ResetRequestGuidPropery); if (test.Any()) { return("Properties already added."); } AddMemberGroups(); return(AddMemberProperties()); }
/// <summary> /// The execute. /// </summary> /// <returns> /// The <see cref="IContent"/>. /// </returns> public IContent Execute() { MultiLogHelper.Info <FastTrackDataInstaller>("Adding MemberType"); _memberType = this.AddMemberType(); MultiLogHelper.Info <FastTrackDataInstaller>("Adding example media"); this.AddExampleMedia(); // Adds the Merchello Data MultiLogHelper.Info <FastTrackDataInstaller>("Starting to add example FastTrack data"); this.AddMerchelloData(); // Adds the example Umbraco data MultiLogHelper.Info <FastTrackDataInstaller>("Starting to add example Merchello Umbraco data"); return(this.AddUmbracoData()); }
internal static IEnumerable <MemberColumn> GetColumns(this IMemberType type, string[] excludedColumns) { foreach (var group in type.PropertyGroups.OrderBy(g => g.SortOrder)) { // TODO: Check for sensitive data. foreach (var property in group.PropertyTypes .Where(p => !excludedColumns.Contains(p.Alias)) .OrderBy(p => p.SortOrder) .Select(p => new MemberColumn { Id = p.Alias, Alias = p.Alias, Name = p.Name })) { yield return(property); } } }
/// <summary> /// Initializes a new instance of the <see cref="Member" /> class. /// Constructor for creating a Member object /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="username"></param> /// <param name="contentType"></param> /// <param name="userId"></param> /// <param name="isApproved"></param> public Member(string name, string email, string username, IMemberType contentType, int userId, bool isApproved = true) : base(name, -1, contentType, new PropertyCollection()) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException( "Value can't be empty or consist only of white-space characters.", nameof(name)); } if (email == null) { throw new ArgumentNullException(nameof(email)); } if (string.IsNullOrWhiteSpace(email)) { throw new ArgumentException( "Value can't be empty or consist only of white-space characters.", nameof(email)); } if (username == null) { throw new ArgumentNullException(nameof(username)); } if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentException( "Value can't be empty or consist only of white-space characters.", nameof(username)); } _email = email; _username = username; CreatorId = userId; IsApproved = isApproved; // this cannot be null but can be empty _rawPasswordValue = string.Empty; }
public void Built_In_Member_Type_Properties_Are_Automatically_Added_When_Creating() { var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); repository.AddOrUpdate(memberType); unitOfWork.Commit(); memberType = repository.Get(memberType.Id); Assert.That(memberType.PropertyTypes.Count(), Is.EqualTo(3 + Constants.Conventions.Member.GetStandardPropertyTypeStubs().Count)); Assert.That(memberType.PropertyGroups.Count(), Is.EqualTo(2)); } }
public void Member_Can_View_Property() { IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); ServiceContext.MemberTypeService.Save(memberType); var prop = memberType.PropertyTypes.First().Alias; memberType.SetMemberCanViewProperty(prop, true); ServiceContext.MemberTypeService.Save(memberType); //re-get memberType = ServiceContext.MemberTypeService.Get(memberType.Id); foreach (var p in memberType.PropertyTypes.Where(x => x.Alias != prop)) { Assert.IsFalse(memberType.MemberCanViewProperty(p.Alias)); } Assert.IsTrue(memberType.MemberCanViewProperty(prop)); }
/// <summary> /// Constructor for creating a Member object /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="username"></param> /// <param name="contentType"></param> public Member(string name, string email, string username, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { Mandate.ParameterNotNull(contentType, "contentType"); Mandate.ParameterNotNullOrEmpty(name, "name"); Mandate.ParameterNotNullOrEmpty(email, "email"); Mandate.ParameterNotNullOrEmpty(username, "username"); _contentTypeAlias = contentType.Alias; _contentType = contentType; _email = email; _username = username; IsApproved = true; //this cannot be null but can be empty _rawPasswordValue = ""; }
private async Task <IdentityResult> UpdateMemberAsync(ProfileModel model, MemberIdentityUser currentMember) { using IScope scope = _scopeProvider.CreateScope(autoComplete: true); currentMember.Email = model.Email; currentMember.Name = model.Name; currentMember.UserName = model.UserName; currentMember.Comments = model.Comments; IdentityResult saveResult = await _memberManager.UpdateAsync(currentMember); if (!saveResult.Succeeded) { return(saveResult); } // now we can update the custom properties // TODO: Ideally we could do this all through our MemberIdentityUser IMember member = _memberService.GetByKey(currentMember.Key); if (member == null) { // should never happen throw new InvalidOperationException($"Could not find a member with key: {member.Key}."); } IMemberType memberType = _memberTypeService.Get(member.ContentTypeId); if (model.MemberProperties != null) { foreach (MemberPropertyModel property in model.MemberProperties //ensure the property they are posting exists .Where(p => memberType.PropertyTypeExists(p.Alias)) .Where(property => member.Properties.Contains(property.Alias)) //needs to be editable .Where(p => memberType.MemberCanEditProperty(p.Alias))) { member.Properties[property.Alias].SetValue(property.Value); } } _memberService.Save(member); return(saveResult); }
//TODO: To solve Collections/CG.Var.CustomStack.cs test internal TypeExpression Clone(IDictionary <int, TypeVariable> clonedTypeVariables, IList <EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed, IDictionary <String, TypeExpression> evaluated) { if (!this.HasTypeVariables()) { return(this); } // * We clone the ClassType object ClassType newClassType = (ClassType)this.MemberwiseClone(); if (evaluated.Keys.Contains(this.FullName)) { return(evaluated[this.FullName]); } evaluated.Add(this.FullName, newClassType); // * We clone the fields of the class that has type varrables newClassType.fieldList = new Dictionary <string, AccessModifier>(); newClassType.Members = new Dictionary <string, AccessModifier>(); foreach (KeyValuePair <string, AccessModifier> pair in this.Fields) { IMemberType newFieldType = null; if (pair.Value.Type is FieldType) { newFieldType = (IMemberType)((FieldType)pair.Value.Type).Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed, evaluated); } else { newFieldType = (IMemberType)pair.Value.Type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed); } AccessModifier newAccessModifier = new AccessModifier(pair.Value.Modifiers, pair.Value.MemberIdentifier, newFieldType, false); newClassType.fieldList[pair.Key] = newAccessModifier; newClassType.Members[pair.Key] = newAccessModifier; } foreach (KeyValuePair <string, AccessModifier> pair in this.Methods) { newClassType.Members[pair.Key] = pair.Value; } // * Clones the base class if (this.BaseClass.HasTypeVariables()) { newClassType.baseClass = (ClassType)this.BaseClass.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed); } // * The new class type is returned newClassType.ValidTypeExpression = false; return(newClassType); }
// 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); } }
private AccessModifier[] getAccessModifiers(IBCLUserType bclUserType, bool isInterface) { List <AccessModifier> list = new List <AccessModifier>(); Type type = Type.GetType(bclUserType.Name); MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public); foreach (MemberInfo member in members) { // * Duck typing :-) IMemberType memberType = (IMemberType)bclUserType.GetType().GetMethod("FindMember").Invoke(bclUserType, new object[] { member.Name }); AccessModifier accessModifier = new AccessModifier(Introspection.getMethodModifierList(member), member.Name, memberType, isInterface); list.Add(accessModifier); } AccessModifier[] result = new AccessModifier[list.Count]; list.CopyTo(result); return(result); }
public static Member CreateSimpleContent(IMemberType contentType, string name, string email, string password, string username, int parentId) { var member = new Member(name, email, username, password, parentId, contentType) { CreatorId = 0, Email = email, Password = password, Username = username }; member.SetValue("title", name + " member"); member.SetValue("bodyText", "This is a subpage"); member.SetValue("author", "John Doe"); member.ResetDirtyProperties(false); return member; }
public void Built_In_Member_Type_Properties_Are_Automatically_Added_When_Creating() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); repository.Save(memberType); memberType = repository.Get(memberType.Id); Assert.That(memberType.PropertyTypes.Count(), Is.EqualTo(3 + Constants.Conventions.Member.GetStandardPropertyTypeStubs().Count)); Assert.That(memberType.PropertyGroups.Count(), Is.EqualTo(2)); } }
public static Member CreateSimpleContent(IMemberType contentType, string name, string email, string password, string username, int parentId) { var member = new Member(name, email, username, password, parentId, contentType) { CreatorId = 0, Email = email, Password = password, Username = username }; member.SetValue("title", name + " member"); member.SetValue("bodyText", "This is a subpage"); member.SetValue("author", "John Doe"); member.ResetDirtyProperties(false); return(member); }
// no MapAll - take care private void Map(IMemberType source, MemberTypeDisplay target, MapperContext context) { MapTypeToDisplayBase <MemberTypeDisplay, MemberPropertyTypeDisplay>(source, target); //map the MemberCanEditProperty,MemberCanViewProperty,IsSensitiveData foreach (var propertyType in source.PropertyTypes) { var localCopy = propertyType; var displayProp = target.Groups.SelectMany(dest => dest.Properties).SingleOrDefault(dest => dest.Alias.InvariantEquals(localCopy.Alias)); if (displayProp == null) { continue; } displayProp.MemberCanEditProperty = source.MemberCanEditProperty(localCopy.Alias); displayProp.MemberCanViewProperty = source.MemberCanViewProperty(localCopy.Alias); displayProp.IsSensitiveData = source.IsSensitiveProperty(localCopy.Alias); } }
private IMember MapDtoToContent(MemberDto dto) { IMemberType memberType = _memberTypeRepository.Get(dto.ContentDto.ContentTypeId); Member member = ContentBaseFactory.BuildEntity(dto, memberType); // get properties - indexed by version id var versionId = dto.ContentVersionDto.Id; var temp = new TempContent <Member>(dto.ContentDto.NodeId, versionId, 0, memberType); var properties = GetPropertyCollections(new List <TempContent <Member> > { temp }); member.Properties = properties[versionId]; // reset dirty initial properties (U4-1946) member.ResetDirtyProperties(false); return(member); }
public static IEnumerable <MemberPropertyTypeDto> BuildMemberPropertyTypeDtos(IMemberType entity) { if (entity is not MemberType memberType || memberType.PropertyTypes.Any() == false) { return(Enumerable.Empty <MemberPropertyTypeDto>()); } var dtos = memberType.PropertyTypes.Select(x => new MemberPropertyTypeDto { NodeId = entity.Id, PropertyTypeId = x.Id, CanEdit = memberType.MemberCanEditProperty(x.Alias), ViewOnProfile = memberType.MemberCanViewProperty(x.Alias), IsSensitive = memberType.IsSensitiveProperty(x.Alias), }).ToList(); return(dtos); }
public void Bug_Changing_Built_In_Member_Type_Property_Type_Aliases_Results_In_Exception() { var stubs = Constants.Conventions.Member.GetStandardPropertyTypeStubs(); var provider = TestObjects.GetScopeProvider(Logger); using (provider.CreateScope()) { var repository = CreateRepository(provider); IMemberType memberType = MockedContentTypes.CreateSimpleMemberType("mtype"); // created without the stub properties Assert.AreEqual(1, memberType.PropertyGroups.Count); Assert.AreEqual(3, memberType.PropertyTypes.Count()); // saving *new* member type adds the stub properties repository.Save(memberType); // saving has added (and saved) the stub properties Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); foreach (var stub in stubs) { var prop = memberType.PropertyTypes.First(x => x.Alias == stub.Key); prop.Alias = prop.Alias + "__0000"; } // saving *existing* member type does *not* ensure stub properties repository.Save(memberType); // therefore, nothing has changed Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); // fetching ensures that the stub properties are there memberType = repository.Get("mtype"); Assert.IsNotNull(memberType); Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count * 2, memberType.PropertyTypes.Count()); } }
/// <summary> /// Constructor for creating a Member object /// </summary> /// <param name="name">Name of the content</param> /// <param name="contentType">ContentType for the current Content object</param> public Member(string name, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { _contentType = contentType; }
/// <summary> /// The execute. /// </summary> /// <returns> /// The <see cref="IContent"/>. /// </returns> public IContent Execute() { MultiLogHelper.Info<FastTrackDataInstaller>("Adding MemberType"); _memberType = this.AddMemberType(); MultiLogHelper.Info<FastTrackDataInstaller>("Adding example media"); this.AddExampleMedia(); // Adds the Merchello Data MultiLogHelper.Info<FastTrackDataInstaller>("Starting to add example FastTrack data"); this.AddMerchelloData(); // Adds the example Umbraco data MultiLogHelper.Info<FastTrackDataInstaller>("Starting to add example Merchello Umbraco data"); return this.AddUmbracoData(); }