mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed admin delete commands
This commit is contained in:
parent
e41fa8c199
commit
d02ed91220
@ -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,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,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">
|
||||
|
@ -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">
|
||||
|
@ -55,6 +55,9 @@
|
||||
"pageloadDoTimer": "readonly",
|
||||
"pageloadStopTimer": "readonly",
|
||||
|
||||
// AdminCommon.js Functions
|
||||
"deleteItem": "readonly",
|
||||
|
||||
// Common variables
|
||||
"oidcConfig": "readonly"
|
||||
}
|
||||
|
@ -18,4 +18,4 @@ $(function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
31
Teknik/Scripts/Admin/AdminCommon.js
Normal file
31
Teknik/Scripts/Admin/AdminCommon.js
Normal file
@ -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">×</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">×</button>' + parseErrorMessage(response.responseText) + '</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
@ -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 () {
|
||||
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">×</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">×</button>' + parseErrorMessage(response.responseText) + '</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
deleteItem('paste', id, deleteDataURL, homeUrl, "Are you sure you want to delete this paste?");
|
||||
});
|
||||
}
|
||||
|
@ -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 () {
|
||||
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">×</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">×</button>' + parseErrorMessage(response.responseText) + '</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
deleteItem('shortenedUrl', id, deleteDataURL, homeUrl, "Are you sure you want to delete this shortened url?");
|
||||
});
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
||||
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">×</button>' + parseErrorMessage(response) + '</div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
var id = $(this).data('upload-id');
|
||||
deleteItem('upload', id, deleteDataURL, homeUrl, "Are you sure you want to delete this upload?");
|
||||
});
|
||||
}
|
||||
|
@ -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
8444
Teknik/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user