diff --git a/app/Models/Campaign.php b/app/Models/Campaign.php index dc5abf31d4..afdd03b119 100644 --- a/app/Models/Campaign.php +++ b/app/Models/Campaign.php @@ -42,6 +42,7 @@ * @property array $ui_settings * @property boolean $is_open * @property boolean $is_featured + * @property boolean $is_discreet * @property Carbon $featured_until * @property string $featured_reason * @property array|null $default_images @@ -98,6 +99,7 @@ class Campaign extends Model 'ui_settings', 'settings', 'is_open', + 'is_discreet', ]; protected $casts = [ @@ -227,6 +229,15 @@ public function isPublic(): bool { return $this->visibility_id == self::VISIBILITY_PUBLIC; } + + /** + * Determine if a campaign is discreet + */ + public function isDiscreet(): bool + { + return $this->is_discreet; + } + /** * * Determine if a campaign is open to submissions diff --git a/app/Models/Scopes/CampaignScopes.php b/app/Models/Scopes/CampaignScopes.php index 272420fdc9..f5be9d4011 100644 --- a/app/Models/Scopes/CampaignScopes.php +++ b/app/Models/Scopes/CampaignScopes.php @@ -89,6 +89,14 @@ public function scopeOpen(Builder $query, bool $open = true): Builder return $query->where('is_open', $open); } + + /** + */ + public function scopeDiscreet(Builder $query, bool $discreet = true): Builder + { + return $query->where('is_discreet', $discreet); + } + /** * Admin crud datagrid */ diff --git a/app/Observers/CampaignObserver.php b/app/Observers/CampaignObserver.php index 2f15d9f5d2..95f36278be 100644 --- a/app/Observers/CampaignObserver.php +++ b/app/Observers/CampaignObserver.php @@ -53,7 +53,7 @@ public function saving(Campaign $campaign) $isPublic = request()->get('is_public', null); if (!empty($isPublic) && $previousVisibility == Campaign::VISIBILITY_PRIVATE) { $campaign->visibility_id = Campaign::VISIBILITY_PUBLIC; - // Default to public for now. Later will have REVIEW mode. + // Default to public for now. Later will have REVIEW mode. } elseif (empty($isPublic) && $previousVisibility != Campaign::VISIBILITY_PRIVATE) { $campaign->visibility_id = Campaign::VISIBILITY_PRIVATE; } diff --git a/app/Renderers/DatagridRenderer2.php b/app/Renderers/DatagridRenderer2.php index d475ea333a..3e9ccc320c 100644 --- a/app/Renderers/DatagridRenderer2.php +++ b/app/Renderers/DatagridRenderer2.php @@ -158,7 +158,7 @@ public function bulks(): array } continue; } - // More specific use cases? + // More specific use cases? } elseif ($bulk === Layout::ACTION_DELETE) { if (auth()->check() && auth()->user()->isAdmin()) { $this->bulks[] = $bulk; diff --git a/app/Services/Api/CampaignService.php b/app/Services/Api/CampaignService.php index 29fae133b0..23941b5d0b 100644 --- a/app/Services/Api/CampaignService.php +++ b/app/Services/Api/CampaignService.php @@ -91,7 +91,7 @@ protected function featured(): self { $this->data['featured'] = []; - $campaigns = Campaign::public()->front()->featured()->get(); + $campaigns = Campaign::public()->front()->featured()->discreet(false)->get(); foreach ($campaigns as $campaign) { $this->data['featured'][] = new CampaignResource($campaign); } @@ -112,6 +112,7 @@ protected function campaigns(): self ->front((int)$this->request->get('sort_field_name')) ->featured(false) ->filterPublic($this->request->only(['language', 'system', 'is_boosted', 'is_open', 'genre'])) + ->discreet(false) ->paginate(); $this->data['campaigns'] = CampaignResource::collection($campaigns); } diff --git a/app/Services/Campaign/BoostService.php b/app/Services/Campaign/BoostService.php index 99a521aec7..356fa61381 100644 --- a/app/Services/Campaign/BoostService.php +++ b/app/Services/Campaign/BoostService.php @@ -121,8 +121,10 @@ public function unboost(CampaignBoost $campaignBoost): self } $this->user->log(UserLog::TYPE_CAMPAIGN_UNBOOST); } + $boostCount = $this->campaign->boosts()->count(); + $this->campaign->boost_count = $boostCount; + $this->campaign->is_discreet = 0; - $this->campaign->boost_count = $this->campaign->boosts()->count(); $this->campaign->saveQuietly(); if (isset($this->user)) { diff --git a/database/migrations/2024_01_26_194006_update_campaigns_add_is_discreet.php b/database/migrations/2024_01_26_194006_update_campaigns_add_is_discreet.php new file mode 100644 index 0000000000..f9ce8a8198 --- /dev/null +++ b/database/migrations/2024_01_26_194006_update_campaigns_add_is_discreet.php @@ -0,0 +1,29 @@ +boolean('is_discreet')->default(0); + $table->index('is_discreet'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('campaigns', function (Blueprint $table) { + $table->dropIndex(['is_discreet']); + $table->dropColumn('is_discreet'); + }); + } +}; diff --git a/lang/en/campaigns.php b/lang/en/campaigns.php index d8b3daa2a6..9b6e3cc7c0 100644 --- a/lang/en/campaigns.php +++ b/lang/en/campaigns.php @@ -47,6 +47,7 @@ 'connections' => 'Show an entity\'s connection table by default (instead of relation explorer for premium campaigns)', 'css' => 'CSS', 'description' => 'Description', + 'is_discreet' => 'Discreet setting', 'entity_count' => 'Entity Count', 'entity_privacy' => 'Default new entity privacy', 'entry' => 'Campaign description', @@ -85,6 +86,7 @@ '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.', + 'is_discreet' => 'If enabled, the campaign will be public, but not displayed in the public campaigns interface (exclusive to premium campaigns).', 'locale' => 'The language your campaign is written in. This is used for generating content and grouping public campaigns.', 'name' => 'Your campaign/world can have any name as long as it contains at least 4 letters or numbers.', 'no_entry' => 'Looks like the campaign doesn\'t have a description yet! Let\'s fix that.', diff --git a/resources/views/campaigns/forms/panes/public.blade.php b/resources/views/campaigns/forms/panes/public.blade.php index f70f9afb68..f933cce1b1 100644 --- a/resources/views/campaigns/forms/panes/public.blade.php +++ b/resources/views/campaigns/forms/panes/public.blade.php @@ -83,6 +83,12 @@ 'quickCreator' => false ]]) + + {!! Form::hidden('is_discreet', 0) !!} + + {!! Form::checkbox('is_discreet', 1, $model->is_discreet ?? '', ['disabled' => !$model->boosted() ? 'disabled' : null]) !!} + + diff --git a/tests/Feature/FrontCampaignTest.php b/tests/Feature/FrontCampaignTest.php index 2caecc1bb8..e8a765e8c6 100644 --- a/tests/Feature/FrontCampaignTest.php +++ b/tests/Feature/FrontCampaignTest.php @@ -85,3 +85,11 @@ ->assertStatus(200) ->assertJsonCount(1, 'campaigns'); ; + +it('public campaigns GET buut no results due to is_discreet') + ->asUser() + ->withCampaign(['is_discreet' => true]) + ->get('/api/public/campaigns') + ->assertStatus(200) + ->assertJsonCount(0, 'campaigns') +;