Skip to content

Commit

Permalink
Merge pull request #809 from owlchester/premium-public-but-not-visible
Browse files Browse the repository at this point in the history
Premium: Public but not visible in public.
  • Loading branch information
ilestis authored Jan 31, 2024
2 parents b96176f + d9ee472 commit ed03f7d
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/Models/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +99,7 @@ class Campaign extends Model
'ui_settings',
'settings',
'is_open',
'is_discreet',
];

protected $casts = [
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Scopes/CampaignScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Api/CampaignService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Services/Campaign/BoostService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('campaigns', function (Blueprint $table) {
$table->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');
});
}
};
2 changes: 2 additions & 0 deletions lang/en/campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.',
Expand Down
6 changes: 6 additions & 0 deletions resources/views/campaigns/forms/panes/public.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
'quickCreator' => false
]])
</x-forms.field>
<x-forms.field field="discreet" :label="__('campaigns.fields.is_discreet')" :disabled="true">
{!! Form::hidden('is_discreet', 0) !!}
<x-checkbox :text="__('campaigns.helpers.is_discreet')">
{!! Form::checkbox('is_discreet', 1, $model->is_discreet ?? '', ['disabled' => !$model->boosted() ? 'disabled' : null]) !!}
</x-checkbox>
</x-forms.field>
</x-grid>

</x-grid>
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/FrontCampaignTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
;

0 comments on commit ed03f7d

Please sign in to comment.