Ejemplo n.º 1
0
        public IActionResult ExportMemberData(Guid key)
        {
            IUser currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;

            if (currentUser.HasAccessToSensitiveData() == false)
            {
                return(Forbid());
            }

            MemberExportModel member = ((MemberService)_memberService).ExportMember(key);

            if (member is null)
            {
                throw new NullReferenceException("No member found with key " + key);
            }

            var json = _jsonSerializer.Serialize(member);

            var fileName = $"{member.Name}_{member.Email}.txt";

            // Set custom header so umbRequestHelper.downloadFile can save the correct filename
            HttpContext.Response.Headers.Add("x-filename", fileName);

            return(File(Encoding.UTF8.GetBytes(json), MediaTypeNames.Application.Octet, fileName));
        }
        private MemberExportModel MapToExportModel(IMember record, IEnumerable <string> includedColumns)
        {
#if NET5_0_OR_GREATER
            var model = ExportMember(record.Key);
#else
            // Hack: using the internal ExportMember method on the MemberService as it auto does auditing etc.
            // We don't actually use this data though.
            var exportMethod = typeof(MemberService).GetMethod("ExportMember", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            _ = exportMethod.Invoke(this, new object[] { record.Key }) as dynamic;

            var model = new MemberExportModel
            {
                Id          = record.Id,
                Key         = record.Key,
                Name        = record.Name,
                Username    = record.Username,
                Email       = record.Email,
                Groups      = GetAllRoles(record.Id).ToList(),
                MemberType  = record.ContentTypeAlias,
                CreateDate  = record.CreateDate,
                UpdateDate  = record.UpdateDate,
                IsApproved  = record.IsApproved,
                IsLockedOut = record.IsLockedOut,
            };

            foreach (var property in includedColumns)
            {
                // Try to work out the type
                object propertyValue;
                if (record.Properties.Contains(property)) //.IndexOfKey(property) > -1)
                {
                    switch (record.Properties[property].PropertyType.PropertyEditorAlias)
                    {
                    case PropertyEditors.Aliases.Boolean:
                        propertyValue = record.GetValue <bool>(property);
                        break;

                    case PropertyEditors.Legacy.Aliases.Date:
                        propertyValue = record.GetValue <DateTime?>(property)?.Date;
                        break;

                    case PropertyEditors.Aliases.DateTime:
                        propertyValue = record.GetValue <DateTime?>(property);
                        break;

                    default:
                        propertyValue = record.GetValue(property);
                        break;
                    }
                    model.Properties.Add(record.Properties[property].PropertyType.Name, propertyValue);
                }
            }
#endif

            return(model);
        }
 public ExportedMemberNotification(IMember member, MemberExportModel exported)
 {
     Member   = member;
     Exported = exported;
 }
Ejemplo n.º 4
0
 public ExportedMemberEventArgs(IMember member, MemberExportModel exported)
 {
     Member   = member;
     Exported = exported;
 }
        internal static IEnumerable <MemberExportModel> ToExportModel(this IEnumerable <SearchResult> searchResults, IEnumerable <string> includedColumns)
        {
            foreach (var result in searchResults)
            {
                Guid key = Guid.Empty;
                if (!result.Fields.ContainsKey("__key") || !Guid.TryParse(result.Fields["__key"], out key))
                {
                    if (result.Fields.ContainsKey("__Key"))
                    {
                        Guid.TryParse(result.Fields["__Key"], out key);
                    }
                }

                if (key == Guid.Empty)
                {
                    yield break;
                }

                // Hack: using the internal ExportMember method on the MemberService as it auto does auditing etc.
                var     memberService = ApplicationContext.Current.Services.MemberService;
                var     exportMethod  = memberService.GetType().GetMethod("ExportMember", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                dynamic exportedData  = exportMethod.Invoke(memberService, new object[] { key }) as dynamic;

                var record = ApplicationContext.Current.Services.MemberService.GetByKey(key);
                var member = new MemberExportModel
                {
                    Id           = record.Id,
                    Key          = key,
                    Name         = record.Name,
                    Username     = record.Username,
                    Email        = record.Email,
                    MemberGroups = result[Constants.Members.Groups],
                    MemberType   = record.ContentTypeAlias,
                    IsApproved   = record.IsApproved,
                    IsLockedOut  = record.IsLockedOut
                };

                foreach (var property in includedColumns)
                {
                    // Try to work out the type
                    object propertyValue;
                    switch (record.Properties[property].PropertyType.PropertyEditorAlias)
                    {
                    case CoreConstants.PropertyEditors.TrueFalseAlias:
                        propertyValue = record.GetValue <bool>(property);
                        break;

                    case CoreConstants.PropertyEditors.DateAlias:
                        propertyValue = record.GetValue <DateTime?>(property)?.Date;
                        break;

                    case CoreConstants.PropertyEditors.DateTimeAlias:
                        propertyValue = record.GetValue <DateTime?>(property);
                        break;

                    default:
                        propertyValue = record.GetValue(property);
                        break;
                    }
                    member.Properties.Add(record.Properties[property].PropertyType.Name, propertyValue);
                }

                yield return(member);
            }
        }