Browse Source

Fixed delete functions for non-user content

master
Teknikode 1 month ago
parent
commit
f54a0d9d4e

+ 1
- 1
Teknik/Areas/Paste/Controllers/PasteController.cs View File

@@ -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);

+ 1
- 1
Teknik/Areas/Shortener/Controllers/ShortenerController.cs View File

@@ -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);

+ 2
- 2
Teknik/Areas/Upload/Controllers/UploadController.cs View File

@@ -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);

+ 1
- 1
Teknik/Areas/Vault/Controllers/VaultController.cs View File

@@ -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);

Loading…
Cancel
Save