Introduce GET only API endpoints
[MAILPOET-2378]
This commit is contained in:
committed by
Jack Kitterhing
parent
c450efa4df
commit
0bd46d72e0
@ -6,11 +6,16 @@ use MailPoet\Config\AccessControl;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
abstract class Endpoint {
|
||||
const TYPE_POST = 'POST';
|
||||
const TYPE_GET = 'GET';
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||
'methods' => [],
|
||||
];
|
||||
|
||||
protected static $get_methods = [];
|
||||
|
||||
function successResponse(
|
||||
$data = [], $meta = [], $status = Response::STATUS_OK
|
||||
) {
|
||||
@ -36,4 +41,14 @@ abstract class Endpoint {
|
||||
}
|
||||
return new ErrorResponse($errors, $meta, Response::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
public function isMethodAllowed($name, $type) {
|
||||
if ($type === self::TYPE_GET && !in_array($name, static::$get_methods)) {
|
||||
return false;
|
||||
}
|
||||
if ($type === self::TYPE_POST && in_array($name, static::$get_methods)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user