Reading List Change (#972)

* Allow an admin to delete another user's reading list

* Allow an admin to delete another user's reading list
This commit is contained in:
Joseph Milazzo 2022-01-20 08:54:08 -08:00 committed by GitHub
parent 1dd6e054c6
commit 1a0fd3445d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,12 +164,15 @@ namespace API.Controllers
public async Task<ActionResult> DeleteList([FromQuery] int readingListId)
{
var user = await _unitOfWork.UserRepository.GetUserWithReadingListsByUsernameAsync(User.GetUsername());
var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);
var readingList = user.ReadingLists.SingleOrDefault(r => r.Id == readingListId);
if (readingList == null)
if (readingList == null && !isAdmin)
{
return BadRequest("User is not associated with this reading list");
}
readingList = await _unitOfWork.ReadingListRepository.GetReadingListByIdAsync(readingListId);
user.ReadingLists.Remove(readingList);
if (_unitOfWork.HasChanges() && await _unitOfWork.CommitAsync())
@ -211,7 +214,7 @@ namespace API.Controllers
}
/// <summary>
/// Update the properites (title, summary) of a reading list
/// Update the properties (title, summary) of a reading list
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>