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

Premium: Public but not visible in public. #809

Merged
merged 3 commits into from
Jan 31, 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
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 @@
'ui_settings',
'settings',
'is_open',
'is_discreet',
];

protected $casts = [
Expand Down Expand Up @@ -157,7 +159,7 @@
public function admins()
{
$users = [];
foreach ($this->roles()->with(['users', 'users.user'])->where('is_admin', '1')->get() as $role) {

Check failure on line 162 in app/Models/Campaign.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Relation 'user' is not found in App\Models\CampaignRoleUser model.
foreach ($role->users as $user) {
if (!isset($users[$user->id])) {
$users[$user->user->id] = $user->user;
Expand Down Expand Up @@ -227,6 +229,15 @@
{
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
2 changes: 1 addition & 1 deletion app/Observers/CampaignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$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;
}
Expand Down Expand Up @@ -235,7 +235,7 @@

$existing = [];
/** @var GameSystems $systems */
foreach ($campaign->systems as $system) {

Check failure on line 238 in app/Observers/CampaignObserver.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

PHPDoc tag @var for variable $systems contains unknown class App\Observers\GameSystems.
$existing[$system->id] = $system->name;
}
$new = [];
Expand Down
2 changes: 1 addition & 1 deletion app/Renderers/DatagridRenderer2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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')
;
Loading