-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5360 from NuGet/dev
Merge dev->master
- Loading branch information
Showing
174 changed files
with
7,357 additions
and
2,603 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,41 @@ | ||
.page-manage-packages { | ||
@section-margin-top: 40px; | ||
|
||
h1 { | ||
margin-bottom: 0; | ||
} | ||
|
||
h2 { | ||
margin-bottom: 10px; | ||
margin-top: 0; | ||
} | ||
|
||
.form-section-title { | ||
margin-top: @section-margin-top; | ||
|
||
@media (min-width: @screen-sm-min) { | ||
float: left; | ||
text-align: right; | ||
} | ||
} | ||
|
||
.form-section-data { | ||
@media (min-width: @screen-sm-min) { | ||
margin-top: @section-margin-top; | ||
line-height: 3; | ||
float: right; | ||
text-align: right; | ||
} | ||
} | ||
|
||
.panel { | ||
margin-top: 5px; | ||
} | ||
|
||
.manage-package-listing { | ||
.ms-Icon { | ||
position: relative; | ||
top: 2px; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/NuGetGallery.Core/Auditing/AuditedDeleteAccountAction.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 AuditedDeleteAccountAction | ||
{ | ||
DeleteAccount, | ||
RequestAccountDeletion | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/NuGetGallery.Core/Auditing/DeleteAccountAuditRecord.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,37 @@ | ||
// 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 class DeleteAccountAuditRecord : AuditRecord<AuditedDeleteAccountAction> | ||
{ | ||
public enum ActionStatus | ||
{ | ||
Success, | ||
Failure | ||
} | ||
|
||
public string Username; | ||
|
||
public string AdminUsername; | ||
|
||
public ActionStatus Status; | ||
|
||
public DeleteAccountAuditRecord(string username, ActionStatus status, AuditedDeleteAccountAction action) | ||
: this(username, status, action, adminUsername: string.Empty) | ||
{} | ||
|
||
public DeleteAccountAuditRecord(string username, ActionStatus status, AuditedDeleteAccountAction action, string adminUsername) | ||
: base(action) | ||
{ | ||
Username = username; | ||
AdminUsername = adminUsername; | ||
Status = status; | ||
} | ||
|
||
public override string GetPath() | ||
{ | ||
return Username.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,55 @@ | ||
// 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.Data.Entity; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class DatabaseWrapper : IDatabase | ||
{ | ||
private Database _database; | ||
|
||
public DatabaseWrapper(Database database) | ||
{ | ||
_database = database ?? throw new ArgumentNullException(nameof(database)); | ||
} | ||
|
||
public Task<int> ExecuteSqlCommandAsync(string sql, params object[] parameters) | ||
{ | ||
return _database.ExecuteSqlCommandAsync(sql, parameters); | ||
} | ||
|
||
public DbContextTransaction BeginTransaction() | ||
{ | ||
return _database.BeginTransaction(); | ||
} | ||
|
||
/// <summary> | ||
/// Execute an embedded resource SQL script. | ||
/// </summary> | ||
/// <param name="name">Resource name</param> | ||
/// <param name="parameters">SQL parameters</param> | ||
/// <returns>Resulting <see cref="System.Data.SqlClient.SqlDataReader.RecordsAffected"/></returns> | ||
public async Task<int> ExecuteSqlResourceAsync(string name, params object[] parameters) | ||
{ | ||
string sqlCommand; | ||
|
||
var assembly = Assembly.GetExecutingAssembly(); | ||
using (var reader = new StreamReader(assembly.GetManifestResourceStream(name))) | ||
{ | ||
sqlCommand = await reader.ReadToEndAsync(); | ||
} | ||
|
||
if (string.IsNullOrEmpty(sqlCommand)) | ||
{ | ||
throw new ArgumentException($"SQL resource '{name}' is empty.", "name"); | ||
} | ||
|
||
return await ExecuteSqlCommandAsync(sqlCommand, parameters); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.Entity; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public interface IDatabase | ||
{ | ||
DbContextTransaction BeginTransaction(); | ||
|
||
Task<int> ExecuteSqlCommandAsync(string sql, params object[] parameters); | ||
|
||
Task<int> ExecuteSqlResourceAsync(string name, params object[] parameters); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.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,40 @@ | ||
// 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.Data.SqlClient; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public static class EntitiesContextExtensions | ||
{ | ||
public static async Task<bool> TransformUserToOrganization(this IEntitiesContext context, User accountToTransform, User adminUser, string token) | ||
{ | ||
accountToTransform = accountToTransform ?? throw new ArgumentNullException(nameof(accountToTransform)); | ||
adminUser = adminUser ?? throw new ArgumentNullException(nameof(adminUser)); | ||
|
||
if (string.IsNullOrWhiteSpace(token)) | ||
{ | ||
throw new ArgumentException(nameof(token)); | ||
} | ||
|
||
var database = context.GetDatabase(); | ||
var recordCount = await database.ExecuteSqlResourceAsync( | ||
MigrateUserToOrganization.ResourceName, | ||
new SqlParameter(MigrateUserToOrganization.OrganizationKey, accountToTransform.Key), | ||
new SqlParameter(MigrateUserToOrganization.AdminKey, adminUser.Key), | ||
new SqlParameter(MigrateUserToOrganization.ConfirmationToken, token)); | ||
|
||
return recordCount > 0; | ||
} | ||
|
||
private static class MigrateUserToOrganization | ||
{ | ||
public const string ResourceName = "NuGetGallery.Infrastructure.MigrateUserToOrganization.sql"; | ||
public const string OrganizationKey = "organizationKey"; | ||
public const string AdminKey = "adminKey"; | ||
public const string ConfirmationToken = "token"; | ||
} | ||
} | ||
} |
Oops, something went wrong.