Skip to content

Commit 2a9cedc

Browse files
committed
Fix conflict
2 parents 7e6280e + 55987e4 commit 2a9cedc

13 files changed

Lines changed: 401 additions & 41 deletions

File tree

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22

33
All notable changes to `Filament Forum` will be documented in this file.
44

5+
## v2.0.4 - 2025-12-11
6+
7+
### What's Changed
8+
9+
* Add columnSpanFull() by @andreia in https://github.com/TappNetwork/Filament-Forum/pull/10
10+
11+
**Full Changelog**: https://github.com/TappNetwork/Filament-Forum/compare/v2.0.3...v2.0.4
12+
13+
## v2.0.3 - 2025-11-13
14+
15+
**Full Changelog**: https://github.com/TappNetwork/Filament-Forum/compare/v2.0.2...v2.0.3
16+
17+
## v2.0.1 - 2025-11-13
18+
19+
**Full Changelog**: https://github.com/TappNetwork/Filament-Forum/compare/v2.0.0...v2.0.1
20+
21+
bugfix
22+
23+
## v2.0.0 - 2025-11-13
24+
25+
### What's Changed
26+
27+
* Add forum access control and consolidate user traits by @scottgrayson in https://github.com/TappNetwork/Filament-Forum/pull/8
28+
29+
### New Contributors
30+
31+
* @scottgrayson made their first contribution in https://github.com/TappNetwork/Filament-Forum/pull/8
32+
33+
**Full Changelog**: https://github.com/TappNetwork/Filament-Forum/compare/v1.1.0...v2.0.0
34+
35+
### Breaking Changes
36+
37+
- The three separate traits (HasFavoriteForumPost, HasMentionables, HasForumUserSearch) have been consolidated into a single `ForumUser` trait. Users should update their User model to use `ForumUser` instead of the three separate traits.
38+
539
## v1.1.0 - 2025-10-08
640

741
### What's Changed

README.md

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,25 @@ A forum package for Filament apps that provides both admin and frontend resource
8080

8181
- Ensure your User model has a `name` attribute
8282

83-
- Add `HasFavoriteForumPost` trait to your `User` model:
83+
- Add the `ForumUser` trait to your `User` model:
8484

8585
```php
86-
use Tapp\FilamentForum\Models\Traits\HasFavoriteForumPost;
86+
use Tapp\FilamentForum\Traits\ForumUser;
8787

8888
class User extends Authenticatable
8989
{
9090
// ...
91-
use HasFavoriteForumPost;
91+
use ForumUser;
9292
// ...
9393
}
9494
```
9595

96-
- Add `HasMentionables` trait (you can use it to customize which users are mentionable, see below in "Custom Mentionables") to your `User` model
97-
98-
```php
99-
use Tapp\FilamentForum\Models\Traits\HasMentionables;
100-
101-
class User extends Authenticatable
102-
{
103-
use HasMentionables;
104-
}
105-
```
96+
The `ForumUser` trait provides:
97+
- `forums()` relationship - Get all forums the user is assigned to
98+
- `favoriteForumPosts()` relationship - Get all favorite forum posts
99+
- `getMentionableUsers()` method - Customize which users are mentionable (see "Custom Mentionables" below)
100+
- `hasCustomForumSearch()`, `getForumSearchResults()`, `getForumOptionLabel()` methods - Custom search functionality (see "Custom User Model, Attribute, and Search Functionality" below)
101+
- `isForumAdmin()` method - Override to grant admin access to hidden forums (defaults to `false`)
106102

107103
6. Add to your custom theme (usually`theme.css`) file:
108104

@@ -301,33 +297,11 @@ For more detailed information about implementing multi-tenancy in Filament, see
301297

302298
## Custom User Model, Attribute, and Search Functionality
303299

304-
By default, the `name` column of `User` model is used for the `user` relationship. You can customize it using the `title-attribute` on `filament-form.php` config file.
300+
By default, the `name` column of `User` model is used for the `user` relationship. You can customize it using the `title-attribute` on `filament-forum.php` config file.
305301

