Browse Source

Fixed admin delete commands

pull/111/head
Teknikode 12 months ago
parent
commit
d02ed91220
  1. 31
      Teknik/Areas/Admin/Controllers/AdminController.cs
  2. 2
      Teknik/Areas/Admin/Views/Admin/PasteSearch.cshtml
  3. 2
      Teknik/Areas/Admin/Views/Admin/ShortenedUrlSearch.cshtml
  4. 3
      Teknik/Areas/Admin/Views/Admin/UploadSearch.cshtml
  5. 3
      Teknik/Scripts/.eslintrc
  6. 2
      Teknik/Scripts/Admin/Admin.js
  7. 31
      Teknik/Scripts/Admin/AdminCommon.js
  8. 30
      Teknik/Scripts/Admin/PasteSearch.js
  9. 30
      Teknik/Scripts/Admin/ShortenedUrlSearch.js
  10. 35
      Teknik/Scripts/Admin/UploadSearch.js
  11. 3
      Teknik/bundleconfig.json
  12. 8444
      Teknik/package-lock.json

31
Teknik/Areas/Admin/Controllers/AdminController.cs

@ -259,5 +259,36 @@ namespace Teknik.Areas.Admin.Controllers @@ -259,5 +259,36 @@ namespace Teknik.Areas.Admin.Controllers
}
return Json(new { error = "Unable to delete user" });
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult DeleteData(string type, string id)
{
var context = new ControllerContext();
context.HttpContext = Request.HttpContext;
context.RouteData = RouteData;
context.ActionDescriptor = new Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor();
switch (type)
{
case "upload":
var uploadController = new Upload.Controllers.UploadController(_logger, _config, _dbContext);
uploadController.ControllerContext = context;
return uploadController.Delete(id);
case "paste":
var pasteController = new Paste.Controllers.PasteController(_logger, _config, _dbContext);
pasteController.ControllerContext = context;
return pasteController.Delete(id);
case "shortenedUrl":
var shortenController = new Shortener.Controllers.ShortenerController(_logger, _config, _dbContext);
shortenController.ControllerContext = context;
return shortenController.Delete(id);
case "vault":
var vaultController = new Vault.Controllers.VaultController(_logger, _config, _dbContext);
vaultController.ControllerContext = context;
return vaultController.Delete(id);
}
return Json(new { error = "Invalid Type" });
}
}
}

2
Teknik/Areas/Admin/Views/Admin/PasteSearch.cshtml

@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
<script>
// We need to define the action URLs for the script
var deleteDataURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "DeleteData" })';
var homeUrl = '@Url.SubRouteUrl("admin", "Admin.PasteSearch")';
var searchResultsURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "GetPasteSearchResults" })';
var deletePasteURL = '@Url.SubRouteUrl("p", "Paste.Delete")';
</script>
<div class="container">

2
Teknik/Areas/Admin/Views/Admin/ShortenedUrlSearch.cshtml

@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
<script>
// We need to define the action URLs for the script
var deleteDataURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "DeleteData" })';
var homeUrl = '@Url.SubRouteUrl("admin", "Admin.ShortenedUrlSearch")';
var searchResultsURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "GetShortenedUrlSearchResults" })';
var deleteShortenedURL = '@Url.SubRouteUrl("s", "Shortener.Delete")';
</script>
<div class="container">

3
Teknik/Areas/Admin/Views/Admin/UploadSearch.cshtml

@ -2,8 +2,9 @@ @@ -2,8 +2,9 @@
<script>
// We need to define the action URLs for the script
var deleteDataURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "DeleteData" })';
var homeUrl = '@Url.SubRouteUrl("admin", "Admin.UploadSearch")';
var searchResultsURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "GetUploadSearchResults" })';
var generateDeleteKeyURL = '@Url.SubRouteUrl("u", "Upload.GenerateDeleteKey")';
</script>
<div class="container">

3
Teknik/Scripts/.eslintrc

@ -55,6 +55,9 @@ @@ -55,6 +55,9 @@
"pageloadDoTimer": "readonly",
"pageloadStopTimer": "readonly",
// AdminCommon.js Functions
"deleteItem": "readonly",
// Common variables
"oidcConfig": "readonly"
}

2
Teknik/Scripts/Admin/Admin.js

