-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce PackageRegistrationAuditRecord
- Loading branch information
Showing
8 changed files
with
105 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ public enum PackageAuditAction | |
Created, | ||
Listed, | ||
Unlisted, | ||
AddOwner, | ||
RemoveOwner, | ||
Edit, | ||
UndoEdit | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/NuGetGallery.Core/Auditing/PackageRegistrationAuditAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGetGallery.Auditing | ||
{ | ||
public enum PackageRegistrationAuditAction | ||
{ | ||
AddOwner, | ||
RemoveOwner | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/NuGetGallery.Core/Auditing/PackageRegistrationAuditRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Data; | ||
|
||
namespace NuGetGallery.Auditing | ||
{ | ||
public class PackageRegistrationAuditRecord : AuditRecord<PackageRegistrationAuditAction> | ||
{ | ||
public string Id { get; set; } | ||
public DataTable RegistrationRecord { get; set; } | ||
|
||
public string Reason { get; set; } | ||
|
||
public PackageRegistrationAuditRecord(string id, DataTable registrationRecord, PackageRegistrationAuditAction action, string reason) | ||
: base(action) | ||
{ | ||
Id = id; | ||
RegistrationRecord = registrationRecord; | ||
Reason = reason; | ||
} | ||
|
||
public PackageRegistrationAuditRecord(PackageRegistration packageRegistration, PackageRegistrationAuditAction action, string reason) | ||
: this(packageRegistration.Id, DataTableUtility.ConvertToDataTable(packageRegistration), action, reason) | ||
{ | ||
} | ||
|
||
public override string GetPath() | ||
{ | ||
return $"{Id}".ToLowerInvariant(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Globalization; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public static class DataTableUtility | ||
{ | ||
public static DataTable ConvertToDataTable<T>(T instance) | ||
{ | ||
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); | ||
DataTable table = new DataTable() { Locale = CultureInfo.CurrentCulture }; | ||
|
||
List<object> values = new List<object>(); | ||
for (int i = 0; i < properties.Count; i++) | ||
{ | ||
var propertyDescriptor = properties[i]; | ||
var propertyType = Nullable.GetUnderlyingType(propertyDescriptor.PropertyType) ?? propertyDescriptor.PropertyType; | ||
if (!IsComplexType(propertyType)) | ||
{ | ||
table.Columns.Add(propertyDescriptor.Name, propertyType); | ||
values.Add(propertyDescriptor.GetValue(instance) ?? DBNull.Value); | ||
} | ||
} | ||
|
||
table.Rows.Add(values.ToArray()); | ||
|
||
return table; | ||
} | ||
|
||
private static bool IsComplexType(Type type) | ||
{ | ||
if (type.IsSubclassOf(typeof(ValueType)) || type == typeof(string)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters