Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Campaigns: Default gallery visibility #956

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/Models/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Campaign/GalleryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Gallery/UploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en/campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.',
Expand Down
7 changes: 7 additions & 0 deletions resources/views/campaigns/forms/panes/permission.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
:helper="__('campaigns.helpers.character_personality_visibility')">
<x-forms.select name="entity_personality_visibility" :options="[0 => __('campaigns.privacy.visible'), 1 => __('campaigns.privacy.private')]" :selected="$campaign->entity_personality_visibility ?? null" />
</x-forms.field>

<x-forms.field
field="gallery-visibility"
:label="__('campaigns.fields.gallery_visibility')"
:helper="__('campaigns.helpers.gallery_visibility')">
<x-forms.select name="settings[gallery_visibility]" :options="$visibilities" :selected="$campaign->settings['gallery_visibility'] ?? null" />
</x-forms.field>
</x-grid>
</x-grid>
</div>
Loading