From 7c39aff5a50e5c0f27df3163c3a28dfb855a175f Mon Sep 17 00:00:00 2001 From: Spitfire Date: Fri, 26 Jan 2024 16:35:12 -0600 Subject: [PATCH 1/3] Premium: Public but not visible in public. --- app/Models/Campaign.php | 11 +++++++ app/Models/Scopes/CampaignScopes.php | 8 +++++ app/Services/Api/CampaignService.php | 5 ++-- app/Services/Campaign/BoostService.php | 7 +++-- ...94006_update_campaigns_add_is_discreet.php | 30 +++++++++++++++++++ lang/en/campaigns.php | 2 ++ .../campaigns/forms/panes/public.blade.php | 6 ++++ tests/Feature/FrontCampaignTest.php | 8 +++++ 8 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2024_01_26_194006_update_campaigns_add_is_discreet.php 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/Services/Api/CampaignService.php b/app/Services/Api/CampaignService.php index 29fae133b0..923cded23d 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); } @@ -105,13 +105,14 @@ protected function campaigns(): self { $this->data['campaigns'] = []; - if ($this->isDefaultRequest()) { + if (!$this->isDefaultRequest()) { $this->data['campaigns'] = $this->cachedCampaigns(); } else { $campaigns = Campaign::public() ->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..17139166c1 100644 --- a/app/Services/Campaign/BoostService.php +++ b/app/Services/Campaign/BoostService.php @@ -121,8 +121,11 @@ public function unboost(CampaignBoost $campaignBoost): self } $this->user->log(UserLog::TYPE_CAMPAIGN_UNBOOST); } - - $this->campaign->boost_count = $this->campaign->boosts()->count(); + $boostCount = $this->campaign->boosts()->count(); + $this->campaign->boost_count = $boostCount; + if ($boostCount == 0 && $this->campaign->isDiscreet()) { + $this->campaign->is_discreet = 0; + } $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..984543f6ba --- /dev/null +++ b/database/migrations/2024_01_26_194006_update_campaigns_add_is_discreet.php @@ -0,0 +1,30 @@ +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') +; From 9311e7e79670253a3f6ae4abaef7bf42f65aefc3 Mon Sep 17 00:00:00 2001 From: spitfire305 Date: Fri, 26 Jan 2024 22:37:14 +0000 Subject: [PATCH 2/3] Fix styling --- app/Observers/CampaignObserver.php | 2 +- app/Renderers/DatagridRenderer2.php | 2 +- .../2024_01_26_194006_update_campaigns_add_is_discreet.php | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) 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/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 index 984543f6ba..f9ce8a8198 100644 --- 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 @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */ From d9ee472eead5535c163a692f7f566a1fd3e4d1c0 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Wed, 31 Jan 2024 12:52:22 -0600 Subject: [PATCH 3/3] Implemented requested changes. --- app/Services/Api/CampaignService.php | 2 +- app/Services/Campaign/BoostService.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Services/Api/CampaignService.php b/app/Services/Api/CampaignService.php index 923cded23d..23941b5d0b 100644 --- a/app/Services/Api/CampaignService.php +++ b/app/Services/Api/CampaignService.php @@ -105,7 +105,7 @@ protected function campaigns(): self { $this->data['campaigns'] = []; - if (!$this->isDefaultRequest()) { + if ($this->isDefaultRequest()) { $this->data['campaigns'] = $this->cachedCampaigns(); } else { $campaigns = Campaign::public() diff --git a/app/Services/Campaign/BoostService.php b/app/Services/Campaign/BoostService.php index 17139166c1..356fa61381 100644 --- a/app/Services/Campaign/BoostService.php +++ b/app/Services/Campaign/BoostService.php @@ -123,9 +123,8 @@ public function unboost(CampaignBoost $campaignBoost): self } $boostCount = $this->campaign->boosts()->count(); $this->campaign->boost_count = $boostCount; - if ($boostCount == 0 && $this->campaign->isDiscreet()) { - $this->campaign->is_discreet = 0; - } + $this->campaign->is_discreet = 0; + $this->campaign->saveQuietly(); if (isset($this->user)) {