From 35226c99e293036d930f9ab8e7cc0b9bd3275705 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 25 Sep 2019 01:10:01 -0600 Subject: [PATCH] Add /api/v1/accounts/{id}/unblock endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 36 ++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 37 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 44699332..e6577d38 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -15,6 +15,7 @@ use App\{ FollowRequest, Like, Media, + Notification, Profile, Status, UserFilter, @@ -575,6 +576,41 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * POST /api/v1/accounts/{id}/unblock + * + * @param integer $id + * + * @return \App\Transformer\Api\RelationshipTransformer + */ + public function accountUnblockById(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $user = $request->user(); + $pid = $user->profile_id ?? $user->profile->id; + + if($id == $pid) { + abort(400, 'You cannot unblock yourself'); + } + + $profile = Profile::findOrFail($id); + + UserFilter::whereUserId($pid) + ->whereFilterableId($profile->id) + ->whereFilterableType('App\Profile') + ->whereFilterType('block') + ->delete(); + + Cache::forget("user:filter:list:$pid"); + Cache::forget("api:local:exp:rec:$pid"); + + $resource = new Fractal\Resource\Item($profile, new RelationshipTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + + return response()->json($res); + } + public function statusById(Request $request, $id) { $status = Status::whereVisibility('public')->findOrFail($id); diff --git a/routes/web.php b/routes/web.php index 62b160c3..368d43ab 100644 --- a/routes/web.php +++ b/routes/web.php @@ -88,6 +88,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('accounts/{id}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware('auth:api'); Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->middleware('auth:api'); Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById')->middleware('auth:api'); + Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById')->middleware('auth:api'); // Route::get('accounts/{id}', 'PublicApiController@account'); Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById'); Route::post('avatar/update', 'ApiController@avatarUpdate')->middleware('auth:api');