Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae500f7
Initialize misago.likes app
rafalp Oct 23, 2025
91bb333
Kick off work on likes permissions
rafalp Oct 25, 2025
3ad1a51
Add likes permissions to group model
rafalp Oct 25, 2025
ab79a7c
Fix migration order broken by misago.likes introduction
rafalp Oct 25, 2025
571619e
Fix migration
rafalp Oct 25, 2025
22f37cf
Fix type in migration
rafalp Oct 25, 2025
9044042
Fix tests
rafalp Oct 26, 2025
0ef1994
Add permission hooks
rafalp Oct 29, 2025
9d2cf81
Typo
rafalp Oct 29, 2025
be06590
Add likes permissions impl
rafalp Oct 30, 2025
db65665
Add likes permissions
rafalp Oct 30, 2025
96aba7b
Sync post likes util, improve likes sync migration, wip sync posts li…
rafalp Nov 4, 2025
1b9dc90
Fix docs
rafalp Nov 4, 2025
0a44192
Add tests for synchronizepostlikes management command
rafalp Nov 4, 2025
6a33173
WIP like_post util
rafalp Nov 6, 2025
97d455e
Hooks reference
rafalp Nov 6, 2025
5839720
like_post util with tests
rafalp Nov 6, 2025
adbf747
Add select_for_update option to generic thread views
rafalp Nov 7, 2025
cccb866
Untested remove post like util
rafalp Nov 9, 2025
4ec1928
Fix import error
rafalp Nov 9, 2025
cdc16fc
Add tests form remove_post_like
rafalp Nov 9, 2025
214620a
Add extra tests to remove_post_like
rafalp Nov 9, 2025
6c8dd82
Basic like/unlike views, fetch liked posts for posts feed
rafalp Nov 9, 2025
8c923fb
Fetch liked posts for feed
rafalp Nov 10, 2025
8433373
More work on posts likes UI
rafalp Nov 10, 2025
5573c0f
WIP tests for like post view
rafalp Nov 12, 2025
2a3d45e
Add tests for like post views
rafalp Nov 13, 2025
1b52883
Add tests for unlike post views
rafalp Nov 13, 2025
2a91c89
Add plugin hook for get_post_feed_post_likes_data, wip tests
rafalp Nov 18, 2025
f406efa
Add more tests for posts feed likes context util
rafalp Nov 18, 2025
8911611
WIP test post likes data if user can see likes count only
rafalp Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: BuildUserCategoryPermissionsHookAction`

Misago function used to build user category permissions or the next filter function from another plugin.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
2 changes: 1 addition & 1 deletion dev-docs/plugins/hooks/build-user-permissions-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: BuildUserPermissionsHookAction`

Misago function used to build user permissions from their groups or the next filter function from another plugin.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
131 changes: 131 additions & 0 deletions dev-docs/plugins/hooks/can-see-post-likes-count-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# `can_see_post_likes_count_hook`

This hook wraps a standard Misago function used to check if a user has permission to see a post’s likes count. Returns `True` if they can and `False` if they can't.


## Location

This hook can be imported from `misago.permissions.hooks`:

```python
from misago.permissions.hooks import can_see_post_likes_count_hook
```


## Filter

```python
def custom_can_see_post_likes_count_filter(
action: CanSeePostsLikesCountHookAction,
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
post: Post,
) -> bool:
...
```

A function implemented by a plugin that can be registered in this hook.


### Arguments

#### `action: CanSeePostsLikesCountHookAction`

Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.


#### `users: UserPermissionsProxy`

A proxy object with the current user's permissions.


#### `category: Category`

A category to check permissions for.


#### `thread: Thread`

A thread to check permissions for.


#### `post: Post`

A post to check permissions for.


### Return value

A `bool` with `True` if user can see post's likes count, and `False` if they can't.


## Action

```python
def can_see_post_likes_count_action(
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
post: Post,
) -> bool:
...
```

Misago function used to check if a user has permission to see a post’s likes count. Returns `True` if they can and `False` if they can't.


### Arguments

#### `users: UserPermissionsProxy`

A proxy object with the current user's permissions.


#### `category: Category`

A category to check permissions for.


#### `thread: Thread`

A thread to check permissions for.


#### `post: Post`

A post to check permissions for.


### Return value

A `bool` with `True` if user can see post's likes count, and `False` if they can't.


## Example

The code below implements a custom filter function that blocks a user from seeing a specific post's likes count if it has a flag.

```python
from django.core.exceptions import PermissionDenied
from django.utils.translation import pgettext
from misago.categories.models import Category
from misago.permissions.hooks import can_see_post_likes_count_hook
from misago.permissions.proxy import UserPermissionsProxy
from misago.threads.models import Post, Thread

@can_see_post_likes_count_hook.append_filter
def check_user_can_see_post_likes(
action,
permissions: UserPermissionsProxy,
category: Category,
thread: Thread,
post: Post,
) -> bool:
if post.plugin_data.get("hide_likes"):
return False

return action(permissions, category, thread, post)
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CanUploadPrivateThreadsAttachmentsHookAction`

