Merge pull request #8299 from JakubOnderka/fix-editing-attachment

fix: [UI] Empty form
pull/8300/head
Jakub Onderka 2022-04-25 11:47:33 +02:00 committed by GitHub
commit ad3ba09d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 42 deletions

View File

@ -547,17 +547,17 @@ class GalaxyClustersController extends AppController
public function detach($target_id, $target_type, $tag_id) public function detach($target_id, $target_type, $tag_id)
{ {
if ($this->request->is("ajax") && $this->request->is("get")) { if ($this->request->is('ajax') && $this->request->is('get')) {
$this->set("url", $this->request->url); $this->set('url', Router::url());
return $this->render("/Elements/emtpyForm", false); return $this->render('/Elements/emptyForm', false);
} }
$this->request->allowMethod(["post"]); $this->request->allowMethod(['post']);
try { try {
$this->GalaxyCluster->Galaxy->detachClusterByTagId($this->Auth->user(), $target_id, $target_type, $tag_id); $this->GalaxyCluster->Galaxy->detachClusterByTagId($this->Auth->user(), $target_id, $target_type, $tag_id);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
if (!$this->request->is("ajax")) { if (!$this->request->is('ajax')) {
$this->Flash->error($e->getMessage()); $this->Flash->error($e->getMessage());
} else { } else {
throw $e; throw $e;
@ -566,8 +566,8 @@ class GalaxyClustersController extends AppController
$message = __('Galaxy successfully detached.'); $message = __('Galaxy successfully detached.');
if ($this->request->is("ajax")) { if ($this->request->is('ajax')) {
return $this->RestResponse->viewData(["saved" => true, "check_publish" => true, "success" => $message], "json"); return $this->RestResponse->viewData(['saved' => true, 'check_publish' => true, 'success' => $message], 'json');
} }
$this->Flash->success($message); $this->Flash->success($message);

View File

@ -547,7 +547,7 @@ class Galaxy extends AppModel
/** /**
* @param array $user * @param array $user
* @param int $targetId * @param int $targetId
* @param string $targetType * @param string $targetType Can be 'attribute', 'event' or 'tag_collection'
* @param int $tagId * @param int $tagId
* @return void * @return void
* @throws Exception * @throws Exception
@ -567,20 +567,20 @@ class Galaxy extends AppModel
} elseif ($targetType === 'event') { } elseif ($targetType === 'event') {
$event_id = $targetId; $event_id = $targetId;
} elseif ($targetType !== 'tag_collection') { } elseif ($targetType !== 'tag_collection') {
throw new NotFoundException('Invalid options'); throw new InvalidArgumentException('Invalid target type');
} }
if ($targetType === 'tag_collection') { if ($targetType === 'tag_collection') {
$tag_collection = $this->GalaxyCluster->Tag->TagCollectionTag->TagCollection->fetchTagCollection($user, array( $tag_collection = $this->GalaxyCluster->Tag->TagCollectionTag->TagCollection->fetchTagCollection($user, array(
'conditions' => array('TagCollection.id' => $targetId), 'conditions' => array('TagCollection.id' => $targetId),
'recusive' => -1, 'recursive' => -1,
)); ));
if (empty($tag_collection)) { if (empty($tag_collection)) {
throw new NotFoundException('Invalid Tag Collection'); throw new NotFoundException('Invalid Tag Collection');
} }
$tag_collection = $tag_collection[0]; $tag_collection = $tag_collection[0];
if (!$user["Role"]["perm_site_admin"]) { if (!$user['Role']['perm_site_admin']) {
if (!$user["Role"]['perm_tag_editor'] || $user['org_id'] !== $tag_collection['TagCollection']['org_id']) { if (!$user['Role']['perm_tag_editor'] || $user['org_id'] !== $tag_collection['TagCollection']['org_id']) {
throw new NotFoundException('Invalid Tag Collection'); throw new NotFoundException('Invalid Tag Collection');
} }
} }
@ -589,8 +589,8 @@ class Galaxy extends AppModel
if (empty($event)) { if (empty($event)) {
throw new NotFoundException('Invalid Event.'); throw new NotFoundException('Invalid Event.');
} }
if (!$user["Role"]["perm_site_admin"] && !$user["Role"]['perm_sync']) { if (!$user['Role']['perm_site_admin'] && !$user['Role']['perm_sync']) {
if (!$user["Role"]['perm_tagger'] || ($user['org_id'] !== $event['Event']['org_id'] && $user['org_id'] !== $event['Event']['orgc_id'])) { if (!$user['Role']['perm_tagger'] || ($user['org_id'] !== $event['Event']['org_id'] && $user['org_id'] !== $event['Event']['orgc_id'])) {
throw new NotFoundException('Invalid Event.'); throw new NotFoundException('Invalid Event.');
} }
} }
@ -625,7 +625,7 @@ class Galaxy extends AppModel
'conditions' => array('GalaxyCluster.tag_name' => $existingTargetTag['Tag']['name']) 'conditions' => array('GalaxyCluster.tag_name' => $existingTargetTag['Tag']['name'])
)); ));
if (empty($cluster)) { if (empty($cluster)) {
throw new NotFoundException("Tag is not cluster"); throw new NotFoundException('Tag is not cluster');
} }
if ($targetType === 'event') { if ($targetType === 'event') {

View File

@ -5,7 +5,7 @@
$searchUrl = '/events/index/searchtag:'; $searchUrl = '/events/index/searchtag:';
switch ($scope) { switch ($scope) {
case 'event': case 'event':
$id = h($event['Event']['id']); $id = intval($event['Event']['id']);
if (!empty($missingTaxonomies)) { if (!empty($missingTaxonomies)) {
echo __( echo __(
'Missing taxonomies: <span class="red bold">%s</span><br>', 'Missing taxonomies: <span class="red bold">%s</span><br>',
@ -23,7 +23,6 @@
} }
$full = $isAclTagger && $tagAccess && empty($static_tags_only); $full = $isAclTagger && $tagAccess && empty($static_tags_only);
$fullLocal = $isAclTagger && $localTagAccess && empty($static_tags_only); $fullLocal = $isAclTagger && $localTagAccess && empty($static_tags_only);
$host_org_editor = (int)$me['org_id'] === Configure::read('MISP.host_org_id') && $isAclTagger && empty($static_tags_only);
$tagData = ""; $tagData = "";
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (empty($tag['Tag'])) { if (empty($tag['Tag'])) {
@ -32,12 +31,12 @@
if (empty($tag['Tag']['colour'])) { if (empty($tag['Tag']['colour'])) {
$tag['Tag']['colour'] = '#0088cc'; $tag['Tag']['colour'] = '#0088cc';
} }
$aStyle = 'background-color:' . h($tag['Tag']['colour']) . ';color:' . $this->TextColour->getTextColour($tag['Tag']['colour']) . ';'; $aStyle = 'background-color:' . h($tag['Tag']['colour']) . ';color:' . $this->TextColour->getTextColour($tag['Tag']['colour']);
$aClass = 'tag nowrap'; $aClass = 'tag nowrap';
$aText = trim($tag['Tag']['name']); $aText = trim($tag['Tag']['name']);
$aTextModified = null; $aTextModified = null;
if (isset($tag_display_style)) { if (isset($tag_display_style)) {
if (!isset($tag_display_style) || $tag_display_style == 1) { if ($tag_display_style == 1) {
// default behaviour, do nothing for now // default behaviour, do nothing for now
} else if ($tag_display_style == 2) { } else if ($tag_display_style == 2) {
$separator_pos = strpos($aText, ':'); $separator_pos = strpos($aText, ':');
@ -65,16 +64,11 @@
if (!empty($tag['Tag']['id'])) { if (!empty($tag['Tag']['id'])) {
$span_tag = sprintf( $span_tag = sprintf(
'<a href="%s" style="%s" class="%s"%s data-tag-id="%s">%s</a>', '<a href="%s" style="%s" class="%s"%s data-tag-id="%s">%s</a>',
sprintf( $baseurl . $searchUrl . intval($tag['Tag']['id']),
'%s%s%s',
$baseurl,
$searchUrl,
h($tag['Tag']['id'])
),
$aStyle, $aStyle,
$aClass, $aClass,
isset($aTextModified) ? ' title="' . $aText . '"' : '', isset($aTextModified) ? ' title="' . $aText . '"' : '',
h($tag['Tag']['id']), intval($tag['Tag']['id']),
isset($aTextModified) ? $aTextModified : $aText isset($aTextModified) ? $aTextModified : $aText
); );
} else { } else {
@ -95,10 +89,10 @@
"0", "0",
__('Remove tag %s', h($tag['Tag']['name'])), __('Remove tag %s', h($tag['Tag']['name'])),
sprintf( sprintf(
"removeObjectTagPopup(this, '%s', '%s', '%s')", "removeObjectTagPopup(this, '%s', %s, %s)",
$scope, $scope,
$id, $id,
h($tag['Tag']['id']) intval($tag['Tag']['id'])
) )
); );
} }
@ -132,35 +126,33 @@
'<span class="tag-list-container">%s</span>', '<span class="tag-list-container">%s</span>',
$tagData $tagData
); );
$tagConflictData = '';
if (!empty($tagConflicts['global'])) { if (!empty($tagConflicts['global'])) {
$tagConflictData .= '<div><div class="alert alert-error tag-conflict-notice">'; echo '<div><div class="alert alert-error tag-conflict-notice">';
$tagConflictData .= '<i class="fas fa-globe-americas icon"></i>'; echo '<i class="fas fa-globe-americas icon"></i>';
$tagConflictData .= '<div class="text-container">'; echo '<div class="text-container">';
foreach ($tagConflicts['global'] as $tagConflict) { foreach ($tagConflicts['global'] as $tagConflict) {
$tagConflictData .= sprintf( echo sprintf(
'<strong>%s</strong><br>', '<strong>%s</strong><br>',
h($tagConflict['conflict']) h($tagConflict['conflict'])
); );
foreach ($tagConflict['tags'] as $tag) { foreach ($tagConflict['tags'] as $tag) {
$tagConflictData .= sprintf('<span class="apply_css_arrow nowrap">%s</span><br>', h($tag)); echo sprintf('<span class="apply_css_arrow nowrap">%s</span><br>', h($tag));
} }
} }
$tagConflictData .= '</div></div></span>'; echo '</div></div></span>';
} }
if (!empty($tagConflicts['local'])) { if (!empty($tagConflicts['local'])) {
$tagConflictData .= '<div><div class="alert alert-error tag-conflict-notice">'; echo '<div><div class="alert alert-error tag-conflict-notice">';
$tagConflictData .= '<i class="fas fa-user icon"></i>'; echo '<i class="fas fa-user icon"></i>';
$tagConflictData .= '<div class="text-container">'; echo '<div class="text-container">';
foreach ($tagConflicts['local'] as $tagConflict) { foreach ($tagConflicts['local'] as $tagConflict) {
$tagConflictData .= sprintf( echo sprintf(
'<strong>%s</strong><br>', '<strong>%s</strong><br>',
h($tagConflict['conflict']) h($tagConflict['conflict'])
); );
foreach ($tagConflict['tags'] as $tag) { foreach ($tagConflict['tags'] as $tag) {
$tagConflictData .= sprintf('<span class="apply_css_arrow nowrap">%s</span><br>', h($tag)); echo sprintf('<span class="apply_css_arrow nowrap">%s</span><br>', h($tag));
} }
} }
$tagConflictData .= '</div></div></span>'; echo '</div></div></span>';
} }
echo $tagConflictData;