Example #1
0
        // helpers

        private void MapUserGroupBasic(UserGroupBasic target, IEnumerable <string> sourceAllowedSections, int?sourceStartContentId, int?sourceStartMediaId, MapperContext context)
        {
            var allSections = _sectionService.GetSections();

            target.Sections = context.MapEnumerable <ISection, Section>(allSections.Where(x => sourceAllowedSections.Contains(x.Alias)));

            if (sourceStartMediaId > 0)
            {
                target.MediaStartNode = context.Map <EntityBasic>(_entityService.Get(sourceStartMediaId.Value, UmbracoObjectTypes.Media));
            }
            else if (sourceStartMediaId == -1)
            {
                target.MediaStartNode = CreateRootNode(_textService.Localize("media/mediaRoot"));
            }

            if (sourceStartContentId > 0)
            {
                target.ContentStartNode = context.Map <EntityBasic>(_entityService.Get(sourceStartContentId.Value, UmbracoObjectTypes.Document));
            }
            else if (sourceStartContentId == -1)
            {
                target.ContentStartNode = CreateRootNode(_textService.Localize("content/contentRoot"));
            }

            if (target.Icon.IsNullOrWhiteSpace())
            {
                target.Icon = Constants.Icons.UserGroup;
            }
        }
Example #2
0
        // no MapAll - take care
        private void Map(IContentType source, DocumentTypeDisplay target, MapperContext context)
        {
            MapTypeToDisplayBase <DocumentTypeDisplay, PropertyTypeDisplay>(source, target);

            target.AllowCultureVariant = source.VariesByCulture();
            target.AllowSegmentVariant = source.VariesBySegment();

            //sync templates
            target.AllowedTemplates = context.MapEnumerable <ITemplate, EntityBasic>(source.AllowedTemplates);

            if (source.DefaultTemplate != null)
            {
                target.DefaultTemplate = context.Map <EntityBasic>(source.DefaultTemplate);
            }

            //default listview
            target.ListViewEditorName = Constants.Conventions.DataTypes.ListViewPrefix + "Content";

            if (string.IsNullOrEmpty(source.Alias))
            {
                return;
            }

            var name = Constants.Conventions.DataTypes.ListViewPrefix + source.Alias;

            if (_dataTypeService.GetDataType(name) != null)
            {
                target.ListViewEditorName = name;
            }
        }
 // Umbraco.Code.MapAll
 private void Map(ContentItemDisplay source, ContentItemDisplayWithSchedule target, MapperContext context)
 {
     target.AllowedActions   = source.AllowedActions;
     target.AllowedTemplates = source.AllowedTemplates;
     target.AllowPreview     = source.AllowPreview;
     target.ContentApps      = source.ContentApps;
     target.ContentDto       = source.ContentDto;
     target.ContentTypeAlias = source.ContentTypeAlias;
     target.ContentTypeId    = source.ContentTypeId;
     target.ContentTypeKey   = source.ContentTypeKey;
     target.ContentTypeName  = source.ContentTypeName;
     target.DocumentType     = source.DocumentType;
     target.Errors           = source.Errors;
     target.Icon             = source.Icon;
     target.Id                = source.Id;
     target.IsBlueprint       = source.IsBlueprint;
     target.IsChildOfListView = source.IsChildOfListView;
     target.IsContainer       = source.IsContainer;
     target.IsElement         = source.IsElement;
     target.Key               = source.Key;
     target.Owner             = source.Owner;
     target.ParentId          = source.ParentId;
     target.Path              = source.Path;
     target.PersistedContent  = source.PersistedContent;
     target.SortOrder         = source.SortOrder;
     target.TemplateAlias     = source.TemplateAlias;
     target.TemplateId        = source.TemplateId;
     target.Trashed           = source.Trashed;
     target.TreeNodeUrl       = source.TreeNodeUrl;
     target.Udi               = source.Udi;
     target.UpdateDate        = source.UpdateDate;
     target.Updater           = source.Updater;
     target.Urls              = source.Urls;
     target.Variants          = context.MapEnumerable <ContentVariantDisplay, ContentVariantScheduleDisplay>(source.Variants);
 }
