Skip to content

Commit

Permalink
minor formatting cleanup + ensure controllers are all partial (requir…
Browse files Browse the repository at this point in the history
…ed for T4 strong-typed routes)
  • Loading branch information
xavierdecoster committed Jun 24, 2015
1 parent 67cba29 commit 70d9a13
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 150 deletions.
1 change: 1 addition & 0 deletions NuGetGallery.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PartialTypeWithSinglePart/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">Copyright (c) .NET Foundation. All rights reserved.&#xD;
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.</s:String>
<s:String x:Key="/Default/Housekeeping/ProjectModelSynchronizer/UseMsbuildStrategy/@EntryValue">AUTO</s:String></wpf:ResourceDictionary>
20 changes: 9 additions & 11 deletions src/NuGetGallery/Authentication/AuthenticationService.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// 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.Diagnostics;
using System.Linq;
using System.Web;
using NuGetGallery.Diagnostics;
using System.Data.Entity;
using System.Globalization;
using Microsoft.Owin;
using System.Linq;
using System.Security.Claims;
using NuGetGallery.Configuration;
using Microsoft.Owin.Security;
using NuGetGallery.Authentication.Providers;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Web.Mvc;
using Microsoft.Owin;
using NuGetGallery.Auditing;
using NuGetGallery.Authentication.Providers;
using NuGetGallery.Configuration;
using NuGetGallery.Diagnostics;

namespace NuGetGallery.Authentication
{
Expand Down Expand Up @@ -367,7 +365,7 @@ public async virtual Task<AuthenticateExternalLoginResult> ReadExternalLoginCred
Trace.Error("External Authentication is missing required claim: " + ClaimTypes.NameIdentifier);
return new AuthenticateExternalLoginResult();
}

