1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed delete functions for non-user content

This commit is contained in:
Uncled1023 2021-12-20 21:07:52 -08:00
parent ba8c0bb1b1
commit f54a0d9d4e
4 changed files with 5 additions and 5 deletions

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

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

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

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