Skip to content

Commit 982e7cd

Browse files
committed
Deduplicate invalid username error message, document UpdateUser API endpoint more
1 parent b1a9dbc commit 982e7cd

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

Refresh.Interfaces.APIv3/Endpoints/Admin/AdminUserApiEndpoints.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ public ApiOkResponse ResetUserPlanetsByUsername(RequestContext context, GameData
164164

165165
[ApiV3Endpoint("admin/users/{idType}/{id}", HttpMethods.Patch), MinimumRole(GameUserRole.Moderator)]
166166
[DocSummary("Updates the specified user's profile with the given data")]
167+
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
168+
[DocError(typeof(ApiValidationError), ApiValidationError.MayNotOverwriteRoleErrorWhen)]
169+
[DocError(typeof(ApiValidationError), ApiValidationError.RoleMissingErrorWhen)]
170+
[DocError(typeof(ApiValidationError), ApiValidationError.WrongRoleUpdateMethodErrorWhen)]
171+
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.IconMissingErrorWhen)]
172+
[DocError(typeof(ApiValidationError), ApiValidationError.InvalidUsernameErrorWhen)]
167173
public ApiResponse<ApiExtendedGameUserResponse> UpdateUser(RequestContext context, GameDatabaseContext database,
168-
GameUser user, ApiAdminUpdateUserRequest body, DataContext dataContext, string idType, string id)
174+
GameUser user, ApiAdminUpdateUserRequest body, DataContext dataContext,
175+
[DocSummary("The type of identifier used to look up the user. Can be either 'uuid' or 'username'.")] string idType,
176+
[DocSummary("The UUID or username of the user, depending on the specified ID type.")] string id)
169177
{
170178
GameUser? targetUser = database.GetUserByIdAndType(idType, id);
171179

@@ -190,20 +198,19 @@ public ApiResponse<ApiExtendedGameUserResponse> UpdateUser(RequestContext contex
190198
}
191199

192200
if (body.IconHash != null && database.GetAssetFromHash(body.IconHash) == null)
193-
return ApiNotFoundError.Instance;
201+
return ApiNotFoundError.IconMissingError;
194202

195203
if (body.VitaIconHash != null && database.GetAssetFromHash(body.VitaIconHash) == null)
196-
return ApiNotFoundError.Instance;
204+
return ApiNotFoundError.IconMissingError;
197205

198206
if (body.BetaIconHash != null && database.GetAssetFromHash(body.BetaIconHash) == null)
199-
return ApiNotFoundError.Instance;
207+
return ApiNotFoundError.IconMissingError;
200208

201-
if (body.Username != null) {
209+
if (body.Username != null)
210+
{
202211
if (!database.IsUsernameValid(body.Username))
203-
return new ApiValidationError(
204-
"The username must be valid. " +
205-
"The requirements are 3 to 16 alphanumeric characters, plus hyphens and underscores. " +
206-
"Are you sure you used a PSN/RPCN username?");
212+
return new ApiValidationError(ApiValidationError.InvalidUsernameErrorWhen
213+
+ " Are you sure you used a PSN/RPCN username?");
207214

208215
database.RenameUser(targetUser, body.Username);
209216
}

Refresh.Interfaces.APIv3/Endpoints/ApiTypes/Errors/ApiNotFoundError.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class ApiNotFoundError : ApiError
2424

2525
public const string PhotoMissingErrorWhen = "The photo could not be found";
2626
public static readonly ApiNotFoundError PhotoMissingError = new(PhotoMissingErrorWhen);
27+
28+
public const string IconMissingErrorWhen = "The icon could not be found";
29+
public static readonly ApiNotFoundError IconMissingError = new(IconMissingErrorWhen);
2730

2831
public const string ContestMissingErrorWhen = "The contest could not be found";
2932
public static readonly ApiNotFoundError ContestMissingError = new(ContestMissingErrorWhen);

Refresh.Interfaces.APIv3/Endpoints/ApiTypes/Errors/ApiValidationError.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class ApiValidationError : ApiError
7676

7777
public const string ContestDataMissingErrorWhen = "The contest must at least have a title, aswell as a start and end date specified";
7878
public static readonly ApiValidationError ContestDataMissingError = new(ContestDataMissingErrorWhen);
79+
80+
public const string InvalidUsernameErrorWhen = "The username must be valid. The requirements are 3 to 16 alphanumeric characters, plus hyphens and underscores.";
81+
public static readonly ApiValidationError InvalidUsernameError = new(InvalidUsernameErrorWhen);
7982

8083
public ApiValidationError(string message) : base(message) {}
8184
}

Refresh.Interfaces.APIv3/Endpoints/AuthenticationApiEndpoints.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public ApiOkResponse DenyVerificationRequest(RequestContext context, GameDatabas
288288

289289
[ApiV3Endpoint("register", HttpMethods.Post), Authentication(false)]
290290
[DocSummary("Registers a new user.")]
291+
[DocError(typeof(ApiValidationError), ApiValidationError.InvalidUsernameErrorWhen)]
291292
[DocRequestBody(typeof(ApiRegisterRequest))]
292293
#if !DEBUG
293294
[RateLimitSettings(3600, 10, 3600 / 2, "register")]
@@ -315,10 +316,8 @@ public ApiResponse<IApiAuthenticationResponse> Register(RequestContext context,
315316
return new ApiAuthenticationError("You aren't allowed to play on this instance.");
316317

317318
if (!database.IsUsernameValid(body.Username))
318-
return new ApiValidationError(
319-
"The username must be valid. " +
320-
"The requirements are 3 to 16 alphanumeric characters, plus hyphens and underscores. " +
321-
"Are you sure you used your PSN/RPCN username?");
319+
return new ApiValidationError(ApiValidationError.InvalidUsernameErrorWhen
320+
+ " Are you sure you used your PSN/RPCN username?");
322321

323322
if (database.IsUsernameQueued(body.Username) || database.IsEmailQueued(body.EmailAddress))
324323
return UserInQueueError();

0 commit comments

Comments
 (0)