Add missing attributes, fix response codes, fix route parameter casing

This commit is contained in:
crobibero
2020-06-20 18:02:07 -06:00
parent deac459b62
commit 10ddbc34ec
13 changed files with 172 additions and 163 deletions

View File

@@ -105,17 +105,17 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Gets a user by Id.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <response code="200">User returned.</response>
/// <response code="404">User not found.</response>
/// <returns>An <see cref="UserDto"/> with information about the user or a <see cref="NotFoundResult"/> if the user was not found.</returns>
[HttpGet("{id}")]
[HttpGet("{userId}")]
[Authorize(Policy = Policies.IgnoreSchedule)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<UserDto> GetUserById([FromRoute] Guid id)
public ActionResult<UserDto> GetUserById([FromRoute] Guid userId)
{
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (user == null)
{
@@ -129,17 +129,17 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Deletes a user.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <response code="200">User deleted.</response>
/// <response code="404">User not found.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="NotFoundResult"/> if the user was not found.</returns>
[HttpDelete("{id}")]
[HttpDelete("{userId}")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult DeleteUser([FromRoute] Guid id)
public ActionResult DeleteUser([FromRoute] Guid userId)
{
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (user == null)
{
@@ -154,23 +154,23 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Authenticates a user.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="pw">The password as plain text.</param>
/// <param name="password">The password sha1-hash.</param>
/// <response code="200">User authenticated.</response>
/// <response code="403">Sha1-hashed password only is not allowed.</response>
/// <response code="404">User not found.</response>
/// <returns>A <see cref="Task"/> containing an <see cref="AuthenticationResult"/>.</returns>
[HttpPost("{id}/Authenticate")]
[HttpPost("{userId}/Authenticate")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<AuthenticationResult>> AuthenticateUser(
[FromRoute, Required] Guid id,
[FromRoute, Required] Guid userId,
[FromQuery, BindRequired] string pw,
[FromQuery, BindRequired] string password)
{
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (user == null)
{
@@ -230,27 +230,27 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Updates a user's password.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="request">The <see cref="UpdateUserPassword"/> request.</param>
/// <response code="200">Password successfully reset.</response>
/// <response code="403">User is not allowed to update the password.</response>
/// <response code="404">User not found.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="ForbidResult"/> or a <see cref="NotFoundResult"/> on failure.</returns>
[HttpPost("{id}/Password")]
[HttpPost("{userId}/Password")]
[Authorize]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult> UpdateUserPassword(
[FromRoute] Guid id,
[FromRoute] Guid userId,
[FromBody] UpdateUserPassword request)
{
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, true))
{
return Forbid("User is not allowed to update the password.");
}
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (user == null)
{
@@ -288,27 +288,27 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Updates a user's easy password.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="request">The <see cref="UpdateUserEasyPassword"/> request.</param>
/// <response code="200">Password successfully reset.</response>
/// <response code="403">User is not allowed to update the password.</response>
/// <response code="404">User not found.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="ForbidResult"/> or a <see cref="NotFoundResult"/> on failure.</returns>
[HttpPost("{id}/EasyPassword")]
[HttpPost("{userId}/EasyPassword")]
[Authorize]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult UpdateUserEasyPassword(
[FromRoute] Guid id,
[FromRoute] Guid userId,
[FromBody] UpdateUserEasyPassword request)
{
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, true))
{
return Forbid("User is not allowed to update the easy password.");
}
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (user == null)
{
@@ -330,19 +330,19 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Updates a user.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="updateUser">The updated user model.</param>
/// <response code="204">User updated.</response>
/// <response code="400">User information was not supplied.</response>
/// <response code="403">User update forbidden.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="BadRequestResult"/> or a <see cref="ForbidResult"/> on failure.</returns>
[HttpPost("{id}")]
[HttpPost("{userId}")]
[Authorize]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<ActionResult> UpdateUser(
[FromRoute] Guid id,
[FromRoute] Guid userId,
[FromBody] UserDto updateUser)
{
if (updateUser == null)
@@ -350,12 +350,12 @@ namespace Jellyfin.Api.Controllers
return BadRequest();
}
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, false))
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, false))
{
return Forbid("User update not allowed.");
}
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
if (string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal))
{
@@ -374,19 +374,19 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Updates a user policy.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="newPolicy">The new user policy.</param>
/// <response code="204">User policy updated.</response>
/// <response code="400">User policy was not supplied.</response>
/// <response code="403">User policy update forbidden.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="BadRequestResult"/> or a <see cref="ForbidResult"/> on failure..</returns>
[HttpPost("{id}/Policy")]
[HttpPost("{userId}/Policy")]
[Authorize]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult UpdateUserPolicy(
[FromRoute] Guid id,
[FromRoute] Guid userId,
[FromBody] UserPolicy newPolicy)
{
if (newPolicy == null)
@@ -394,7 +394,7 @@ namespace Jellyfin.Api.Controllers
return BadRequest();
}
var user = _userManager.GetUserById(id);
var user = _userManager.GetUserById(userId);
// If removing admin access
if (!(newPolicy.IsAdministrator && user.HasPermission(PermissionKind.IsAdministrator)))
@@ -423,7 +423,7 @@ namespace Jellyfin.Api.Controllers
_sessionManager.RevokeUserTokens(user.Id, currentToken);
}
_userManager.UpdatePolicy(id, newPolicy);
_userManager.UpdatePolicy(userId, newPolicy);
return NoContent();
}
@@ -431,25 +431,25 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Updates a user configuration.
/// </summary>
/// <param name="id">The user id.</param>
/// <param name="userId">The user id.</param>
/// <param name="userConfig">The new user configuration.</param>
/// <response code="204">User configuration updated.</response>
/// <response code="403">User configuration update forbidden.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("{id}/Configuration")]
[HttpPost("{userId}/Configuration")]
[Authorize]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult UpdateUserConfiguration(
[FromRoute] Guid id,
[FromRoute] Guid userId,
[FromBody] UserConfiguration userConfig)
{
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, false))
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, false))
{
return Forbid("User configuration update not allowed");
}
_userManager.UpdateConfiguration(id, userConfig);
_userManager.UpdateConfiguration(userId, userConfig);
return NoContent();
}