@ -18,4 +18,4 @@ $(function () { @@ -18,4 +18,4 @@ $(function () {
}
});
});
});
});

31
Teknik/Scripts/Admin/AdminCommon.js

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
/* exported deleteItem */
function deleteItem(type, id, deleteUrl, redirectUrl, confirmationMsg) {
deleteConfirm(confirmationMsg, function (result) {
if (result) {
$.ajax({
type: "POST",
url: deleteUrl,
data: AddAntiForgeryToken({ type: type, id: id }),
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.location.replace(redirectUrl);
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
});
}

30
Teknik/Scripts/Admin/PasteSearch.js

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
/* globals searchResultsURL, deletePasteURL, homeUrl */
/* globals searchResultsURL, deleteDataURL, homeUrl */
$(document).ready(function () {
$('#Query').on('input', function () {
var query = $(this).val();
@ -32,32 +32,6 @@ $(document).ready(function () { @@ -32,32 +32,6 @@ $(document).ready(function () {
function LinkPasteDelete(selector) {
$(selector).click(function () {
var id = $(this).data('paste-id');
deleteConfirm("Are you sure you want to delete this paste?", function (result) {
if (result) {
$.ajax({
type: "POST",
url: deletePasteURL,
data: { id: id },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.location.replace(homeUrl);
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
});
deleteItem('paste', id, deleteDataURL, homeUrl, "Are you sure you want to delete this paste?");
});
}

30
Teknik/Scripts/Admin/ShortenedUrlSearch.js

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
/* globals searchResultsURL, deleteShortenedURL, homeUrl */
/* globals searchResultsURL, deleteDataURL, homeUrl */
$(document).ready(function () {
$('#Query').on('input', function () {
var query = $(this).val();
@ -32,32 +32,6 @@ $(document).ready(function () { @@ -32,32 +32,6 @@ $(document).ready(function () {
function LinkShortUrlDelete(selector) {
$(selector).click(function () {
var id = $(this).data('short-id');
deleteConfirm("Are you sure you want to delete this shortened url?", function (result) {
if (result) {
$.ajax({
type: "POST",
url: deleteShortenedURL,
data: { id: id },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.location.replace(homeUrl);
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
});
deleteItem('shortenedUrl', id, deleteDataURL, homeUrl, "Are you sure you want to delete this shortened url?");
});
}

35
Teknik/Scripts/Admin/UploadSearch.js

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
/* globals searchResultsURL, generateDeleteKeyURL */
/* globals searchResultsURL, deleteDataURL, homeUrl */
$(document).ready(function () {
$('#Query').on('input', function () {
var query = $(this).val();
@ -31,36 +31,7 @@ $(document).ready(function () { @@ -31,36 +31,7 @@ $(document).ready(function () {
function LinkUploadDelete(selector) {
$(selector).click(function () {
var deleteUrl = $(this).attr('id');
var uploadID = $(this).data('upload-id');
deleteConfirm("Are you sure you want to delete this upload?", function (result) {
if (result) {
if (deleteUrl !== '') {
window.open(deleteUrl, '_blank');
window.location.reload();
}
else {
$.ajax({
type: "POST",
url: generateDeleteKeyURL,
data: { file: uploadID },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.open(response.result.url, '_blank');
window.location.reload();
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
}
});
}
}
});
var id = $(this).data('upload-id');
deleteItem('upload', id, deleteDataURL, homeUrl, "Are you sure you want to delete this upload?");
});
}

3
Teknik/bundleconfig.json

@ -8,18 +8,21 @@ @@ -8,18 +8,21 @@
{
"outputFileName": "./wwwroot/js/uploadSearch.min.js",
"inputFiles": [
"./wwwroot/js/App/Admin/AdminCommon.js",
"./wwwroot/js/App/Admin/UploadSearch.js"
]
},
{
"outputFileName": "./wwwroot/js/pasteSearch.min.js",
"inputFiles": [
"./wwwroot/js/App/Admin/AdminCommon.js",
"./wwwroot/js/App/Admin/PasteSearch.js"
]
},
{
"outputFileName": "./wwwroot/js/shortenedUrlSearch.min.js",
"inputFiles": [
"./wwwroot/js/App/Admin/AdminCommon.js",
"./wwwroot/js/App/Admin/ShortenedUrlSearch.js"
]
},

8444
Teknik/package-lock.json generated

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save