var nameClaim = result.Identity.FindFirst(ClaimTypes.Name);
if (nameClaim == null)
{
Expand Down Expand Up @@ -595,7 +593,7 @@ private async Task MigrateCredentials(User user, List<Credential> creds, string
Entities.DeleteOnCommit(cred);
}
await Auditing.SaveAuditRecord(new UserAuditRecord(user, UserAuditAction.RemovedCredential, toRemove));

// Now add one if there are no credentials left
if (creds.Count == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace NuGetGallery
{
public class ApiController
public partial class ApiController
: AppController
{
private readonly IAppConfiguration _config;
Expand Down
27 changes: 3 additions & 24 deletions src/NuGetGallery/Controllers/AppController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
// 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.Security.Claims;
using System.Security.Principal;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Owin;
using Ninject;
using NuGetGallery.Authentication;
using System.Net;
using NuGetGallery.Configuration;

namespace NuGetGallery
{
public abstract partial class AppController : Controller
public abstract partial class AppController
: Controller
{
private IOwinContext _overrideContext;

Expand Down Expand Up @@ -51,20 +46,4 @@ protected internal virtual ActionResult SafeRedirect(string returnUrl)
return new SafeRedirectResult(returnUrl, Url.Home());
}
}

public class NuGetContext
{
private Lazy<User> _currentUser;

public ConfigurationService Config { get; internal set; }
public User CurrentUser { get { return _currentUser.Value; } }

public NuGetContext(AppController ctrl)
{
Config = Container.Kernel.TryGet<ConfigurationService>();

_currentUser = new Lazy<User>(() =>
ctrl.OwinContext.GetCurrentUser());
}
}
}
23 changes: 11 additions & 12 deletions src/NuGetGallery/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
// 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.Web;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web.Mvc;
using NuGetGallery.Authentication;
using NuGetGallery.Filters;
using System.Threading.Tasks;
using System.Security.Claims;
using System.Text.RegularExpressions;
using System.Diagnostics;
using NuGetGallery.Infrastructure;
using System.Net.Mail;

namespace NuGetGallery
{
public partial class AuthenticationController : AppController
public partial class AuthenticationController
: AppController
{
public AuthenticationService AuthService { get; protected set; }
public IUserService UserService { get; protected set; }
public IMessageService MessageService { get; protected set; }

// For sub-classes to initialize services themselves
protected AuthenticationController()
{
}

public AuthenticationService AuthService { get; protected set; }
public IUserService UserService { get; protected set; }
public IMessageService MessageService { get; protected set; }


public AuthenticationController(
AuthenticationService authService,
IUserService userService,
Expand Down
7 changes: 2 additions & 5 deletions src/NuGetGallery/Controllers/CuratedFeedsController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// 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.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using NuGet;
using NuGetGallery;

namespace NuGetGallery
{
Expand Down Expand Up @@ -77,7 +74,7 @@ public virtual async Task<ActionResult> ListPackages(string curatedFeedName, str
int totalHits = results.Hits;
if (page == 1 && !results.Data.Any())
{
// In the event the index wasn't updated, we may get an incorrect count.
// In the event the index wasn't updated, we may get an incorrect count.
totalHits = 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/NuGetGallery/Controllers/CuratedPackagesController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 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.Linq;
using System.Web.Mvc;
using System.Data.Entity;

namespace NuGetGallery
{
[Authorize]
public partial class CuratedPackagesController : AppController
public partial class CuratedPackagesController
: AppController
{
internal ICuratedFeedService CuratedFeedService { get; set; }
internal IEntitiesContext EntitiesContext { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/NuGetGallery/Controllers/ErrorsController.cs
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
Expand Down
8 changes: 5 additions & 3 deletions src/NuGetGallery/Controllers/JsonApiController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 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.Globalization;
using System.Linq;
using System.Web.Mvc;
using MvcHaack.Ajax;
using System.Globalization;

namespace NuGetGallery
{
public partial class JsonApiController : JsonController
public partial class JsonApiController
: JsonController
{
private readonly IMessageService _messageService;
private readonly IEntityRepository<PackageOwnerRequest> _packageOwnerRequestRepository;
Expand Down Expand Up @@ -79,7 +81,7 @@ public object AddPackageOwner(string id, string username)
var ownerRequest = _packageService.CreatePackageOwnerRequest(package, currentUser, user);

var confirmationUrl = Url.ConfirmationUrl(
"ConfirmOwner",
"ConfirmOwner",
"Packages",
user.Username,
ownerRequest.ConfirmationCode,
Expand Down
24 changes: 24 additions & 0 deletions src/NuGetGallery/Controllers/NuGetContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 Ninject;
using NuGetGallery.Configuration;

namespace NuGetGallery
{
public class NuGetContext
{
private readonly Lazy<User> _currentUser;

public NuGetContext(AppController ctrl)
{
Config = Container.Kernel.TryGet<ConfigurationService>();

_currentUser = new Lazy<User>(() => ctrl.OwinContext.GetCurrentUser());
}

public ConfigurationService Config { get; internal set; }
public User CurrentUser { get { return _currentUser.Value; } }
}
}
11 changes: 6 additions & 5 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

namespace NuGetGallery
{
public partial class PackagesController : AppController
public partial class PackagesController
: AppController
{
// TODO: add support for URL-based package submission
// TODO: add support for uploading logos and screenshots
Expand Down Expand Up @@ -395,7 +396,7 @@ public virtual ActionResult ReportAbuse(string id, string version)
// If user logged on in as owner a different tab, then clicked the link, we can redirect them to ReportMyPackage
if (package.IsOwner(user))
{
return RedirectToAction("ReportMyPackage", new {id, version});
return RedirectToAction("ReportMyPackage", new { id, version });
}

if (user.Confirmed)
Expand All @@ -404,11 +405,11 @@ public virtual ActionResult ReportAbuse(string id, string version)
}
}

ViewData[Constants.ReturnUrlViewDataKey] = Url.Action("ReportMyPackage", new {id, version});
ViewData[Constants.ReturnUrlViewDataKey] = Url.Action("ReportMyPackage", new { id, version });
return View(model);
}

private static readonly ReportPackageReason[] ReportMyPackageReasons = new[] {
private static readonly ReportPackageReason[] ReportMyPackageReasons = {
ReportPackageReason.ContainsPrivateAndConfidentialData,
ReportPackageReason.PublishedWithWrongVersion,
ReportPackageReason.ReleasedInPublicByAccident,
Expand Down Expand Up @@ -956,7 +957,7 @@ private async Task<INupkg> SafeCreatePackage(NuGetGallery.User currentUser, Stre
{
caught = ipex.AsUserSafeException();
}
catch(InvalidDataException idex)
catch (InvalidDataException idex)
{
caught = idex.AsUserSafeException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/NuGetGallery/Controllers/PagesController.cs
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;
using System.Linq;
using System.Net;
Expand All @@ -8,7 +9,8 @@

namespace NuGetGallery
{
public partial class PagesController : AppController
public partial class PagesController
: AppController
{
public IContentService ContentService { get; protected set; }

Expand Down
9 changes: 5 additions & 4 deletions src/NuGetGallery/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Globalization;
using System.Linq;
using System.Net;
Expand All @@ -11,7 +11,8 @@

namespace NuGetGallery
{
public partial class StatisticsController : AppController
public partial class StatisticsController
: AppController
{
private readonly IStatisticsService _statisticsService = null;
private readonly IAggregateStatsService _aggregateStatsService = null;
Expand Down Expand Up @@ -108,7 +109,7 @@ public virtual async Task<ActionResult> Index()
}

var availablity = await Task.WhenAll(
_statisticsService.LoadDownloadPackages(),
_statisticsService.LoadDownloadPackages(),
_statisticsService.LoadDownloadPackageVersions(),
_statisticsService.LoadNuGetClientVersion(),
_statisticsService.LoadLast6Months());
Expand Down Expand Up @@ -269,7 +270,7 @@ private void ProcessReport(StatisticsPackagesReport report, string[] groupby, st
}
else
{
// the pivot array is used as the Columns in the report so we resize because this was the final set of columns
// the pivot array is used as the Columns in the report so we resize because this was the final set of columns

Array.Resize(ref pivot, dim);
}
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetGallery/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace NuGetGallery
{
public partial class UsersController : AppController
public partial class UsersController
: AppController
{
public ICuratedFeedService CuratedFeedService { get; protected set; }
public IUserService UserService { get; protected set; }
Expand Down
Loading

0 comments on commit 70d9a13

Please sign in to comment.