306302
The Filament Forum plugin also supports custom search functionality for user selects in forms and filters. This allows you to customize which users' columns are used to search and display in dropdowns (eg. if your `User` model doesn't have a `name` column).
307303

308-
## Setup
309-
310-
### 1. Add the Trait to Your User Model
311-
312-
Add the `HasForumUserSearch` trait to your User model:
313-
314-
```php
315-
<?php
316-
317-
namespace App\Models;
318-
319-
use Illuminate\Foundation\Auth\User as Authenticatable;
320-
use Tapp\FilamentForum\Traits\HasForumUserSearch;
321-
322-
class User extends Authenticatable
323-
{
324-
use HasForumUserSearch;
325-
326-
// Your existing model code...
327-
}
328-
```
329-
330-
### 2. Configure Your User Model Class
304+
### Configure Your User Model Class
331305

332306
Make sure your `config/filament-forum.php` file points to the correct `User` model:
333307

@@ -338,7 +312,7 @@ Make sure your `config/filament-forum.php` file points to the correct `User` mod
338312
],
339313
```
340314

341-
### 3. Customize the Search Methods
315+
### Customize the Search Methods
342316

343317
Override the trait methods in your User model to customize search behavior:
344318

@@ -348,11 +322,11 @@ Override the trait methods in your User model to customize search behavior:
348322
namespace App\Models;
349323

350324
use Illuminate\Foundation\Auth\User as Authenticatable;
351-
use Tapp\FilamentForum\Traits\HasForumUserSearch;
325+
use Tapp\FilamentForum\Traits\ForumUser;
352326

353327
class User extends Authenticatable
354328
{
355-
use HasForumUserSearch;
329+
use ForumUser;
356330

357331
/**
358332
* Custom search that searches both name and email
@@ -392,6 +366,31 @@ public static function getMentionableUsers()
392366
}
393367
```
394368

369+
## Forum Access Control
370+
371+
Forums can be set as public (visible to all logged-in users) or hidden (only visible to assigned users). Forum admins can see all hidden forums regardless of assignment.
372+
373+
### Setting Forum Access
374+
375+
In the admin panel, you can set a forum as hidden by checking the "Hidden Forum" checkbox. Hidden forums will only be visible to:
376+
- Users who are explicitly assigned to the forum
377+
- Forum admins (users where `isForumAdmin()` returns `true`)
378+
379+
### Forum Admin Access
380+
381+
Override the `isForumAdmin()` method in your User model to grant admin access:
382+
383+
```php
384+
// In your User model
385+
public function isForumAdmin(): bool
386+
{
387+
// Example: Grant admin access based on roles
388+
return $this->hasRole('Admin') || $this->hasRole('Forum Admin');
389+
}
390+
```
391+
392+
Forum admins can see and access all hidden forums, even if they're not assigned to them.
393+
395394
## User Avatar
396395

