Browse Source

Fixed delete functions for non-user content

master
Teknikode 6 months ago
parent
commit
f54a0d9d4e
  1. 2
      Teknik/Areas/Paste/Controllers/PasteController.cs
  2. 2
      Teknik/Areas/Shortener/Controllers/ShortenerController.cs
  3. 4
      Teknik/Areas/Upload/Controllers/UploadController.cs
  4. 2
      Teknik/Areas/Vault/Controllers/VaultController.cs

2
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -374,7 +374,7 @@ namespace Teknik.Areas.Paste.Controllers @@ -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);

2
Teknik/Areas/Shortener/Controllers/ShortenerController.cs

@ -86,7 +86,7 @@ namespace Teknik.Areas.Shortener.Controllers @@ -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);

4
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -510,7 +510,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -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 @@ -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);

2
Teknik/Areas/Vault/Controllers/VaultController.cs

@ -435,7 +435,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -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