Skip to content

Commit 7c1f349

Browse files
authored
Add flag to enable/disable UI DB access (#7144)
* Add new config for showing DB access in admin panel. * Update route registrationt to respect new flag. * Update web.config with new flag.
1 parent 7844e95 commit 7c1f349

7 files changed

Lines changed: 35 additions & 14 deletions

File tree

src/NuGetGallery/Areas/Admin/AdminAreaRegistration.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Autofac.Features.Indexed;
66
using NuGet.Services.Sql;
77
using NuGetGallery.Areas.Admin.DynamicData;
8+
using NuGetGallery.Configuration;
89

910
namespace NuGetGallery.Areas.Admin
1011
{
@@ -16,10 +17,15 @@ public class AdminAreaRegistration : AreaRegistration
1617

1718
public override void RegisterArea(AreaRegistrationContext context)
1819
{
19-
var galleryDbConnectionFactory = DependencyResolver.Current.GetService<ISqlConnectionFactory>();
20+
var galleryConfigurationService = DependencyResolver.Current.GetService<IGalleryConfigurationService>();
21+
22+
if (galleryConfigurationService.Current.AdminPanelDatabaseAccessEnabled)
23+
{
24+
var galleryDbConnectionFactory = DependencyResolver.Current.GetService<ISqlConnectionFactory>();
25+
DynamicDataManager.Register(context.Routes, "Admin/Database", galleryDbConnectionFactory);
26+
}
2027

2128
context.Routes.Ignore("Admin/Errors.axd/{*pathInfo}"); // ELMAH owns this root
22-
DynamicDataManager.Register(context.Routes, "Admin/Database", galleryDbConnectionFactory);
2329

2430
context.MapRoute(
2531
"Admin_default",

src/NuGetGallery/Areas/Admin/Controllers/HomeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public HomeController(IContentService content, IGalleryConfigurationService conf
2323
public virtual ActionResult Index()
2424
{
2525
var viewModel = new HomeViewModel(
26+
showDatabaseAdmin: _config.Current.AdminPanelDatabaseAccessEnabled,
2627
showValidation: _config.Current.AsynchronousPackageValidationEnabled);
2728

2829
return View(viewModel);

src/NuGetGallery/Areas/Admin/ViewModels/HomeViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ namespace NuGetGallery.Areas.Admin.ViewModels
55
{
66
public class HomeViewModel
77
{
8-
public HomeViewModel(bool showValidation)
8+
public HomeViewModel(bool showDatabaseAdmin, bool showValidation)
99
{
10+
ShowDatabaseAdmin = showDatabaseAdmin;
1011
ShowValidation = showValidation;
1112
}
1213

14+
public bool ShowDatabaseAdmin { get; }
15+
1316
public bool ShowValidation { get; }
1417
}
1518
}

src/NuGetGallery/Areas/Admin/Views/Home/Index.cshtml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
<section role="main" class="container main-container">
88
<h1>Site Administration</h1>
99
<ul>
10-
<li>
11-
<h2>
12-
<a href="~/Admin/Database">
13-
<i class="ms-Icon ms-Icon--Database"></i>
14-
<span>Database Administration</span>
15-
</a>
16-
</h2>
17-
<p>
18-
Get direct access to the database to manipulate Users, Packages, etc. USE WITH CAUTION.
19-
</p>
20-
</li>
10+
@if (Model.ShowDatabaseAdmin)
11+
{
12+
<li>
13+
<h2>
14+
<a href="~/Admin/Database">
15+
<i class="ms-Icon ms-Icon--Database"></i>
16+
<span>Database Administration</span>
17+
</a>
18+
</h2>
19+
<p>
20+
Get direct access to the database to manipulate Users, Packages, etc. USE WITH CAUTION.
21+
</p>
22+
</li>
23+
}
2124
<li>
2225
<h2>
2326
<a href="~/Admin/Errors.axd">

src/NuGetGallery/Configuration/AppConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class AppConfiguration : IAppConfiguration
7272

7373
public TimeSpan FeatureFlagsRefreshInterval { get; set; }
7474

75+
public bool AdminPanelDatabaseAccessEnabled { get; set; }
76+
7577
public bool AsynchronousPackageValidationEnabled { get; set; }
7678

7779
public bool BlockingAsynchronousPackageValidationEnabled { get; set; }

src/NuGetGallery/Configuration/IAppConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public interface IAppConfiguration : IMessageServiceConfiguration
9595
/// </summary>
9696
TimeSpan FeatureFlagsRefreshInterval { get; set; }
9797

98+
/// <summary>
99+
/// Gets a boolean indicating whether DB admin through web UI should be accesible.
100+
/// </summary>
101+
bool AdminPanelDatabaseAccessEnabled { get; set; }
102+
98103
/// <summary>
99104
/// Gets a boolean indicating whether asynchronous package validation is enabled.
100105
/// </summary>

src/NuGetGallery/Web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<add key="Gallery.AzureStorageReadAccessGeoRedundant" value="false"/>
3939
<!-- If the storage account has to fall-back to a secondary (when Read Access Geo Redundant is enabled in Azure storage), change Gallery.AzureStorageReadAccessGeoRedundant to true -->
4040
<add key="Gallery.FeatureFlagsRefreshInterval" value="00:01:00" />
41+
<add key="Gallery.AdminPanelDatabaseAccessEnabled" value="false"/>
4142
<add key="Gallery.AsynchronousPackageValidationEnabled" value="false"/>
4243
<add key="Gallery.BlockingAsynchronousPackageValidationEnabled" value="false"/>
4344
<add key="Gallery.AsynchronousPackageValidationDelay" value="00:00:05"/>

0 commit comments

Comments
 (0)