Example #4
0
 // Umbraco.Code.MapAll -Notifications -Udi -Icon -IsCurrentUser -Trashed -ResetPasswordValue
 // Umbraco.Code.MapAll -Alias -AdditionalData
 private void Map(IUser source, UserDisplay target, MapperContext context)
 {
     target.AvailableCultures         = _textService.GetSupportedCultures().ToDictionary(x => x.Name, x => x.DisplayName);
     target.Avatars                   = source.GetUserAvatarUrls(_appCaches.RuntimeCache);
     target.CalculatedStartContentIds = GetStartNodes(source.CalculateContentStartNodeIds(_entityService), UmbracoObjectTypes.Document, "content/contentRoot", context);
     target.CalculatedStartMediaIds   = GetStartNodes(source.CalculateMediaStartNodeIds(_entityService), UmbracoObjectTypes.Media, "media/mediaRoot", context);
     target.CreateDate                = source.CreateDate;
     target.Culture                   = source.GetUserCulture(_textService, _globalSettings).ToString();
     target.Email     = source.Email;
     target.EmailHash = source.Email.ToLowerInvariant().Trim().GenerateHash();
     target.FailedPasswordAttempts = source.FailedPasswordAttempts;
     target.Id                     = source.Id;
     target.Key                    = source.Key;
     target.LastLockoutDate        = source.LastLockoutDate;
     target.LastLoginDate          = source.LastLoginDate == default ? null : (DateTime?)source.LastLoginDate;
     target.LastPasswordChangeDate = source.LastPasswordChangeDate;
     target.Name                   = source.Name;
     target.Navigation             = CreateUserEditorNavigation();
     target.ParentId               = -1;
     target.Path                   = "-1," + source.Id;
     target.StartContentIds        = GetStartNodes(source.StartContentIds.ToArray(), UmbracoObjectTypes.Document, "content/contentRoot", context);
     target.StartMediaIds          = GetStartNodes(source.StartMediaIds.ToArray(), UmbracoObjectTypes.Media, "media/mediaRoot", context);
     target.UpdateDate             = source.UpdateDate;
     target.UserGroups             = context.MapEnumerable <IReadOnlyUserGroup, UserGroupBasic>(source.Groups);
     target.Username               = source.Username;
     target.UserState              = source.UserState;
 }
Example #5
0
        // Umbraco.Code.MapAll -AllowPreview -Errors -PersistedContent
        private void Map(IContent source, ContentItemDisplay target, MapperContext context)
        {
            target.AllowedActions   = GetActions(source);
            target.AllowedTemplates = GetAllowedTemplates(source);
            target.ContentApps      = _commonMapper.GetContentApps(source);
            target.ContentTypeId    = source.ContentType.Id;
            target.ContentTypeKey   = source.ContentType.Key;
            target.ContentTypeAlias = source.ContentType.Alias;
            target.ContentTypeName  = _localizedTextService.UmbracoDictionaryTranslate(source.ContentType.Name);
            target.DocumentType     = _commonMapper.GetContentType(source, context);
            target.Icon             = source.ContentType.Icon;
            target.Id                = source.Id;
            target.IsBlueprint       = source.Blueprint;
            target.IsChildOfListView = DetermineIsChildOfListView(source, context);
            target.IsContainer       = source.ContentType.IsContainer;
            target.IsElement         = source.ContentType.IsElement;
            target.Key               = source.Key;
            target.Owner             = _commonMapper.GetOwner(source, context);
            target.ParentId          = source.ParentId;
            target.Path              = source.Path;
            target.SortOrder         = source.SortOrder;
            target.TemplateAlias     = GetDefaultTemplate(source);
            target.TemplateId        = source.TemplateId ?? default;
            target.Trashed           = source.Trashed;
            target.TreeNodeUrl       = _commonMapper.GetTreeNodeUrl <ContentTreeController>(source);
            target.Udi               = Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
            target.UpdateDate        = source.UpdateDate;
            target.Updater           = _commonMapper.GetCreator(source, context);
            target.Urls              = GetUrls(source);
            target.Variants          = _contentVariantMapper.Map(source, context);

            target.ContentDto            = new ContentPropertyCollectionDto();
            target.ContentDto.Properties = context.MapEnumerable <Property, ContentPropertyDto>(source.Properties);
        }
