Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/lb_secs_as_mins
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Apr 18, 2024
2 parents 057a37f + eddab13 commit f727847
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/Actions/ClearAccountDataAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->relatedUsers()->detach();
$user->inverseRelatedUsers()->detach();
// TODO $user->ratings()->delete();
DB::statement('DELETE FROM Rating WHERE User = :username', ['username' => $user->User]);
$user->gameListEntries()->delete();
Expand Down
2 changes: 1 addition & 1 deletion app/Community/Components/UserActivityFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions app/Community/Concerns/ActsAsCommunityMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ public function gameListEntries(?string $type = null): HasMany
/**
* @return BelongsToMany<User>
*/
public function relationships(): BelongsToMany
public function relatedUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, (new UserRelation())->getTable(), 'user_id', 'related_user_id');
}

/**
* @return BelongsToMany<User>
*/
public function inverseRelationships(): BelongsToMany
public function inverseRelatedUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, (new UserRelation())->getTable(), 'related_user_id', 'user_id');
}

/**
* @return BelongsToMany<User>
*/
public function following(): BelongsToMany
public function followedUsers(): BelongsToMany
{
return $this->relationships()->where('Friendship', '=', UserRelationship::Following);
return $this->relatedUsers()->where('Friendship', '=', UserRelationship::Following);
}

/**
* @return BelongsToMany<User>
*/
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
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/database/user-permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/Helpers/render/achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function game(): BelongsTo
/**
* @return BelongsToMany<User>
*/
public function players(): BelongsToMany
public function playerUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, 'player_achievements', 'achievement_id', 'user_id')
->using(PlayerAchievement::class);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/ForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Models/ForumTopicComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion app/Models/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function leaderboards(): HasMany
/**
* @return BelongsToMany<User>
*/
public function players(): BelongsToMany
public function playerUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, 'player_games')
->using(PlayerGame::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::table('GameData', function (Blueprint $table) {
$table->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();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/game/compare-progress.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
])

<?php
$followedUserIds = $user->following()->select(['UserAccounts.ID', 'UserAccounts.User'])->pluck('ID');
$followedUserIds = $user->followedUsers()->select(['UserAccounts.ID', 'UserAccounts.User'])->pluck('ID');
$followedUserCompletion = null;
if (!empty($followedUserIds)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
])

<li>
<a class="btn py-2 pr-3 block transition-transform lg:active:scale-[97%]" href="{{ $href }}">
<span class="icon icon-md mx-1">{{ $icon }}</span>
{{ $slot }}
<a class="btn py-2 w-full px-3 inline-flex gap-x-2 transition-transform lg:active:scale-[97%]" href="{{ $href }}">
<span>{{ $icon }}</span>
<span>{{ $slot }}</span>
</a>
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
Official Forum Topic
</x-game.link-buttons.game-link-button>
@else
@can('createForumTopic', App\Models\User::class, App\Models\Game::class)
@can('createForumTopic', $game)
<x-game.link-buttons.create-forum-topic-button :gameId="$game->id" />
@endcan
@endif
Expand Down
4 changes: 2 additions & 2 deletions resources/views/pages-legacy/editpost.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
Expand Down Expand Up @@ -46,7 +46,7 @@
<x-base.form.input type="hidden" name="comment" value="{{ $foundPost->ID }}" />

<x-base.form.input label="{{ __res('forum', 1) }}" readonly value="{{ $topic->forum->Title }}" inline :fullWidth="false" />
<x-base.form.input label="{{ __res('author', 1) }}" readonly value="{{ $topic->user->User }}" inline :fullWidth="false" />
<x-base.form.input label="{{ __res('author', 1) }}" readonly value="{{ $topic->user?->User ?? 'Deleted user' }}" inline :fullWidth="false" />
<x-base.form.input label="{{ __res('forum-topic', 1) }}" readonly :value="$topic->Title" inline />

<x-base.form.textarea
Expand Down
5 changes: 4 additions & 1 deletion resources/views/pages-legacy/searchresults.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@
case SearchType::Achievement:
echo "<td>Achievement</td>";
echo "<td colspan='2'>";
echo "<td>";
/** @var ?Achievement $achievement */
$achievement = Achievement::find($nextID);
echo achievementAvatar($achievement);
echo "</td><td>";
$gameData = getGameData($achievement['GameID']);
echo gameAvatar($gameData);
echo "</td>";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
@if ($userAgent['clientVersion'] !== 'Unknown')
{{ $userAgent['clientVersion'] }}
@endif
@if ($userAgent['os'])
@if (!empty($userAgent['os']))
({{ $userAgent['os'] }})
@endif
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

@if ($canModerate)
<x-hidden-controls>
<div style="width:20%">
<div class="grid md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5">
<ul class="flex flex-col gap-2">
<x-game.link-buttons.game-link-button
icon="🔬"
Expand Down
97 changes: 97 additions & 0 deletions tests/Feature/Platform/Action/ClearAccountDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace Tests\Feature\Platform\Action;

use App\Actions\ClearAccountDataAction;
use App\Community\Enums\SubscriptionSubjectType;
use App\Community\Enums\UserGameListType;
use App\Community\Enums\UserRelationship;
use App\Models\MessageThread;
use App\Models\MessageThreadParticipant;
use App\Models\Subscription;
use App\Models\User;
use App\Models\UserGameListEntry;
use App\Models\UserRelation;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\Feature\Platform\Concerns\TestsPlayerAchievements;
use Tests\Feature\Platform\Concerns\TestsPlayerBadges;
use Tests\TestCase;

class ClearAccountDataTest extends TestCase
{
use RefreshDatabase;

use TestsPlayerAchievements;
use TestsPlayerBadges;

public function testClearsData(): void
{
/** @var User $user1 */
$user1 = User::factory()->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);
}
}

0 comments on commit f727847

Please sign in to comment.