|
@@ -6,7 +6,6 @@ from django.utils.translation import ngettext
|
|
|
|
|
|
from ...acl import algebra
|
|
from ...acl import algebra
|
|
from ...acl.decorators import return_boolean
|
|
from ...acl.decorators import return_boolean
|
|
-from ...admin.forms import YesNoSwitch
|
|
|
|
from ...categories.models import Category, CategoryRole
|
|
from ...categories.models import Category, CategoryRole
|
|
from ...categories.permissions import get_categories_roles
|
|
from ...categories.permissions import get_categories_roles
|
|
from ..models import Post, Thread
|
|
from ..models import Post, Thread
|
|
@@ -45,7 +44,8 @@ class CategoryPermissionsForm(forms.Form):
|
|
"Time limit for changing marked best answer in owned thread, in minutes"
|
|
"Time limit for changing marked best answer in owned thread, in minutes"
|
|
),
|
|
),
|
|
help_text=_(
|
|
help_text=_(
|
|
- "Enter 0 to don't limit time for changing marked best answer in owned thread."
|
|
|
|
|
|
+ "Enter 0 to don't limit time for changing marked best answer in "
|
|
|
|
+ "owned thread."
|
|
),
|
|
),
|
|
initial=0,
|
|
initial=0,
|
|
min_value=0,
|
|
min_value=0,
|
|
@@ -55,8 +55,6 @@ class CategoryPermissionsForm(forms.Form):
|
|
def change_permissions_form(role):
|
|
def change_permissions_form(role):
|
|
if isinstance(role, CategoryRole):
|
|
if isinstance(role, CategoryRole):
|
|
return CategoryPermissionsForm
|
|
return CategoryPermissionsForm
|
|
- else:
|
|
|
|
- return None
|
|
|
|
|
|
|
|
|
|
|
|
def build_acl(acl, roles, key_name):
|
|
def build_acl(acl, roles, key_name):
|
|
@@ -140,7 +138,8 @@ def allow_mark_best_answer(user_acl, target):
|
|
if not category_acl.get("can_mark_best_answers"):
|
|
if not category_acl.get("can_mark_best_answers"):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- 'You don\'t have permission to mark best answers in the "%(category)s" category.'
|
|
|
|
|
|
+ "You don't have permission to mark best answers in the "
|
|
|
|
+ '"%(category)s" category.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
@@ -151,8 +150,8 @@ def allow_mark_best_answer(user_acl, target):
|
|
):
|
|
):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to mark best answer in this thread because you didn't "
|
|
|
|
- "start it."
|
|
|
|
|
|
+ "You don't have permission to mark best answer in this thread "
|
|
|
|
+ "because you didn't start it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -160,16 +159,16 @@ def allow_mark_best_answer(user_acl, target):
|
|
if target.category.is_closed:
|
|
if target.category.is_closed:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to mark best answer in this thread because its "
|
|
|
|
- 'category "%(category)s" is closed.'
|
|
|
|
|
|
+ "You don't have permission to mark best answer in this thread "
|
|
|
|
+ 'because its category "%(category)s" is closed.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
if target.is_closed:
|
|
if target.is_closed:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You can't mark best answer in this thread because it's closed and you don't "
|
|
|
|
- "have permission to open it."
|
|
|
|
|
|
+ "You can't mark best answer in this thread because it's closed "
|
|
|
|
+ "and you don't have permission to open it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -186,8 +185,8 @@ def allow_change_best_answer(user_acl, target):
|
|
if not category_acl.get("can_change_marked_answers"):
|
|
if not category_acl.get("can_change_marked_answers"):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to change this thread's marked answer because it's "
|
|
|
|
- 'in the "%(category)s" category.'
|
|
|
|
|
|
+ "You don't have permission to change this thread's marked answer "
|
|
|
|
+ 'because it\'s in the "%(category)s" category.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
@@ -196,31 +195,26 @@ def allow_change_best_answer(user_acl, target):
|
|
if user_acl["user_id"] != target.starter_id:
|
|
if user_acl["user_id"] != target.starter_id:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to change this thread's marked answer because you "
|
|
|
|
- "are not a thread starter."
|
|
|
|
|
|
+ "You don't have permission to change this thread's marked answer "
|
|
|
|
+ "because you are not a thread starter."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
if not has_time_to_change_answer(user_acl, target):
|
|
if not has_time_to_change_answer(user_acl, target):
|
|
|
|
+ # pylint: disable=line-too-long
|
|
|
|
+ message = ngettext(
|
|
|
|
+ "You don't have permission to change best answer that was marked for more than %(minutes)s minute.",
|
|
|
|
+ "You don't have permission to change best answer that was marked for more than %(minutes)s minutes.",
|
|
|
|
+ category_acl["best_answer_change_time"],
|
|
|
|
+ )
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
- ngettext(
|
|
|
|
- (
|
|
|
|
- "You don't have permission to change best answer that was marked for more "
|
|
|
|
- "than %(minutes)s minute."
|
|
|
|
- ),
|
|
|
|
- (
|
|
|
|
- "You don't have permission to change best answer that was marked for more "
|
|
|
|
- "than %(minutes)s minutes."
|
|
|
|
- ),
|
|
|
|
- category_acl["best_answer_change_time"],
|
|
|
|
- )
|
|
|
|
- % {"minutes": category_acl["best_answer_change_time"]}
|
|
|
|
|
|
+ message % {"minutes": category_acl["best_answer_change_time"]}
|
|
)
|
|
)
|
|
|
|
|
|
if target.best_answer_is_protected and not category_acl["can_protect_posts"]:
|
|
if target.best_answer_is_protected and not category_acl["can_protect_posts"]:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to change this thread's best answer because "
|
|
|
|
- "a moderator has protected it."
|
|
|
|
|
|
+ "You don't have permission to change this thread's best answer "
|
|
|
|
+ "because a moderator has protected it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -240,8 +234,8 @@ def allow_unmark_best_answer(user_acl, target):
|
|
if not category_acl.get("can_change_marked_answers"):
|
|
if not category_acl.get("can_change_marked_answers"):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- 'You don\'t have permission to unmark threads answers in the "%(category)s" '
|
|
|
|
- "category."
|
|
|
|
|
|
+ "You don't have permission to unmark threads answers in "
|
|
|
|
+ 'the "%(category)s" category.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
@@ -250,48 +244,43 @@ def allow_unmark_best_answer(user_acl, target):
|
|
if user_acl["user_id"] != target.starter_id:
|
|
if user_acl["user_id"] != target.starter_id:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to unmark this best answer because you are not a "
|
|
|
|
- "thread starter."
|
|
|
|
|
|
+ "You don't have permission to unmark this best answer "
|
|
|
|
+ "because you are not a thread starter."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
if not has_time_to_change_answer(user_acl, target):
|
|
if not has_time_to_change_answer(user_acl, target):
|
|
|
|
+ # pylint: disable=line-too-long
|
|
|
|
+ message = ngettext(
|
|
|
|
+ "You don't have permission to unmark best answer that was marked for more than %(minutes)s minute.",
|
|
|
|
+ "You don't have permission to unmark best answer that was marked for more than %(minutes)s minutes.",
|
|
|
|
+ category_acl["best_answer_change_time"],
|
|
|
|
+ )
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
- ngettext(
|
|
|
|
- (
|
|
|
|
- "You don't have permission to unmark best answer that was marked for more "
|
|
|
|
- "than %(minutes)s minute."
|
|
|
|
- ),
|
|
|
|
- (
|
|
|
|
- "You don't have permission to unmark best answer that was marked for more "
|
|
|
|
- "than %(minutes)s minutes."
|
|
|
|
- ),
|
|
|
|
- category_acl["best_answer_change_time"],
|
|
|
|
- )
|
|
|
|
- % {"minutes": category_acl["best_answer_change_time"]}
|
|
|
|
|
|
+ message % {"minutes": category_acl["best_answer_change_time"]}
|
|
)
|
|
)
|
|
|
|
|
|
if not category_acl["can_close_threads"]:
|
|
if not category_acl["can_close_threads"]:
|
|
if target.category.is_closed:
|
|
if target.category.is_closed:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to unmark this best answer because its category "
|
|
|
|
- '"%(category)s" is closed.'
|
|
|
|
|
|
+ "You don't have permission to unmark this best answer "
|
|
|
|
+ 'because its category "%(category)s" is closed.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
if target.is_closed:
|
|
if target.is_closed:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You can't unmark this thread's best answer because it's closed and you "
|
|
|
|
- "don't have permission to open it."
|
|
|
|
|
|
+ "You can't unmark this thread's best answer "
|
|
|
|
+ "because it's closed and you don't have permission to open it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
if target.best_answer_is_protected and not category_acl["can_protect_posts"]:
|
|
if target.best_answer_is_protected and not category_acl["can_protect_posts"]:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to unmark this thread's best answer because a "
|
|
|
|
- "moderator has protected it."
|
|
|
|
|
|
+ "You don't have permission to unmark this thread's best answer "
|
|
|
|
+ "because a moderator has protected it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -311,7 +300,8 @@ def allow_mark_as_best_answer(user_acl, target):
|
|
if not category_acl.get("can_mark_best_answers"):
|
|
if not category_acl.get("can_mark_best_answers"):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- 'You don\'t have permission to mark best answers in the "%(category)s" category.'
|
|
|
|
|
|
+ "You don't have permission to mark best answers "
|
|
|
|
+ 'in the "%(category)s" category.'
|
|
)
|
|
)
|
|
% {"category": target.category}
|
|
% {"category": target.category}
|
|
)
|
|
)
|
|
@@ -322,8 +312,8 @@ def allow_mark_as_best_answer(user_acl, target):
|
|
):
|
|
):
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to mark best answer in this thread because you "
|
|
|
|
- "didn't start it."
|
|
|
|
|
|
+ "You don't have permission to mark best answer in this thread "
|
|
|
|
+ "because you didn't start it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -341,8 +331,8 @@ def allow_mark_as_best_answer(user_acl, target):
|
|
if target.is_protected and not category_acl["can_protect_posts"]:
|
|
if target.is_protected and not category_acl["can_protect_posts"]:
|
|
raise PermissionDenied(
|
|
raise PermissionDenied(
|
|
_(
|
|
_(
|
|
- "You don't have permission to mark this post as best answer because a moderator "
|
|
|
|
- "has protected it."
|
|
|
|
|
|
+ "You don't have permission to mark this post as best answer "
|
|
|
|
+ "because a moderator has protected it."
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
@@ -378,5 +368,5 @@ def has_time_to_change_answer(user_acl, target):
|
|
diff = timezone.now() - target.best_answer_marked_on
|
|
diff = timezone.now() - target.best_answer_marked_on
|
|
diff_minutes = int(diff.total_seconds() / 60)
|
|
diff_minutes = int(diff.total_seconds() / 60)
|
|
return diff_minutes < change_time
|
|
return diff_minutes < change_time
|
|
- else:
|
|
|
|
- return True
|
|
|
|
|
|
+
|
|
|
|
+ return True
|