Example #6
0
        private IEnumerable <PropertyEditorBasic> MapAvailableEditors(IDataType source, MapperContext context)
        {
            var properties = _propertyEditors
                             .Where(x => !x.IsDeprecated || _contentSettings.ShowDeprecatedPropertyEditors || source.EditorAlias == x.Alias)
                             .OrderBy(x => x.Name);

            return(context.MapEnumerable <IDataEditor, PropertyEditorBasic>(properties));
        }
Example #7
0
        // no MapAll - relies on the non-generic method
        private void MapTypeToDisplayBase <TSource, TSourcePropertyType, TTarget, TTargetPropertyType>(TSource source, TTarget target, MapperContext context)
            where TSource : ContentTypeSave <TSourcePropertyType>
            where TSourcePropertyType : PropertyTypeBasic
            where TTarget : ContentTypeCompositionDisplay <TTargetPropertyType>
            where TTargetPropertyType : PropertyTypeDisplay
        {
            MapTypeToDisplayBase(source, target);

            target.Groups = context.MapEnumerable <PropertyGroupBasic <TSourcePropertyType>, PropertyGroupDisplay <TTargetPropertyType> >(source.Groups);
        }
    // Umbraco.Code.MapAll -AllowPreview -Errors -PersistedContent
    private void Map <TVariant>(IContent source, ContentItemDisplay <TVariant> target, MapperContext context)
        where TVariant : ContentVariantDisplay
    {
        // Both GetActions and DetermineIsChildOfListView use parent, so get it once here
        // Parent might already be in context, so check there before using content service
        IContent?parent;

        if (context.Items.TryGetValue("Parent", out var parentObj) &&
            parentObj is IContent typedParent)
        {
            parent = typedParent;
        }
        else
        {
            parent = _contentService.GetParent(source);
        }

        target.AllowedActions   = GetActions(source, parent, context);
        target.AllowedTemplates = GetAllowedTemplates(source);
        target.ContentApps      = _commonMapper.GetContentAppsForEntity(source);
        target.ContentTypeId    = source.ContentType.Id;
        target.ContentTypeKey   = source.ContentType.Key;
        target.ContentTypeAlias = source.ContentType.Alias;
        target.ContentTypeName  =
            _localizedTextService.UmbracoDictionaryTranslate(_cultureDictionary, source.ContentType.Name);
        target.DocumentType      = _commonMapper.GetContentType(source, context);
        target.Icon              = source.ContentType.Icon;
        target.Id                = source.Id;
        target.IsBlueprint       = source.Blueprint;
        target.IsChildOfListView = DetermineIsChildOfListView(source, parent, context);
        target.IsContainer       = source.ContentType.IsContainer;
        target.IsElement         = source.ContentType.IsElement;
        target.Key               = source.Key;
        target.Owner             = _commonMapper.GetOwner(source, context);
        target.ParentId          = source.ParentId;
        target.Path              = source.Path;
        target.SortOrder         = source.SortOrder;
        target.TemplateAlias     = GetDefaultTemplate(source);
        target.TemplateId        = source.TemplateId ?? default;
        target.Trashed           = source.Trashed;
        target.TreeNodeUrl       = _commonTreeNodeMapper.GetTreeNodeUrl <ContentTreeController>(source);
        target.Udi               =
            Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
        target.UpdateDate = source.UpdateDate;
        target.Updater    = _commonMapper.GetCreator(source, context);
        target.Urls       = GetUrls(source);
        target.Variants   = _contentVariantMapper.Map <TVariant>(source, context);

        target.ContentDto = new ContentPropertyCollectionDto
        {
            Properties = context.MapEnumerable <IProperty, ContentPropertyDto>(source.Properties).WhereNotNull()
        };
    }
