Skip to content

Commit f2b1d91

Browse files
committed
Cleanup - admin controller removed
1 parent 153fb20 commit f2b1d91

File tree

6 files changed

+39
-56
lines changed

6 files changed

+39
-56
lines changed

src/App/Controllers/AdminController.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/App/Controllers/BlogController.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Core.Helpers;
33
using Core.Services;
44
using Markdig;
5+
using Microsoft.AspNetCore.Authorization;
56
using Microsoft.AspNetCore.Identity;
67
using Microsoft.AspNetCore.Mvc;
78
using Microsoft.AspNetCore.Mvc.ViewEngines;
@@ -189,7 +190,14 @@ public async Task<IActionResult> Error(int code)
189190
}
190191
}
191192

192-
[HttpPost, Route("account/logout")]
193+
[HttpGet("admin")]
194+
[Authorize]
195+
public IActionResult Admin()
196+
{
197+
return Redirect("~/admin/posts");
198+
}
199+
200+
[HttpPost("account/logout")]
193201
public async Task<IActionResult> Logout()
194202
{
195203
await _sm.SignOutAsync();

src/App/Pages/Admin/Settings/Import.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
var importSubmit = function () {
3939
$('.loading').fadeIn('fast');
4040
var data = new FormData($('#frmImport')[0]);
41-
DataService.upload('admin/importfeed', data, importCallback, fail);
41+
DataService.upload('api/settings/importfeed', data, importCallback, fail);
4242
}
4343
var importCallback = function (data) {
4444

src/App/wwwroot/admin/js/app/notificationsController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
return false;
55
}
66
function remove(id) {
7-
dataService.remove("admin/notifications/remove/" + id, removeCallback, fail);
7+
dataService.remove("api/settings/removenotification/" + id, removeCallback, fail);
88
}
99
function removeCallback() {
1010
toastr.success('Removed');

src/Core/Api/SettingsController.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ namespace Core.Api
1919
public class SettingsController : ControllerBase
2020
{
2121
IDataService _data;
22+
IImportService _feed;
2223
IOptions<RequestLocalizationOptions> _options;
2324

24-
public SettingsController(IDataService data, IOptions<RequestLocalizationOptions> options)
25+
public SettingsController(IDataService data, IImportService feed, IOptions<RequestLocalizationOptions> options)
2526
{
2627
_data = data;
28+
_feed = feed;
2729
_options = options;
2830
}
2931

@@ -97,5 +99,29 @@ public async Task<ActionResult<BlogItem>> Post(BlogItem model)
9799
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
98100
}
99101
}
102+
103+
[HttpPost("importfeed")]
104+
[Administrator]
105+
public async Task<IEnumerable<ImportMessage>> ImportFeed(IFormFile file)
106+
{
107+
var author = _data.Authors.Single(a => a.AppUserName == User.Identity.Name);
108+
109+
if (!author.IsAdmin)
110+
Redirect("~/pages/shared/_error/403");
111+
112+
var webRoot = Url.Content("~/");
113+
114+
return await _feed.Import(file, User.Identity.Name, webRoot);
115+
}
116+
117+
[HttpDelete("removenotification/{id}")]
118+
[Administrator]
119+
public async Task RemoveNotification(int id)
120+
{
121+
var note = _data.Notifications.Single(n => n.Id == id);
122+
_data.Notifications.Remove(note);
123+
_data.Complete();
124+
await Task.CompletedTask;
125+
}
100126
}
101127
}

src/Core/Extensions/StringExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ public static string SanitizeFileName(this string str)
226226
{
227227
str = str.SanitizePath();
228228

229-
if (str.Count(x => x == '.') > 1)
230-
throw new ApplicationException("Invalid file name");
229+
//TODO: add filename specific validation here
231230

232231
return str;
233232
}

0 commit comments

Comments
 (0)