From f54a0d9d4ebe70184d395867238425b71728620e Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Mon, 20 Dec 2021 21:07:52 -0800 Subject: [PATCH] Fixed delete functions for non-user content --- Teknik/Areas/Paste/Controllers/PasteController.cs | 2 +- Teknik/Areas/Shortener/Controllers/ShortenerController.cs | 2 +- Teknik/Areas/Upload/Controllers/UploadController.cs | 4 ++-- Teknik/Areas/Vault/Controllers/VaultController.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Teknik/Areas/Paste/Controllers/PasteController.cs b/Teknik/Areas/Paste/Controllers/PasteController.cs index 47e747b..3b57b6c 100644 --- a/Teknik/Areas/Paste/Controllers/PasteController.cs +++ b/Teknik/Areas/Paste/Controllers/PasteController.cs @@ -374,7 +374,7 @@ namespace Teknik.Areas.Paste.Controllers Models.Paste foundPaste = _dbContext.Pastes.Where(p => p.Url == id).FirstOrDefault(); if (foundPaste != null) { - if (foundPaste.User.Username == User.Identity.Name || + if (foundPaste.User?.Username == User.Identity.Name || User.IsInRole("Admin")) { PasteHelper.DeleteFile(_dbContext, _config, _logger, foundPaste); diff --git a/Teknik/Areas/Shortener/Controllers/ShortenerController.cs b/Teknik/Areas/Shortener/Controllers/ShortenerController.cs index 82065c7..26c19f9 100644 --- a/Teknik/Areas/Shortener/Controllers/ShortenerController.cs +++ b/Teknik/Areas/Shortener/Controllers/ShortenerController.cs @@ -86,7 +86,7 @@ namespace Teknik.Areas.Shortener.Controllers ShortenedUrl shortenedUrl = _dbContext.ShortenedUrls.Where(s => s.ShortUrl == id).FirstOrDefault(); if (shortenedUrl != null) { - if (shortenedUrl.User.Username == User.Identity.Name || + if (shortenedUrl.User?.Username == User.Identity.Name || User.IsInRole("Admin")) { _dbContext.ShortenedUrls.Remove(shortenedUrl); diff --git a/Teknik/Areas/Upload/Controllers/UploadController.cs b/Teknik/Areas/Upload/Controllers/UploadController.cs index e2bc79e..fb42839 100644 --- a/Teknik/Areas/Upload/Controllers/UploadController.cs +++ b/Teknik/Areas/Upload/Controllers/UploadController.cs @@ -510,7 +510,7 @@ namespace Teknik.Areas.Upload.Controllers Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault(); if (upload != null) { - if (upload.User.Username == User.Identity.Name || + if (upload.User?.Username == User.Identity.Name || User.IsInRole("Admin")) { string delKey = StringHelper.RandomString(_config.UploadConfig.DeleteKeyLength); @@ -531,7 +531,7 @@ namespace Teknik.Areas.Upload.Controllers Models.Upload foundUpload = _dbContext.Uploads.Where(u => u.Url == id).FirstOrDefault(); if (foundUpload != null) { - if (foundUpload.User.Username == User.Identity.Name || + if (foundUpload.User?.Username == User.Identity.Name || User.IsInRole("Admin")) { UploadHelper.DeleteFile(_dbContext, _config, _logger, foundUpload); diff --git a/Teknik/Areas/Vault/Controllers/VaultController.cs b/Teknik/Areas/Vault/Controllers/VaultController.cs index b7c6df7..b3c8bab 100644 --- a/Teknik/Areas/Vault/Controllers/VaultController.cs +++ b/Teknik/Areas/Vault/Controllers/VaultController.cs @@ -435,7 +435,7 @@ namespace Teknik.Areas.Vault.Controllers Vault.Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == id).FirstOrDefault(); if (foundVault != null) { - if (foundVault.User.Username == User.Identity.Name || + if (foundVault.User?.Username == User.Identity.Name || User.IsInRole("Admin")) { _dbContext.Vaults.Remove(foundVault);