Misago function that checks whether a user has permission to upload attachments in private threads.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CanUploadThreadsAttachmentsHookAction`

Misago function that checks if a user has permission to upload attachments in a category.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckAccessCategoryPermissionHookAction`

Misago function used to check if a user has permission to access a category of unknown type (threads, private threads, or plugin-defined). Raises Django’s `Http404` or `PermissionDenied` if they can't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckAccessPostPermissionHookAction`

Misago function used to check if a user has permission to access a post of unknown type (threads, private threads, or plugin-defined). Raises Django’s `Http404` or `PermissionDenied` if they can't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckAccessThreadPermissionHookAction`

Misago function used to check if a user has permission to access a thread of unknown type (threads, private threads, or plugin-defined). Raises Django’s `Http404` or `PermissionDenied` if they can't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckBrowseCategoryPermissionHookAction`

Misago function used to check if the user has permission to browse a category. It also checks if the user can see the category. It raises Django's `Http404` if they can't see it or `PermissionDenied` with an error message if they can't browse it.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckDeleteAttachmentPermissionHookAction`

Misago function used to check if a user has permission to delete an attachment. It raises `PermissionDenied` if they are not allowed to delete it.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckDownloadAttachmentPermissionHookAction`

Misago function used to check if a user has permission to download an attachment. It raises Django's `Http404` if the user cannot see the attachment or `PermissionDenied` if they are not allowed to download it.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckEditPrivateThreadPermissionHookAction`

Misago function used to check if the user has permission to edit a private thread. It raises Django's `PermissionDenied` with an error message if they can't edit it.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckEditPrivateThreadPostPermissionHookAction`

Misago function used to check if the user has permission to edit a post in a private thread. It raises Django's `PermissionDenied` with an error message if they can't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckEditThreadPermissionHookAction`

Misago function used to check if the user has permission to edit a thread. It raises Django's `PermissionDenied` with an error message if they can't edit it.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckEditThreadPostPermissionHookAction`

Misago function used to check if the user has permission to edit a post in a thread. It raises Django's `PermissionDenied` with an error message if they can't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
127 changes: 127 additions & 0 deletions dev-docs/plugins/hooks/check-like-post-permission-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# `check_like_post_permission_hook`

This hook wraps a standard Misago function used to check if a user has permission to like a post. Raises Django’s `PermissionDenied` if they can't.


## Location

This hook can be imported from `misago.permissions.hooks`:

```python
from misago.permissions.hooks import check_like_post_permission_hook
```


## Filter

```python
def custom_check_like_post_permission_filter(
action: CheckLikePostPermissionHookAction,
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
post: Post,
) -> None:
...
```

A function implemented by a plugin that can be registered in this hook.


### Arguments

#### `action: CheckLikePostPermissionHookAction`

Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.


#### `user_permissions: UserPermissionsProxy`

A proxy object with the current user's permissions.


#### `category: Category`

A category to check permissions for.


#### `thread: Thread`

A thread to check permissions for.


#### `post: Post`

A post to check permissions for.


## Action

```python
def check_like_post_permission_action(
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
post: Post,
) -> None:
...
```

Misago function used to check if a user has permission to like a post. Raises Django’s `PermissionDenied` if they can't.


### Arguments

#### `user_permissions: UserPermissionsProxy`

A proxy object with the current user's permissions.


#### `category: Category`

A category to check permissions for.


#### `thread: Thread`

A thread to check permissions for.


#### `post: Post`

A post to check permissions for.


## Example

The code below implements a custom filter function that blocks a user from liking a specific post if there is a custom flag set on it.

```python
from django.core.exceptions import PermissionDenied
from django.utils.translation import pgettext
from misago.categories.models import Category
from misago.permissions.hooks import check_like_post_permission_hook
from misago.permissions.proxy import UserPermissionsProxy
from misago.threads.models import Post, Thread

@check_like_post_permission_hook.append_filter
def check_user_can_like_post(
action,
permissions: UserPermissionsProxy,
category: Category,
thread: Thread,
post: Post,
) -> None:
# Run standard permission checks
action(permissions, category, thread, post)

if post.plugin_data.get("disable_likes"):
raise PermissionDenied(
pgettext(
"post permission error",
"You can't like this post."
)
)
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A function implemented by a plugin that can be registered in this hook.

#### `action: CheckPrivateThreadsPermissionHookAction`

Misago function used to check if the user has a permission to access private threads feature. Raises Django's `PermissionDenied` with an error message if they don't.
Next function registered in this hook, either a custom function or Misago's standard one.

See the [action](#action) section for details.

Expand Down
Loading