Add update and delete

This commit is contained in:
Emelia Smith 2024-03-29 23:05:48 +01:00
parent 652654e24f
commit 21466556d4
No known key found for this signature in database
3 changed files with 43 additions and 2 deletions

View file

@ -35,4 +35,4 @@ class ApiController extends Controller {
return $v != null; return $v != null;
}, ARRAY_FILTER_USE_BOTH); }, ARRAY_FILTER_USE_BOTH);
} }
} }

View file

@ -73,4 +73,43 @@ class DomainBlocksController extends ApiController {
return $this->json(new DomainBlockResource($domain_block)); return $this->json(new DomainBlockResource($domain_block));
} }
}
public function update(Request $request, $id) {
$this->validate($request, [
'severity' => [
'sometimes',
Rule::in(['noop', 'silence', 'suspend'])
],
'reject_media' => 'sometimes|required|boolean',
'reject_reports' => 'sometimes|required|boolean',
'private_comment' => 'sometimes|string|min:1|max:1000',
'public_comment' => 'sometimes|string|min:1|max:1000',
'obfuscate' => 'sometimes|required|boolean'
]);
$severity = $request->input('severity');
$private_comment = $request->input('private_comment');
$instance = Instance::moderated()->findOrFail($id);
$instance->banned = $severity === 'suspend';
$instance->unlisted = $severity === 'silence';
$instance->notes = [$private_comment];
$instance->save();
InstanceService::refresh();
return $this->json(new DomainBlockResource($instance));
}
public function delete(Request $request, $id) {
$instance = Instance::moderated()->findOrFail($id);
$instance->banned = false;
$instance->unlisted = false;
$instance->save();
InstanceService::refresh();
return $this->json([], [], 200);
}
}

View file

@ -106,6 +106,8 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::get('domain_blocks', 'Api\V1\Admin\DomainBlocksController@index')->middleware($middleware); Route::get('domain_blocks', 'Api\V1\Admin\DomainBlocksController@index')->middleware($middleware);
Route::post('domain_blocks', 'Api\V1\Admin\DomainBlocksController@create')->middleware($middleware); Route::post('domain_blocks', 'Api\V1\Admin\DomainBlocksController@create')->middleware($middleware);
Route::get('domain_blocks/{id}', 'Api\V1\Admin\DomainBlocksController@show')->middleware($middleware); Route::get('domain_blocks/{id}', 'Api\V1\Admin\DomainBlocksController@show')->middleware($middleware);
Route::put('domain_blocks/{id}', 'Api\V1\Admin\DomainBlocksController@update')->middleware($middleware);
Route::delete('domain_blocks/{id}', 'Api\V1\Admin\DomainBlocksController@delete')->middleware($middleware);
})->middleware($middleware); })->middleware($middleware);
}); });