Skip to content

Commit

Permalink
fix(api/proffile): Fix bad property validation on profile update
Browse files Browse the repository at this point in the history
The code changes in this commit fix a bug related to property validation on profile updates. Specifically, the `ProfileRoles` property was not being properly validated and could result in unexpected behavior. This issue has been resolved by updating the code in the `ProfileController.cs` and `PlayerService.cs` files.

In `ProfileController.cs`, the code has been modified to correctly handle the case where the user's roles are null or empty. Previously, it would return an empty enumerable instead of an empty array.

In `PlayerService.cs`, some unnecessary using statements have been removed, which improves code cleanliness and organization.

Additionally, in the `UserProfileFlagsDTO.cs` file, the default value for the `ProfileRoles` property has been set to an empty array to ensure consistency and avoid potential issues with null values.
  • Loading branch information
SakuraIsayeki committed Jan 25, 2024
1 parent 1a05203 commit b32c393
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion WowsKarma.Api/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<IActionResult> GetProfileFlagsAsync(uint id) => await _playerS
? Ok(player.Adapt<UserProfileFlagsDTO>() with
{
PostsBanned = player.IsBanned(),
ProfileRoles = (await _userService.GetUserAsync(id))?.Roles.Select(r => r.Id) ?? Enumerable.Empty<byte>()
ProfileRoles = (await _userService.GetUserAsync(id))?.Roles.Select(r => r.Id) ?? []
})
: NotFound();

Expand Down
1 change: 0 additions & 1 deletion WowsKarma.Api/Services/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Hangfire;
using Hangfire.Tags.Attributes;
using Nodsoft.Wargaming.Api.Client.Clients.Wows;
using Nodsoft.Wargaming.Api.Common.Data.Responses.Wows.Public;
using Nodsoft.Wargaming.Api.Common.Data.Responses.Wows.Vortex;
using WowsKarma.Api.Data;
using WowsKarma.Api.Infrastructure.Exceptions;
Expand Down
4 changes: 2 additions & 2 deletions WowsKarma.Common/Models/DTOs/UserProfileFlagsDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public sealed record UserProfileFlagsDTO

public bool OptedOut { get; init; }
public DateTimeOffset OptOutChanged { get; init; }
public IEnumerable<byte> ProfileRoles { get; init; }

public IEnumerable<byte> ProfileRoles { get; init; } = [];
}

0 comments on commit b32c393

Please sign in to comment.