diff --git a/app/Models/Campaign.php b/app/Models/Campaign.php index 759729ea6..4ba1d6cda 100644 --- a/app/Models/Campaign.php +++ b/app/Models/Campaign.php @@ -414,6 +414,13 @@ public function getDefaultVisibilityAttribute(): mixed return Arr::get($this->settings, 'default_visibility', 'all'); } + /** + */ + public function getDefaultGalleryVisibilityAttribute(): mixed + { + return Arr::get($this->settings, 'gallery_visibility', 'all'); + } + /** * Determine the campaign's default visibility_id select option */ @@ -433,6 +440,25 @@ public function defaultVisibility(): Visibility return Visibility::All; } + /** + * Determine the gallery's default visibility_id select option + */ + public function defaultGalleryVisibility(): Visibility + { + $visibility = $this->getDefaultGalleryVisibilityAttribute(); + if ($visibility == 'admin' && auth()->user()->isAdmin()) { + return Visibility::Admin; + } elseif ($visibility == 'admin-self') { + return Visibility::AdminSelf; + } elseif ($visibility == 'members') { + return Visibility::Member; + } elseif ($visibility == 'self') { + return Visibility::Self; + } + + return Visibility::All; + } + /** * Checks if the campaign's public role has no read permissions */ diff --git a/app/Services/Campaign/GalleryService.php b/app/Services/Campaign/GalleryService.php index bfd1eea7a..03cc4aeea 100644 --- a/app/Services/Campaign/GalleryService.php +++ b/app/Services/Campaign/GalleryService.php @@ -138,7 +138,7 @@ public function store(GalleryImageStore $request, string $field = 'file'): array $image->size = (int) ceil($source->getSize() / 1024); // kb $image->name = mb_substr($name, 0, 45); $image->folder_id = $request->post('folder_id'); - $image->visibility_id = $this->campaign->defaultVisibility(); + $image->visibility_id = $this->campaign->defaultGalleryVisibility(); // Check remaining space again before saving, as the user could be near max and uploading multiple // files at a time to bypass the size restrictions diff --git a/app/Services/Gallery/UploadService.php b/app/Services/Gallery/UploadService.php index cea788daa..82fb42580 100644 --- a/app/Services/Gallery/UploadService.php +++ b/app/Services/Gallery/UploadService.php @@ -51,7 +51,7 @@ public function file(UploadedFile $file): array $this->image->name = Str::beforeLast($file->getClientOriginalName(), '.'); $this->image->ext = Str::before($file->extension(), '?'); $this->image->size = (int) ceil($file->getSize() / 1024); // kb - $this->image->visibility_id = $this->campaign->defaultVisibility(); + $this->image->visibility_id = $this->campaign->defaultGalleryVisibility(); $this->image->save(); $file->storePubliclyAs($this->image->folder, $this->image->file); @@ -109,7 +109,7 @@ public function url(string $url): array $this->image->campaign_id = $this->campaign->id; $this->image->ext = $file->guessExtension(); $this->image->size = (int) ceil($copiedFileSize); // kb - $this->image->visibility_id = $this->campaign->defaultVisibility(); + $this->image->visibility_id = $this->campaign->defaultGalleryVisibility(); $this->image->save(); if ($this->image->isSvg()) { diff --git a/lang/en/campaigns.php b/lang/en/campaigns.php index a36bef4d1..d53ec1126 100644 --- a/lang/en/campaigns.php +++ b/lang/en/campaigns.php @@ -53,6 +53,7 @@ 'excerpt' => 'Campaign dashboard text', 'featured' => 'Featured campaign', 'followers' => 'Followers', + 'gallery_visibility' => 'Default Gallery Image Visibility', 'genre' => 'Genre(s)', 'header_image' => 'Campaign dashboard background image', 'image' => 'Sidebar image', @@ -81,6 +82,7 @@ 'entity_count_v3' => 'This number is recalculated every :amount hours.', 'entity_privacy' => 'When creating a new entity as an admin, select the default privacy setting of the new entity.', 'excerpt' => 'The contents of this field will be displayed on the dashboard in the campaign header widget, so write a few sentences introducing your world. If this field is empty, the first 1000 characters of the campaign\'s entry field will be used instead.', + 'gallery_visibility' => 'Default Visibility value when uploading images to the gallery.', 'header_image' => 'Image displayed as a background in the campaign header dashboard widget.', 'hide_history' => 'If enabled, only members of the campaign\'s :admin role will have access to an entity\'s history (log of changes).', 'hide_members' => 'If enabled, only members of the campaign\'s :admin role will have access to the list of the campaign\'s members.', diff --git a/resources/views/campaigns/forms/panes/permission.blade.php b/resources/views/campaigns/forms/panes/permission.blade.php index c823b5043..7ddcfe0db 100644 --- a/resources/views/campaigns/forms/panes/permission.blade.php +++ b/resources/views/campaigns/forms/panes/permission.blade.php @@ -34,6 +34,13 @@ :helper="__('campaigns.helpers.character_personality_visibility')"> + + + +