Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI for validation tables (just orchestrator tables) #4861

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/NuGetGallery.Core/Entities/EntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NuGetGallery
{
public class EntityRepository<T>
: IEntityRepository<T>
where T : class, IEntity, new()
where T : class, new()
{
private readonly IEntitiesContext _entities;

Expand All @@ -27,21 +27,14 @@ public void DeleteOnCommit(T entity)
_entities.Set<T>().Remove(entity);
}

public T GetEntity(int key)
{
return _entities.Set<T>().Find(key);
}

public IQueryable<T> GetAll()
{
return _entities.Set<T>();
}

public int InsertOnCommit(T entity)
public void InsertOnCommit(T entity)
{
_entities.Set<T>().Add(entity);

return entity.Key;
}
}
}
5 changes: 2 additions & 3 deletions src/NuGetGallery.Core/Entities/IEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
namespace NuGetGallery
{
public interface IEntityRepository<T>
where T : class, IEntity, new()
where T : class, new()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this interface to enable use on the ValidationEntitiesContext.

{
Task CommitChangesAsync();
void DeleteOnCommit(T entity);
T GetEntity(int key);
IQueryable<T> GetAll();
int InsertOnCommit(T entity);
void InsertOnCommit(T entity);
}
}
6 changes: 3 additions & 3 deletions src/NuGetGallery/App_Start/AppActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
using System.IO;
using System.Security.Claims;
using System.Web.Helpers;
using System.Web.Http;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Http.ExceptionHandling;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
Expand All @@ -22,9 +23,8 @@
using NuGetGallery.Diagnostics;
using NuGetGallery.Infrastructure;
using NuGetGallery.Infrastructure.Jobs;
using WebBackgrounder;
using WebActivatorEx;
using System.Web.Http.ExceptionHandling;
using WebBackgrounder;

[assembly: PreApplicationStartMethod(typeof(AppActivator), "PreStart")]
[assembly: PostApplicationStartMethod(typeof(AppActivator), "PostStart")]
Expand Down
22 changes: 22 additions & 0 deletions src/NuGetGallery/App_Start/DefaultDependenciesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using NuGet.Services.Validation;
using NuGetGallery.Areas.Admin;
using NuGetGallery.Areas.Admin.Models;
using NuGetGallery.Areas.Admin.Services;
using NuGetGallery.Auditing;
using NuGetGallery.Configuration;
using NuGetGallery.Configuration.SecretReader;
Expand Down Expand Up @@ -333,8 +334,29 @@ protected override void Load(ContainerBuilder builder)
ConfigureAutocomplete(builder, configuration);
}

private static void ConfigureValidationAdmin(ContainerBuilder builder, ConfigurationService configuration)
{
builder.Register(c => new ValidationEntitiesContext(configuration.Current.SqlConnectionStringValidation))
.AsSelf()
.InstancePerLifetimeScope();

builder.RegisterType<ValidationEntityRepository<PackageValidationSet>>()
.As<IEntityRepository<PackageValidationSet>>()
.InstancePerLifetimeScope();

builder.RegisterType<ValidationEntityRepository<PackageValidation>>()
.As<IEntityRepository<PackageValidation>>()
.InstancePerLifetimeScope();

builder.RegisterType<ValidationAdminService>()
.AsSelf()
.InstancePerLifetimeScope();
}

private void RegisterAsynchronousValidation(ContainerBuilder builder, ConfigurationService configuration)
{
ConfigureValidationAdmin(builder, configuration);

builder
.RegisterType<ServiceBusMessageSerializer>()
.As<IServiceBusMessageSerializer>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Web.Mvc;

namespace NuGetGallery.Areas.Admin.Controllers
Expand Down
14 changes: 11 additions & 3 deletions src/NuGetGallery/Areas/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
// 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.Diagnostics.CodeAnalysis;
using System.Web.Mvc;
using NuGetGallery.Areas.Admin.ViewModels;
using NuGetGallery.Configuration;

namespace NuGetGallery.Areas.Admin.Controllers
{
public partial class HomeController : AdminControllerBase
{
private readonly IContentService _content;
private readonly IGalleryConfigurationService _config;

public HomeController(IContentService content)
public HomeController(IContentService content, IGalleryConfigurationService config)
{
_content = content;
_content = content ?? throw new ArgumentNullException(nameof(content));
_config = config ?? throw new ArgumentNullException(nameof(config));
}

[HttpGet]
public virtual ActionResult Index()
{
return View();
var viewModel = new HomeViewModel(
showValidation: _config.Current.AsynchronousPackageValidationEnabled);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this ever be false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default git clone case is this (and NuGet.org, today).

return View(viewModel);
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.Linq;
using System.Web.Mvc;
using NuGet.Versioning;
using NuGetGallery.Areas.Admin.Services;
using NuGetGallery.Areas.Admin.ViewModels;

namespace NuGetGallery.Areas.Admin.Controllers
{
public class ValidationController : AdminControllerBase
{
private readonly ValidationAdminService _validationAdminService;

public ValidationController(ValidationAdminService validationAdminService)
{
_validationAdminService = validationAdminService ?? throw new ArgumentNullException(nameof(validationAdminService));
}

[HttpGet]
public virtual ActionResult Index()
{
return View(nameof(Index), new ValidationPageViewModel());
}

[HttpGet]
public virtual ActionResult Search(string q)
{
var packageValidationSets = _validationAdminService.Search(q ?? string.Empty);

// Sort by lexigraphically package ID then put newer stuff on top.
var groups = packageValidationSets
.OrderBy(x => x.PackageId)
.ThenByDescending(x => NuGetVersion.Parse(x.PackageNormalizedVersion))
.ThenByDescending(x => x.PackageKey)
.ThenByDescending(x => x.Created)
.ThenByDescending(x => x.Key)
.GroupBy(x => x.PackageKey);

var validatedPackages = new List<ValidatedPackageViewModel>();
foreach (var group in groups)
{
foreach (var set in group)
{
// Put completed validations first then put new validations on top.
set.PackageValidations = set.PackageValidations
.OrderByDescending(x => x.ValidationStatus)
.ThenByDescending(x => x.ValidationStatusTimestamp)
.ToList();
}

var deletedStatus = _validationAdminService.GetPackageDeletedStatus(group.Key);
var validatedPackage = new ValidatedPackageViewModel(group.ToList(), deletedStatus);
validatedPackages.Add(validatedPackage);
}

return View(nameof(Index), new ValidationPageViewModel(q, validatedPackages));
}
}
}
12 changes: 12 additions & 0 deletions src/NuGetGallery/Areas/Admin/Models/DeletedStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.Areas.Admin.Models
{
public enum PackageDeletedStatus
{
SoftDeleted,
NotDeleted,
Unknown,
}
}
Loading