From 586d39420e63212c651869c908feaef4d244db50 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 16:22:53 -0500 Subject: [PATCH 1/2] Rename doignore to doIgnoreThread --- view/js/main.js | 2 +- view/theme/frio/templates/search_item.tpl | 4 ++-- view/theme/frio/templates/wall_thread.tpl | 8 ++++---- view/theme/quattro/templates/wall_thread.tpl | 4 ++-- view/theme/vier/templates/wall_thread.tpl | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/view/js/main.js b/view/js/main.js index 1e051de835..3613ee78f6 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -725,7 +725,7 @@ function doPin(ident) { }); } -function doignore(ident) { +function doIgnoreThread(ident) { ident = ident.toString(); $('#like-rotator-' + ident).show(); $.get('item/ignore/' + ident, function(data) { diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 3f03f822a5..6e76f23d6a 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -229,10 +229,10 @@ {{if $item.ignore}}
  • - {{$item.ignore.do}} + {{$item.ignore.do}}
  • - {{$item.ignore.undo}} + {{$item.ignore.undo}}
  • {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index b8286dd46c..f632b0bba1 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -381,10 +381,10 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.ignore}}
  • - {{$item.ignore.do}} + {{$item.ignore.do}}
  • - {{$item.ignore.undo}} + {{$item.ignore.undo}}
  • {{/if}} @@ -540,10 +540,10 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.ignore}}
  • - {{$item.ignore.do}} + {{$item.ignore.do}}
  • - {{$item.ignore.undo}} + {{$item.ignore.undo}}
  • {{/if}} diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index 58c68968b0..671b7643f3 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -106,8 +106,8 @@ {{$item.star.undo}} {{/if}} {{if $item.ignore}} - {{$item.ignore.do}} - {{$item.ignore.undo}} + {{$item.ignore.do}} + {{$item.ignore.undo}} {{/if}} {{if $item.tagger}} {{$item.tagger.add}} diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index 96762c60c4..1e4806c9e0 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -144,8 +144,8 @@ {{$item.star.undo}} {{/if}} {{if $item.ignore}} - {{$item.ignore.do}} - {{$item.ignore.undo}} + {{$item.ignore.do}} + {{$item.ignore.undo}} {{/if}} {{if $item.tagger}} {{$item.tagger.add}} From 6d31c11e57cfcf143a7554e733746320730f0a15 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jan 2021 16:23:46 -0500 Subject: [PATCH 2/2] Move GET item/ignore/{id} to POST item/{id}/ignore --- src/Module/Item/Ignore.php | 29 +++++++++++++++++------------ static/routes.config.php | 2 +- view/js/main.js | 4 ++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Module/Item/Ignore.php b/src/Module/Item/Ignore.php index 1883faa905..668e493109 100644 --- a/src/Module/Item/Ignore.php +++ b/src/Module/Item/Ignore.php @@ -41,18 +41,17 @@ class Ignore extends BaseModule throw new HttpException\ForbiddenException($l10n->t('Access denied.')); } - $args = DI::args(); - $dba = DI::dba(); - - $message_id = intval($args->get(2)); - - if (empty($message_id) || !is_int($message_id)) { + if (empty($parameters['id'])) { throw new HTTPException\BadRequestException(); } - $thread = Post::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]); + $itemId = intval($parameters['id']); + + $dba = DI::dba(); + + $thread = Post::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $itemId]); if (!$dba->isResult($thread)) { - throw new HTTPException\BadRequestException(); + throw new HTTPException\NotFoundException(); } // Numeric values are needed for the json output further below @@ -61,11 +60,11 @@ class Ignore extends BaseModule switch ($thread['uid'] ?? 0) { // if the thread is from the current user case local_user(): - $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]); + $dba->update('thread', ['ignored' => $ignored], ['iid' => $itemId]); break; // 0 (null will get transformed to 0) => it's a public post case 0: - $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true); + $dba->update('user-item', ['ignored' => $ignored], ['iid' => $itemId, 'uid' => local_user()], true); break; // Throws a BadRequestException and not a ForbiddenException on purpose // Avoids harvesting existing, but forbidden IIDs (security issue) @@ -86,7 +85,13 @@ class Ignore extends BaseModule DI::baseUrl()->redirect($return_path . $rand); } - // the json doesn't really matter, it will either be 0 or 1 - System::jsonExit($ignored); + $return = [ + 'status' => 'ok', + 'item_id' => $itemId, + 'verb' => 'ignore', + 'state' => $ignored, + ]; + + System::jsonExit($return); } } diff --git a/static/routes.config.php b/static/routes.config.php index 564b920d61..6acad3827e 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -291,8 +291,8 @@ return [ ], '/item' => [ - '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]], '/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], + '/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]], '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], ], diff --git a/view/js/main.js b/view/js/main.js index 3613ee78f6..4921ea94f7 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -728,8 +728,8 @@ function doPin(ident) { function doIgnoreThread(ident) { ident = ident.toString(); $('#like-rotator-' + ident).show(); - $.get('item/ignore/' + ident, function(data) { - if (data === 1) { + $.post('item/' + ident + '/ignore', function(data) { + if (data.state === 1) { $('#ignored-' + ident) .addClass('ignored') .removeClass('unignored');