Commit workspace changes
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\PinGroupActivityItemRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupActivityItem;
|
||||
use App\Services\GroupActivityService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupActivityStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupActivityService $activity,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupActivity', [
|
||||
'title' => $group->name . ' Activity',
|
||||
'description' => 'Track public and internal group events from one activity timeline.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'activity' => $this->activity->studioFeed($group, $request->user(), 30),
|
||||
'pinPattern' => $group->canPinActivity($request->user()) ? route('studio.groups.activity.pin', ['group' => $group, 'item' => '__ITEM__']) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function pin(PinGroupActivityItemRequest $request, Group $group, GroupActivityItem $item): RedirectResponse
|
||||
{
|
||||
$this->authorize('pinActivity', $group);
|
||||
abort_unless((int) $item->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->activity->pin($item, $request->user(), (bool) $request->boolean('is_pinned', ! $item->is_pinned));
|
||||
|
||||
return back()->with('success', 'Activity updated.');
|
||||
}
|
||||
}
|
||||
63
app/Http/Controllers/Studio/GroupAssetStudioController.php
Normal file
63
app/Http/Controllers/Studio/GroupAssetStudioController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\StoreGroupAssetRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupAssetRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupAsset;
|
||||
use App\Services\GroupAssetService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupAssetStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupAssetService $assets,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupAssets', [
|
||||
'title' => $group->name . ' Assets',
|
||||
'description' => 'Manage reusable group files, templates, brand assets, and reference packs.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->assets->studioListing($group, $request->user(), $request->only(['bucket', 'category', 'q', 'page', 'per_page'])),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'categoryOptions' => collect((array) config('groups.assets.categories', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.assets.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'statusOptions' => collect((array) config('groups.assets.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'storeUrl' => $group->canManageAssets($request->user()) ? route('studio.groups.assets.store', ['group' => $group]) : null,
|
||||
'updatePattern' => $group->canManageAssets($request->user()) ? route('studio.groups.assets.update', ['group' => $group, 'asset' => '__ASSET__']) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupAssetRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageAssets', $group);
|
||||
|
||||
$this->assets->store($group, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Asset uploaded.');
|
||||
}
|
||||
|
||||
public function update(UpdateGroupAssetRequest $request, Group $group, GroupAsset $asset): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageAssets', $group);
|
||||
abort_unless((int) $asset->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->assets->update($asset, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Asset updated.');
|
||||
}
|
||||
}
|
||||
126
app/Http/Controllers/Studio/GroupChallengeStudioController.php
Normal file
126
app/Http/Controllers/Studio/GroupChallengeStudioController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\AttachArtworkToGroupChallengeRequest;
|
||||
use App\Http\Requests\Groups\StoreGroupChallengeRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupChallengeRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupChallenge;
|
||||
use App\Services\GroupChallengeService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupChallengeStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupChallengeService $challenges,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupChallenges', [
|
||||
'title' => $group->name . ' Challenges',
|
||||
'description' => 'Run creative prompts, themed sprints, and public or internal participation campaigns.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->challenges->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
'createUrl' => route('studio.groups.challenges.create', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupChallengeEditor', [
|
||||
'title' => 'Create challenge',
|
||||
'description' => 'Set the timeline, rules, and participation model for a new group challenge.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'challenge' => null,
|
||||
'statusOptions' => collect((array) config('groups.challenges.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.challenges.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'participationScopeOptions' => collect((array) config('groups.challenges.participation_scopes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'judgingModeOptions' => collect((array) config('groups.challenges.judging_modes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'storeUrl' => route('studio.groups.challenges.store', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupChallengeRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
|
||||
$challenge = $this->challenges->create($group, $request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.challenges.edit', ['group' => $group, 'challenge' => $challenge])
|
||||
->with('success', 'Challenge created.');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Group $group, GroupChallenge $challenge): Response
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupChallengeEditor', [
|
||||
'title' => 'Edit challenge',
|
||||
'description' => 'Publish and curate challenge entries from one editing view.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'challenge' => $this->challenges->detailPayload($challenge, $request->user()),
|
||||
'statusOptions' => collect((array) config('groups.challenges.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.challenges.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'participationScopeOptions' => collect((array) config('groups.challenges.participation_scopes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'judgingModeOptions' => collect((array) config('groups.challenges.judging_modes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'updateUrl' => route('studio.groups.challenges.update', ['group' => $group, 'challenge' => $challenge]),
|
||||
'publishUrl' => route('studio.groups.challenges.publish', ['group' => $group, 'challenge' => $challenge]),
|
||||
'attachArtworkUrl' => route('studio.groups.challenges.attach-artwork', ['group' => $group, 'challenge' => $challenge]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupChallengeRequest $request, Group $group, GroupChallenge $challenge): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->challenges->update($challenge, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Challenge updated.');
|
||||
}
|
||||
|
||||
public function publish(Request $request, Group $group, GroupChallenge $challenge): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->challenges->publish($challenge, $request->user());
|
||||
|
||||
return back()->with('success', 'Challenge published.');
|
||||
}
|
||||
|
||||
public function attachArtwork(AttachArtworkToGroupChallengeRequest $request, Group $group, GroupChallenge $challenge): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageChallenges', $group);
|
||||
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
|
||||
|
||||
$artwork = Artwork::query()->findOrFail((int) $request->validated('artwork_id'));
|
||||
$this->challenges->attachArtwork($challenge, $artwork, $request->user());
|
||||
|
||||
return back()->with('success', 'Artwork attached to challenge.');
|
||||
}
|
||||
}
|
||||
110
app/Http/Controllers/Studio/GroupEventStudioController.php
Normal file
110
app/Http/Controllers/Studio/GroupEventStudioController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\StoreGroupEventRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupEventRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupEvent;
|
||||
use App\Services\GroupEventService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupEventStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupEventService $events,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageEvents', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupEvents', [
|
||||
'title' => $group->name . ' Events',
|
||||
'description' => 'Manage launches, milestones, streams, and timeline-aware group moments.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->events->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
'createUrl' => route('studio.groups.events.create', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageEvents', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupEventEditor', [
|
||||
'title' => 'Create event',
|
||||
'description' => 'Schedule a release, internal session, livestream, or other group event.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'event' => null,
|
||||
'typeOptions' => collect((array) config('groups.events.types', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'statusOptions' => collect((array) config('groups.events.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.events.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'challengeOptions' => $group->challenges()->orderBy('title')->get(['id', 'title'])->map(fn ($challenge): array => ['id' => (int) $challenge->id, 'title' => $challenge->title])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'storeUrl' => route('studio.groups.events.store', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupEventRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageEvents', $group);
|
||||
|
||||
$event = $this->events->create($group, $request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.events.edit', ['group' => $group, 'event' => $event])
|
||||
->with('success', 'Event created.');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Group $group, GroupEvent $event): Response
|
||||
{
|
||||
abort_unless($group->canManageEvents($request->user()) || $group->canPublishEventUpdates($request->user()), 403);
|
||||
abort_unless((int) $event->group_id === (int) $group->id, 404);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupEventEditor', [
|
||||
'title' => 'Edit event',
|
||||
'description' => 'Refine public details and publish event updates safely.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'event' => $this->events->detailPayload($event),
|
||||
'typeOptions' => collect((array) config('groups.events.types', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'statusOptions' => collect((array) config('groups.events.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.events.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'challengeOptions' => $group->challenges()->orderBy('title')->get(['id', 'title'])->map(fn ($challenge): array => ['id' => (int) $challenge->id, 'title' => $challenge->title])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'updateUrl' => route('studio.groups.events.update', ['group' => $group, 'event' => $event]),
|
||||
'publishUrl' => route('studio.groups.events.publish', ['group' => $group, 'event' => $event]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupEventRequest $request, Group $group, GroupEvent $event): RedirectResponse
|
||||
{
|
||||
abort_unless($group->canManageEvents($request->user()) || $group->canPublishEventUpdates($request->user()), 403);
|
||||
abort_unless((int) $event->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->events->update($event, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Event updated.');
|
||||
}
|
||||
|
||||
public function publish(Request $request, Group $group, GroupEvent $event): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageEvents', $group);
|
||||
abort_unless((int) $event->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->events->publish($event, $request->user());
|
||||
|
||||
return back()->with('success', 'Event published.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\ReviewGroupJoinRequestRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupJoinRequest;
|
||||
use App\Services\GroupJoinRequestService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupJoinRequestStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupJoinRequestService $joinRequests,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('reviewJoinRequests', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupJoinRequests', [
|
||||
'title' => $group->name . ' Join requests',
|
||||
'description' => 'Review incoming applications, compare requested roles, and approve or reject requests with audit history.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->joinRequests->mapRequests($group, $request->user(), $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
'roleOptions' => [
|
||||
['value' => Group::ROLE_MEMBER, 'label' => 'Contributor'],
|
||||
['value' => Group::ROLE_EDITOR, 'label' => 'Editor'],
|
||||
['value' => Group::ROLE_ADMIN, 'label' => 'Admin'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function approve(ReviewGroupJoinRequestRequest $request, Group $group, GroupJoinRequest $joinRequest): RedirectResponse
|
||||
{
|
||||
$this->authorize('reviewJoinRequests', $group);
|
||||
abort_unless((int) $joinRequest->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->joinRequests->approve(
|
||||
$joinRequest,
|
||||
$request->user(),
|
||||
$request->validated('role'),
|
||||
$request->validated('review_notes'),
|
||||
);
|
||||
|
||||
return back()->with('success', 'Join request approved.');
|
||||
}
|
||||
|
||||
public function reject(ReviewGroupJoinRequestRequest $request, Group $group, GroupJoinRequest $joinRequest): RedirectResponse
|
||||
{
|
||||
$this->authorize('reviewJoinRequests', $group);
|
||||
abort_unless((int) $joinRequest->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->joinRequests->reject(
|
||||
$joinRequest,
|
||||
$request->user(),
|
||||
$request->validated('review_notes'),
|
||||
);
|
||||
|
||||
return back()->with('success', 'Join request rejected.');
|
||||
}
|
||||
}
|
||||
133
app/Http/Controllers/Studio/GroupPostStudioController.php
Normal file
133
app/Http/Controllers/Studio/GroupPostStudioController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\StoreGroupPostRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupPostRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupPost;
|
||||
use App\Services\GroupPostService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupPostStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupPostService $posts,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupPosts', [
|
||||
'title' => $group->name . ' Posts',
|
||||
'description' => 'Publish announcements, releases, recruitment calls, and pinned updates from the group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->posts->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
'createUrl' => route('studio.groups.posts.create', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupPostEditor', [
|
||||
'title' => 'Create post',
|
||||
'description' => 'Draft a new public announcement for the group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'post' => null,
|
||||
'typeOptions' => $this->typeOptions(),
|
||||
'storeUrl' => route('studio.groups.posts.store', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupPostRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
|
||||
$post = $this->posts->create($group, $request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.posts.edit', ['group' => $group, 'post' => $post])
|
||||
->with('success', 'Draft created.');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Group $group, GroupPost $post): Response
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
abort_unless((int) $post->group_id === (int) $group->id, 404);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupPostEditor', [
|
||||
'title' => 'Edit post',
|
||||
'description' => 'Update copy, publish state, and pinned status for this group post.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'post' => $this->posts->mapStudioPost($group, $post),
|
||||
'typeOptions' => $this->typeOptions(),
|
||||
'storeUrl' => null,
|
||||
'updateUrl' => route('studio.groups.posts.update', ['group' => $group, 'post' => $post]),
|
||||
'publishUrl' => route('studio.groups.posts.publish', ['group' => $group, 'post' => $post]),
|
||||
'pinUrl' => route('studio.groups.posts.pin', ['group' => $group, 'post' => $post]),
|
||||
'archiveUrl' => route('studio.groups.posts.archive', ['group' => $group, 'post' => $post]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupPostRequest $request, Group $group, GroupPost $post): RedirectResponse
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
abort_unless((int) $post->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->posts->update($post, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Post updated.');
|
||||
}
|
||||
|
||||
public function publish(Request $request, Group $group, GroupPost $post): RedirectResponse
|
||||
{
|
||||
$this->authorize('publishPosts', $group);
|
||||
abort_unless((int) $post->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->posts->publish($post, $request->user());
|
||||
|
||||
return back()->with('success', 'Post published.');
|
||||
}
|
||||
|
||||
public function pin(Request $request, Group $group, GroupPost $post): RedirectResponse
|
||||
{
|
||||
$this->authorize('pinPosts', $group);
|
||||
abort_unless((int) $post->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->posts->pin($post, $request->user(), ! $post->is_pinned);
|
||||
|
||||
return back()->with('success', $post->is_pinned ? 'Post unpinned.' : 'Post pinned.');
|
||||
}
|
||||
|
||||
public function archive(Request $request, Group $group, GroupPost $post): RedirectResponse
|
||||
{
|
||||
$this->authorize('managePosts', $group);
|
||||
abort_unless((int) $post->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->posts->archive($post, $request->user());
|
||||
|
||||
return back()->with('success', 'Post archived.');
|
||||
}
|
||||
|
||||
private function typeOptions(): array
|
||||
{
|
||||
return [
|
||||
['value' => GroupPost::TYPE_ANNOUNCEMENT, 'label' => 'Announcement'],
|
||||
['value' => GroupPost::TYPE_RELEASE, 'label' => 'Release'],
|
||||
['value' => GroupPost::TYPE_RECRUITMENT, 'label' => 'Recruitment'],
|
||||
['value' => GroupPost::TYPE_UPDATE, 'label' => 'Update'],
|
||||
];
|
||||
}
|
||||
}
|
||||
167
app/Http/Controllers/Studio/GroupProjectStudioController.php
Normal file
167
app/Http/Controllers/Studio/GroupProjectStudioController.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\AttachArtworkToGroupProjectRequest;
|
||||
use App\Http\Requests\Groups\AttachAssetToGroupProjectRequest;
|
||||
use App\Http\Requests\Groups\StoreGroupMilestoneRequest;
|
||||
use App\Http\Requests\Groups\StoreGroupProjectRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupMilestoneRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupProjectRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupProjectStatusRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupAsset;
|
||||
use App\Models\GroupPost;
|
||||
use App\Models\GroupProject;
|
||||
use App\Models\GroupProjectMilestone;
|
||||
use App\Services\GroupProjectService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupProjectStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupProjectService $projects,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupProjects', [
|
||||
'title' => $group->name . ' Projects',
|
||||
'description' => 'Manage structured group releases, collaboration hubs, and showcase pages.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->projects->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
'createUrl' => route('studio.groups.projects.create', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupProjectEditor', [
|
||||
'title' => 'Create project',
|
||||
'description' => 'Set up a project page that can collect artworks, assets, notes, and release state.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'project' => null,
|
||||
'statusOptions' => collect((array) config('groups.projects.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.projects.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'memberOptions' => $this->projects->memberOptions($group->loadMissing('owner.profile')),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'postOptions' => $group->posts()->latest('updated_at')->limit(20)->get(['id', 'title'])->map(fn (GroupPost $post): array => ['id' => (int) $post->id, 'title' => $post->title])->values()->all(),
|
||||
'storeUrl' => route('studio.groups.projects.store', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupProjectRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
|
||||
$project = $this->projects->create($group, $request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.projects.edit', ['group' => $group, 'project' => $project])
|
||||
->with('success', 'Project created.');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Group $group, GroupProject $project): Response
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupProjectEditor', [
|
||||
'title' => 'Edit project',
|
||||
'description' => 'Update status, attachments, and project presentation.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'project' => $this->projects->detailPayload($project, $request->user()),
|
||||
'statusOptions' => collect((array) config('groups.projects.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.projects.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'memberOptions' => $this->projects->memberOptions($group->loadMissing('owner.profile')),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'assetOptions' => $group->assets()->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn (GroupAsset $asset): array => ['id' => (int) $asset->id, 'title' => $asset->title])->values()->all(),
|
||||
'postOptions' => $group->posts()->latest('updated_at')->limit(20)->get(['id', 'title'])->map(fn (GroupPost $post): array => ['id' => (int) $post->id, 'title' => $post->title])->values()->all(),
|
||||
'updateUrl' => route('studio.groups.projects.update', ['group' => $group, 'project' => $project]),
|
||||
'statusUrl' => route('studio.groups.projects.status', ['group' => $group, 'project' => $project]),
|
||||
'attachArtworkUrl' => route('studio.groups.projects.attach-artwork', ['group' => $group, 'project' => $project]),
|
||||
'attachAssetUrl' => route('studio.groups.projects.attach-asset', ['group' => $group, 'project' => $project]),
|
||||
'storeMilestoneUrl' => route('studio.groups.projects.milestones.store', ['group' => $group, 'project' => $project]),
|
||||
'updateMilestonePattern' => route('studio.groups.projects.milestones.update', ['group' => $group, 'project' => $project, 'milestone' => '__MILESTONE__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupProjectRequest $request, Group $group, GroupProject $project): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->projects->update($project, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Project updated.');
|
||||
}
|
||||
|
||||
public function attachArtwork(AttachArtworkToGroupProjectRequest $request, Group $group, GroupProject $project): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
$artwork = Artwork::query()->findOrFail((int) $request->validated('artwork_id'));
|
||||
$this->projects->attachArtwork($project, $artwork, $request->user());
|
||||
|
||||
return back()->with('success', 'Artwork attached to project.');
|
||||
}
|
||||
|
||||
public function attachAsset(AttachAssetToGroupProjectRequest $request, Group $group, GroupProject $project): RedirectResponse
|
||||
{
|
||||
$this->authorize('attachAssetsToProjects', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
$asset = GroupAsset::query()->findOrFail((int) $request->validated('asset_id'));
|
||||
$this->projects->attachAsset($project, $asset, $request->user());
|
||||
|
||||
return back()->with('success', 'Asset attached to project.');
|
||||
}
|
||||
|
||||
public function status(UpdateGroupProjectStatusRequest $request, Group $group, GroupProject $project): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageProjects', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->projects->updateStatus($project, $request->user(), (string) $request->validated('status'));
|
||||
|
||||
return back()->with('success', 'Project status updated.');
|
||||
}
|
||||
|
||||
public function storeMilestone(StoreGroupMilestoneRequest $request, Group $group, GroupProject $project): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageMilestones', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->projects->createMilestone($project, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Project milestone created.');
|
||||
}
|
||||
|
||||
public function updateMilestone(UpdateGroupMilestoneRequest $request, Group $group, GroupProject $project, GroupProjectMilestone $milestone): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageMilestones', $group);
|
||||
abort_unless((int) $project->group_id === (int) $group->id, 404);
|
||||
abort_unless((int) $milestone->group_project_id === (int) $project->id, 404);
|
||||
|
||||
$this->projects->updateMilestone($milestone, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Project milestone updated.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\UpdateGroupRecruitmentRequest;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupRecruitmentService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupRecruitmentStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupRecruitmentService $recruitment,
|
||||
) {
|
||||
}
|
||||
|
||||
public function show(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageRecruitment', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupRecruitment', [
|
||||
'title' => $group->name . ' Recruitment',
|
||||
'description' => 'Show open roles publicly, describe your workflow, and control how applicants should get in touch.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'recruitment' => $this->groups->recruitmentPayload($group),
|
||||
'contactModes' => [
|
||||
['value' => 'join_request', 'label' => 'Join request'],
|
||||
['value' => 'direct_message', 'label' => 'Direct message'],
|
||||
['value' => 'external_link', 'label' => 'External link'],
|
||||
],
|
||||
'visibilityOptions' => [
|
||||
['value' => 'public', 'label' => 'Public'],
|
||||
['value' => 'members_only', 'label' => 'Members only'],
|
||||
['value' => 'private', 'label' => 'Private'],
|
||||
],
|
||||
'roleOptions' => collect(config('groups.recruitment.roles', []))
|
||||
->map(fn (string $role): array => ['value' => $role, 'label' => $role])
|
||||
->values()
|
||||
->all(),
|
||||
'skillOptions' => collect(config('groups.recruitment.skills', []))
|
||||
->map(fn (string $skill): array => ['value' => $skill, 'label' => $skill])
|
||||
->values()
|
||||
->all(),
|
||||
'updateUrl' => route('studio.groups.recruitment.update', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupRecruitmentRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageRecruitment', $group);
|
||||
|
||||
$this->recruitment->upsert($group, $request->validated(), $request->user());
|
||||
|
||||
return back()->with('success', 'Recruitment profile updated.');
|
||||
}
|
||||
}
|
||||
177
app/Http/Controllers/Studio/GroupReleaseStudioController.php
Normal file
177
app/Http/Controllers/Studio/GroupReleaseStudioController.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\AttachArtworkToGroupReleaseRequest;
|
||||
use App\Http\Requests\Groups\AttachContributorToGroupReleaseRequest;
|
||||
use App\Http\Requests\Groups\StoreGroupMilestoneRequest;
|
||||
use App\Http\Requests\Groups\StoreGroupReleaseRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupMilestoneRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupReleaseRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupReleaseStageRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupRelease;
|
||||
use App\Models\GroupReleaseMilestone;
|
||||
use App\Models\User;
|
||||
use App\Services\GroupReleaseService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupReleaseStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupReleaseService $releases,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupReleases', [
|
||||
'title' => $group->name . ' Releases',
|
||||
'description' => 'Manage release pipelines, contributors, and publication stages for major group drops.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->releases->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
|
||||
'createUrl' => route('studio.groups.releases.create', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupReleaseEditor', [
|
||||
'title' => 'Create release',
|
||||
'description' => 'Build a release page and move it from concept through publishing.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'release' => null,
|
||||
'statusOptions' => collect((array) config('groups.releases.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => str_replace('_', ' ', ucfirst($value))])->values()->all(),
|
||||
'stageOptions' => collect((array) config('groups.releases.stages', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.releases.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'memberOptions' => $this->releases->memberOptions($group->loadMissing('owner.profile')),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'storeUrl' => route('studio.groups.releases.store', ['group' => $group]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupReleaseRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
|
||||
$release = $this->releases->create($group, $request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.releases.show', ['group' => $group, 'release' => $release])
|
||||
->with('success', 'Release created.');
|
||||
}
|
||||
|
||||
public function show(Request $request, Group $group, GroupRelease $release): Response
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupReleaseEditor', [
|
||||
'title' => 'Edit release',
|
||||
'description' => 'Update the release story, stage, contributors, and publish plan.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'release' => $this->releases->detailPayload($release, $request->user()),
|
||||
'statusOptions' => collect((array) config('groups.releases.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => str_replace('_', ' ', ucfirst($value))])->values()->all(),
|
||||
'stageOptions' => collect((array) config('groups.releases.stages', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'visibilityOptions' => collect((array) config('groups.releases.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
|
||||
'memberOptions' => $this->releases->memberOptions($group->loadMissing('owner.profile')),
|
||||
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
|
||||
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
|
||||
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
|
||||
'updateUrl' => route('studio.groups.releases.update', ['group' => $group, 'release' => $release]),
|
||||
'stageUrl' => route('studio.groups.releases.stage', ['group' => $group, 'release' => $release]),
|
||||
'publishUrl' => route('studio.groups.releases.publish', ['group' => $group, 'release' => $release]),
|
||||
'attachArtworkUrl' => route('studio.groups.releases.attach-artwork', ['group' => $group, 'release' => $release]),
|
||||
'attachContributorUrl' => route('studio.groups.releases.attach-contributor', ['group' => $group, 'release' => $release]),
|
||||
'storeMilestoneUrl' => route('studio.groups.releases.milestones.store', ['group' => $group, 'release' => $release]),
|
||||
'updateMilestonePattern' => route('studio.groups.releases.milestones.update', ['group' => $group, 'release' => $release, 'milestone' => '__MILESTONE__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupReleaseRequest $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->releases->update($release, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Release updated.');
|
||||
}
|
||||
|
||||
public function stage(UpdateGroupReleaseStageRequest $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('moveReleaseStage', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->releases->updateStage($release, $request->user(), (string) $request->validated('current_stage'));
|
||||
|
||||
return back()->with('success', 'Release stage updated.');
|
||||
}
|
||||
|
||||
public function publish(Request $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('publishReleases', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->releases->publish($release, $request->user());
|
||||
|
||||
return back()->with('success', 'Release published.');
|
||||
}
|
||||
|
||||
public function attachArtwork(AttachArtworkToGroupReleaseRequest $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$artwork = Artwork::query()->findOrFail((int) $request->validated('artwork_id'));
|
||||
$this->releases->attachArtwork($release, $artwork, $request->user());
|
||||
|
||||
return back()->with('success', 'Artwork attached to release.');
|
||||
}
|
||||
|
||||
public function attachContributor(AttachContributorToGroupReleaseRequest $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageReleases', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$contributor = User::query()->findOrFail((int) $request->validated('user_id'));
|
||||
$this->releases->attachContributor($release, $contributor, $request->user(), $request->validated('role_label'));
|
||||
|
||||
return back()->with('success', 'Contributor attached to release.');
|
||||
}
|
||||
|
||||
public function storeMilestone(StoreGroupMilestoneRequest $request, Group $group, GroupRelease $release): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageMilestones', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
|
||||
$this->releases->createMilestone($release, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Release milestone created.');
|
||||
}
|
||||
|
||||
public function updateMilestone(UpdateGroupMilestoneRequest $request, Group $group, GroupRelease $release, GroupReleaseMilestone $milestone): RedirectResponse
|
||||
{
|
||||
$this->authorize('manageMilestones', $group);
|
||||
abort_unless((int) $release->group_id === (int) $group->id, 404);
|
||||
abort_unless((int) $milestone->group_release_id === (int) $release->id, 404);
|
||||
|
||||
$this->releases->updateMilestone($milestone, $request->user(), $request->validated());
|
||||
|
||||
return back()->with('success', 'Release milestone updated.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupDiscoveryService;
|
||||
use App\Services\GroupReputationService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupReputationStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupReputationService $reputation,
|
||||
private readonly GroupDiscoveryService $discovery,
|
||||
) {
|
||||
}
|
||||
|
||||
public function show(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewReputationDashboard', $group);
|
||||
|
||||
$this->reputation->refreshGroup($group);
|
||||
$metrics = $this->discovery->refresh($group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupReputation', [
|
||||
'title' => $group->name . ' Reputation',
|
||||
'description' => 'Review contributor reliability, badge unlocks, and internal trust metrics.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'reputation' => $this->reputation->summary($group),
|
||||
'trustSignals' => $this->reputation->trustSignals($group),
|
||||
'metrics' => [
|
||||
'freshness_score' => (float) $metrics->freshness_score,
|
||||
'activity_score' => (float) $metrics->activity_score,
|
||||
'release_score' => (float) $metrics->release_score,
|
||||
'trust_score' => (float) $metrics->trust_score,
|
||||
'collaboration_score' => (float) $metrics->collaboration_score,
|
||||
'last_calculated_at' => $metrics->last_calculated_at?->toISOString(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
62
app/Http/Controllers/Studio/GroupReviewStudioController.php
Normal file
62
app/Http/Controllers/Studio/GroupReviewStudioController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\ReviewGroupArtworkRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupArtworkReviewService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupReviewStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupArtworkReviewService $reviews,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupReviewQueue', [
|
||||
'title' => $group->name . ' Review queue',
|
||||
'description' => 'Approve, reject, or request changes for artwork submitted under this group identity.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->reviews->listing($group, $request->user(), $request->only(['bucket', 'page', 'per_page'])),
|
||||
'recentHistory' => $this->groups->recentHistory($group),
|
||||
]);
|
||||
}
|
||||
|
||||
public function approve(ReviewGroupArtworkRequest $request, Group $group, Artwork $artwork): RedirectResponse
|
||||
{
|
||||
$this->authorize('reviewSubmissions', $group);
|
||||
$this->reviews->approve($group, $artwork, $request->user(), $request->validated('review_notes'));
|
||||
|
||||
return back()->with('success', 'Artwork approved and published.');
|
||||
}
|
||||
|
||||
public function needsChanges(ReviewGroupArtworkRequest $request, Group $group, Artwork $artwork): RedirectResponse
|
||||
{
|
||||
$this->authorize('reviewSubmissions', $group);
|
||||
$this->reviews->requestChanges($group, $artwork, $request->user(), $request->validated('review_notes'));
|
||||
|
||||
return back()->with('success', 'Changes requested from the uploader.');
|
||||
}
|
||||
|
||||
public function reject(ReviewGroupArtworkRequest $request, Group $group, Artwork $artwork): RedirectResponse
|
||||
{
|
||||
$this->authorize('reviewSubmissions', $group);
|
||||
$this->reviews->reject($group, $artwork, $request->user(), $request->validated('review_notes'));
|
||||
|
||||
return back()->with('success', 'Artwork rejected.');
|
||||
}
|
||||
}
|
||||
235
app/Http/Controllers/Studio/GroupStudioController.php
Normal file
235
app/Http/Controllers/Studio/GroupStudioController.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Groups\StoreGroupRequest;
|
||||
use App\Http\Requests\Groups\UpdateGroupRequest;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupMembershipService;
|
||||
use App\Services\GroupService;
|
||||
use App\Services\GroupArtworkReviewService;
|
||||
use App\Services\GroupJoinRequestService;
|
||||
use App\Services\GroupReputationService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class GroupStudioController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupMembershipService $memberships,
|
||||
private readonly GroupJoinRequestService $joinRequests,
|
||||
private readonly GroupArtworkReviewService $artworkReviews,
|
||||
private readonly GroupReputationService $reputation,
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$groups = Group::query()
|
||||
->with(['owner.profile', 'members'])
|
||||
->where(function ($query) use ($user): void {
|
||||
$query->where('owner_user_id', $user->id)
|
||||
->orWhereHas('members', function ($memberQuery) use ($user): void {
|
||||
$memberQuery->where('user_id', $user->id)
|
||||
->where('status', Group::STATUS_ACTIVE);
|
||||
});
|
||||
})
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (Group $group): array => $this->groups->mapGroupCard($group, $user))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return Inertia::render('Studio/StudioGroupsIndex', [
|
||||
'title' => 'Groups',
|
||||
'description' => 'Create collective publishing identities, manage memberships, and switch into shared artwork and collection workflows.',
|
||||
'groups' => $groups,
|
||||
'pendingInvites' => $this->memberships->pendingInvitationsForUser($user),
|
||||
'endpoints' => [
|
||||
'create' => route('studio.groups.create'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
$this->authorize('create', Group::class);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupCreate', [
|
||||
'title' => 'Create Group',
|
||||
'description' => 'Set up a shared publishing identity for collaborative uploads and collections.',
|
||||
'visibilityOptions' => [
|
||||
['value' => Group::VISIBILITY_PUBLIC, 'label' => 'Public'],
|
||||
['value' => Group::VISIBILITY_UNLISTED, 'label' => 'Unlisted'],
|
||||
['value' => Group::VISIBILITY_PRIVATE, 'label' => 'Private'],
|
||||
],
|
||||
'membershipPolicyOptions' => [
|
||||
['value' => Group::MEMBERSHIP_INVITE_ONLY, 'label' => 'Invite only'],
|
||||
],
|
||||
'endpoints' => [
|
||||
'store' => route('studio.groups.store'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreGroupRequest $request): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', Group::class);
|
||||
|
||||
$group = $this->groups->createGroup($request->user(), $request->validated());
|
||||
|
||||
return redirect()->route('studio.groups.show', ['group' => $group]);
|
||||
}
|
||||
|
||||
public function show(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
$viewer = $request->user();
|
||||
|
||||
return Inertia::render('Studio/StudioGroupDashboard', [
|
||||
'title' => $group->name,
|
||||
'description' => $group->headline ?: 'Shared publishing overview for this group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $viewer),
|
||||
'dashboard' => $this->groups->studioDashboardSummary($group),
|
||||
'draftsPendingAction' => $this->groups->studioArtworkPreviewItems($group, 'drafts', 4),
|
||||
'recentArtworks' => $this->groups->studioArtworkPreviewItems($group, 'published', 6),
|
||||
'recentCollections' => $this->groups->studioCollectionPreviewItems($group, 4),
|
||||
'members' => $this->memberships->mapMembers($group, $viewer),
|
||||
'recentPosts' => $this->groups->recentPostCards($group, 3),
|
||||
'recentProjects' => $this->groups->recentProjectCards($group, $viewer, 3),
|
||||
'recentReleases' => $this->groups->recentReleaseCards($group, $viewer, 3),
|
||||
'recentChallenges' => $this->groups->recentChallengeCards($group, $viewer, 3),
|
||||
'recentEvents' => $this->groups->recentEventCards($group, $viewer, 3),
|
||||
'recentActivity' => $this->groups->studioActivityFeed($group, $viewer, 8),
|
||||
'recruitment' => $this->groups->recruitmentPayload($group),
|
||||
'reputationSummary' => $this->reputation->summary($group),
|
||||
'trustSignals' => $this->reputation->trustSignals($group),
|
||||
'pendingJoinRequests' => $group->canReviewJoinRequests($viewer)
|
||||
? $this->joinRequests->mapRequests($group, $viewer, ['bucket' => 'pending', 'per_page' => 4])['items']
|
||||
: [],
|
||||
'reviewQueuePreview' => $this->artworkReviews->listing($group, $viewer, ['bucket' => 'submitted', 'per_page' => 4])['items'],
|
||||
'recentHistory' => $this->groups->recentHistory($group, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
public function artworks(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupArtworks', [
|
||||
'title' => $group->name . ' Artworks',
|
||||
'description' => 'Browse every artwork published through this shared identity.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->groups->studioArtworkListing($group, $request->only(['bucket', 'q', 'page', 'per_page'])),
|
||||
'uploadUrl' => route('upload', ['group' => $group->slug]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function collections(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupCollections', [
|
||||
'title' => $group->name . ' Collections',
|
||||
'description' => 'Manage collections published under this group identity.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'listing' => $this->groups->studioCollectionListing($group, $request->only(['bucket', 'q', 'page', 'per_page'])),
|
||||
'createUrl' => route('settings.collections.create', ['group' => $group->slug]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function members(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('viewStudio', $group);
|
||||
$viewer = $request->user();
|
||||
$canManageMembers = $group->canManageMembers($viewer);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupMembers', [
|
||||
'title' => $group->name . ' Members',
|
||||
'description' => 'Invite, remove, and promote the people who can publish and curate under this group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $viewer),
|
||||
'members' => $this->memberships->mapMembers($group, $viewer),
|
||||
'canManageMembers' => $canManageMembers,
|
||||
'permissionOverrideOptions' => array_map(static fn (string $permission): array => [
|
||||
'value' => $permission,
|
||||
'label' => str_replace('_', ' ', $permission),
|
||||
], Group::allowedPermissionOverrides()),
|
||||
'endpoints' => $canManageMembers ? [
|
||||
'invite' => route('studio.groups.members.store', ['group' => $group]),
|
||||
'invitations' => route('studio.groups.invitations', ['group' => $group]),
|
||||
'updatePattern' => route('studio.groups.members.update', ['group' => $group, 'member' => '__MEMBER__']),
|
||||
'permissionsPattern' => route('studio.groups.members.permissions.update', ['group' => $group, 'member' => '__MEMBER__']),
|
||||
'transferPattern' => route('studio.groups.members.transfer', ['group' => $group, 'member' => '__MEMBER__']),
|
||||
'deletePattern' => route('studio.groups.members.destroy', ['group' => $group, 'member' => '__MEMBER__']),
|
||||
] : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function invitations(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('manageMembers', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupInvitations', [
|
||||
'title' => $group->name . ' Invitations',
|
||||
'description' => 'Manage outstanding invites, resend collaboration roles, and review recent invite history for this group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'members' => $this->memberships->mapMembers($group, $request->user()),
|
||||
'invitations' => $this->memberships->mapInvitations($group, $request->user()),
|
||||
'endpoints' => [
|
||||
'invite' => route('studio.groups.members.store', ['group' => $group]),
|
||||
'deletePattern' => route('studio.groups.invitations.destroy', ['group' => $group, 'invitation' => '__INVITATION__']),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function settings(Request $request, Group $group): Response
|
||||
{
|
||||
$this->authorize('update', $group);
|
||||
|
||||
return Inertia::render('Studio/StudioGroupSettings', [
|
||||
'title' => $group->name . ' Settings',
|
||||
'description' => 'Update the public presentation and collaboration defaults for this group.',
|
||||
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
|
||||
'featuredArtworkOptions' => $this->groups->studioFeaturedArtworkOptions($group),
|
||||
'visibilityOptions' => [
|
||||
['value' => Group::VISIBILITY_PUBLIC, 'label' => 'Public'],
|
||||
['value' => Group::VISIBILITY_UNLISTED, 'label' => 'Unlisted'],
|
||||
['value' => Group::VISIBILITY_PRIVATE, 'label' => 'Private'],
|
||||
],
|
||||
'membershipPolicyOptions' => [
|
||||
['value' => Group::MEMBERSHIP_INVITE_ONLY, 'label' => 'Invite only'],
|
||||
],
|
||||
'endpoints' => [
|
||||
'update' => route('studio.groups.update', ['group' => $group]),
|
||||
'archive' => route('studio.groups.archive', ['group' => $group]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateGroupRequest $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $group);
|
||||
|
||||
$group = $this->groups->updateGroup($group, $request->validated(), $request->user());
|
||||
|
||||
return redirect()->route('studio.groups.settings', ['group' => $group]);
|
||||
}
|
||||
|
||||
public function archive(Request $request, Group $group): RedirectResponse
|
||||
{
|
||||
$this->authorize('archive', $group);
|
||||
|
||||
$group = $this->groups->archiveGroup($group, $request->user());
|
||||
|
||||
return redirect()->route('studio.groups.settings', ['group' => $group]);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\Models\ContentType;
|
||||
use App\Models\ArtworkVersion;
|
||||
use App\Services\Cdn\ArtworkCdnPurgeService;
|
||||
use App\Services\ArtworkSearchIndexer;
|
||||
use App\Services\ArtworkAttributionService;
|
||||
use App\Services\TagService;
|
||||
use App\Services\ArtworkVersioningService;
|
||||
use App\Services\Studio\StudioArtworkQueryService;
|
||||
@@ -118,7 +119,7 @@ final class StudioArtworksApiController extends Controller
|
||||
* PUT /api/studio/artworks/{id}
|
||||
* Update artwork details (title, description, visibility).
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
public function update(Request $request, int $id, ArtworkAttributionService $attribution): JsonResponse
|
||||
{
|
||||
$artwork = $request->user()->artworks()->findOrFail($id);
|
||||
|
||||
@@ -138,8 +139,32 @@ final class StudioArtworksApiController extends Controller
|
||||
'description_source' => 'sometimes|nullable|string|in:manual,ai_generated,ai_applied,mixed',
|
||||
'tags_source' => 'sometimes|nullable|string|in:manual,ai_generated,ai_applied,mixed',
|
||||
'category_source' => 'sometimes|nullable|string|in:manual,ai_generated,ai_applied,mixed',
|
||||
'group' => 'sometimes|nullable|string|max:90',
|
||||
'primary_author_user_id' => 'sometimes|nullable|integer|min:1',
|
||||
'contributor_user_ids' => 'sometimes|array|max:20',
|
||||
'contributor_user_ids.*' => 'integer|min:1',
|
||||
'contributor_credits' => 'sometimes|array|max:20',
|
||||
'contributor_credits.*.user_id' => 'required|integer|min:1',
|
||||
'contributor_credits.*.credit_role' => 'nullable|string|max:80',
|
||||
'contributor_credits.*.is_primary' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$hasAttributionUpdates = array_key_exists('group', $validated)
|
||||
|| array_key_exists('primary_author_user_id', $validated)
|
||||
|| array_key_exists('contributor_user_ids', $validated)
|
||||
|| array_key_exists('contributor_credits', $validated);
|
||||
|
||||
$attributionPayload = [
|
||||
'group' => $validated['group'] ?? $artwork->group?->slug,
|
||||
'primary_author_user_id' => $validated['primary_author_user_id'] ?? $artwork->primary_author_user_id,
|
||||
'contributor_user_ids' => $validated['contributor_user_ids'] ?? $artwork->contributors()->pluck('user_id')->all(),
|
||||
'contributor_credits' => $validated['contributor_credits'] ?? $artwork->contributors()->get()->map(fn ($contributor): array => [
|
||||
'user_id' => (int) $contributor->user_id,
|
||||
'credit_role' => $contributor->credit_role,
|
||||
'is_primary' => (bool) $contributor->is_primary,
|
||||
])->values()->all(),
|
||||
];
|
||||
|
||||
$visibility = (string) ($validated['visibility'] ?? ($artwork->visibility ?: ((bool) $artwork->is_public ? Artwork::VISIBILITY_PUBLIC : Artwork::VISIBILITY_PRIVATE)));
|
||||
$mode = (string) ($validated['mode'] ?? ($artwork->artwork_status === 'scheduled' ? 'schedule' : 'now'));
|
||||
$timezone = array_key_exists('timezone', $validated)
|
||||
@@ -165,7 +190,7 @@ final class StudioArtworksApiController extends Controller
|
||||
$tags = $validated['tags'] ?? null;
|
||||
$categoryId = $validated['category_id'] ?? null;
|
||||
$contentTypeId = $validated['content_type_id'] ?? null;
|
||||
unset($validated['tags'], $validated['category_id'], $validated['content_type_id'], $validated['visibility'], $validated['mode'], $validated['publish_at'], $validated['timezone']);
|
||||
unset($validated['tags'], $validated['category_id'], $validated['content_type_id'], $validated['visibility'], $validated['mode'], $validated['publish_at'], $validated['timezone'], $validated['group'], $validated['primary_author_user_id'], $validated['contributor_user_ids'], $validated['contributor_credits']);
|
||||
|
||||
$validated['visibility'] = $visibility;
|
||||
$validated['artwork_timezone'] = $timezone;
|
||||
@@ -215,6 +240,10 @@ final class StudioArtworksApiController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasAttributionUpdates) {
|
||||
$artwork = $attribution->apply($artwork->fresh(['group.members', 'contributors', 'primaryAuthor.profile']), $request->user(), $attributionPayload);
|
||||
}
|
||||
|
||||
// Reindex in Meilisearch
|
||||
try {
|
||||
if ((bool) $artwork->is_public && (bool) $artwork->is_approved && $artwork->published_at) {
|
||||
@@ -227,7 +256,7 @@ final class StudioArtworksApiController extends Controller
|
||||
}
|
||||
|
||||
// Reload relationships for response
|
||||
$artwork->load(['categories.contentType', 'tags']);
|
||||
$artwork->load(['categories.contentType', 'tags', 'group', 'primaryAuthor.profile', 'contributors.user.profile']);
|
||||
$primaryCategory = $artwork->categories->first();
|
||||
|
||||
return response()->json([
|
||||
@@ -243,6 +272,14 @@ final class StudioArtworksApiController extends Controller
|
||||
'artwork_status' => $artwork->artwork_status,
|
||||
'artwork_timezone' => $artwork->artwork_timezone,
|
||||
'slug' => $artwork->slug,
|
||||
'group_slug' => $artwork->group?->slug,
|
||||
'primary_author_user_id' => (int) ($artwork->primary_author_user_id ?: $artwork->user_id),
|
||||
'contributor_user_ids' => $artwork->contributors->pluck('user_id')->map(fn ($contributorId): int => (int) $contributorId)->values()->all(),
|
||||
'contributor_credits' => $artwork->contributors->map(fn ($contributor): array => [
|
||||
'user_id' => (int) $contributor->user_id,
|
||||
'credit_role' => $contributor->credit_role,
|
||||
'is_primary' => (bool) $contributor->is_primary,
|
||||
])->values()->all(),
|
||||
'content_type_id' => $primaryCategory?->contentType?->id,
|
||||
'category_id' => $primaryCategory?->id,
|
||||
'tags' => $artwork->tags->map(fn ($t) => ['id' => $t->id, 'name' => $t->name, 'slug' => $t->slug])->values()->all(),
|
||||
|
||||
@@ -5,7 +5,10 @@ declare(strict_types=1);
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Group;
|
||||
use App\Models\ContentType;
|
||||
use App\Services\GroupMembershipService;
|
||||
use App\Services\GroupService;
|
||||
use App\Services\Studio\CreatorStudioAnalyticsService;
|
||||
use App\Services\Studio\CreatorStudioAssetService;
|
||||
use App\Services\Studio\CreatorStudioCalendarService;
|
||||
@@ -417,11 +420,24 @@ final class StudioController extends Controller
|
||||
*/
|
||||
public function edit(Request $request, int $id): Response
|
||||
{
|
||||
$artwork = $request->user()->artworks()
|
||||
->with(['stats', 'categories.contentType', 'tags', 'artworkAiAssist'])
|
||||
$user = $request->user();
|
||||
$artwork = $user->artworks()
|
||||
->with(['stats', 'categories.contentType', 'tags', 'artworkAiAssist', 'group.members', 'primaryAuthor.profile', 'contributors.user.profile'])
|
||||
->findOrFail($id);
|
||||
|
||||
$primaryCategory = $artwork->categories->first();
|
||||
$availableGroups = app(GroupService::class)->studioOptionsForUser($user);
|
||||
$membershipService = app(GroupMembershipService::class);
|
||||
$contributorOptionsByGroup = [];
|
||||
|
||||
foreach ($availableGroups as $groupOption) {
|
||||
$group = Group::query()->with('members')->where('slug', (string) ($groupOption['slug'] ?? ''))->first();
|
||||
if (! $group || ! $group->hasActiveMember($user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$contributorOptionsByGroup[(string) $group->slug] = $membershipService->contributorOptions($group);
|
||||
}
|
||||
|
||||
return Inertia::render('Studio/StudioArtworkEdit', [
|
||||
'artwork' => [
|
||||
@@ -443,6 +459,14 @@ final class StudioController extends Controller
|
||||
'width' => $artwork->width,
|
||||
'height' => $artwork->height,
|
||||
'mime_type' => $artwork->mime_type,
|
||||
'group_slug' => $artwork->group?->slug,
|
||||
'primary_author_user_id' => (int) ($artwork->primary_author_user_id ?: $artwork->user_id),
|
||||
'contributor_user_ids' => $artwork->contributors->pluck('user_id')->map(fn ($id): int => (int) $id)->values()->all(),
|
||||
'contributor_credits' => $artwork->contributors->map(fn ($contributor): array => [
|
||||
'user_id' => (int) $contributor->user_id,
|
||||
'credit_role' => $contributor->credit_role,
|
||||
'is_primary' => (bool) $contributor->is_primary,
|
||||
])->values()->all(),
|
||||
'content_type_id' => $primaryCategory?->contentType?->id,
|
||||
'category_id' => $primaryCategory?->id,
|
||||
'parent_category_id' => $primaryCategory?->parent_id ? $primaryCategory->parent_id : $primaryCategory?->id,
|
||||
@@ -459,6 +483,8 @@ final class StudioController extends Controller
|
||||
'requires_reapproval' => (bool) $artwork->requires_reapproval,
|
||||
],
|
||||
'contentTypes' => $this->getCategories(),
|
||||
'groupOptions' => $availableGroups,
|
||||
'contributorOptionsByGroup' => $contributorOptionsByGroup,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
403
app/Http/Controllers/Studio/StudioNewsController.php
Normal file
403
app/Http/Controllers/Studio/StudioNewsController.php
Normal file
@@ -0,0 +1,403 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\News\NewsService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use cPad\Plugins\News\Models\NewsArticle;
|
||||
use cPad\Plugins\News\Models\NewsCategory;
|
||||
use cPad\Plugins\News\Models\NewsTag;
|
||||
|
||||
final class StudioNewsController extends Controller
|
||||
{
|
||||
public function __construct(private readonly NewsService $news)
|
||||
{
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
return Inertia::render('Studio/StudioNewsIndex', [
|
||||
'title' => 'Newsroom',
|
||||
'description' => 'Plan announcements, publish editorial stories, and connect articles to the rest of Nova.',
|
||||
'listing' => $this->news->studioListing($request->only(['q', 'status', 'type', 'category_id', 'per_page', 'page'])),
|
||||
'statusOptions' => $this->news->editorialStatusOptions(),
|
||||
'typeOptions' => $this->news->articleTypeOptions(),
|
||||
'categoryOptions' => $this->news->categoryOptions(),
|
||||
'createUrl' => route('studio.news.create'),
|
||||
'categoriesUrl' => route('studio.news.categories'),
|
||||
'tagsUrl' => route('studio.news.tags'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
return Inertia::render('Studio/StudioNewsEditor', [
|
||||
'title' => 'Create article',
|
||||
'description' => 'Draft a new News story with editorial workflow, SEO metadata, and related entity links.',
|
||||
'article' => null,
|
||||
'typeOptions' => $this->news->articleTypeOptions(),
|
||||
'statusOptions' => $this->news->editorialStatusOptions(),
|
||||
'categoryOptions' => $this->news->categoryOptions(),
|
||||
'tagOptions' => $this->news->tagOptions(),
|
||||
'relationTypeOptions' => $this->news->relationTypeOptions(),
|
||||
'storeUrl' => route('studio.news.store'),
|
||||
'entitySearchUrl' => route('studio.news.entity-search'),
|
||||
'categoriesUrl' => route('studio.news.categories'),
|
||||
'tagsUrl' => route('studio.news.tags'),
|
||||
'defaultAuthor' => $this->news->searchEntities('user', (string) $request->user()->username)[0] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$article = $this->news->storeArticle($request->user(), $this->validateArticle($request));
|
||||
|
||||
return redirect()->route('studio.news.edit', ['article' => $article->id])->with('success', 'Article draft created.');
|
||||
}
|
||||
|
||||
public function edit(Request $request, NewsArticle $article): Response
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
return Inertia::render('Studio/StudioNewsEditor', [
|
||||
'title' => 'Edit article',
|
||||
'description' => 'Refine the story, tune SEO, and attach related Nova entities before publishing.',
|
||||
'article' => $this->news->mapStudioArticle($article, $request->user()),
|
||||
'typeOptions' => $this->news->articleTypeOptions(),
|
||||
'statusOptions' => $this->news->editorialStatusOptions(),
|
||||
'categoryOptions' => $this->news->categoryOptions(),
|
||||
'tagOptions' => $this->news->tagOptions(),
|
||||
'relationTypeOptions' => $this->news->relationTypeOptions(),
|
||||
'updateUrl' => route('studio.news.update', ['article' => $article->id]),
|
||||
'previewUrl' => route('studio.news.preview', ['article' => $article->id]),
|
||||
'publishUrl' => route('studio.news.publish', ['article' => $article->id]),
|
||||
'archiveUrl' => route('studio.news.archive', ['article' => $article->id]),
|
||||
'featureUrl' => route('studio.news.feature', ['article' => $article->id]),
|
||||
'pinUrl' => route('studio.news.pin', ['article' => $article->id]),
|
||||
'entitySearchUrl' => route('studio.news.entity-search'),
|
||||
'categoriesUrl' => route('studio.news.categories'),
|
||||
'tagsUrl' => route('studio.news.tags'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function preview(Request $request, NewsArticle $article): View
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$article->loadMissing(['author.profile', 'category', 'tags', 'relatedEntities']);
|
||||
|
||||
$related = NewsArticle::with('author', 'category')
|
||||
->published()
|
||||
->when($article->category_id, fn ($query) => $query->where('category_id', $article->category_id))
|
||||
->where('id', '!=', $article->id)
|
||||
->editorialOrder()
|
||||
->limit(config('news.related_limit', 4))
|
||||
->get();
|
||||
|
||||
return view('news.show', [
|
||||
'article' => $article,
|
||||
'related' => $related,
|
||||
'relatedEntities' => $this->news->resolveRelatedEntities($article, $request->user()),
|
||||
'previewMode' => true,
|
||||
'previewCanonical' => route('studio.news.preview', ['article' => $article->id]),
|
||||
'previewBackUrl' => route('studio.news.edit', ['article' => $article->id]),
|
||||
] + $this->news->sidebarData());
|
||||
}
|
||||
|
||||
public function update(Request $request, NewsArticle $article): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$this->news->updateArticle($article, $request->user(), $this->validateArticle($request, $article));
|
||||
|
||||
return back()->with('success', 'Article updated.');
|
||||
}
|
||||
|
||||
public function publish(Request $request, NewsArticle $article): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$this->news->publish($article);
|
||||
|
||||
return back()->with('success', 'Article published.');
|
||||
}
|
||||
|
||||
public function archive(Request $request, NewsArticle $article): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$this->news->archive($article);
|
||||
|
||||
return back()->with('success', 'Article archived.');
|
||||
}
|
||||
|
||||
public function feature(Request $request, NewsArticle $article): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$updated = $this->news->toggleFeature($article);
|
||||
|
||||
return back()->with('success', $updated->is_featured ? 'Article featured.' : 'Article removed from featured surface.');
|
||||
}
|
||||
|
||||
public function pin(Request $request, NewsArticle $article): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$updated = $this->news->togglePin($article);
|
||||
|
||||
return back()->with('success', $updated->is_pinned ? 'Article pinned.' : 'Article unpinned.');
|
||||
}
|
||||
|
||||
public function categories(Request $request): Response
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
return Inertia::render('Studio/StudioNewsTaxonomies', [
|
||||
'title' => 'News taxonomies',
|
||||
'description' => 'Manage News categories and tags used across the editorial surface.',
|
||||
'activeTab' => 'categories',
|
||||
'categories' => NewsCategory::query()
|
||||
->withCount('publishedArticles')
|
||||
->ordered()
|
||||
->get()
|
||||
->map(fn (NewsCategory $category): array => [
|
||||
'id' => (int) $category->id,
|
||||
'name' => (string) $category->name,
|
||||
'slug' => (string) $category->slug,
|
||||
'description' => (string) ($category->description ?? ''),
|
||||
'position' => (int) $category->position,
|
||||
'is_active' => (bool) $category->is_active,
|
||||
'published_count' => (int) $category->published_articles_count,
|
||||
])
|
||||
->all(),
|
||||
'tags' => $this->tagPayload(),
|
||||
'storeCategoryUrl' => route('studio.news.categories.store'),
|
||||
'storeTagUrl' => route('studio.news.tags.store'),
|
||||
'updateCategoryUrlPattern' => route('studio.news.categories.update', ['category' => '__CATEGORY__']),
|
||||
'updateTagUrlPattern' => route('studio.news.tags.update', ['tag' => '__TAG__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function tags(Request $request): Response
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
return Inertia::render('Studio/StudioNewsTaxonomies', [
|
||||
'title' => 'News taxonomies',
|
||||
'description' => 'Manage News categories and tags used across the editorial surface.',
|
||||
'activeTab' => 'tags',
|
||||
'categories' => NewsCategory::query()
|
||||
->withCount('publishedArticles')
|
||||
->ordered()
|
||||
->get()
|
||||
->map(fn (NewsCategory $category): array => [
|
||||
'id' => (int) $category->id,
|
||||
'name' => (string) $category->name,
|
||||
'slug' => (string) $category->slug,
|
||||
'description' => (string) ($category->description ?? ''),
|
||||
'position' => (int) $category->position,
|
||||
'is_active' => (bool) $category->is_active,
|
||||
'published_count' => (int) $category->published_articles_count,
|
||||
])
|
||||
->all(),
|
||||
'tags' => $this->tagPayload(),
|
||||
'storeCategoryUrl' => route('studio.news.categories.store'),
|
||||
'storeTagUrl' => route('studio.news.tags.store'),
|
||||
'updateCategoryUrlPattern' => route('studio.news.categories.update', ['category' => '__CATEGORY__']),
|
||||
'updateTagUrlPattern' => route('studio.news.tags.update', ['tag' => '__TAG__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeCategory(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:120', 'unique:news_categories,name'],
|
||||
'slug' => ['nullable', 'string', 'max:120', 'unique:news_categories,slug'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'position' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
NewsCategory::query()->create([
|
||||
'name' => trim((string) $validated['name']),
|
||||
'slug' => NewsCategory::generateUniqueSlug((string) ($validated['slug'] ?? $validated['name'])),
|
||||
'description' => $validated['description'] ?? null,
|
||||
'position' => (int) ($validated['position'] ?? 0),
|
||||
'is_active' => (bool) ($validated['is_active'] ?? true),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Category created.');
|
||||
}
|
||||
|
||||
public function updateCategory(Request $request, NewsCategory $category): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:120', Rule::unique('news_categories', 'name')->ignore($category->id)],
|
||||
'slug' => ['nullable', 'string', 'max:120', Rule::unique('news_categories', 'slug')->ignore($category->id)],
|
||||
'description' => ['nullable', 'string'],
|
||||
'position' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$category->update([
|
||||
'name' => trim((string) $validated['name']),
|
||||
'slug' => NewsCategory::generateUniqueSlug((string) ($validated['slug'] ?? $validated['name']), (int) $category->id),
|
||||
'description' => $validated['description'] ?? null,
|
||||
'position' => (int) ($validated['position'] ?? 0),
|
||||
'is_active' => (bool) ($validated['is_active'] ?? true),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Category updated.');
|
||||
}
|
||||
|
||||
public function storeTag(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:80', 'unique:news_tags,name'],
|
||||
'slug' => ['nullable', 'string', 'max:80', 'unique:news_tags,slug'],
|
||||
]);
|
||||
|
||||
NewsTag::query()->create([
|
||||
'name' => trim((string) $validated['name']),
|
||||
'slug' => $this->uniqueTagSlug((string) ($validated['slug'] ?? $validated['name'])),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Tag created.');
|
||||
}
|
||||
|
||||
public function updateTag(Request $request, NewsTag $tag): RedirectResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:80', Rule::unique('news_tags', 'name')->ignore($tag->id)],
|
||||
'slug' => ['nullable', 'string', 'max:80', Rule::unique('news_tags', 'slug')->ignore($tag->id)],
|
||||
]);
|
||||
|
||||
$tag->update([
|
||||
'name' => trim((string) $validated['name']),
|
||||
'slug' => $this->uniqueTagSlug((string) ($validated['slug'] ?? $validated['name']), (int) $tag->id),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Tag updated.');
|
||||
}
|
||||
|
||||
public function entitySearch(Request $request): JsonResponse
|
||||
{
|
||||
$this->authorizeNews($request);
|
||||
|
||||
$validated = $request->validate([
|
||||
'type' => ['required', Rule::in(array_column($this->news->relationTypeOptions(), 'value'))],
|
||||
'q' => ['nullable', 'string', 'max:120'],
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'items' => $this->news->searchEntities((string) $validated['type'], (string) ($validated['q'] ?? ''), $request->user()),
|
||||
]);
|
||||
}
|
||||
|
||||
private function authorizeNews(Request $request): void
|
||||
{
|
||||
abort_unless($request->user() && ($request->user()->isAdmin() || $request->user()->isModerator()), 403);
|
||||
}
|
||||
|
||||
private function validateArticle(Request $request, ?NewsArticle $article = null): array
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['nullable', 'string', 'max:255'],
|
||||
'excerpt' => ['nullable', 'string', 'max:800'],
|
||||
'content' => ['required', 'string', 'max:50000'],
|
||||
'cover_image' => ['nullable', 'string', 'max:2048'],
|
||||
'type' => ['required', Rule::in(array_column($this->news->articleTypeOptions(), 'value'))],
|
||||
'category_id' => ['nullable', 'integer', 'exists:news_categories,id'],
|
||||
'author_id' => ['nullable', 'integer', 'exists:users,id'],
|
||||
'editorial_status' => ['required', Rule::in(array_column($this->news->editorialStatusOptions(), 'value'))],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
'is_pinned' => ['nullable', 'boolean'],
|
||||
'tag_ids' => ['nullable', 'array'],
|
||||
'tag_ids.*' => ['integer', 'exists:news_tags,id'],
|
||||
'meta_title' => ['nullable', 'string', 'max:255'],
|
||||
'meta_description' => ['nullable', 'string', 'max:300'],
|
||||
'meta_keywords' => ['nullable', 'string', 'max:255'],
|
||||
'canonical_url' => ['nullable', 'url', 'max:2048'],
|
||||
'og_title' => ['nullable', 'string', 'max:255'],
|
||||
'og_description' => ['nullable', 'string', 'max:300'],
|
||||
'og_image' => ['nullable', 'string', 'max:2048'],
|
||||
'relations' => ['nullable', 'array', 'max:12'],
|
||||
'relations.*.entity_type' => ['required_with:relations', Rule::in(array_column($this->news->relationTypeOptions(), 'value'))],
|
||||
'relations.*.entity_id' => ['required_with:relations', 'integer', 'min:1'],
|
||||
'relations.*.context_label' => ['nullable', 'string', 'max:120'],
|
||||
]);
|
||||
|
||||
if (($validated['editorial_status'] ?? null) === NewsArticle::EDITORIAL_STATUS_SCHEDULED && empty($validated['published_at'])) {
|
||||
throw ValidationException::withMessages([
|
||||
'published_at' => 'Scheduled articles need a publish date and time.',
|
||||
]);
|
||||
}
|
||||
|
||||
return $validated;
|
||||
}
|
||||
|
||||
private function tagPayload(): array
|
||||
{
|
||||
return NewsTag::query()
|
||||
->withCount(['articles' => fn ($query) => $query->published()])
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (NewsTag $tag): array => [
|
||||
'id' => (int) $tag->id,
|
||||
'name' => (string) $tag->name,
|
||||
'slug' => (string) $tag->slug,
|
||||
'published_count' => (int) $tag->articles_count,
|
||||
])
|
||||
->all();
|
||||
}
|
||||
|
||||
private function uniqueTagSlug(string $source, ?int $ignoreId = null): string
|
||||
{
|
||||
$base = Str::slug($source);
|
||||
$slug = $base !== '' ? $base : 'tag';
|
||||
$counter = 1;
|
||||
|
||||
$query = NewsTag::query()->where('slug', $slug);
|
||||
if ($ignoreId !== null) {
|
||||
$query->where('id', '!=', $ignoreId);
|
||||
}
|
||||
|
||||
while ($query->exists()) {
|
||||
$slug = ($base !== '' ? $base : 'tag') . '-' . $counter++;
|
||||
$query = NewsTag::query()->where('slug', $slug);
|
||||
if ($ignoreId !== null) {
|
||||
$query->where('id', '!=', $ignoreId);
|
||||
}
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user