mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update StoryController, add parental controls support
This commit is contained in:
parent
fe30cd25d1
commit
71c148c61e
2 changed files with 645 additions and 614 deletions
|
@ -29,6 +29,7 @@ use App\Jobs\StoryPipeline\StoryFanout;
|
|||
use App\Jobs\StoryPipeline\StoryDelete;
|
||||
use ImageOptimizer;
|
||||
use App\Models\Conversation;
|
||||
use App\Services\UserRoleService;
|
||||
|
||||
class StoryComposeController extends Controller
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ class StoryComposeController extends Controller
|
|||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$count = Story::whereProfileId($user->profile_id)
|
||||
->whereActive(true)
|
||||
->where('expires_at', '>', now())
|
||||
|
@ -177,6 +178,7 @@ class StoryComposeController extends Controller
|
|||
|
||||
$id = $request->input('media_id');
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::whereProfileId($user->profile_id)
|
||||
->findOrFail($id);
|
||||
|
||||
|
@ -218,6 +220,8 @@ class StoryComposeController extends Controller
|
|||
public function compose(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
return view('stories.compose');
|
||||
}
|
||||
|
@ -241,6 +245,8 @@ class StoryComposeController extends Controller
|
|||
'can_react' => 'required|boolean'
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
$count = Story::whereProfileId($pid)
|
||||
|
@ -329,6 +335,9 @@ class StoryComposeController extends Controller
|
|||
'id' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$sid = $request->input('id');
|
||||
$type = $request->input('type');
|
||||
|
@ -387,7 +396,8 @@ class StoryComposeController extends Controller
|
|||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$text = $request->input('reaction');
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
|
||||
abort_if(!$story->can_react, 422);
|
||||
|
@ -461,7 +471,8 @@ class StoryComposeController extends Controller
|
|||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$text = $request->input('caption');
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
|
||||
abort_if(!$story->can_reply, 422);
|
||||
|
|
|
@ -28,13 +28,18 @@ use League\Fractal\Serializer\ArraySerializer;
|
|||
use League\Fractal\Resource\Item;
|
||||
use App\Transformer\ActivityPub\Verb\StoryVerb;
|
||||
use App\Jobs\StoryPipeline\StoryViewDeliver;
|
||||
use App\Services\UserRoleService;
|
||||
|
||||
class StoryController extends StoryComposeController
|
||||
{
|
||||
public function recent(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return [];
|
||||
}
|
||||
$pid = $user->profile_id;
|
||||
|
||||
if(config('database.default') == 'pgsql') {
|
||||
$s = Cache::remember('pf:stories:recent-by-id:' . $pid, 900, function() use($pid) {
|
||||
|
@ -114,7 +119,11 @@ class StoryController extends StoryComposeController
|
|||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$authed = $request->user()->profile_id;
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return [];
|
||||
}
|
||||
$authed = $user->profile_id;
|
||||
$profile = Profile::findOrFail($id);
|
||||
|
||||
if($authed != $profile->id && !FollowerService::follows($authed, $profile->id)) {
|
||||
|
@ -173,8 +182,11 @@ class StoryController extends StoryComposeController
|
|||
'id' => 'required|min:1',
|
||||
]);
|
||||
$id = $request->input('id');
|
||||
|
||||
$authed = $request->user()->profile;
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return [];
|
||||
}
|
||||
$authed = $user->profile;
|
||||
|
||||
$story = Story::with('profile')
|
||||
->findOrFail($id);
|
||||
|
@ -210,7 +222,10 @@ class StoryController extends StoryComposeController
|
|||
public function exists(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return response()->json(false);
|
||||
}
|
||||
return response()->json(Story::whereProfileId($id)
|
||||
->whereActive(true)
|
||||
->exists());
|
||||
|
@ -234,6 +249,11 @@ class StoryController extends StoryComposeController
|
|||
'sid' => 'required|string'
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$sid = $request->input('sid');
|
||||
|
||||
|
|
Loading…
Reference in a new issue