This hook allows plugins to replace or extend the permission check for the "can edit thread poll" permission.
This hook can be imported from misago.permissions.hooks:
from misago.permissions.hooks import check_edit_thread_poll_permission_hookdef custom_check_edit_thread_poll_permission_filter(
action: CheckEditThreadPollPermissionHookAction,
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
poll: Poll,
) -> None:
...A function implemented by a plugin that can be registered in this hook.
Next function registered in this hook, either a custom function or Misago's standard one.
See the action section for details.
A proxy object with the current user's permissions.
A category to check permissions for.
A thread to check permissions for.
A poll to check permissions for.
def check_edit_thread_poll_permission_action(
permissions: 'UserPermissionsProxy',
category: Category,
thread: Thread,
poll: Poll,
) -> None:
...Misago function used to check if the user has permission to edit a thread poll. Raises Django's PermissionDenied exception with an error message if the user lacks permission.
A proxy object with the current user's permissions.
A category to check permissions for.
A thread to check permissions for.
A poll to check permissions for.
Prevents a user from editing a poll in a thread if it has more than 5 votes.
from django.core.exceptions import PermissionDenied
from django.utils.translation import pgettext
from misago.categories.models import Category
from misago.polls.models import Poll
from misago.threads.models import Thread
from misago.permissions.hooks import check_edit_thread_poll_permission_hook
from misago.permissions.proxy import UserPermissionsProxy
@check_edit_thread_poll_permission_hook.append_filter
def check_user_can_edit_poll(
action,
permissions: UserPermissionsProxy,
category: Category,
thread: Thread,
poll: Poll,
) -> None:
# Run standard permission checks
action(permissions, category, thread, poll)
if poll.votes > 5:
raise PermissionDenied(
pgettext(
"poll permission error",
"You cannot edit polls that have received more than 5 votes."
)
)