Example #9
0
    private IEnumerable <ContentEditing.Language> GetLanguages(MapperContext context)
    {
        var allLanguages = _localizationService.GetAllLanguages().OrderBy(x => x.Id).ToList();

        if (allLanguages.Count == 0)
        {
            // This should never happen
            return(Enumerable.Empty <ContentEditing.Language>());
        }

        return(context.MapEnumerable <ILanguage, ContentEditing.Language>(allLanguages).WhereNotNull().ToList());
    }
    // no MapAll - take care
    private void Map(IContentType source, DocumentTypeDisplay target, MapperContext context)
    {
        MapTypeToDisplayBase <DocumentTypeDisplay, PropertyTypeDisplay>(source, target);

        if (source is IContentTypeWithHistoryCleanup sourceWithHistoryCleanup)
        {
            target.HistoryCleanup = new HistoryCleanupViewModel
            {
                PreventCleanup = sourceWithHistoryCleanup.HistoryCleanup?.PreventCleanup ?? false,
                KeepAllVersionsNewerThanDays =
                    sourceWithHistoryCleanup.HistoryCleanup?.KeepAllVersionsNewerThanDays,
                KeepLatestVersionPerDayForDays =
                    sourceWithHistoryCleanup.HistoryCleanup?.KeepLatestVersionPerDayForDays,
                GlobalKeepAllVersionsNewerThanDays =
                    _contentSettings.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays,
                GlobalKeepLatestVersionPerDayForDays =
                    _contentSettings.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays,
                GlobalEnableCleanup = _contentSettings.ContentVersionCleanupPolicy.EnableCleanup,
            };
        }

        target.AllowCultureVariant = source.VariesByCulture();
        target.AllowSegmentVariant = source.VariesBySegment();
        target.ContentApps         = _commonMapper.GetContentAppsForEntity(source);

        // sync templates
        if (source.AllowedTemplates is not null)
        {
            target.AllowedTemplates =
                context.MapEnumerable <ITemplate, EntityBasic>(source.AllowedTemplates).WhereNotNull();
        }

        if (source.DefaultTemplate != null)
        {
            target.DefaultTemplate = context.Map <EntityBasic>(source.DefaultTemplate);
        }

        // default listview
        target.ListViewEditorName = Constants.Conventions.DataTypes.ListViewPrefix + "Content";

        if (string.IsNullOrEmpty(source.Alias))
        {
            return;
        }

        var name = Constants.Conventions.DataTypes.ListViewPrefix + source.Alias;

        if (_dataTypeService.GetDataType(name) != null)
        {
            target.ListViewEditorName = name;
        }
    }
Example #11
0
        public IEnumerable <ContentVariantDisplay> Map(IContent source, MapperContext context)
        {
            var result = new List <ContentVariantDisplay>();

            if (!source.ContentType.VariesByCulture())
            {
                //this is invariant so just map the IContent instance to ContentVariationDisplay
                result.Add(context.Map <ContentVariantDisplay>(source));
            }
            else
            {
                var allLanguages = _localizationService.GetAllLanguages().OrderBy(x => x.Id).ToList();
                if (allLanguages.Count == 0)
                {
                    return(Enumerable.Empty <ContentVariantDisplay>());                        //this should never happen
                }
                var langs = context.MapEnumerable <ILanguage, Language>(allLanguages).ToList();

                //create a variant for each language, then we'll populate the values
                var variants = langs.Select(x =>
                {
                    //We need to set the culture in the mapping context since this is needed to ensure that the correct property values
                    //are resolved during the mapping
                    context.SetCulture(x.IsoCode);
                    return(context.Map <ContentVariantDisplay>(source));
                }).ToList();

                for (int i = 0; i < langs.Count; i++)
                {
                    var x       = langs[i];
                    var variant = variants[i];

                    variant.Language = x;
                    variant.Name     = source.GetCultureName(x.IsoCode);
                }

                //Put the default language first in the list & then sort rest by a-z
                var defaultLang = variants.SingleOrDefault(x => x.Language.IsDefault);

                //Remove the default language from the list for now
                variants.Remove(defaultLang);

                //Sort the remaining languages a-z
                variants = variants.OrderBy(x => x.Name).ToList();

                //Insert the default language as the first item
                variants.Insert(0, defaultLang);

                return(variants);
            }
            return(result);
        }
