Forum permission¶
The forum_permission
application provides the proper tools to allow permission checks on forums.
It defines permission abstract models and provides
Abstract models¶
Forum permission abstract models¶
This module defines abstract models provided by the forum_permission
application.
-
class
machina.apps.forum_permission.abstract_models.
AbstractForumPermission
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Represents a single forum permission.
The models that subclass
AbstractForumPermission
can be used to define forum permissions. A forum permission is basically defined by a codename and some booleans indicating if the considered permission can be granted globally (in that case the permission applies to all forums) or not.-
name
¶ Returns the name of the considered permission.
-
-
class
machina.apps.forum_permission.abstract_models.
AbstractGroupForumPermission
(*args, **kwargs)¶ Bases:
machina.apps.forum_permission.abstract_models.BaseAuthForumPermission
Represents a per-group forum object permission.
-
class
machina.apps.forum_permission.abstract_models.
AbstractUserForumPermission
(*args, **kwargs)¶ Bases:
machina.apps.forum_permission.abstract_models.BaseAuthForumPermission
Represents a per-user forum object permission.
-
clean
()¶ Validates the current instance.
-
-
class
machina.apps.forum_permission.abstract_models.
BaseAuthForumPermission
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Represents a per-auth-component forum object permission.
Checker¶
Forum permission checker¶
This module defines a ForumPermissionChecker
abstraction that allows to check forum
permissions on specific forum instances.
-
class
machina.apps.forum_permission.checker.
ForumPermissionChecker
(user)¶ Bases:
object
The ForumPermissionChecker allows to check forum permissions on Forum instances.
-
get_perms
(forum)¶ Returns the list of permission codenames of all permissions for the given forum.
-
get_perms_for_forumlist
(forums, perm_codenames=None)¶ Computes and returns a dictionary of [forum] to (set of permissions) for the user, taking into account precendence of permissions:
- forum > global
- user > group > all_authenticated_users
Expects: - forums to be a list of forum objects - perm_codenames to be a list of permission codes (strings) to look for or None
-
has_perm
(perm, forum)¶ Checks if the considered user has given permission for the passed forum.
-
Handler¶
Forum permission handler¶
This module defines a PermissionHandler
abstraction that allows to implement filter or
access logic related to forums.
-
class
machina.apps.forum_permission.handler.
PermissionHandler
¶ Bases:
object
Defines filter / access logic related to forums.
The
PermissionHandler
class allows to filter lists of forums and to perform permission verifications on forums. It uses theForumPermissionChecker
class to perform these verifications.-
can_access_moderation_queue
(user)¶ Returns True if the passed user can access the moderation queue.
-
can_add_announcements
(forum, user)¶ Given a forum, checks whether the user can append announcements to it.
-
can_add_post
(topic, user)¶ Given a topic, checks whether the user can append posts to it.
-
can_add_stickies
(forum, user)¶ Given a forum, checks whether the user can append stickies to it.
-
can_add_topic
(forum, user)¶ Given a forum, checks whether the user can append topics to it.
-
can_approve_posts
(forum, user)¶ Given a forum, checks whether the user can approve its posts.
-
can_attach_files
(forum, user)¶ Given a forum, checks whether the user can add attachments to posts.
-
can_create_polls
(forum, user)¶ Given a forum, checks whether the user can add a topic with an embedded poll.
-
can_delete_post
(post, user)¶ Given a forum post, checks whether the user can delete the latter.
-
can_delete_topics
(forum, user)¶ Given a forum, checks whether the user can delete its topics.
Note: the
can_delete_posts
permission is used here because a user who can delete all the posts of a topic is also able to delete the topic itself.
-
can_download_files
(forum, user)¶ Given a forum, checks whether the user can download files attached to posts.
-
can_edit_post
(post, user)¶ Given a forum post, checks whether the user can edit the latter.
-
can_lock_topics
(forum, user)¶ Given a forum, checks whether the user can lock its topics.
-
can_move_topics
(forum, user)¶ Given a forum, checks whether the user can move its topics to another forum.
-
can_post_without_approval
(forum, user)¶ Given a forum, checks whether the user can add a posts and topics without approval.
-
can_read_forum
(forum, user)¶ Given a forum, checks whether the user can read its content.
-
can_subscribe_to_topic
(topic, user)¶ Given a topic, checks whether the user can add it to their subscription list.
-
can_unsubscribe_from_topic
(topic, user)¶ Given a topic, checks whether the user can remove it from their subscription list.
-
can_update_topics_to_announces
(forum, user)¶ Given a forum, checks whether the user can change its topic types to announces.
-
can_update_topics_to_normal_topics
(forum, user)¶ Given a forum, checks whether the user can change its topic types to normal topics.
-
can_update_topics_to_sticky_topics
(forum, user)¶ Given a forum, checks whether the user can change its topic types to sticky topics.
-
can_vote_in_poll
(poll, user)¶ Given a poll, checks whether the user can answer to it.
-
forum_list_filter
(qs, user)¶ Filters the given queryset in order to return a list of forums that can be seen and read by the specified user (at least).
-
get_moderation_queue_forums
(user)¶ Returns the list of forums whose posts can be approved by the considered user.
-
get_readable_forums
(forums, user)¶ Returns a queryset of forums that can be read by the considered user.
-
get_target_forums_for_moved_topics
(user)¶ Returns a list of forums in which the considered user can add topics that have been moved from another forum.
-