Merged in bugfix/HOR-1750 (pull request #5644)
HOR-1750 Approved-by: Paula Quispe <paula.quispe@processmaker.com> Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Policies;
|
||||
|
||||
use \Luracast\Restler\iAuthenticate;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
/**
|
||||
* ControlUnderUpdating sends an error signal 503 to report that the application
|
||||
* is in update.
|
||||
*/
|
||||
class ControlUnderUpdating implements iAuthenticate
|
||||
{
|
||||
|
||||
/**
|
||||
* Access verification method.
|
||||
*
|
||||
* API access will be denied when this method returns false
|
||||
*
|
||||
* @return boolean true when api access is allowed false otherwise
|
||||
* @throws RestException
|
||||
*/
|
||||
public function __isAllowed()
|
||||
{
|
||||
$response = true;
|
||||
self::verifyUnderUpgrading();
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface iAuthenticate
|
||||
* @return string string to be used with WWW-Authenticate header
|
||||
* @example Basic
|
||||
* @example Digest
|
||||
* @example OAuth
|
||||
* @return string
|
||||
*/
|
||||
public function __getWWWAuthenticateString()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify under upgrading, if the state is under update an exception is
|
||||
* thrown of type RestException.
|
||||
* @throws RestException
|
||||
*/
|
||||
public static function verifyUnderUpgrading()
|
||||
{
|
||||
$underUpdating = \Bootstrap::isPMUnderUpdating();
|
||||
if ($underUpdating['action']) {
|
||||
$sysTemp = true;
|
||||
if (defined('SYS_TEMP')) {
|
||||
$sysTemp = $underUpdating['workspace'] == SYS_TEMP;
|
||||
}
|
||||
if ($underUpdating['workspace'] == 'true' || $sysTemp) {
|
||||
$message = 'The server is currently unable to handle the request '
|
||||
. 'due to temporary overloading or server maintenance ('
|
||||
. 'an application update has probably been performed on '
|
||||
. 'the server)';
|
||||
throw new RestException(503, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -284,6 +284,8 @@ class Server implements iAuthenticate
|
||||
*/
|
||||
public function postToken($request = null, $returnResponse = false)
|
||||
{
|
||||
\ProcessMaker\Policies\ControlUnderUpdating::verifyUnderUpgrading();
|
||||
|
||||
// Handle a request for an OAuth2.0 Access Token and send the response to the client
|
||||
if ($request == null) {
|
||||
$request = \OAuth2\Request::createFromGlobals();
|
||||
|
||||
Reference in New Issue
Block a user