Example #12
0
        // Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames
        private static void Map(PropertyGroupBasic <MemberPropertyTypeBasic> source, PropertyGroupDisplay <MemberPropertyTypeDisplay> target, MapperContext context)
        {
            if (source.Id > 0)
            {
                target.Id = source.Id;
            }

            target.Inherited = source.Inherited;
            target.Name      = source.Name;
            target.SortOrder = source.SortOrder;

            target.Properties = context.MapEnumerable <MemberPropertyTypeBasic, MemberPropertyTypeDisplay>(source.Properties);
        }
Example #13
0
 // Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames
 private static void Map(PropertyGroupBasic <PropertyTypeBasic> source, PropertyGroupDisplay <PropertyTypeDisplay> target, MapperContext context)
 {
     target.Inherited = source.Inherited;
     if (source.Id > 0)
     {
         target.Id = source.Id;
     }
     target.Key        = source.Key;
     target.Type       = source.Type;
     target.Name       = source.Name;
     target.Alias      = source.Alias;
     target.SortOrder  = source.SortOrder;
     target.Properties = context.MapEnumerable <PropertyTypeBasic, PropertyTypeDisplay>(source.Properties);
 }
Example #14
0
 // Umbraco.Code.MapAll -Edited -Updater -Alias
 private void Map(IMedia source, ContentItemBasic <ContentPropertyBasic> target, MapperContext context)
 {
     target.ContentTypeAlias = source.ContentType.Alias;
     target.CreateDate       = source.CreateDate;
     target.Icon             = source.ContentType.Icon;
     target.Id              = source.Id;
     target.Key             = source.Key;
     target.Name            = source.Name;
     target.Owner           = _commonMapper.GetOwner(source, context);
     target.ParentId        = source.ParentId;
     target.Path            = source.Path;
     target.Properties      = context.MapEnumerable <Property, ContentPropertyBasic>(source.Properties);
     target.SortOrder       = source.SortOrder;
     target.State           = null;
     target.Trashed         = source.Trashed;
     target.Udi             = Udi.Create(Constants.UdiEntityType.Media, source.Key);
     target.UpdateDate      = source.UpdateDate;
     target.VariesByCulture = source.ContentType.VariesByCulture();
 }
Example #15
0
 // Umbraco.Code.MapAll -Trashed -Edited -Updater -Alias -VariesByCulture
 private void Map(IMember source, MemberBasic target, MapperContext context)
 {
     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      = _commonMapper.GetOwner(source, context);
     target.ParentId   = source.ParentId;
     target.Path       = source.Path;
     target.Properties = context.MapEnumerable <Property, ContentPropertyBasic>(source.Properties);
     target.SortOrder  = source.SortOrder;
     target.State      = null;
     target.Udi        = Udi.Create(Constants.UdiEntityType.Member, source.Key);
     target.UpdateDate = source.UpdateDate;
     target.Username   = source.Username;
 }
Example #16
0
 // Umbraco.Code.MapAll -Notifications -IsCurrentUser -Udi -Icon -Trashed -Alias -AdditionalData
 private void Map(IUser source, UserBasic target, MapperContext context)
 {
     //Loading in the user avatar's requires an external request if they don't have a local file avatar, this means that initial load of paging may incur a cost
     //Alternatively, if this is annoying the back office UI would need to be updated to request the avatars for the list of users separately so it doesn't look
     //like the load time is waiting.
     target.Avatars       = source.GetUserAvatarUrls(_appCaches.RuntimeCache);
     target.Culture       = source.GetUserCulture(_textService, _globalSettings).ToString();
     target.Email         = source.Email;
     target.EmailHash     = source.Email.ToLowerInvariant().Trim().ToMd5();
     target.Id            = source.Id;
     target.Key           = source.Key;
     target.LastLoginDate = source.LastLoginDate == default ? null : (DateTime?)source.LastLoginDate;
     target.Name          = source.Name;
     target.ParentId      = -1;
     target.Path          = "-1," + source.Id;
     target.UserGroups    = context.MapEnumerable <IReadOnlyUserGroup, UserGroupBasic>(source.Groups);
     target.Username      = source.Username;
     target.UserState     = source.UserState;
 }
