示例#1
0
        public static GridViewModel BuildPagedGridView(int pageIndex, int pageSize, List <AuditLogEntry> entries, FolderIdentifier folderIdentifier, Func <IItemQueryResponse, object> sortSelector = null)
        {
            // first we need to convert recipeients into IItemQueryResponse objects
            var queryResponseEntries = new List <ManagerAuditLogEntryModel>();

            foreach (var entry in entries)
            {
                queryResponseEntries.Add(new ManagerAuditLogEntryModel()
                {
                    Name      = String.Format($"{entry.Message} {entry.Created}"),
                    Key       = String.Empty,
                    Message   = entry.Message,
                    UserName  = entry.UserName,
                    EntryType = AuditLogEntry.GetTitleForEntryType(entry.EntryType),
                    // Probably do some parsing for this date format
                    Created           = entry.Created,
                    AllowedOperations = GetAllowedOperationsForAuditLogEntry(entry, folderIdentifier).ToArray(),
                });
            }

            var grid = new GridViewModel
            {
                Rows        = new List <IItemQueryResponse>(),
                Title       = GridViewModel.GRID_TITLES_EDISOVERY_AUDIT_LOG,
                PageIndex   = pageIndex,
                PageSize    = pageSize,
                GridColumns = new List <GridColumnSpecification>()
                {
                    new GridColumnSpecification()
                    {
                        IsSortable = true, KeyName = "message", Label = "Entry"
                    },
                    new GridColumnSpecification()
                    {
                        IsSortable = true, KeyName = "userName", Label = "User Name"
                    },
                    new GridColumnSpecification()
                    {
                        IsSortable = true, KeyName = "entryType", Label = "Entry Type"
                    },
                    new GridColumnSpecification()
                    {
                        IsSortable = true, KeyName = "created", Label = "Created"
                    },
                },
            };

            grid.TotalRows  = entries.Count();
            grid.RowsInPage = Math.Min(grid.TotalRows, grid.PageSize);
            grid.PageCount  = (grid.TotalRows / grid.PageSize)
                              + (
                (grid.TotalRows % grid.PageSize == 0)
                        ? 0
                        : 1
                );
            grid.IsLastPage = (grid.PageIndex == grid.PageCount - 1);

            // Here we're calculating paging, and sending that back on the grid view.
            grid.Rows = queryResponseEntries
                        .OrderByDescending(f => (sortSelector == null)
                    ? f.Created
                    : sortSelector(f)
                                           )
                        .Skip(grid.PageSize * grid.PageIndex)
                        .Take(grid.PageSize);

            grid.AllowedOperations = new List <AllowedOperation>()
            {
            };

            return(grid);
        }
示例#2
0
 private static List <AllowedOperation> GetAllowedOperationsForAuditLogEntry(AuditLogEntry entry, FolderIdentifier folderIdentifier)
 {
     return(new List <AllowedOperation>()
     {
     });
 }
示例#3
0
        /// <summary>
        /// In nearly all cases except very specific ones, the connection override should remain null.
        /// </summary>
        /// <param name="auditLogEntry"></param>
        /// <param name="identifier"></param>
        /// <param name="connectionOverride"></param>
        /// <returns></returns>
        public async Task <AuditLogEntry> AddEntry(AuditLogEntry auditLogEntry, FolderIdentifier identifier, APIConnection connectionOverride = null)
        {
            // In some cases we need to be able to pass a special connection in, such is the case for
            // an eDiscovery logged in user.  This connection needs to come in, because we want to use their credentials, and piggy back off their account.
            // The connection in that case as it's passed in through DI won't have a logged in user, and calls to things like 'open folder' will fail.
            if (connectionOverride != null)
            {
                this.connection = connectionOverride;
            }

            var currentUserModel = await connection.User.GetAsync(connection.UserIdentifier);

            // This will save us having to set this everywhere it's created.
            if (!auditLogEntry.Created.HasValue)
            {
                auditLogEntry.Created = DateTime.UtcNow;
            }

            if (String.IsNullOrEmpty(auditLogEntry.UserKey))
            {
                auditLogEntry.UserKey = currentUserModel.Identifier.UserKey;
            }

            if (String.IsNullOrEmpty(auditLogEntry.UserName))
            {
                auditLogEntry.UserName = currentUserModel.EmailAddress;
            }

            // Check to see if there's already an audit log started.  This will give me an empty list, if one
            // doesn't exist, so I'm garunteed this won't result in null.
            var auditLogMetadataEntries = await this.GetAllEntries(identifier);

            var lastEntry = new AuditLogEntry();

            if (auditLogMetadataEntries.Count > 0)
            {
                lastEntry = auditLogMetadataEntries[auditLogMetadataEntries.Count - 1];
            }

            // we're only going to add an audit log entry if there's something different in this entry
            // and the last entry.  The created date will always be different, so we're checking these properties individualy.
            if (lastEntry.Message != auditLogEntry.Message ||
                lastEntry.EntryType != auditLogEntry.EntryType ||
                lastEntry.UserKey != auditLogEntry.UserKey ||
                lastEntry.UserName != auditLogEntry.UserName ||
                lastEntry.ModuleType != auditLogEntry.ModuleType
                )
            {
                auditLogMetadataEntries.Add(auditLogEntry);
                await connection.ConcurrencyRetryBlock(async() =>
                {
                    var folder = await connection.Folder.GetAsync(identifier);

                    folder.Write(AUDIT_LOG_LOCATION, auditLogMetadataEntries);
                    await connection.Folder.PutAsync(folder);
                });

                return(auditLogEntry);
            }

            return(null);
        }