diff --git a/src/NuGetGallery/App_Data/Files/Content/ReadOnly.md b/src/NuGetGallery/App_Data/Files/Content/ReadOnly.md new file mode 100644 index 0000000000..15a14ceaa1 --- /dev/null +++ b/src/NuGetGallery/App_Data/Files/Content/ReadOnly.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/NuGetGallery/Constants.cs b/src/NuGetGallery/Constants.cs index 5d77341fb2..45cf7f90bf 100644 --- a/src/NuGetGallery/Constants.cs +++ b/src/NuGetGallery/Constants.cs @@ -44,6 +44,7 @@ public static class ContentNames { public static readonly string Home = "Home"; public static readonly string Alert = "Alert"; + public static readonly string ReadOnly = "ReadOnly"; public static readonly string TermsOfUse = "Terms-Of-Use"; public static readonly string PrivacyPolicy = "Privacy-Policy"; public static readonly string Team = "Team"; diff --git a/src/NuGetGallery/Controllers/ApiController.cs b/src/NuGetGallery/Controllers/ApiController.cs index 3fac4bca59..75c0d16fe1 100644 --- a/src/NuGetGallery/Controllers/ApiController.cs +++ b/src/NuGetGallery/Controllers/ApiController.cs @@ -15,11 +15,13 @@ using NuGetGallery.Authentication; using NuGetGallery.Filters; using NuGetGallery.Packaging; +using NuGetGallery.Configuration; namespace NuGetGallery { public partial class ApiController : AppController { + private readonly IAppConfiguration _config; public IEntitiesContext EntitiesContext { get; set; } public INuGetExeDownloaderService NugetExeDownloaderService { get; set; } public IPackageFileService PackageFileService { get; set; } @@ -44,7 +46,8 @@ public partial class ApiController : AppController IIndexingService indexingService, ISearchService searchService, IAutomaticallyCuratePackageCommand autoCuratePackage, - IStatusService statusService) + IStatusService statusService, + IAppConfiguration config) { EntitiesContext = entitiesContext; PackageService = packageService; @@ -57,6 +60,7 @@ public partial class ApiController : AppController SearchService = searchService; AutoCuratePackage = autoCuratePackage; StatusService = statusService; + _config = config; } public ApiController( @@ -70,8 +74,9 @@ public partial class ApiController : AppController ISearchService searchService, IAutomaticallyCuratePackageCommand autoCuratePackage, IStatusService statusService, - IStatisticsService statisticsService) - : this(entitiesContext, packageService, packageFileService, userService, nugetExeDownloaderService, contentService, indexingService, searchService, autoCuratePackage, statusService) + IStatisticsService statisticsService, + IAppConfiguration config) + : this(entitiesContext, packageService, packageFileService, userService, nugetExeDownloaderService, contentService, indexingService, searchService, autoCuratePackage, statusService, config) { StatisticsService = statisticsService; } @@ -336,8 +341,19 @@ public virtual ActionResult PublishPackage(string id, string version) public virtual async Task ServiceAlert() { + string alertString = null; var alert = await ContentService.GetContentItemAsync(Constants.ContentNames.Alert, TimeSpan.Zero); - return Content(alert == null ? (string)null : alert.ToString(), "text/html"); + if (alert != null) + { + alertString = alert.ToString(); + } + + if (String.IsNullOrEmpty(alertString) && _config.ReadOnlyMode) + { + var readOnly = await ContentService.GetContentItemAsync(Constants.ContentNames.ReadOnly, TimeSpan.Zero); + alertString = (readOnly == null) ? (string)null : readOnly.ToString(); + } + return Content(alertString, "text/html"); } public virtual async Task Team() diff --git a/src/NuGetGallery/NuGetGallery.csproj b/src/NuGetGallery/NuGetGallery.csproj index 573277f206..671148e677 100644 --- a/src/NuGetGallery/NuGetGallery.csproj +++ b/src/NuGetGallery/NuGetGallery.csproj @@ -963,6 +963,7 @@ +