chg: [internal] Check if update is possible

pull/7959/head
Jakub Onderka 2021-11-14 12:11:20 +01:00
parent 0cc7804219
commit aecf9499ad
6 changed files with 29 additions and 15 deletions

View File

@ -1824,12 +1824,11 @@ class ServersController extends AppController
public function update($branch = false)
{
if ($this->request->is('post')) {
$branch = false;
$filterData = array(
'request' => $this->request,
'named_params' => $this->params['named'],
'paramArray' => ['branch'],
'ordered_url_params' => @compact($paramArray),
'ordered_url_params' => [],
'additional_delimiters' => PHP_EOL
);
$exception = false;
@ -1852,8 +1851,8 @@ class ServersController extends AppController
return new CakeResponse(array('body' => $update, 'type' => 'txt'));
}
} else {
$branch = $this->Server->getCurrentBranch();
$this->set('branch', $branch);
$this->set('isUpdatePossible', $this->Server->isUpdatePossible());
$this->set('branch', $this->Server->getCurrentBranch());
$this->render('ajax/update');
}
}

View File

@ -3870,6 +3870,15 @@ class Server extends AppModel
}
}
/**
* Check if MISP update is possible.
* @return bool
*/
public function isUpdatePossible()
{
return $this->getCurrentBranch() !== false && is_writable(APP);
}
public function checkoutMain()
{
$mainBranch = '2.4';

View File

@ -1,9 +1,11 @@
<div class="confirmation">
<?php
echo $this->Form->create('Server', array('style' => 'margin:0px;', 'id' => 'PromptForm', 'url' => $baseurl . '/servers/update'));
?>
<legend>Update MISP</legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<div class="inner">
<?php if (!$isUpdatePossible): ?>
<p>Update is not possible because you are not on a branch or MISP folder is not writeable by current user.</p>
<span role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="btn btn-inverse" id="PromptNoButton" onClick="cancelPrompt();"><?php echo __('Cancel');?></span>
<?php else: ?>
<?= $this->Form->create('Server', array('style' => 'margin:0px;', 'id' => 'PromptForm', 'url' => $baseurl . '/servers/update')); ?>
<p><?php echo __('Do you want to pull the latest commit from the %s branch? If you have made local changes to MISP the merge will fail.', h($branch));?></p>
<table>
<tr>
@ -17,8 +19,7 @@
</td>
</tr>
</table>
<?= $this->Form->end(); ?>
<?php endif; ?>
</div>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -1,6 +1,6 @@
<div class="confirmation">
<legend><?php echo __('ZeroMQ Server Status');?></legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<legend><?php echo __('ZeroMQ Server Status');?></legend>
<div class="inner">
<?php if (isset($time)): ?>
<p><b><?php echo __('Reply time');?></b>: <?= $this->Time->time($time); ?><br>
<b><?php echo __('Start time');?></b>: <?= $this->Time->time($time2); ?><br>

View File

@ -885,6 +885,12 @@ a.proposal_link_red:hover {
color:white;
}
.confirmation .inner {
padding-left:5px;
padding-right:5px;
padding-bottom:5px;
}
.popover-legend {
border-radius: 5px 5px 0px 0px;
margin-bottom:5px;

View File

@ -183,8 +183,7 @@ function cancelPrompt(isolated) {
$("#gray_out").fadeOut();
}
$("#popover_form").fadeOut();
$("#confirmation_box").fadeOut();
$("#confirmation_box").empty();
$("#confirmation_box").fadeOut().empty();
$('.have-a-popover').popover('destroy');
}