private void EditorModelEventManager_SendingContentModel(HttpActionExecutedContext sender, EditorModelEventArgs <ContentItemDisplay> e) { if (e.Model.ContentTypeAlias == "ENTER CONTENT ALIAS HERE") { IUser currentUser = UmbracoContext.Current.Security.CurrentUser; if (!currentUser.Groups.Any(g => g.Name == "Administrators")) { ContentPropertyDisplay propertyToHide = e.Model.Properties.FirstOrDefault(f => f.Alias == "ENTER PROPERTY ALIAS HERE"); propertyToHide.Readonly = true; } } }
/// <summary> /// Returns the login property display field /// </summary> /// <param name="member"></param> /// <param name="display"></param> /// <param name="localizedText"></param> /// <returns></returns> /// <remarks> /// If the membership provider installed is the umbraco membership provider, then we will allow changing the username, however if /// the membership provider is a custom one, we cannot allow changing the username because MembershipProvider's do not actually natively /// allow that. /// </remarks> internal static ContentPropertyDisplay GetLoginProperty(IMember member, ILocalizedTextService localizedText) { var prop = new ContentPropertyDisplay { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}login", Label = localizedText.Localize(null, "login"), Value = member.Username }; prop.View = "textbox"; prop.Validation.Mandatory = true; return(prop); }
/// <summary> /// Returns the login property display field /// </summary> /// <param name="memberService"></param> /// <param name="member"></param> /// <param name="display"></param> /// <param name="localizedText"></param> /// <returns></returns> /// <remarks> /// If the membership provider installed is the umbraco membership provider, then we will allow changing the username, however if /// the membership provider is a custom one, we cannot allow chaning the username because MembershipProvider's do not actually natively /// allow that. /// </remarks> internal static ContentPropertyDisplay GetLoginProperty(IMemberService memberService, IMember member, ILocalizedTextService localizedText) { var prop = new ContentPropertyDisplay { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}login", Label = localizedText.Localize("login"), Value = member.Username }; var scenario = memberService.GetMembershipScenario(); //only allow editing if this is a new member, or if the membership provider is the umbraco one if (member.HasIdentity == false || scenario == MembershipScenario.NativeUmbraco) { prop.View = "textbox"; prop.Validation.Mandatory = true; } else { prop.View = "readonlyvalue"; } return(prop); }
private void Map(Property source, ContentPropertyDisplay target, MapperContext context) { // assume this is mapping everything and no MapAll is required _contentPropertyDisplayMapper.Map(source, target, context); }
private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService, ILocalizedTextService localizedText, IContentTypeService contentTypeService, ILogger logger) { // Adapted from ContentModelMapper //map the IsChildOfListView (this is actually if it is a descendant of a list view!) var parent = media.Parent(); display.IsChildOfListView = parent != null && (parent.ContentType.IsContainer || contentTypeService.HasContainerInPath(parent.Path)); //map the tree node url if (HttpContext.Current != null) { var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var url = urlHelper.GetUmbracoApiService <MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null)); display.TreeNodeUrl = url; } if (media.ContentType.IsContainer) { TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService, localizedText); } var genericProperties = new List <ContentPropertyDisplay> { new ContentPropertyDisplay { Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = localizedText.Localize("content/mediatype"), Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName), View = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View } }; TabsAndPropertiesResolver.MapGenericProperties(media, display, localizedText, genericProperties, properties => { if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) { var mediaTypeLink = string.Format("#/settings/mediatypes/edit/{0}", media.ContentTypeId); //Replace the doctype property var docTypeProperty = properties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix)); docTypeProperty.Value = new List <object> { new { linkText = media.ContentType.Name, url = mediaTypeLink, target = "_self", icon = "icon-item-arrangement" } }; docTypeProperty.View = "urllist"; } // inject 'Link to media' as the first generic property var links = media.GetUrls(UmbracoConfig.For.UmbracoSettings().Content, logger); if (links.Any()) { var link = new ContentPropertyDisplay { Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = localizedText.Localize("media/urls"), Value = string.Join(",", links), View = "urllist" }; properties.Insert(0, link); } }); }
public FluidityEntityEditModel ToEditModel(FluiditySectionConfig section, FluidityCollectionConfig collection, object entity) { var isNew = entity == null; var entityId = entity?.GetPropertyValue(collection.IdProperty); var entityCompositeId = entityId != null ? collection.Alias + "!" + entityId : null; var display = new FluidityEntityEditModel { Id = entity?.GetPropertyValue(collection.IdProperty) ?? collection.IdProperty.Type.GetDefaultValue(), Name = collection?.NameProperty != null?entity?.GetPropertyValue(collection.NameProperty).ToString() : collection.NameSingular, HasNameProperty = collection.NameProperty != null, Section = section.Alias, Tree = section.Tree.Alias, CollectionIsReadOnly = collection.IsReadOnly, Collection = collection.Alias, CollectionNameSingular = collection.NameSingular, CollectionNamePlural = collection.NamePlural, CollectionIconSingular = collection.IconSingular, CollectionIconPlural = collection.IconPlural, IsChildOfListView = collection.ViewMode == FluidityViewMode.List, IsChildOfTreeView = collection.ViewMode == FluidityViewMode.Tree, TreeNodeUrl = "/umbraco/backoffice/fluidity/FluidityTree/GetTreeNode/" + entityCompositeId + "?application=" + section.Alias, CreateDate = entity != null && collection.DateCreatedProperty != null ? (DateTime)entity.GetPropertyValue(collection.DateCreatedProperty) : DateTime.MinValue, UpdateDate = entity != null && collection.DateModifiedProperty != null ? (DateTime)entity.GetPropertyValue(collection.DateCreatedProperty) : DateTime.MinValue, Path = collection.Path + (entity != null ? FluidityConstants.PATH_SEPERATOR + collection.Alias + "!" + entity.GetPropertyValue(collection.IdProperty) : string.Empty) }; if (collection.Editor?.Tabs != null) { var tabs = new List <Tab <ContentPropertyDisplay> >(); foreach (var tab in collection.Editor.Tabs) { var tabScaffold = new Tab <ContentPropertyDisplay> { Id = tabs.Count, Alias = tab.Name, Label = tab.Name, IsActive = tabs.Count == 0 }; var properties = new List <ContentPropertyDisplay>(); if (tab.Fields != null) { foreach (var field in tab.Fields) { var dataTypeInfo = _dataTypeHelper.ResolveDataType(field, collection.IsReadOnly); dataTypeInfo.PropertyEditor.ValueEditor.ConfigureForDisplay(dataTypeInfo.PreValues); var propEditorConfig = dataTypeInfo.PropertyEditor.PreValueEditor.ConvertDbToEditor(dataTypeInfo.PropertyEditor.DefaultPreValues, dataTypeInfo.PreValues); // Calculate value object value = !isNew ? entity?.GetPropertyValue(field.Property) : field.DefaultValueFunc != null?field.DefaultValueFunc() : field.Property.Type.GetDefaultValue(); var encryptedProp = collection.EncryptedProperties?.FirstOrDefault(x => x.Name == field.Property.Name); if (encryptedProp != null) { value = SecurityHelper.Decrypt(value.ToString()); } if (field.ValueMapper != null) { value = field.ValueMapper.ModelToEditor(value); } var dummyProp = new Property(new PropertyType(dataTypeInfo.DataTypeDefinition), value); value = dataTypeInfo.PropertyEditor.ValueEditor.ConvertDbToEditor(dummyProp, dummyProp.PropertyType, _dataTypeService); // Calculate label var label = field.Label; if (label.IsNullOrWhiteSpace()) { var attr = field.Property.PropertyInfo.GetCustomAttribute <DisplayNameAttribute>(true); if (attr != null) { label = attr.DisplayName; } else { label = field.Property.Name.SplitPascalCasing(); } } // Calculate description var description = field.Description; if (description.IsNullOrWhiteSpace()) { var attr = field.Property.PropertyInfo.GetCustomAttribute <DescriptionAttribute>(true); if (attr != null) { description = attr.Description; } } var propertyScaffold = new ContentPropertyDisplay { Id = properties.Count, Alias = field.Property.Name, Label = label, Description = description, Editor = dataTypeInfo.PropertyEditor.Alias, View = dataTypeInfo.PropertyEditor.ValueEditor.View, Config = propEditorConfig, HideLabel = dataTypeInfo.PropertyEditor.ValueEditor.HideLabel, Value = value }; properties.Add(propertyScaffold); } } tabScaffold.Properties = properties; tabs.Add(tabScaffold); } display.Tabs = tabs; } return(display); }