Added a new policy to require being an admin. Implemented ability to delete a user.
This commit is contained in:
parent
bb276a5984
commit
f0919042b0
6 changed files with 44 additions and 5 deletions
|
|
@ -26,10 +26,18 @@ namespace API.Controllers
|
|||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete]
|
||||
[HttpDelete("delete-user")]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
return BadRequest("Not Implemented");
|
||||
var user = await _userRepository.GetUserByUsernameAsync(username);
|
||||
_userRepository.Delete(user);
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Could not delete the user.");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,14 +77,13 @@ namespace API.Controllers
|
|||
// return Ok(await _libraryRepository.GetLibrariesForUserAsync(user));
|
||||
// }
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPut("update-for")]
|
||||
public async Task<ActionResult<MemberDto>> UpdateLibrary(UpdateLibraryDto updateLibraryDto)
|
||||
{
|
||||
// TODO: Only admins can do this
|
||||
var user = await _userRepository.GetUserByUsernameAsync(updateLibraryDto.Username);
|
||||
|
||||
if (user == null) return BadRequest("Could not validate user");
|
||||
if (!user.IsAdmin) return Unauthorized("Only admins are permitted");
|
||||
|
||||
user.Libraries = new List<Library>();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue