private PublishedContentType CreatePublishedContentType(PublishedItemType itemType, string alias) { if (GetPublishedContentTypeByAlias != null) { return(GetPublishedContentTypeByAlias(alias)); } IContentTypeComposition contentType; switch (itemType) { case PublishedItemType.Content: contentType = _contentTypeService.Get(alias); break; case PublishedItemType.Media: contentType = _mediaTypeService.Get(alias); break; case PublishedItemType.Member: contentType = _memberTypeService.Get(alias); break; default: throw new ArgumentOutOfRangeException(nameof(itemType)); } if (contentType == null) { throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with alias \"{alias}\"."); } return(_publishedContentTypeFactory.CreateContentType(contentType)); }
/// <summary> /// Returns a display node with a list view to render members /// </summary> /// <param name="listName">The member type to list</param> /// <returns>The member list for display</returns> public MemberListDisplay GetListNodeDisplay(string listName) { IMemberType?foundType = _memberTypeService.Get(listName); var name = foundType != null ? foundType.Name : listName; var apps = new List <ContentApp> { ListViewContentAppFactory.CreateContentApp(_dataTypeService, _propertyEditors, listName, "member", Constants.DataTypes.DefaultMembersListView) }; apps[0].Active = true; var display = new MemberListDisplay { ContentTypeAlias = listName, ContentTypeName = name, Id = listName, IsContainer = true, Name = listName == Constants.Conventions.MemberTypes.AllMembersListId ? "All Members" : name, Path = "-1," + listName, ParentId = -1, ContentApps = apps }; return(display); }
private IEnumerable <UmbracoProperty> GetMemberProperties(IMember member) { var builtIns = Umbraco.Core.Constants.Conventions.Member.GetStandardPropertyTypeStubs() .Select(x => x.Key).ToArray(); var memberType = _memberTypeService.Get(member.ContentTypeId); var viewProperties = new List <UmbracoProperty>(); foreach (var prop in memberType.PropertyTypes.Where(x => builtIns.Contains(x.Alias) == false)) { var value = string.Empty; var propValue = member.Properties[prop.Alias]; if (propValue != null && propValue.GetValue() != null) { value = propValue.GetValue().ToString(); } var viewProperty = new UmbracoProperty { Alias = prop.Alias, Name = prop.Name, Value = value }; viewProperties.Add(viewProperty); } return(viewProperties); }
/// <inheritdoc /> /// <remarks>Overridden to deal with custom member properties and permissions.</remarks> public override IEnumerable <Tab <ContentPropertyDisplay> > Map(IMember source, MapperContext context) { var provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); var memberType = _memberTypeService.Get(source.ContentTypeId); IgnoreProperties = memberType.CompositionPropertyTypes .Where(x => x.HasIdentity == false) .Select(x => x.Alias) .ToArray(); var resolved = base.Map(source, context); // IMember.IsLockedOut can't be set to true, so make it readonly when that's the case (you can only unlock) var isLockedOutPropertyAlias = Constants.Conventions.Member.IsLockedOut; if (provider.IsUmbracoMembershipProvider() && provider is IUmbracoMemberTypeMembershipProvider umbracoProvider) { // This is kind of a hack because a developer is supposed to be allowed to set their property editor - would have been much easier // if we just had all of the membership provider fields on the member table :( // TODO: But is there a way to map the IMember.IsLockedOut to the property ? i dunno. isLockedOutPropertyAlias = umbracoProvider.LockPropertyTypeAlias; } var isLockedOutProperty = resolved.SelectMany(x => x.Properties).FirstOrDefault(x => x.Alias == isLockedOutPropertyAlias); if (isLockedOutProperty?.Value != null && isLockedOutProperty.Value.ToString() != "1") { isLockedOutProperty.Readonly = true; } return(resolved); }
private string GetIcon(LogDto logItem) { switch (logItem.EntityType.ToLower()) { case "document": return(_contentService.GetById(logItem.NodeId).ContentType.Icon); case "media": return(_mediaService.GetById(logItem.NodeId).ContentType.Icon); case "member": return(_memberTypeService.Get(_memberService.GetById(logItem.NodeId).ContentTypeAlias).Icon); case "documenttype": return(_contentTypeService.Get(logItem.NodeId).Icon); case "mediatype": return(_mediaTypeService.Get(logItem.NodeId).Icon); case "membertype": return(_memberTypeService.Get(logItem.NodeId).Icon); case "datatype": return(_dataTypeService.GetAll(new[] { logItem.NodeId }).FirstOrDefault().Editor.Icon); case "dictionaryitem": return("icon-book-alt"); default: return("icon-newspaper"); } }
/// <summary> /// Gets the member type a given id /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult <MemberTypeDisplay> GetById(int id) { var mt = _memberTypeService.Get(id); if (mt == null) { return(NotFound()); } var dto = _umbracoMapper.Map <IMemberType, MemberTypeDisplay>(mt); return(dto); }
public IEnumerable <MemberColumn> GetMemberColumns(string memberType = null) { var excludedColumns = settings.ExcludedColumns ?? Array.Empty <string>(); bool foundType = false; if (!string.IsNullOrWhiteSpace(memberType)) { var type = memberTypeService.Get(memberType); if (type != null) { foundType = true; foreach (var col in type.GetColumns(excludedColumns)) { yield return(col); } } } if (!foundType) { // This is only used to track columns we already have added. var columns = new List <string>(); foreach (var type in memberTypeService.GetAll()) { foreach (var col in type.GetColumns(excludedColumns)) { if (!columns.Contains(col.Alias)) { columns.Add(col.Alias); yield return(col); } } } } }
public IEnumerable <ContentPropertyBasic> Resolve(IMember source, MemberBasic destination, IEnumerable <ContentPropertyBasic> destMember, ResolutionContext context) { var umbracoContext = _umbracoContextAccessor.UmbracoContext; if (umbracoContext == null) { throw new InvalidOperationException("Cannot resolve value without an UmbracoContext available"); } var result = Mapper.Map <IEnumerable <Property>, IEnumerable <ContentPropertyBasic> >( // Sort properties so items from different compositions appear in correct order (see U4-9298). Map sorted properties. source.Properties.OrderBy(prop => prop.PropertyType.SortOrder)) .ToList(); var memberType = _memberTypeService.Get(source.ContentTypeId); //now update the IsSensitive value foreach (var prop in result) { //check if this property is flagged as sensitive var isSensitiveProperty = memberType.IsSensitiveProperty(prop.Alias); //check permissions for viewing sensitive data if (isSensitiveProperty && umbracoContext.Security.CurrentUser.HasAccessToSensitiveData() == false) { //mark this property as sensitive prop.IsSensitive = true; //clear the value prop.Value = null; } } return(result); }
protected override ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings) { var menu = MenuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { // root actions menu.Items.Add(new CreateChildEntity(LocalizedTextService)); menu.Items.Add(new RefreshNode(LocalizedTextService, true)); return(menu); } else { var memberType = _memberTypeService.Get(int.Parse(id)); if (memberType != null) { menu.Items.Add <ActionCopy>(LocalizedTextService, opensDialog: true, useLegacyIcon: false); } // delete member type/group menu.Items.Add <ActionDelete>(LocalizedTextService, opensDialog: true, useLegacyIcon: false); } return(menu); }
private void ReturnDefaultMemberType() { IMemberType memberType = Substitute.For <IMemberType>(); memberType.Alias = DefaultMemberTypeAlias; _memberTypeService.Get(DefaultMemberType).Returns(memberType); }
public ExecutionResult Execute() { var memberType = _memberTypeService.Get(UsersInstallationConstants.DataTypeAliases.Member); var phoneProperty = new PropertyType("Umbraco.Textbox", DataTypeDatabaseType.Nvarchar) { Alias = UsersInstallationConstants.DataTypePropertyAliases.Phone, Name = UsersInstallationConstants.DataTypePropertyNames.Phone }; var departmentProperty = new PropertyType("Umbraco.Textbox", DataTypeDatabaseType.Nvarchar) { Alias = UsersInstallationConstants.DataTypePropertyAliases.Department, Name = UsersInstallationConstants.DataTypePropertyNames.Department }; var profileTab = UsersInstallationConstants.DataTypeTabAliases.ProfileTabAlias; if (!memberType.PropertyTypeExists(phoneProperty.Alias)) { memberType.AddPropertyType(phoneProperty, profileTab); } if (!memberType.PropertyTypeExists(departmentProperty.Alias)) { memberType.AddPropertyType(departmentProperty, profileTab); } _memberTypeService.Save(memberType); return(ExecutionResult.Success); }
public IEnumerable <DataListItem> GetItems(Dictionary <string, object> config) { DataListItem mapMember(IMember member) { var guidUdi = Udi.Create(UmbConstants.UdiEntityType.Member, member.Key).ToString(); return(new DataListItem { Name = member.Name, Value = guidUdi, Icon = member.ContentType.Icon ?? UmbConstants.Icons.Member, Description = guidUdi, }); }; if (config.TryGetValueAs("memberType", out JArray array) == true && array.Count > 0 && array[0].Value <string>() is string str && string.IsNullOrWhiteSpace(str) == false && GuidUdi.TryParse(str, out var udi) == true) { var memberType = _memberTypeService.Get(udi.Guid); if (memberType != null) { return(_memberService.GetMembersByMemberType(memberType.Id).Select(mapMember)); } }
private void Map(IMember source, MemberListItem target, MapperContext context) { target.ContentTypeId = source.ContentType.Id; target.ContentTypeAlias = source.ContentType.Alias; target.CreateDate = source.CreateDate; target.Email = source.Email; target.Icon = source.ContentType.Icon; target.Id = int.MaxValue; target.Key = source.Key; target.Name = source.Name; target.Owner = GetOwner(source, context); target.ParentId = source.ParentId; target.Path = source.Path; #if NET5_0_OR_GREATER var properties = source.Properties.ToArray(); target.Properties = context.MapEnumerable <IProperty, ContentPropertyBasic>(properties); #else target.Properties = context.MapEnumerable <Property, ContentPropertyBasic>(source.Properties); #endif target.SortOrder = source.SortOrder; target.State = null; target.Udi = Udi.Create(UdiEntityType.Member, source.Key); target.UpdateDate = source.UpdateDate; target.Username = source.Username; target.MemberGroups = GetMemberGroups(source.Username); target.IsLockedOut = source.IsLockedOut; target.IsApproved = source.IsApproved; target.ContentType = memberTypeService.Get(source.ContentType.Alias); }
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()); }
/// <inheritdoc /> /// <remarks>Overridden to deal with custom member properties and permissions.</remarks> public override IEnumerable <Tab <ContentPropertyDisplay> > Map(IMember source, MapperContext context) { var memberType = _memberTypeService.Get(source.ContentTypeId); if (memberType is not null) { IgnoreProperties = memberType.CompositionPropertyTypes .Where(x => x.HasIdentity == false) .Select(x => x.Alias) .ToArray(); } var resolved = base.Map(source, context); return(resolved); }
/// <summary> /// Creates a model to use for registering new members with custom member properties /// </summary> /// <param name="memberTypeAlias"></param> /// <returns></returns> public virtual RegisterModel CreateRegistrationModel(string memberTypeAlias = null) { var provider = _membershipProvider; if (provider.IsUmbracoMembershipProvider()) { memberTypeAlias = memberTypeAlias ?? Constants.Conventions.MemberTypes.DefaultAlias; var memberType = _memberTypeService.Get(memberTypeAlias); if (memberType == null) { throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias); } var builtIns = Constants.Conventions.Member.GetStandardPropertyTypeStubs().Select(x => x.Key).ToArray(); var model = RegisterModel.CreateModel(); model.MemberTypeAlias = memberTypeAlias; model.MemberProperties = GetMemberPropertiesViewModel(memberType, builtIns).ToList(); return(model); } else { var model = RegisterModel.CreateModel(); model.MemberTypeAlias = string.Empty; return(model); } }
public IEnumerable<PropertyType> GetAvailableProfileProperties() { var mts = _memberTypeService.Get(MemberTypeAlias); var profileTab = mts.PropertyGroups.FirstOrDefault(i => i.Name.Equals(MemberProfileTabName)); var properties = profileTab.PropertyTypes .Where(i => !i.Alias.Equals(RelatedUserPropertyName)); return properties; }
private IPublishedContentType CreatePublishedContentType(PublishedItemType itemType, Guid key) { IContentTypeComposition contentType = itemType switch { PublishedItemType.Content => _contentTypeService.Get(key), PublishedItemType.Media => _mediaTypeService.Get(key), PublishedItemType.Member => _memberTypeService.Get(key), _ => throw new ArgumentOutOfRangeException(nameof(itemType)), }; if (contentType == null) { throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with key \"{key}\"."); } return(_publishedContentTypeFactory.CreateContentType(contentType)); }
/// <inheritdoc /> /// <remarks>Overridden to deal with custom member properties and permissions.</remarks> public override IEnumerable <Tab <ContentPropertyDisplay> > Map(IMember source, MapperContext context) { var memberType = _memberTypeService.Get(source.ContentTypeId); IgnoreProperties = memberType.CompositionPropertyTypes .Where(x => x.HasIdentity == false) .Select(x => x.Alias) .ToArray(); var resolved = base.Map(source, context); // This is kind of a hack because a developer is supposed to be allowed to set their property editor - would have been much easier // if we just had all of the membership provider fields on the member table :( // TODO: But is there a way to map the IMember.IsLockedOut to the property ? i dunno. var isLockedOutProperty = resolved.SelectMany(x => x.Properties).FirstOrDefault(x => x.Alias == Constants.Conventions.Member.IsLockedOut); if (isLockedOutProperty?.Value != null && isLockedOutProperty.Value.ToString() != "1") { isLockedOutProperty.View = "readonlyvalue"; isLockedOutProperty.Value = _localizedTextService.Localize("general", "no"); } if (_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser != null && _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) { var memberTypeLink = $"#/member/memberTypes/edit/{source.ContentTypeId}"; // Replace the doctype property var docTypeProperty = resolved.SelectMany(x => x.Properties) .First(x => x.Alias == $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}doctype"); docTypeProperty.Value = new List <object> { new { linkText = source.ContentType.Name, url = memberTypeLink, target = "_self", icon = Constants.Icons.ContentType } }; docTypeProperty.View = "urllist"; } return(resolved); }
/// <summary> /// these shoud be doable with the entity service, but for now, we /// are grouping these making it eaiser should we add another /// contentTypeBased type to it. /// </summary> /// <param name="key"></param> /// <returns></returns> private IContentTypeBase LookupByKey(Guid key) { IContentTypeBase item = default(IContentTypeBase); switch (_itemType) { case Constants.Packaging.DocumentTypeNodeName: item = _contentTypeService.GetContentType(key); break; case "MediaType": item = _contentTypeService.GetMediaType(key); break; case "MemberType": item = _memberTypeService.Get(key); break; } return(item); }
/// <inheritdoc /> /// <remarks>Overridden to deal with custom member properties and permissions.</remarks> public override IEnumerable <Tab <ContentPropertyDisplay> > Map(IMember source, MapperContext context) { var memberType = _memberTypeService.Get(source.ContentTypeId); IgnoreProperties = memberType.CompositionPropertyTypes .Where(x => x.HasIdentity == false) .Select(x => x.Alias) .ToArray(); var resolved = base.Map(source, context); // IMember.IsLockedOut can't be set to true, so make it readonly when that's the case (you can only unlock) var isLockedOutProperty = resolved.SelectMany(x => x.Properties).FirstOrDefault(x => x.Alias == Constants.Conventions.Member.IsLockedOut); if (isLockedOutProperty?.Value != null && isLockedOutProperty.Value.ToString() != "1") { isLockedOutProperty.Readonly = true; } return(resolved); }
private MembershipScenario GetMembershipScenario() { var provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); if (provider.IsUmbracoMembershipProvider()) { return MembershipScenario.NativeUmbraco; } var memberType = _memberTypeService.Get(Constants.Conventions.MemberTypes.DefaultAlias); return memberType != null ? MembershipScenario.CustomProviderWithUmbracoLink : MembershipScenario.StandaloneCustomProvider; }
public MembershipScenario Resolve(IMember source) { var provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); if (provider.IsUmbracoMembershipProvider()) { return(MembershipScenario.NativeUmbraco); } var memberType = _memberTypeService.Get(Constants.Conventions.MemberTypes.DefaultAlias); return(memberType != null ? MembershipScenario.CustomProviderWithUmbracoLink : MembershipScenario.StandaloneCustomProvider); }
private IContentTypeBase SyncMemberType(ContentTypeRegistration registration, IContentTypeBase result) { result.ResetDirtyProperties(false); Save(result); //need to save to ensure no sync issues when we load from the legacy API bool modified = false; var member = new umbraco.cms.businesslogic.member.MemberType(result.Id); foreach (var prop in member.PropertyTypes) { var propReg = registration.Properties.SingleOrDefault(x => x.Alias == prop.Alias); if (propReg != null) { var attr = propReg.Metadata.GetCodeFirstAttribute <MemberPropertyAttribute>(); if (attr != null) { if (attr.MemberCanEdit != member.MemberCanEdit(prop)) { member.setMemberCanEdit(prop, attr.MemberCanEdit); modified = true; } if (attr.ShowOnProfile != member.ViewOnProfile(prop)) { member.setMemberViewOnProfile(prop, attr.ShowOnProfile); modified = true; } } } } if (modified) { modified = false; member.Save(); } return(_service.Get(member.Id)); }
/// <summary> /// Gets an instance of IMember used when creating a member /// </summary> /// <param name="model"></param> /// <returns></returns> /// <remarks> /// Depending on whether a custom membership provider is configured this will return different results. /// </remarks> private IMember CreateNew(MemberSave model) { var contentType = _memberTypeService.Get(model.ContentTypeAlias); if (contentType == null) { throw new InvalidOperationException("No member type found with alias " + model.ContentTypeAlias); } //remove all membership properties, these values are set with the membership provider. FilterMembershipProviderProperties(contentType); //return the new member with the details filled in return(new Member(model.Name, model.Email, model.Username, model.Password.NewPassword, contentType)); }
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); }
// 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 string GetContentPath(IMemberType item) { string path = string.Empty; if (item != null) { if (item.ParentId != 0) { var parent = _memberTypeService.Get(item.ParentId); if (parent != null) { path = GetContentPath(parent); } } path = Path.Combine(path, item.Alias.ToSafeFileName()); } return(path); }
/// <summary> /// This ensures that the internal membership property types are removed from validation before processing the validation /// since those properties are actually mapped to real properties of the IMember. /// This also validates any posted data for fields that are sensitive. /// </summary> /// <param name="model"></param> /// <param name="modelWithProperties"></param> /// <param name="actionContext"></param> /// <returns></returns> public override bool ValidateProperties(MemberSave model, IContentProperties <ContentPropertyBasic> modelWithProperties, HttpActionContext actionContext) { var propertiesToValidate = model.Properties.ToList(); var defaultProps = ConventionsHelper.GetStandardPropertyTypeStubs(); var exclude = defaultProps.Select(x => x.Value.Alias).ToArray(); foreach (var remove in exclude) { propertiesToValidate.RemoveAll(property => property.Alias == remove); } //if the user doesn't have access to sensitive values, then we need to validate the incoming properties to check //if a sensitive value is being submitted. if (UmbracoContextAccessor.UmbracoContext.Security.CurrentUser.HasAccessToSensitiveData() == false) { var contentType = _memberTypeService.Get(model.PersistedContent.ContentTypeId); var sensitiveProperties = contentType .PropertyTypes.Where(x => contentType.IsSensitiveProperty(x.Alias)) .ToList(); foreach (var sensitiveProperty in sensitiveProperties) { var prop = propertiesToValidate.FirstOrDefault(x => x.Alias == sensitiveProperty.Alias); if (prop != null) { //this should not happen, this means that there was data posted for a sensitive property that //the user doesn't have access to, which means that someone is trying to hack the values. var message = $"property with alias: {prop.Alias} cannot be posted"; actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, new InvalidOperationException(message)); return(false); } } } return(ValidateProperties(propertiesToValidate, model.PersistedContent.Properties.ToList(), actionContext)); }
private IEnumerable <UmbracoProperty> GetMemberProperties(IMember member) { var builtIns = ((Dictionary <string, PropertyType>) typeof(Umbraco.Core.Constants.Conventions.Member).CallStaticMethod("GetStandardPropertyTypeStubs")) .Select(x => x.Key).ToArray(); var memberType = _memberTypeService.Get(member.ContentTypeAlias); if (memberType == null) { throw new NullReferenceException("No member type found with alias " + member.ContentTypeAlias); } var viewProperties = new List <UmbracoProperty>(); foreach (var prop in memberType.PropertyTypes.Where(x => builtIns.Contains(x.Alias) == false)) { var value = string.Empty; var propValue = member.Properties[prop.Alias]; if (propValue != null && propValue.Value != null) { value = propValue.Value.ToString(); } var viewProperty = new UmbracoProperty { Alias = prop.Alias, Name = prop.Name, Value = value }; viewProperties.Add(viewProperty); } return(viewProperties); }