Skip to content

Commit 8683a9b

Browse files
authored
Merge pull request #56 from bdach/update-username
Ensure creator username is updated on set updates
2 parents 8d38b2e + 01c2b98 commit 8683a9b

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,14 +1840,14 @@ osu file format v14
18401840
}
18411841

18421842
[Fact]
1843-
public async Task TestPatch_BeatmapWithNoChanges_BumpsLastUpdateDate()
1843+
public async Task TestPatch_BeatmapWithNoChanges_BumpsLastUpdateDateAndUpdatesCreatorUsername()
18441844
{
18451845
using var db = await DatabaseAccess.GetConnectionAsync();
18461846
await db.ExecuteAsync(
18471847
"INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
18481848

18491849
await db.ExecuteAsync(
1850-
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'test user', -1, 0, -1, CURRENT_TIMESTAMP)");
1850+
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'old username', -1, 0, -1, CURRENT_TIMESTAMP)");
18511851

18521852
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
18531853
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
@@ -1875,6 +1875,41 @@ await db.ExecuteAsync(
18751875
Assert.True(response.IsSuccessStatusCode);
18761876

18771877
WaitForDatabaseState(@"SELECT COUNT(1) FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526 AND `last_update` > '2020-01-01 00:00:00'", 1, CancellationToken);
1878+
WaitForDatabaseState(@"SELECT `creator` FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526", "test", CancellationToken);
1879+
}
1880+
1881+
[Fact]
1882+
public async Task TestPatchPackage_UpdatesCreatorUsername()
1883+
{
1884+
using var db = await DatabaseAccess.GetConnectionAsync();
1885+
await db.ExecuteAsync(
1886+
"INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
1887+
1888+
await db.ExecuteAsync(
1889+
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'old username', -1, 0, -1, CURRENT_TIMESTAMP)");
1890+
1891+
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
1892+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
1893+
1894+
using (var dstStream = File.OpenWrite(Path.Combine(beatmapStorage.BaseDirectory, "241526")))
1895+
using (var srcStream = TestResources.GetResource(osz_filename)!)
1896+
await srcStream.CopyToAsync(dstStream);
1897+
await db.ExecuteAsync(@"INSERT INTO `beatmapset_versions` (`beatmapset_id`) VALUES (241526)");
1898+
1899+
var request = new HttpRequestMessage(HttpMethod.Patch, "/beatmapsets/241526");
1900+
1901+
using var content = new MultipartFormDataContent($"{Guid.NewGuid()}----");
1902+
using var osuFileStream = TestResources.GetResource(osu_filename)!;
1903+
content.Add(new StreamContent(osuFileStream), "filesChanged", osu_filename);
1904+
content.Add(new StringContent("Soleily - Renatus (test) [Platter].osu"), "filesDeleted");
1905+
request.Content = content;
1906+
request.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1907+
1908+
var response = await Client.SendAsync(request);
1909+
Assert.True(response.IsSuccessStatusCode);
1910+
1911+
WaitForDatabaseState(@"SELECT COUNT(1) FROM `osu_beatmaps` WHERE `beatmapset_id` = 241526 AND `deleted_at` IS NULL", 12, CancellationToken);
1912+
WaitForDatabaseState(@"SELECT `creator` FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526", "test", CancellationToken);
18781913
}
18791914

18801915
[Fact]

osu.Server.BeatmapSubmission/BeatmapSubmissionController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ private static async Task reviveBeatmapSet(MySqlConnection connection, uint user
404404
private async Task<bool> updateBeatmapSetFromArchiveAsync(osu_beatmapset beatmapSet, Stream beatmapStream, MySqlConnection db)
405405
{
406406
using var archiveReader = new ZipArchiveReader(beatmapStream);
407-
var parser = new BeatmapPackageParser(await db.GetUsernameAsync(beatmapSet.user_id));
407+
string username = await db.GetUsernameAsync(beatmapSet.user_id);
408+
var parser = new BeatmapPackageParser(username);
408409
var parseResult = parser.Parse(beatmapSet.beatmapset_id, archiveReader);
409410

410411
checkPackageSize(beatmapStream.Length, parseResult);
@@ -421,6 +422,7 @@ private async Task<bool> updateBeatmapSetFromArchiveAsync(osu_beatmapset beatmap
421422

422423
if (fileSet.SetEquals(parseResult.Files))
423424
{
425+
beatmapSet.creator = username;
424426
await db.MarkBeatmapSetUpdatedAsync(beatmapSet, transaction);
425427
await transaction.CommitAsync();
426428
return false;
@@ -454,6 +456,7 @@ private async Task<bool> updateBeatmapSetFromArchiveAsync(osu_beatmapset beatmap
454456
if (beatmapIds.Count > 0)
455457
throw new InvariantException($"Beatmap package is missing .osu files for beatmaps with IDs: {string.Join(", ", beatmapIds)}", LogLevel.Warning);
456458

459+
parseResult.BeatmapSet.creator = username;
457460
await db.UpdateBeatmapSetAsync(parseResult.BeatmapSet, transaction);
458461

459462
await transaction.CommitAsync();

osu.Server.BeatmapSubmission/DatabaseOperationExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public static Task UpdateBeatmapSetAsync(this MySqlConnection db, osu_beatmapset
286286
UPDATE `osu_beatmapsets`
287287
SET
288288
`artist` = @artist, `artist_unicode` = @artist_unicode, `title` = @title, `title_unicode` = @title_unicode,
289-
`source` = @source, `tags` = @tags, `video` = @video, `storyboard` = @storyboard,
289+
`creator` = @creator, `source` = @source, `tags` = @tags, `video` = @video, `storyboard` = @storyboard,
290290
`storyboard_hash` = @storyboard_hash, `bpm` = @bpm, `filename` = @filename, `displaytitle` = @displaytitle,
291291
`body_hash` = NULL, `header_hash` = NULL, `osz2_hash` = NULL, `active` = 1, `last_update` = CURRENT_TIMESTAMP
292292
WHERE `beatmapset_id` = @beatmapset_id
@@ -296,14 +296,15 @@ public static Task UpdateBeatmapSetAsync(this MySqlConnection db, osu_beatmapset
296296
}
297297

298298
/// <summary>
299-
/// Only bumps the <paramref name="beatmapset"/>'s <c>last_update</c> date without performing any other changes.
299+
/// Only updates the <paramref name="beatmapset"/>'s <c>last_update</c> date and <c>creator</c> name without performing any other changes.
300300
/// Used in scenarios where a submission occurred for a beatmap with no changes.
301301
/// Bumping the update date is important in such cases, because if it is e.g. an update after reviving the beatmap,
302302
/// not bumping the update date will cause the beatmap to move to the graveyard again on the next day after the update.
303+
/// Updating the creator name is important in cases of name changes, especially ones with username history scrubbed.
303304
/// </summary>
304305
public static Task MarkBeatmapSetUpdatedAsync(this MySqlConnection db, osu_beatmapset beatmapset, MySqlTransaction? transaction = null)
305306
{
306-
return db.ExecuteAsync("UPDATE `osu_beatmapsets` SET `last_update` = CURRENT_TIMESTAMP WHERE `beatmapset_id` = @beatmapset_id", beatmapset, transaction);
307+
return db.ExecuteAsync("UPDATE `osu_beatmapsets` SET `last_update` = CURRENT_TIMESTAMP, `creator` = @creator WHERE `beatmapset_id` = @beatmapset_id", beatmapset, transaction);
307308
}
308309

309310
public static async Task<ulong> InsertBeatmapsetFileAsync(this MySqlConnection db, beatmapset_file file, MySqlTransaction? transaction = null)

0 commit comments

Comments
 (0)