fix: duplicated method

pull/9143/head
Luciano Righetti 2023-06-15 16:50:08 +02:00
parent 66b3e80727
commit 2416a9e148
1 changed files with 43 additions and 40 deletions

View File

@ -3,11 +3,6 @@
namespace App\Controller; namespace App\Controller;
use App\Controller\AppController; use App\Controller\AppController;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use Cake\Database\Expression\QueryExpression;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Exception\ForbiddenException;
class CommunitiesController extends AppController class CommunitiesController extends AppController
{ {
@ -16,7 +11,8 @@ class CommunitiesController extends AppController
public function index() public function index()
{ {
$this->CRUD->index([ $this->CRUD->index(
[
'filters' => $this->filterFields, 'filters' => $this->filterFields,
'quickFilters' => $this->quickFilterFields, 'quickFilters' => $this->quickFilterFields,
'quickFilterForMetaField' => ['enabled' => true, 'wildcard_search' => true], 'quickFilterForMetaField' => ['enabled' => true, 'wildcard_search' => true],
@ -41,7 +37,9 @@ class CommunitiesController extends AppController
[ [
'label' => __('ENISA CSIRT Network (GOV)'), 'label' => __('ENISA CSIRT Network (GOV)'),
'filterConditionFunction' => function($query) { 'filterConditionFunction' => function($query) {
return $this->CRUD->setParentConditionsForMetaFields($query, [ return $this->CRUD->setParentConditionsForMetaFields(
$query,
[
'ENISA CSIRT Network' => [ 'ENISA CSIRT Network' => [
[ [
'field' => 'constituency', 'field' => 'constituency',
@ -52,14 +50,16 @@ class CommunitiesController extends AppController
'value' => 'Member', 'value' => 'Member',
], ],
] ]
]); ]
);
} }
] ]
], ],
], ],
'contain' => $this->containFields, 'contain' => $this->containFields,
'statisticsFields' => $this->statisticsFields, 'statisticsFields' => $this->statisticsFields,
]); ]
);
$responsePayload = $this->CRUD->getResponsePayload(); $responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) { if (!empty($responsePayload)) {
return $responsePayload; return $responsePayload;
@ -67,29 +67,29 @@ class CommunitiesController extends AppController
$this->set('metaGroup', 'Communities'); $this->set('metaGroup', 'Communities');
} }
public function index() // public function index()
{ // {
$filters = $this->IndexFilter->harvestParameters(array('context', 'value')); // $filters = $this->IndexFilter->harvestParameters(array('context', 'value'));
if (empty($filters['context'])) { // if (empty($filters['context'])) {
$filters['context'] = 'vetted'; // $filters['context'] = 'vetted';
} // }
if (!empty($filters['value'])) { // if (!empty($filters['value'])) {
$filters['value'] = strtolower($filters['value']); // $filters['value'] = strtolower($filters['value']);
} else { // } else {
$filters['value'] = false; // $filters['value'] = false;
} // }
$community_list = $this->Community->getCommunityList($filters['context'], $filters['value']); // $community_list = $this->Community->getCommunityList($filters['context'], $filters['value']);
//foreach ($community) // //foreach ($community)
if ($this->_isRest()) { // if ($this->_isRest()) {
return $this->RestResponse->viewData($community_list, $this->response->type()); // return $this->RestResponse->viewData($community_list, $this->response->type());
} // }
App::uses('CustomPaginationTool', 'Tools'); // App::uses('CustomPaginationTool', 'Tools');
$customPagination = new CustomPaginationTool(); // $customPagination = new CustomPaginationTool();
$customPagination->truncateAndPaginate($community_list, $this->params, $this->modelClass, true); // $customPagination->truncateAndPaginate($community_list, $this->params, $this->modelClass, true);
$this->set('community_list', $community_list); // $this->set('community_list', $community_list);
$this->set('context', $filters['context']); // $this->set('context', $filters['context']);
} // }
public function view($id) public function view($id)
{ {
@ -106,11 +106,14 @@ class CommunitiesController extends AppController
{ {
$community = $this->Community->getCommunity($id); $community = $this->Community->getCommunity($id);
$this->loadModel('User'); $this->loadModel('User');
$gpgkey = $this->User->find('first', array( $gpgkey = $this->User->find(
'conditions' => array('User.id' => $this->Auth->user('id')), 'first',
[
'conditions' => ['User.id' => $this->Auth->user('id')],
'recursive' => -1, 'recursive' => -1,
'fields' => array('User.gpgkey') 'fields' => ['User.gpgkey']
)); ]
);
if (!empty($gpgkey['User']['gpgkey'])) { if (!empty($gpgkey['User']['gpgkey'])) {
$gpgkey = $gpgkey['User']['gpgkey']; $gpgkey = $gpgkey['User']['gpgkey'];
} else { } else {
@ -126,7 +129,7 @@ class CommunitiesController extends AppController
$this->request->data['Server']['gpgkey'] = $gpgkey; $this->request->data['Server']['gpgkey'] = $gpgkey;
} else { } else {
if (empty($this->request->data['Server'])) { if (empty($this->request->data['Server'])) {
$this->request->data = array('Server' => $this->request->data); $this->request->data = ['Server' => $this->request->data];
} }
$body = sprintf( $body = sprintf(
'To whom it may concern, 'To whom it may concern,
@ -166,7 +169,7 @@ Thank you in advance!',
) )
); );
$imgPath = APP . WEBROOT_DIR . DS . 'img' . DS . 'orgs' . DS; $imgPath = APP . WEBROOT_DIR . DS . 'img' . DS . 'orgs' . DS;
$possibleFields = array('id', 'name'); $possibleFields = ['id', 'name'];
$image = false; $image = false;
App::uses('File', 'Utility'); App::uses('File', 'Utility');
foreach ($possibleFields as $field) { foreach ($possibleFields as $field) {
@ -187,7 +190,7 @@ Thank you in advance!',
if (!empty($this->request->data['Server']['gpgkey'])) { if (!empty($this->request->data['Server']['gpgkey'])) {
$params['attachments']['requestor.asc'] = $this->request->data['Server']['gpgkey']; $params['attachments']['requestor.asc'] = $this->request->data['Server']['gpgkey'];
} }
$params = array(); $params = [];
$params['to'] = $community['email']; $params['to'] = $community['email'];
$params['reply-to'] = empty($this->request->data['Server']['email']) ? $this->Auth->user('email') : $this->request->data['Server']['email']; $params['reply-to'] = empty($this->request->data['Server']['email']) ? $this->Auth->user('email') : $this->request->data['Server']['email'];
$params['requestor_gpgkey'] = empty($this->request->data['Server']['gpgkey']) ? $gpgkey : $this->request->data['Server']['gpgkey']; $params['requestor_gpgkey'] = empty($this->request->data['Server']['gpgkey']) ? $gpgkey : $this->request->data['Server']['gpgkey'];
@ -211,7 +214,7 @@ Thank you in advance!',
} else { } else {
if ($result === true) { if ($result === true) {
$this->Flash->success($message); $this->Flash->success($message);
$this->redirect(array('controller' => 'communities', 'action' => 'view', $id)); $this->redirect(['controller' => 'communities', 'action' => 'view', $id]);
} elseif ($result) { } elseif ($result) {
$this->set('result', $result); $this->set('result', $result);
if (empty($this->request->data['Server']['mock'])) { if (empty($this->request->data['Server']['mock'])) {
@ -220,7 +223,7 @@ Thank you in advance!',
$this->render('request_access_email'); $this->render('request_access_email');
} else { } else {
$this->Flash->error($message); $this->Flash->error($message);
$this->redirect(array('controller' => 'communities', 'action' => 'view', $id)); $this->redirect(['controller' => 'communities', 'action' => 'view', $id]);
} }
} }
if (!empty($this->request->data['Server']['mock'])) { if (!empty($this->request->data['Server']['mock'])) {