Example #17
0
        private IEnumerable <DataTypeConfigurationFieldDisplay> MapPreValues(IDataType dataType, MapperContext context)
        {
            // in v7 it was apparently fine to have an empty .EditorAlias here, in which case we would map onto
            // an empty fields list, which made no sense since there would be nothing to map to - and besides,
            // a datatype without an editor alias is a serious issue - v8 wants an editor here

            if (string.IsNullOrWhiteSpace(dataType.EditorAlias) || !_propertyEditors.TryGet(dataType.EditorAlias, out var editor))
            {
                throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\".");
            }

            var configurationEditor = editor.GetConfigurationEditor();
            var fields = context.MapEnumerable <ConfigurationField, DataTypeConfigurationFieldDisplay>(configurationEditor.Fields);
            var configurationDictionary = configurationEditor.ToConfigurationEditor(dataType.Configuration);

            MapConfigurationFields(dataType, fields, configurationDictionary);

            return(fields);
        }
Example #18
0
        private IEnumerable <DataTypeConfigurationFieldDisplay> MapPreValues(IDataEditor source, MapperContext context)
        {
            // this is a new data type, initialize default configuration
            // get the configuration editor,
            // get the configuration fields and map to UI,
            // get the configuration default values and map to UI

            var configurationEditor = source.GetConfigurationEditor();

            var fields = context.MapEnumerable <ConfigurationField, DataTypeConfigurationFieldDisplay>(configurationEditor.Fields);

            var defaultConfiguration = configurationEditor.DefaultConfiguration;

            if (defaultConfiguration != null)
            {
                MapConfigurationFields(null, fields, defaultConfiguration);
            }

            return(fields);
        }
        private static void Map(IEnumerable <ILanguage> source, IEnumerable <ContentEditing.Language> target, MapperContext context)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (!(target is List <ContentEditing.Language> list))
            {
                throw new NotSupportedException($"{nameof(target)} must be a List<Language>.");
            }

            var temp = context.MapEnumerable <ILanguage, ContentEditing.Language>(source);

            //Put the default language first in the list & then sort rest by a-z
            var defaultLang = temp.SingleOrDefault(x => x.IsDefault);

            // insert default lang first, then remaining language a-z
            list.Add(defaultLang);
            list.AddRange(temp.Where(x => x != defaultLang).OrderBy(x => x.Name));
        }
Example #20
0
 // Umbraco.Code.MapAll -Alias
 private void Map(IContent source, ContentItemBasic <ContentPropertyBasic> target, MapperContext context)
 {
     target.ContentTypeAlias = source.ContentType.Alias;
     target.CreateDate       = source.CreateDate;
     target.Edited           = source.Edited;
     target.Icon             = source.ContentType.Icon;
     target.Id              = source.Id;
     target.Key             = source.Key;
     target.Name            = GetName(source, context);
     target.Owner           = _commonMapper.GetOwner(source, context);
     target.ParentId        = source.ParentId;
     target.Path            = source.Path;
     target.Properties      = context.MapEnumerable <Property, ContentPropertyBasic>(source.Properties);
     target.SortOrder       = source.SortOrder;
     target.State           = _basicStateMapper.Map(source, context);
     target.Trashed         = source.Trashed;
     target.Udi             = Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
     target.UpdateDate      = GetUpdateDate(source, context);
     target.Updater         = _commonMapper.GetCreator(source, context);
     target.VariesByCulture = source.ContentType.VariesByCulture();
 }
Example #21
0
 // Umbraco.Code.MapAll
 private static void Map(IContent source, ContentPropertyCollectionDto target, MapperContext context)
 {
     target.Properties = context.MapEnumerable <Property, ContentPropertyDto>(source.Properties);
 }
