# 如果所有权转移给自己，则无法取消点赞帖子

**URL:** <https://meta.discourse.org/t/unable-to-unlike-post-if-ownership-is-transferred-to-self/158526>\
**Category:** Bug\
**Created:** [2020年七月22日 18:15 UTC](https://meta.discourse.org/t/unable-to-unlike-post-if-ownership-is-transferred-to-self/158526 "2020-07-22T18:15:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wesochuck](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wesochuck/32/108706_2.png) [@wesochuck](https://meta.discourse.org/u/wesochuck)\
**Post date:** [2020年七月22日 18:15 UTC](https://meta.discourse.org/t/unable-to-unlike-post-if-ownership-is-transferred-to-self/158526/1 "2020-07-22T18:15:18Z")

</div>

复现步骤：

1. 点赞另一位用户的帖子
2. 获取该帖子的所有权
3. 您将看到两个点赞按钮，并且无法取消点赞该帖子  
 ![image](https://global.discourse-cdn.com/meta/original/3X/1/5/15b6c2234aac4cef6d6e869ea163bb8bb49716f4.png)

我推测，禁止用户点赞自己帖子的逻辑在转移所有权时生效，因此作为新所有者，您无法取消点赞该帖子。

---

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [2020年八月14日 23:45 UTC](https://meta.discourse.org/t/unable-to-unlike-post-if-ownership-is-transferred-to-self/158526/3 "2020-08-14T23:45:48Z")

</div>

我创建了一个 PR 来解决这个问题：

> <https://github.com/discourse/discourse/pull/10446>
>
> If a user has liked a post that has passed the
> \`post\_undo\_action\_window\_mins\` s…ystem setting window and you transfer ownership
> of that post to that user you will be the owner of a post that you have
> liked, but cannot unlike resulting in a weird UI behavior. This commit
> fixes this issue.
> 
> The existing tests didn't check for the timeout window for unliking
> posts so I added that in.
> 
> I couldn't find a good way to do this logic inside of the guardian class
> so rather than duplicating behavior of the \`PostActionDestroyer\` class
> inside of the \`PostOwnerChanger\` I decided to pass in a "bypass"
> variable that could be used to check if the calling class is the
> 'post\_owner\_changer' and bypass the guardian instead. I went this route
> because the guardian \`can\_delete\_post\_action\` method has no way of
> distinguishing how to allow a user to be able to unlike their own posts
> after the timeout window but only on a post owner change.

我发现，如果在“取消点赞”的超时窗口内，所有权转移可以正常移除点赞；但如果已超过该窗口（例如在旧帖上），点赞就无法被移除，因为此时无法通过守护检查，即无法取消对自己帖子的点赞。

---

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [2020年八月19日 19:22 UTC](https://meta.discourse.org/t/unable-to-unlike-post-if-ownership-is-transferred-to-self/158526/4 "2020-08-19T19:22:16Z")

</div>


