fix: [API] Deprecation header

pull/7685/head
Jakub Onderka 2021-08-23 15:39:25 +02:00
parent 683c1df861
commit b5bb93c51e
3 changed files with 5 additions and 15 deletions

View File

@ -19,6 +19,7 @@ App::uses('RequestRearrangeTool', 'Tools');
* @property IndexFilterComponent $IndexFilter
* @property RateLimitComponent $RateLimit
* @property CompressedRequestHandlerComponent $CompressedRequestHandler
* @property DeprecationComponent $Deprecation
*/
class AppController extends Controller
{
@ -353,7 +354,7 @@ class AppController extends Controller
$deprecationWarnings = __('WARNING: This functionality is deprecated and will be removed in the near future. ') . $deprecationWarnings;
if ($this->_isRest()) {
$this->response->header('X-Deprecation-Warning', $deprecationWarnings);
$this->components['RestResponse']['deprecationWarnings'] = $deprecationWarnings;
$this->RestResponse->setHeader('X-Deprecation-Warning', $deprecationWarnings);
} else {
$this->Flash->warning($deprecationWarnings);
}

View File

@ -1,6 +1,4 @@
<?php
class DeprecationComponent extends Component
{
public $redis = false;
@ -10,7 +8,7 @@ class DeprecationComponent extends Component
* - simple controller->action structure
* - each endpoint can be set to to a deprecation warning message or false
*/
public $deprecatedEndpoints = false;
private $deprecatedEndpoints;
public function initialize(Controller $controller) {
$this->deprecatedEndpoints = array(
@ -59,24 +57,18 @@ class DeprecationComponent extends Component
if ($this->redis) {
@$this->redis->hincrby(
'misp:deprecation',
sprintf(
'%s:%s:%s',
$controller,
$action,
$user_id
),
"$controller:$action:$user_id",
1
);
$result = $this->redis->hGetAll('misp:deprecation');
}
return false;
}
public function getDeprecatedAccessList($model)
{
$rearranged = array();
$this->redis = $model->setupRedis();
if ($this->redis) {
$rearranged = array();
@$result = $this->redis->hGetAll('misp:deprecation');
if (!empty($result)) {
foreach ($result as $key => $value) {

View File

@ -599,9 +599,6 @@ class RestResponseComponent extends Component
if (!empty($headers)) {
$cakeResponse->header($headers);
}
if (!empty($deprecationWarnings)) {
$cakeResponse->header('X-Deprecation-Warning', $deprecationWarnings);
}
if ($download) {
$cakeResponse->download($download);
}