Example #22
0
        // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Sections -Notifications -Udi
        // Umbraco.Code.MapAll -Trashed -AdditionalData -Users -AssignedPermissions
        private void Map(IUserGroup source, UserGroupDisplay target, MapperContext context)
        {
            target.Alias = source.Alias;
            target.DefaultPermissions = MapUserGroupDefaultPermissions(source);
            target.Icon      = source.Icon;
            target.Id        = source.Id;
            target.Key       = source.Key;
            target.Name      = source.Name;
            target.ParentId  = -1;
            target.Path      = "-1," + source.Id;
            target.UserCount = source.UserCount;

            MapUserGroupBasic(target, source.AllowedSections, source.StartContentId, source.StartMediaId, context);

            //Important! Currently we are never mapping to multiple UserGroupDisplay objects but if we start doing that
            // this will cause an N+1 and we'll need to change how this works.
            var users = _userService.GetAllInGroup(source.Id);

            target.Users = context.MapEnumerable <IUser, UserBasic>(users);

            //Deal with assigned permissions:

            var allContentPermissions = _userService.GetPermissions(source, true)
                                        .ToDictionary(x => x.EntityId, x => x);

            IEntitySlim[] contentEntities;
            if (allContentPermissions.Keys.Count == 0)
            {
                contentEntities = Array.Empty <IEntitySlim>();
            }
            else
            {
                // a group can end up with way more than 2000 assigned permissions,
                // so we need to break them into groups in order to avoid breaking
                // the entity service due to too many Sql parameters.

                var list = new List <IEntitySlim>();
                foreach (var idGroup in allContentPermissions.Keys.InGroupsOf(2000))
                {
                    list.AddRange(_entityService.GetAll(UmbracoObjectTypes.Document, idGroup.ToArray()));
                }
                contentEntities = list.ToArray();
            }

            var allAssignedPermissions = new List <AssignedContentPermissions>();

            foreach (var entity in contentEntities)
            {
                var contentPermissions = allContentPermissions[entity.Id];

                var assignedContentPermissions = context.Map <AssignedContentPermissions>(entity);
                assignedContentPermissions.AssignedPermissions = AssignedUserGroupPermissions.ClonePermissions(target.DefaultPermissions);

                //since there is custom permissions assigned to this node for this group, we need to clear all of the default permissions
                //and we'll re-check it if it's one of the explicitly assigned ones
                foreach (var permission in assignedContentPermissions.AssignedPermissions.SelectMany(x => x.Value))
                {
                    permission.Checked = false;
                    permission.Checked = contentPermissions.AssignedPermissions.Contains(permission.PermissionCode, StringComparer.InvariantCulture);
                }

                allAssignedPermissions.Add(assignedContentPermissions);
            }

            target.AssignedPermissions = allAssignedPermissions;
        }
 /// <summary>
 ///     Maps a list of <see cref="Property" /> to a list of <see cref="ContentPropertyDisplay" />
 /// </summary>
 /// <param name="content"></param>
 /// <param name="properties"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 protected virtual List <ContentPropertyDisplay> MapProperties(IContentBase content, List <IProperty> properties, MapperContext context) =>
 context.MapEnumerable <IProperty, ContentPropertyDisplay>(properties.OrderBy(x => x.PropertyType?.SortOrder))
 .WhereNotNull().ToList();
 /// <summary>
 /// Maps a list of <see cref="Property"/> to a list of <see cref="ContentPropertyDisplay"/>
 /// </summary>
 /// <param name="content"></param>
 /// <param name="properties"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 protected virtual List <ContentPropertyDisplay> MapProperties(IContentBase content, List <Property> properties, MapperContext context)
 {
     return(context.MapEnumerable <Property, ContentPropertyDisplay>(properties.OrderBy(x => x.PropertyType.SortOrder)));
 }
Example #25
0
 // Umbraco.Code.MapAll
 private static void Map(IMember source, ContentPropertyCollectionDto target, MapperContext context)
 {
     target.Properties = context.MapEnumerable <IProperty, ContentPropertyDto>(source.Properties).WhereNotNull();
 }