Skip to content

Commit

Permalink
Merge pull request #5360 from NuGet/dev
Browse files Browse the repository at this point in the history
Merge dev->master
  • Loading branch information
cristinamanum authored Jan 26, 2018
2 parents c60dcba + cb773cf commit 2cf067e
Show file tree
Hide file tree
Showing 174 changed files with 7,357 additions and 2,603 deletions.
35 changes: 34 additions & 1 deletion src/Bootstrap/dist/css/bootstrap-theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Bootstrap/dist/js/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2017 Twitter, Inc.
* Copyright 2011-2018 Twitter, Inc.
* Licensed under the MIT license
*/

Expand Down
1 change: 1 addition & 0 deletions src/Bootstrap/less/theme/all.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "page-list-packages.less";
@import "page-manage-curated-feed.less";
@import "page-manage-owners.less";
@import "page-manage-packages.less";
@import "page-delete-package.less";
@import "page-profile.less";
@import "page-report-abuse.less";
Expand Down
6 changes: 5 additions & 1 deletion src/Bootstrap/less/theme/page-api-keys.less
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

.api-key-details {
padding: @section-padding;
border-bottom: @section-border;

.ms-Icon {
position: relative;
Expand All @@ -89,4 +88,9 @@
}
}
}

.api-key-details:not(:first-child)
{
border-top: @section-border;
}
}
41 changes: 41 additions & 0 deletions src/Bootstrap/less/theme/page-manage-packages.less
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 src/NuGetGallery.Core/Auditing/AuditedDeleteAccountAction.cs
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 src/NuGetGallery.Core/Auditing/DeleteAccountAuditRecord.cs
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();
}
}
}
55 changes: 55 additions & 0 deletions src/NuGetGallery.Core/Entities/DatabaseWrapper.cs
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);
}
}
}
4 changes: 2 additions & 2 deletions src/NuGetGallery.Core/Entities/EntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void SetCommandTimeout(int? seconds)
ObjectContext.CommandTimeout = seconds;
}

public Database GetDatabase()
public IDatabase GetDatabase()
{
return Database;
return new DatabaseWrapper(Database);
}

#pragma warning disable 618 // TODO: remove Package.Authors completely once production services definitely no longer need it
Expand Down
17 changes: 17 additions & 0 deletions src/NuGetGallery.Core/Entities/IDatabase.cs
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);
}
}
2 changes: 1 addition & 1 deletion src/NuGetGallery.Core/Entities/IEntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public interface IEntitiesContext
IDbSet<T> Set<T>() where T : class;
void DeleteOnCommit<T>(T entity) where T : class;
void SetCommandTimeout(int? seconds);
Database GetDatabase();
IDatabase GetDatabase();
}
}
47 changes: 46 additions & 1 deletion src/NuGetGallery.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace NuGetGallery
/// future if we want to add constraints for user accounts or user-only settings.
/// </summary>
/// <see href="https://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt" />
public class User : IEntity
public class User : IEntity, IEquatable<User>
{
public User() : this(null)
{
Expand All @@ -27,6 +27,7 @@ public User(string username)
SecurityPolicies = new List<UserSecurityPolicy>();
ReservedNamespaces = new HashSet<ReservedNamespace>();
Organizations = new List<Membership>();
OrganizationRequests = new List<MembershipRequest>();
Roles = new List<Role>();
Username = username;
}
Expand Down Expand Up @@ -150,5 +151,49 @@ public bool IsInRole(string roleName)
{
return Roles.Any(r => String.Equals(r.Name, roleName, StringComparison.OrdinalIgnoreCase));
}

public bool Equals(User other)
{
return other.Key == Key;
}

public override bool Equals(object obj)
{
if(obj == null)
{
return false;
}
User user = obj as User;
if(user == null)
{
return false;
}
return Equals(user);
}

public override int GetHashCode()
{
return Key.GetHashCode();
}

public static bool operator ==(User user1, User user2)
{
if (((object)user1) == null || ((object)user2) == null)
{
return Equals(user1, user2);
}

return user1.Equals(user2);
}

public static bool operator !=(User user1, User user2)
{
if (((object)user1) == null || ((object)user2) == null)
{
return !Equals(user1, user2);
}

return !user1.Equals(user2);
}
}
}
40 changes: 40 additions & 0 deletions src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.cs
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";
}
}
}
Loading

0 comments on commit 2cf067e

Please sign in to comment.