From 6ae85cc4d664b13e5ee3a0781de12ab3df12886f Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Fri, 12 Apr 2024 21:51:46 -0400 Subject: [PATCH 01/11] fix(game): remediate missing 'Create Forum Topic' button (#2350) --- resources/views/components/game/link-buttons/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/game/link-buttons/index.blade.php b/resources/views/components/game/link-buttons/index.blade.php index 6b7bb92297..cb663c4821 100644 --- a/resources/views/components/game/link-buttons/index.blade.php +++ b/resources/views/components/game/link-buttons/index.blade.php @@ -55,7 +55,7 @@ Official Forum Topic @else - @can('createForumTopic', App\Models\User::class, App\Models\Game::class) + @can('createForumTopic', $game) @endcan @endif From b5d780f108d60d4574b921ceccd2a2278f6a0f9b Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Fri, 12 Apr 2024 21:55:01 -0400 Subject: [PATCH 02/11] fix(forum): remediate error when editing posts of deleted users (#2347) --- app/Models/ForumTopic.php | 2 +- app/Models/ForumTopicComment.php | 2 +- resources/views/pages-legacy/editpost.blade.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Models/ForumTopic.php b/app/Models/ForumTopic.php index f06e724b9d..afa62e696a 100644 --- a/app/Models/ForumTopic.php +++ b/app/Models/ForumTopic.php @@ -95,7 +95,7 @@ public function getSlugAttribute(): string */ public function user(): BelongsTo { - return $this->belongsTo(User::class, 'author_id', 'ID'); + return $this->belongsTo(User::class, 'author_id', 'ID')->withTrashed(); } /** diff --git a/app/Models/ForumTopicComment.php b/app/Models/ForumTopicComment.php index 536683f357..3836af775a 100644 --- a/app/Models/ForumTopicComment.php +++ b/app/Models/ForumTopicComment.php @@ -62,6 +62,6 @@ public function getPermalinkAttribute(): string */ public function user(): BelongsTo { - return $this->belongsTo(User::class, 'author_id'); + return $this->belongsTo(User::class, 'author_id')->withTrashed(); } } diff --git a/resources/views/pages-legacy/editpost.blade.php b/resources/views/pages-legacy/editpost.blade.php index cb282bd221..6fe70ac0c7 100644 --- a/resources/views/pages-legacy/editpost.blade.php +++ b/resources/views/pages-legacy/editpost.blade.php @@ -18,7 +18,7 @@ abort(404); } -if ($user !== $foundPost->user->User && $permissions < Permissions::Moderator) { +if ($user !== $foundPost->user?->User && $permissions < Permissions::Moderator) { abort_with(back()->withErrors(__('legacy.error.permissions'))); } @@ -46,7 +46,7 @@ - + Date: Fri, 12 Apr 2024 19:58:16 -0600 Subject: [PATCH 03/11] fix error logging dropped claim due to demoting using (#2352) --- app/Helpers/database/user-permission.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/database/user-permission.php b/app/Helpers/database/user-permission.php index fa00eb6654..207c33be12 100644 --- a/app/Helpers/database/user-permission.php +++ b/app/Helpers/database/user-permission.php @@ -121,7 +121,7 @@ function SetAccountPermissionsJSON( $claim->save(); $comment = "$actingUsername dropped $targetUsername's " . ClaimType::toString($claim->ClaimType) . " claim via demotion to $targetUserNewPermissionsString."; - addArticleComment('Server', ArticleType::SetClaim, $claim->GameID, $comment); + addArticleComment('Server', ArticleType::SetClaim, $claim->game_id, $comment); } } From 7fc3c93d31fa386e005bee57808d3471d3ec9d1c Mon Sep 17 00:00:00 2001 From: Jamiras Date: Fri, 12 Apr 2024 21:59:44 -0600 Subject: [PATCH 04/11] fix exception if user agent doesn't contain os information --- .../views/pages/user/[user]/game/[game]/activity.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/user/[user]/game/[game]/activity.blade.php b/resources/views/pages/user/[user]/game/[game]/activity.blade.php index 564aabba97..fd94bf6bba 100644 --- a/resources/views/pages/user/[user]/game/[game]/activity.blade.php +++ b/resources/views/pages/user/[user]/game/[game]/activity.blade.php @@ -112,7 +112,7 @@ @if ($userAgent['clientVersion'] !== 'Unknown') {{ $userAgent['clientVersion'] }} @endif - @if ($userAgent['os']) + @if (!empty($userAgent['os'])) ({{ $userAgent['os'] }}) @endif From db5d6dee8e2b21aec49112e9c45e66235f7fbdd8 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Sat, 13 Apr 2024 09:50:27 -0400 Subject: [PATCH 05/11] fix: remediate user relationship detachment issue (#2353) --- app/Actions/ClearAccountDataAction.php | 4 +- .../Platform/Action/ClearAccountDataTest.php | 97 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Platform/Action/ClearAccountDataTest.php diff --git a/app/Actions/ClearAccountDataAction.php b/app/Actions/ClearAccountDataAction.php index 91223c95ff..e3fea4e8de 100644 --- a/app/Actions/ClearAccountDataAction.php +++ b/app/Actions/ClearAccountDataAction.php @@ -29,8 +29,8 @@ public function execute(User $user): void // TODO $user->activities()->delete(); // TODO $user->emailConfirmations()->delete(); DB::statement('DELETE FROM EmailConfirmations WHERE User = :username', ['username' => $user->User]); - $user->relationships()->delete(); - $user->inverseRelationships()->delete(); + $user->relationships()->detach(); + $user->inverseRelationships()->detach(); // TODO $user->ratings()->delete(); DB::statement('DELETE FROM Rating WHERE User = :username', ['username' => $user->User]); $user->gameListEntries()->delete(); diff --git a/tests/Feature/Platform/Action/ClearAccountDataTest.php b/tests/Feature/Platform/Action/ClearAccountDataTest.php new file mode 100644 index 0000000000..13384e6798 --- /dev/null +++ b/tests/Feature/Platform/Action/ClearAccountDataTest.php @@ -0,0 +1,97 @@ +create(); + /** @var User $user2 */ + $user2 = User::factory()->create(); + + $this->assertNotEquals('', $user2->EmailAddress); + + UserRelation::create([ + 'User' => $user1->User, + 'user_id' => $user1->id, + 'Friend' => $user2->User, + 'related_user_id' => $user2->id, + 'Friendship' => UserRelationship::Following, + ]); + + UserRelation::create([ + 'User' => $user2->User, + 'user_id' => $user2->id, + 'Friend' => $user1->User, + 'related_user_id' => $user1->id, + 'Friendship' => UserRelationship::Following, + ]); + + UserGameListEntry::create([ + 'user_id' => $user2->ID, + 'type' => UserGameListType::AchievementSetRequest, + 'GameID' => 1234, + ]); + + Subscription::create([ + 'user_id' => $user2->ID, + 'subject_type' => SubscriptionSubjectType::GameWall, + 'subject_id' => 5, + 'state' => true, + ]); + + $thread = MessageThread::create([ + 'title' => 'Message', + ]); + MessageThreadParticipant::create([ + 'user_id' => $user1->ID, + 'thread_id' => $thread->id, + ]); + MessageThreadParticipant::create([ + 'user_id' => $user2->ID, + 'thread_id' => $thread->id, + ]); + + $this->assertEquals(1, UserRelation::where('user_id', $user2->id)->count()); + $this->assertEquals(1, UserRelation::where('related_user_id', $user2->id)->count()); + $this->assertEquals(1, UserGameListEntry::where('user_id', $user2->id)->count()); + $this->assertEquals(1, Subscription::where('user_id', $user2->id)->count()); + $this->assertEquals(1, MessageThreadParticipant::where('user_id', $user2->id)->count()); + + $action = new ClearAccountDataAction(); + $action->execute($user2); + + $this->assertEquals(0, UserRelation::where('user_id', $user2->id)->count()); + $this->assertEquals(0, UserRelation::where('related_user_id', $user2->id)->count()); + $this->assertEquals(0, UserGameListEntry::where('user_id', $user2->id)->count()); + $this->assertEquals(0, Subscription::where('user_id', $user2->id)->count()); + $this->assertEquals(0, MessageThreadParticipant::where('user_id', $user2->id)->count()); + + $user2->refresh(); + $this->assertEquals('', $user2->EmailAddress); + } +} From 6c9878b8c748dc94fc5b1f5dfee24ac47a518b91 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Tue, 16 Apr 2024 17:30:11 -0400 Subject: [PATCH 06/11] refactor: rename BelongsToMany model relations (#2355) --- app/Actions/ClearAccountDataAction.php | 4 ++-- app/Community/Components/UserActivityFeed.php | 2 +- app/Community/Concerns/ActsAsCommunityMember.php | 12 ++++++------ app/Models/Achievement.php | 2 +- app/Models/Game.php | 2 +- .../views/components/game/compare-progress.blade.php | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Actions/ClearAccountDataAction.php b/app/Actions/ClearAccountDataAction.php index e3fea4e8de..9735ed3580 100644 --- a/app/Actions/ClearAccountDataAction.php +++ b/app/Actions/ClearAccountDataAction.php @@ -29,8 +29,8 @@ public function execute(User $user): void // TODO $user->activities()->delete(); // TODO $user->emailConfirmations()->delete(); DB::statement('DELETE FROM EmailConfirmations WHERE User = :username', ['username' => $user->User]); - $user->relationships()->detach(); - $user->inverseRelationships()->detach(); + $user->relatedUsers()->detach(); + $user->inverseRelatedUsers()->detach(); // TODO $user->ratings()->delete(); DB::statement('DELETE FROM Rating WHERE User = :username', ['username' => $user->User]); $user->gameListEntries()->delete(); diff --git a/app/Community/Components/UserActivityFeed.php b/app/Community/Components/UserActivityFeed.php index 766346ad48..cf9b055649 100644 --- a/app/Community/Components/UserActivityFeed.php +++ b/app/Community/Components/UserActivityFeed.php @@ -46,7 +46,7 @@ public function allowedFilters(): iterable return [ AllowedFilter::callback('users', function (Builder $query, $value) { if (request()->user() && $value === 'following') { - $followingIds = request()->user()->following()->get(['id'])->pluck('id'); + $followingIds = request()->user()->followedUsers()->get(['id'])->pluck('id'); $followingIds[] = request()->user()->ID; $query->whereIn('user_id', $followingIds); } diff --git a/app/Community/Concerns/ActsAsCommunityMember.php b/app/Community/Concerns/ActsAsCommunityMember.php index a21722a698..938cddabcb 100644 --- a/app/Community/Concerns/ActsAsCommunityMember.php +++ b/app/Community/Concerns/ActsAsCommunityMember.php @@ -50,7 +50,7 @@ public function gameListEntries(?string $type = null): HasMany /** * @return BelongsToMany */ - public function relationships(): BelongsToMany + public function relatedUsers(): BelongsToMany { return $this->belongsToMany(User::class, (new UserRelation())->getTable(), 'user_id', 'related_user_id'); } @@ -58,7 +58,7 @@ public function relationships(): BelongsToMany /** * @return BelongsToMany */ - public function inverseRelationships(): BelongsToMany + public function inverseRelatedUsers(): BelongsToMany { return $this->belongsToMany(User::class, (new UserRelation())->getTable(), 'related_user_id', 'user_id'); } @@ -66,17 +66,17 @@ public function inverseRelationships(): BelongsToMany /** * @return BelongsToMany */ - public function following(): BelongsToMany + public function followedUsers(): BelongsToMany { - return $this->relationships()->where('Friendship', '=', UserRelationship::Following); + return $this->relatedUsers()->where('Friendship', '=', UserRelationship::Following); } /** * @return BelongsToMany */ - public function followers(): BelongsToMany + public function followerUsers(): BelongsToMany { - return $this->inverseRelationships()->where('Friendship', '=', UserRelationship::Following); + return $this->inverseRelatedUsers()->where('Friendship', '=', UserRelationship::Following); } public function isFollowing(string $username): bool diff --git a/app/Models/Achievement.php b/app/Models/Achievement.php index 66bbc47a26..78b824dba1 100644 --- a/app/Models/Achievement.php +++ b/app/Models/Achievement.php @@ -317,7 +317,7 @@ public function game(): BelongsTo /** * @return BelongsToMany */ - public function players(): BelongsToMany + public function playerUsers(): BelongsToMany { return $this->belongsToMany(User::class, 'player_achievements', 'achievement_id', 'user_id') ->using(PlayerAchievement::class); diff --git a/app/Models/Game.php b/app/Models/Game.php index ff0b7e9e6a..405fda56b8 100644 --- a/app/Models/Game.php +++ b/app/Models/Game.php @@ -304,7 +304,7 @@ public function leaderboards(): HasMany /** * @return BelongsToMany */ - public function players(): BelongsToMany + public function playerUsers(): BelongsToMany { return $this->belongsToMany(User::class, 'player_games') ->using(PlayerGame::class); diff --git a/resources/views/components/game/compare-progress.blade.php b/resources/views/components/game/compare-progress.blade.php index 638f318aaa..5f3286af34 100644 --- a/resources/views/components/game/compare-progress.blade.php +++ b/resources/views/components/game/compare-progress.blade.php @@ -9,7 +9,7 @@ ]) following()->select(['UserAccounts.ID', 'UserAccounts.User'])->pluck('ID'); +$followedUserIds = $user->followedUsers()->select(['UserAccounts.ID', 'UserAccounts.User'])->pluck('ID'); $followedUserCompletion = null; if (!empty($followedUserIds)) { From 8192e16fea409bd9b625e4f689232af807147eb9 Mon Sep 17 00:00:00 2001 From: Jamiras <32680403+Jamiras@users.noreply.github.com> Date: Wed, 17 Apr 2024 07:45:03 -0600 Subject: [PATCH 07/11] prevent error migrating fresh database (#2366) --- ...03_17_000000_update_subscription_table.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/database/migrations/platform/2024_03_17_000000_update_subscription_table.php b/database/migrations/platform/2024_03_17_000000_update_subscription_table.php index 9a1ed9a37b..74e9a565b2 100644 --- a/database/migrations/platform/2024_03_17_000000_update_subscription_table.php +++ b/database/migrations/platform/2024_03_17_000000_update_subscription_table.php @@ -13,16 +13,26 @@ public function up(): void // [1] Create `id` column as the new primary key. // SQLite doesn't let us change a primary key after the initial migration. /** @see 2012_10_03_133633_create_base_tables.php */ - Schema::table('Subscription', function (Blueprint $table) { - if (DB::connection()->getDriverName() !== 'sqlite') { - $table->dropPrimary(['SubjectType', 'SubjectID', 'UserID']); - } - }); - Schema::table('Subscription', function (Blueprint $table) { - if (DB::connection()->getDriverName() !== 'sqlite') { - $table->bigIncrements('id')->first(); + if (DB::connection()->getDriverName() !== 'sqlite') { + Schema::table('Subscription', function (Blueprint $table) { + $sm = Schema::getConnection()->getDoctrineSchemaManager(); + $indexesFound = $sm->listTableIndexes('Subscription'); + + $index = $indexesFound['subscription_subjecttype_subjectid_userid_unique'] ?? null; + if ($index) { + if ($index->isUnique()) { + $table->dropUnique(['SubjectType', 'SubjectID', 'UserID']); + } else { + $table->dropPrimary(['SubjectType', 'SubjectID', 'UserID']); + } + } + }); + if (!Schema::hasColumn('Subscription', 'id')) { + Schema::table('Subscription', function (Blueprint $table) { + $table->bigIncrements('id')->first(); + }); } - }); + } // [2] Rename columns to align with Laravel conventions. Schema::table('Subscription', function (Blueprint $table) { From 4d479ec40dbe0aa96010655b4e9f179e1e742bdf Mon Sep 17 00:00:00 2001 From: Jamiras <32680403+Jamiras@users.noreply.github.com> Date: Thu, 18 Apr 2024 07:25:34 -0600 Subject: [PATCH 08/11] also show related game for achievement search results (#2365) --- resources/views/pages-legacy/searchresults.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/views/pages-legacy/searchresults.blade.php b/resources/views/pages-legacy/searchresults.blade.php index cf90c3f3e4..eedf2929c5 100644 --- a/resources/views/pages-legacy/searchresults.blade.php +++ b/resources/views/pages-legacy/searchresults.blade.php @@ -94,10 +94,13 @@ case SearchType::Achievement: echo "Achievement"; - echo ""; + echo ""; /** @var ?Achievement $achievement */ $achievement = Achievement::find($nextID); echo achievementAvatar($achievement); + echo ""; + $gameData = getGameData($achievement['GameID']); + echo gameAvatar($gameData); echo ""; break; From 04c0ef6dc6ae2a62f3c6624396cde7141b0efcfb Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Thu, 18 Apr 2024 09:41:17 -0400 Subject: [PATCH 09/11] fix(game-compare): remediate link button size issue on LG and lower (#2360) --- .../components/game/link-buttons/game-link-button.blade.php | 6 +++--- .../views/pages/user/[user]/game/[game]/compare.blade.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/components/game/link-buttons/game-link-button.blade.php b/resources/views/components/game/link-buttons/game-link-button.blade.php index 36a9cdc773..f2e456faa4 100644 --- a/resources/views/components/game/link-buttons/game-link-button.blade.php +++ b/resources/views/components/game/link-buttons/game-link-button.blade.php @@ -4,8 +4,8 @@ ])
  • - - {{ $icon }} - {{ $slot }} + + {{ $icon }} + {{ $slot }}
  • diff --git a/resources/views/pages/user/[user]/game/[game]/compare.blade.php b/resources/views/pages/user/[user]/game/[game]/compare.blade.php index 1c797dc91a..861582f3b9 100644 --- a/resources/views/pages/user/[user]/game/[game]/compare.blade.php +++ b/resources/views/pages/user/[user]/game/[game]/compare.blade.php @@ -74,7 +74,7 @@ @if ($canModerate) -
    +
      Date: Thu, 18 Apr 2024 09:57:06 -0400 Subject: [PATCH 10/11] fix(achievement): show badge on tooltips even when is false (#2359) --- app/Helpers/render/achievement.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Helpers/render/achievement.php b/app/Helpers/render/achievement.php index ddcbf6f636..eb71c5cc98 100644 --- a/app/Helpers/render/achievement.php +++ b/app/Helpers/render/achievement.php @@ -46,15 +46,17 @@ function achievementAvatar( $tooltip = $tooltip !== false ? $achievement : false; } + $iconUrl = $icon !== false && ($icon || !$label) ? $icon : null; + return avatar( resource: 'achievement', id: $id, label: $label !== false && ($label || !$icon) ? $label : null, link: route('achievement.show', $id), tooltip: is_array($tooltip) - ? renderAchievementCard($tooltip, iconUrl: $icon) + ? renderAchievementCard($tooltip, iconUrl: $iconUrl) : $tooltip, - iconUrl: $icon !== false && ($icon || !$label) ? $icon : null, + iconUrl: $iconUrl, iconSize: $iconSize, iconClass: $iconClass, context: $context, From eddab134d6f7a80fac80b78dbb620ff8921ebeb3 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Thu, 18 Apr 2024 11:45:41 -0400 Subject: [PATCH 11/11] chore: add foreign key to GameData.ForumTopicID (#2358) --- ...024_04_13_000000_update_gamedata_table.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 database/migrations/community/2024_04_13_000000_update_gamedata_table.php diff --git a/database/migrations/community/2024_04_13_000000_update_gamedata_table.php b/database/migrations/community/2024_04_13_000000_update_gamedata_table.php new file mode 100644 index 0000000000..a7f687ebfd --- /dev/null +++ b/database/migrations/community/2024_04_13_000000_update_gamedata_table.php @@ -0,0 +1,31 @@ +unsignedBigInteger('ForumTopicID')->change(); + }); + + Schema::table('GameData', function (Blueprint $table) { + $table->foreign('ForumTopicID')->references('ID')->on('ForumTopic')->onDelete('set null'); + }); + } + + public function down(): void + { + Schema::table('GameData', function (Blueprint $table) { + $table->dropForeign(['ForumTopicID']); + }); + + Schema::table('GameData', function (Blueprint $table) { + $table->integer('ForumTopicID')->change(); + }); + } +};