Merge pull request #9889 from MrPetovan/task/9872-item-ignore
Move GET item/ignore/{id} to POST item/{id}/ignore
	
	
This commit is contained in:
		
				commit
				
					
						b589b35af0
					
				
			
		
					 7 changed files with 31 additions and 26 deletions
				
			
		|  | @ -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); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -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]], | ||||
| 	], | ||||
| 
 | ||||
|  |  | |||
|  | @ -725,11 +725,11 @@ function doPin(ident) { | |||
| 	}); | ||||
| } | ||||
| 
 | ||||
| function doignore(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'); | ||||
|  |  | |||
|  | @ -229,10 +229,10 @@ | |||
| 
 | ||||
| 						{{if $item.ignore}} | ||||
| 							<li role="menuitem"> | ||||
| 								<a id="ignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 								<a id="ignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 							</li> | ||||
| 							<li role="menuitem"> | ||||
| 								<a id="unignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 								<a id="unignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 							</li> | ||||
| 						{{/if}} | ||||
| 
 | ||||
|  |  | |||
|  | @ -381,10 +381,10 @@ as the value of $top_child_total (this is done at the end of this file) | |||
| 
 | ||||
| 						{{if $item.ignore}} | ||||
| 							<li role="menuitem"> | ||||
| 								<a id="ignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 								<a id="ignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 							</li> | ||||
| 							<li role="menuitem"> | ||||
| 								<a id="unignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 								<a id="unignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 							</li> | ||||
| 						{{/if}} | ||||
| 
 | ||||
|  | @ -540,10 +540,10 @@ as the value of $top_child_total (this is done at the end of this file) | |||
| 
 | ||||
| 						{{if $item.ignore}} | ||||
| 							<li role="menuitem"> | ||||
| 							<a id="ignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 							<a id="ignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore.do}}</a> | ||||
| 						</li> | ||||
| 							<li role="menuitem"> | ||||
| 							<a id="unignore-{{$item.id}}" href="javascript:doignore({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 							<a id="unignore-{{$item.id}}" href="javascript:doIgnoreThread({{$item.id}});" class="btn-link {{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="fa fa-eye" aria-hidden="true"></i> {{$item.ignore.undo}}</a> | ||||
| 						</li> | ||||
| 						{{/if}} | ||||
| 
 | ||||
|  |  | |||
|  | @ -106,8 +106,8 @@ | |||
| 				<a href="#" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classundo}}"  title="{{$item.star.undo}}">{{$item.star.undo}}</a> | ||||
| 			{{/if}} | ||||
| 			{{if $item.ignore}} | ||||
| 			    <a href="#" id="ignore-{{$item.id}}" onclick="doignore({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}">{{$item.ignore.do}}</a> | ||||
| 			    <a href="#" id="unignore-{{$item.id}}" onclick="doignore({{$item.id}}); return false;" class="{{$item.ignore.classundo}}" title="{{$item.ignore.undo}}">{{$item.ignore.undo}}</a> | ||||
| 			    <a href="#" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}">{{$item.ignore.do}}</a> | ||||
| 			    <a href="#" id="unignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classundo}}" title="{{$item.ignore.undo}}">{{$item.ignore.undo}}</a> | ||||
| 			{{/if}} | ||||
| 			{{if $item.tagger}} | ||||
| 				<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.tagger.class}}" title="{{$item.tagger.add}}">{{$item.tagger.add}}</a> | ||||
|  |  | |||
|  | @ -144,8 +144,8 @@ | |||
| 				<a role="button" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classundo}}"  title="{{$item.star.undo}}"><i class="icon-star-empty icon-large"><span class="sr-only">{{$item.star.undo}}</span></i></a> | ||||
| 			{{/if}} | ||||
| 			{{if $item.ignore}} | ||||
| 				<a role="button" id="ignore-{{$item.id}}" onclick="doignore({{$item.id}}); return false;"  class="{{$item.ignore.classdo}}"  title="{{$item.ignore.do}}"><i class="icon-bell-slash icon-large"><span class="sr-only">{{$item.ignore.do}}</span></i></a> | ||||
| 				<a role="button" id="unignore-{{$item.id}}" onclick="doignore({{$item.id}}); return false;"  class="{{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="icon-bell-slash-o icon-large"><span class="sr-only">{{$item.ignore.undo}}</span></i></a> | ||||
| 				<a role="button" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;"  class="{{$item.ignore.classdo}}"  title="{{$item.ignore.do}}"><i class="icon-bell-slash icon-large"><span class="sr-only">{{$item.ignore.do}}</span></i></a> | ||||
| 				<a role="button" id="unignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;"  class="{{$item.ignore.classundo}}"  title="{{$item.ignore.undo}}"><i class="icon-bell-slash-o icon-large"><span class="sr-only">{{$item.ignore.undo}}</span></i></a> | ||||
| 			{{/if}} | ||||
| 			{{if $item.tagger}} | ||||
| 				<a role="button" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.tagger.class}}" title="{{$item.tagger.add}}"><i class="icon-tags icon-large"><span class="sr-only">{{$item.tagger.add}}</span></i></a> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue