Skip to content

Commit 4284998

Browse files
scottgraysongithub-actions[bot]
authored andcommitted
Fix styling
1 parent 3e8b1b1 commit 4284998

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

database/migrations/2024_01_01_000000_create_library_items_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function up(): void
2020
$table->foreignId('created_by')->constrained('users');
2121
$table->timestamps();
2222
$table->softDeletes();
23-
23+
2424
$table->index(['parent_id', 'type']);
2525
$table->unique(['parent_id', 'slug'], 'lib_items_parent_slug_unique');
2626
});

database/migrations/2024_01_01_000001_create_library_item_permissions_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function up(): void
1717
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
1818
$table->enum('permission', ['view', 'edit']);
1919
$table->timestamps();
20-
20+
2121
$table->unique(['library_item_id', 'user_id', 'permission'], 'lib_item_perms_unique');
2222
});
2323
}

database/seeders/LibrarySeeder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public function run(): void
1515
{
1616
// Get the first user as the creator
1717
$user = \App\Models\User::first();
18-
19-
if (!$user) {
18+
19+
if (! $user) {
2020
$this->command->warn('No users found. Please create a user first.');
21+
2122
return;
2223
}
2324

@@ -116,10 +117,10 @@ public function run(): void
116117

117118
// Create some sample permissions if there are other users
118119
$otherUsers = \App\Models\User::where('id', '!=', $user->id)->take(2)->get();
119-
120+
120121
if ($otherUsers->count() > 0) {
121122
$this->command->info('Creating sample permissions...');
122-
123+
123124
// Give first other user view access to Documents folder
124125
if ($otherUsers->count() >= 1) {
125126
LibraryItemPermission::create([
@@ -128,7 +129,7 @@ public function run(): void
128129
'permission' => 'view',
129130
]);
130131
}
131-
132+
132133
// Give second other user edit access to Project A
133134
if ($otherUsers->count() >= 2) {
134135
LibraryItemPermission::create([
@@ -150,7 +151,7 @@ public function run(): void
150151
$this->command->info('- Images/');
151152
$this->command->info(' - Photos/');
152153
$this->command->info(' - Graphics/');
153-
154+
154155
if ($otherUsers->count() > 0) {
155156
$this->command->info('Sample permissions created for other users.');
156157
}

src/FilamentLibraryServiceProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tapp\FilamentLibrary;
44

5-
use Filament\Support\Assets\AlpineComponent;
65
use Filament\Support\Assets\Asset;
76
use Filament\Support\Assets\Css;
87
use Filament\Support\Assets\Js;
@@ -49,7 +48,6 @@ public function configurePackage(Package $package): void
4948
$package->hasMigrations($this->getMigrations());
5049
}
5150

52-
5351
if (file_exists($package->basePath('/../resources/lang'))) {
5452
$package->hasTranslations();
5553
}
@@ -101,16 +99,16 @@ protected function getAssetPackageName(): ?string
10199
protected function getAssets(): array
102100
{
103101
$assets = [];
104-
102+
105103
// Only register assets if they exist
106104
if (file_exists(__DIR__ . '/../resources/dist/filament-library.css')) {
107105
$assets[] = Css::make('filament-library-styles', __DIR__ . '/../resources/dist/filament-library.css');
108106
}
109-
107+
110108
if (file_exists(__DIR__ . '/../resources/dist/filament-library.js')) {
111109
$assets[] = Js::make('filament-library-scripts', __DIR__ . '/../resources/dist/filament-library.js');
112110
}
113-
111+
114112
return $assets;
115113
}
116114

@@ -158,5 +156,4 @@ protected function getMigrations(): array
158156
'2024_01_01_000001_create_library_item_permissions_table',
159157
];
160158
}
161-
162159
}

src/Models/LibraryItem.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
class LibraryItem extends Model implements HasMedia
1616
{
17-
use HasFactory, SoftDeletes, InteractsWithMedia;
17+
use HasFactory;
18+
use InteractsWithMedia;
19+
use SoftDeletes;
1820

1921
protected $fillable = [
2022
'name',
@@ -44,7 +46,7 @@ protected static function boot(): void
4446
});
4547

4648
static::updating(function (self $item) {
47-
if ($item->isDirty('name') && !$item->isDirty('slug')) {
49+
if ($item->isDirty('name') && ! $item->isDirty('slug')) {
4850
$item->slug = static::generateUniqueSlug($item->name, $item->parent_id, $item->id);
4951
}
5052
});
@@ -105,9 +107,9 @@ public function scopeForUser($query, $user)
105107
{
106108
return $query->where(function ($q) use ($user) {
107109
$q->where('created_by', $user->id)
108-
->orWhereHas('permissions', function ($permissionQuery) use ($user) {
109-
$permissionQuery->where('user_id', $user->id);
110-
});
110+
->orWhereHas('permissions', function ($permissionQuery) use ($user) {
111+
$permissionQuery->where('user_id', $user->id);
112+
});
111113
});
112114
}
113115

@@ -160,6 +162,7 @@ public function getSizeAttribute(): ?int
160162
}
161163

162164
$media = $this->getFirstMedia('files');
165+
163166
return $media ? $media->size : null;
164167
}
165168

@@ -190,7 +193,7 @@ public function registerMediaCollections(): void
190193
/**
191194
* Register media conversions.
192195
*/
193-
public function registerMediaConversions(Media $media = null): void
196+
public function registerMediaConversions(?Media $media = null): void
194197
{
195198
$this->addMediaConversion('thumb')
196199
->width(300)
@@ -210,7 +213,7 @@ protected static function generateUniqueSlug(string $name, ?int $parentId = null
210213

211214
while (static::where('slug', $slug)
212215
->where('parent_id', $parentId)
213-
->when($excludeId, fn($q) => $q->where('id', '!=', $excludeId))
216+
->when($excludeId, fn ($q) => $q->where('id', '!=', $excludeId))
214217
->exists()) {
215218
$slug = $baseSlug . '-' . $counter;
216219
$counter++;

src/Services/PermissionService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PermissionService
2525
public function hasPermission($user, LibraryItem $item, string $permission): bool
2626
{
2727
$cacheKey = $this->getCacheKey($user->id, $item->id, $permission);
28-
28+
2929
return Cache::remember($cacheKey, self::CACHE_TTL, function () use ($user, $item, $permission) {
3030
return $this->checkPermissionRecursive($user, $item, $permission);
3131
});

src/Traits/HasLibraryAccess.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function canViewLibraryItem(LibraryItem $item): bool
1515
if ($this->isLibraryAdmin()) {
1616
return true;
1717
}
18-
18+
1919
return $item->created_by === $this->id || $item->hasPermission($this, 'view');
2020
}
2121

@@ -28,7 +28,7 @@ public function canEditLibraryItem(LibraryItem $item): bool
2828
if ($this->isLibraryAdmin()) {
2929
return true;
3030
}
31-
31+
3232
return $item->created_by === $this->id || $item->hasPermission($this, 'edit');
3333
}
3434

@@ -43,7 +43,7 @@ public function canViewRootLibraryItems(): bool
4343

4444
/**
4545
* Check if the user is a library admin.
46-
*
46+
*
4747
* Override this method to add role-based logic.
4848
*/
4949
public function isLibraryAdmin(): bool
@@ -66,7 +66,7 @@ public function getAccessibleLibraryItems()
6666
*/
6767
public function getAccessibleRootLibraryItems()
6868
{
69-
if (!$this->canViewRootLibraryItems()) {
69+
if (! $this->canViewRootLibraryItems()) {
7070
return collect();
7171
}
7272

0 commit comments

Comments
 (0)