397396
Optionally, implements Filament's `HasAvatar` interface:

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "tapp/filament-forum",
33
"description": "Forum and comments package for Filament apps.",
44
"type": "library",
5+
"license": "MIT",
56
"autoload": {
67
"psr-4": {
78
"Tapp\\FilamentForum\\": "src/",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('forums', function (Blueprint $table) {
15+
$table->boolean('is_hidden')->default(false)->after('description');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('forums', function (Blueprint $table) {
25+
$table->dropColumn('is_hidden');
26+
});
27+
}
28+
};
29+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('forum_user', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('user_id')->constrained()->onDelete('cascade');
17+
$table->foreignId('forum_id')->constrained('forums')->onDelete('cascade');
18+
$table->timestamps();
19+
$table->unique(['user_id', 'forum_id']);
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::dropIfExists('forum_user');
29+
}
30+
};
31+

src/Filament/Resources/Admin/ForumResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Tapp\FilamentForum\Filament\Resources\Admin\ForumResource\Schemas\ForumForm;
1313
use Tapp\FilamentForum\Filament\Resources\Admin\ForumResource\Tables\ForumsTable;
1414
use Tapp\FilamentForum\Models\Forum;
15+
use Tapp\FilamentForum\RelationManagers\ForumUsersRelationManager;
1516

1617
class ForumResource extends Resource
1718
{
@@ -61,7 +62,7 @@ public static function table(Table $table): Table
6162
public static function getRelations(): array
6263
{
6364
return [
64-
//
65+
ForumUsersRelationManager::make(),
6566
];
6667
}
6768

src/Filament/Resources/Admin/ForumResource/Schemas/ForumForm.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Tapp\FilamentForum\Filament\Resources\Admin\ForumResource\Schemas;
44

5+
use Filament\Forms\Components\Checkbox;
56
use Filament\Forms\Components\Select;
67
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
78
use Filament\Forms\Components\Textarea;
89
use Filament\Forms\Components\TextInput;
910
use Filament\Schemas\Components\Section;
1011
use Filament\Schemas\Schema;
1112
use Illuminate\Database\Eloquent\Model;
13+
use Illuminate\Support\Facades\Auth;
1214

1315
class ForumForm
1416
{
@@ -26,6 +28,7 @@ public static function configure(Schema $schema): Schema
2628
return $record->{$titleAttribute};
2729
})
2830
->searchable()
31+
->default(fn () => Auth::id())
2932
->label(__('filament-forum::filament-forum.forum.form.label.owner'));
3033

3134
// Add custom search functionality if User model has the trait and implements custom methods
@@ -55,6 +58,10 @@ public static function configure(Schema $schema): Schema
5558
->label(__('filament-forum::filament-forum.forum.form.label.image'))
5659
->collection('images')
5760
->columnSpanFull(),
61+
Checkbox::make('is_hidden')
62+
->label('Hidden Forum')
63+
->helperText('If checked, only assigned users can view this forum. If unchecked, all logged in users can view it.')
64+
->live(),
5865
]),
5966
]);
6067
}

src/Filament/Resources/Admin/ForumResource/Tables/ForumsTable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public static function configure(Table $table): Table
6666
// Only render the tooltip if the column content exceeds the length limit.
6767
return $state;
6868
}),
69+
TextColumn::make('is_hidden')
70+
->label('Access')
71+
->badge()
72+
->formatStateUsing(fn (bool $state): string => $state ? 'Hidden' : 'Public')
73+
->color(fn (bool $state): string => $state ? 'warning' : 'success')
74+
->icon(fn (bool $state): string => $state ? 'heroicon-o-lock-closed' : 'heroicon-o-globe-alt'),
6975
TextColumn::make('created_at')
7076
->label(__('filament-forum::filament-forum.forum.table.label.created-at'))
7177
->dateTime()

src/Filament/Resources/Forums/Pages/ListForums.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Filament\Resources\Pages\ListRecords;
66
use Illuminate\Contracts\Support\Htmlable;
7+
use Illuminate\Support\Facades\Auth;
78
use Tapp\FilamentForum\Filament\Resources\Forums\ForumResource;
9+
use Tapp\FilamentForum\Models\Forum;
810

911
class ListForums extends ListRecords
1012
{
@@ -14,4 +16,17 @@ public function getTitle(): string|Htmlable
1416
{
1517
return __('filament-forum::filament-forum.forum.title');
1618
}
19+
20+
protected function getTableQuery(): \Illuminate\Database\Eloquent\Builder
21+
{
22+
$user = Auth::user();
23+
24+
if ($user) {
25+
// Use the accessibleTo scope for better performance
26+
return Forum::accessibleTo($user);
27+
}
28+
29+
// For non-authenticated users, only show public forums
30+
return Forum::where('is_hidden', false);
31+
}
1732
}

src/FilamentForumServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function configurePackage(Package $package): void
2626
->hasAssets()
2727
->hasMigrations([
2828
'create_forums_table',
29+
'add_is_hidden_to_forums_table',
30+
'create_forum_user_table',
2931
'create_forum_posts_table',
3032
'create_favorite_forum_post_table',
3133
'create_forum_post_views_table',

0 commit comments

Comments
 (0)