summaryrefslogtreecommitdiffstats
path: root/forum/auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'forum/auth.py')
-rw-r--r--forum/auth.py90
1 files changed, 45 insertions, 45 deletions
diff --git a/forum/auth.py b/forum/auth.py
index d45e3647..6c9998cb 100644
--- a/forum/auth.py
+++ b/forum/auth.py
@@ -14,7 +14,7 @@ from models import mark_offensive, delete_post_or_answer
from const import TYPE_REPUTATION
import logging
-from forum.conf import settings
+from forum.conf import settings as forum_settings
def can_moderate_users(user):
return user.is_superuser
@@ -22,13 +22,13 @@ def can_moderate_users(user):
def can_vote_up(user):
"""Determines if a User can vote Questions and Answers up."""
return user.is_authenticated() and (
- user.reputation >= settings.MIN_REP_TO_VOTE_UP or
+ user.reputation >= forum_settings.MIN_REP_TO_VOTE_UP or
user.is_superuser)
def can_flag_offensive(user):
"""Determines if a User can flag Questions and Answers as offensive."""
return user.is_authenticated() and (
- user.reputation >= settings.MIN_REP_TO_FLAG_OFFENSIVE or
+ user.reputation >= forum_settings.MIN_REP_TO_FLAG_OFFENSIVE or
user.is_superuser)
def can_add_comments(user,subject):
@@ -36,7 +36,7 @@ def can_add_comments(user,subject):
if user.is_authenticated():
if user.id == subject.author.id:
return True
- if user.reputation >= settings.MIN_REP_TO_LEAVE_COMMENTS:
+ if user.reputation >= forum_settings.MIN_REP_TO_LEAVE_COMMENTS:
return True
if user.is_superuser:
return True
@@ -47,55 +47,55 @@ def can_add_comments(user,subject):
def can_vote_down(user):
"""Determines if a User can vote Questions and Answers down."""
return user.is_authenticated() and (
- user.reputation >= settings.MIN_REP_TO_VOTE_DOWN or
+ user.reputation >= forum_settings.MIN_REP_TO_VOTE_DOWN or
user.is_superuser)
def can_retag_questions(user):
"""Determines if a User can retag Questions."""
return user.is_authenticated() and (
- settings.MIN_REP_TO_RETAG_OTHERS_QUESTIONS
+ forum_settings.MIN_REP_TO_RETAG_OTHERS_QUESTIONS
<= user.reputation
- < settings.MIN_REP_TO_EDIT_OTHERS_POSTS or
+ < forum_settings.MIN_REP_TO_EDIT_OTHERS_POSTS or
user.is_superuser)
def can_edit_post(user, post):
"""Determines if a User can edit the given Question or Answer."""
return user.is_authenticated() and (
user.id == post.author_id or
- (post.wiki and user.reputation >= settings.MIN_REP_TO_EDIT_WIKI) or
- user.reputation >= settings.MIN_REP_TO_EDIT_OTHERS_POSTS or
+ (post.wiki and user.reputation >= forum_settings.MIN_REP_TO_EDIT_WIKI) or
+ user.reputation >= forum_settings.MIN_REP_TO_EDIT_OTHERS_POSTS or
user.is_superuser)
def can_delete_comment(user, comment):
"""Determines if a User can delete the given Comment."""
return user.is_authenticated() and (
user.id == comment.user_id or
- user.reputation >= settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS or
+ user.reputation >= forum_settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS or
user.is_superuser)
def can_view_offensive_flags(user):
"""Determines if a User can view offensive flag counts."""
return user.is_authenticated() and (
- user.reputation >= settings.MIN_REP_TO_VIEW_OFFENSIVE_FLAGS or
+ user.reputation >= forum_settings.MIN_REP_TO_VIEW_OFFENSIVE_FLAGS or
user.is_superuser)
def can_close_question(user, question):
"""Determines if a User can close the given Question."""
return user.is_authenticated() and (
(user.id == question.author_id and
- user.reputation >= settings.MIN_REP_TO_CLOSE_OWN_QUESTIONS) or
- user.reputation >= settings.MIN_REP_TO_CLOSE_OTHERS_QUESTIONS or
+ user.reputation >= forum_settings.MIN_REP_TO_CLOSE_OWN_QUESTIONS) or
+ user.reputation >= forum_settings.MIN_REP_TO_CLOSE_OTHERS_QUESTIONS or
user.is_superuser)
def can_lock_posts(user):
"""Determines if a User can lock Questions or Answers."""
return user.is_authenticated() and (
- user.reputation >= settings.MIN_REP_TO_LOCK_POSTS or
+ user.reputation >= forum_settings.MIN_REP_TO_LOCK_POSTS or
user.is_superuser)
def can_follow_url(user):
"""Determines if the URL link can be followed by Google search engine."""
- return user.reputation >= settings.MIN_REP_TO_DISABLE_URL_NOFOLLOW
+ return user.reputation >= forum_settings.MIN_REP_TO_DISABLE_URL_NOFOLLOW
def can_accept_answer(user, question, answer):
return (user.is_authenticated() and
@@ -106,7 +106,7 @@ def can_accept_answer(user, question, answer):
def can_reopen_question(user, question):
return (user.is_authenticated() and
user.id == question.author_id and
- user.reputation >= settings.MIN_REP_TO_REOPEN_OWN_QUESTIONS) or user.is_superuser
+ user.reputation >= forum_settings.MIN_REP_TO_REOPEN_OWN_QUESTIONS) or user.is_superuser
def can_delete_post(user, post):
if user.is_superuser:
@@ -143,7 +143,7 @@ def can_view_user_edit(request_user, target_user):
def can_upload_files(request_user):
return (request_user.is_authenticated() and
- request_user.reputation >= settings.MIN_REP_TO_UPLOAD_FILES) or \
+ request_user.reputation >= forum_settings.MIN_REP_TO_UPLOAD_FILES) or \
request_user.is_superuser
###########################################
@@ -166,7 +166,7 @@ def onFlaggedItem(item, post, user, timestamp=None):
post.save()
post.author.reputation = calculate_reputation(post.author.reputation,
- settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE)
+ forum_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE)
post.author.save()
question = post
@@ -174,35 +174,35 @@ def onFlaggedItem(item, post, user, timestamp=None):
question = post.question
reputation = Repute(user=post.author,
- negative=settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE,
question=question, reputed_at=timestamp,
reputation_type=-4,
reputation=post.author.reputation)
reputation.save()
#todo: These should be updated to work on same revisions.
- if post.offensive_flag_count == settings.MIN_FLAGS_TO_HIDE_POST:
+ if post.offensive_flag_count == forum_settings.MIN_FLAGS_TO_HIDE_POST:
post.author.reputation = calculate_reputation(post.author.reputation,
- settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION)
+ forum_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION)
post.author.save()
reputation = Repute(user=post.author,
- negative=settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION,
question=question,
reputed_at=timestamp,
reputation_type=-6,
reputation=post.author.reputation)
reputation.save()
- elif post.offensive_flag_count == settings.MIN_FLAGS_TO_DELETE_POST:
+ elif post.offensive_flag_count == forum_settings.MIN_FLAGS_TO_DELETE_POST:
post.author.reputation = calculate_reputation(post.author.reputation,
- settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION)
+ forum_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION)
post.author.save()
reputation = Repute(user=post.author,
- negative=settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION,
question=question,
reputed_at=timestamp,
reputation_type=-7,
@@ -232,7 +232,7 @@ def onAnswerAccept(answer, user, timestamp=None):
answer.author.reputation = calculate_reputation(
answer.author.reputation,
- settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE
+ forum_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE
)
answer.author.save()
reputation = Repute(user=answer.author,
@@ -244,10 +244,10 @@ def onAnswerAccept(answer, user, timestamp=None):
reputation.save()
user.reputation = calculate_reputation(user.reputation,
- settings.REP_GAIN_FOR_ACCEPTING_ANSWER)
+ forum_settings.REP_GAIN_FOR_ACCEPTING_ANSWER)
user.save()
reputation = Repute(user=user,
- positive=settings.REP_GAIN_FOR_ACCEPTING_ANSWER,
+ positive=forum_settings.REP_GAIN_FOR_ACCEPTING_ANSWER,
question=answer.question,
reputed_at=timestamp,
reputation_type=3,
@@ -265,10 +265,10 @@ def onAnswerAcceptCanceled(answer, user, timestamp=None):
answer.question.save()
answer.author.reputation = calculate_reputation(answer.author.reputation,
- settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE)
+ forum_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE)
answer.author.save()
reputation = Repute(user=answer.author,
- negative=settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE,
question=answer.question,
reputed_at=timestamp,
reputation_type=-2,
@@ -276,10 +276,10 @@ def onAnswerAcceptCanceled(answer, user, timestamp=None):
reputation.save()
user.reputation = calculate_reputation(user.reputation,
- settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE)
+ forum_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE)
user.save()
reputation = Repute(user=user,
- negative=settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE,
+ negative=forum_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE,
question=answer.question,
reputed_at=timestamp,
reputation_type=-1,
@@ -299,9 +299,9 @@ def onUpVoted(vote, post, user, timestamp=None):
if not post.wiki:
author = post.author
todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author)
- if todays_rep_gain < settings.MAX_REP_GAIN_PER_USER_PER_DAY:
+ if todays_rep_gain < forum_settings.MAX_REP_GAIN_PER_USER_PER_DAY:
author.reputation = calculate_reputation(author.reputation,
- settings.REP_GAIN_FOR_RECEIVING_UPVOTE)
+ forum_settings.REP_GAIN_FOR_RECEIVING_UPVOTE)
author.save()
question = post
@@ -309,7 +309,7 @@ def onUpVoted(vote, post, user, timestamp=None):
question = post.question
reputation = Repute(user=author,
- positive=settings.REP_GAIN_FOR_RECEIVING_UPVOTE,
+ positive=forum_settings.REP_GAIN_FOR_RECEIVING_UPVOTE,
question=question,
reputed_at=timestamp,
reputation_type=1,
@@ -331,7 +331,7 @@ def onUpVotedCanceled(vote, post, user, timestamp=None):
if not post.wiki:
author = post.author
author.reputation = calculate_reputation(author.reputation,
- settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION)
+ forum_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION)
author.save()
question = post
@@ -339,7 +339,7 @@ def onUpVotedCanceled(vote, post, user, timestamp=None):
question = post.question
reputation = Repute(user=author,
- negative=settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION,
question=question,
reputed_at=timestamp,
reputation_type=-8,
@@ -359,7 +359,7 @@ def onDownVoted(vote, post, user, timestamp=None):
if not post.wiki:
author = post.author
author.reputation = calculate_reputation(author.reputation,
- settings.REP_LOSS_FOR_DOWNVOTING)
+ forum_settings.REP_LOSS_FOR_DOWNVOTING)
author.save()
question = post
@@ -367,7 +367,7 @@ def onDownVoted(vote, post, user, timestamp=None):
question = post.question
reputation = Repute(user=author,
- negative=settings.REP_LOSS_FOR_DOWNVOTING,
+ negative=forum_settings.REP_LOSS_FOR_DOWNVOTING,
question=question,
reputed_at=timestamp,
reputation_type=-3,
@@ -375,11 +375,11 @@ def onDownVoted(vote, post, user, timestamp=None):
reputation.save()
user.reputation = calculate_reputation(user.reputation,
- settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE)
+ forum_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE)
user.save()
reputation = Repute(user=user,
- negative=settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE,
+ negative=forum_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE,
question=question,
reputed_at=timestamp,
reputation_type=-5,
@@ -401,7 +401,7 @@ def onDownVotedCanceled(vote, post, user, timestamp=None):
if not post.wiki:
author = post.author
author.reputation = calculate_reputation(author.reputation,
- settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION)
+ forum_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION)
author.save()
question = post
@@ -409,7 +409,7 @@ def onDownVotedCanceled(vote, post, user, timestamp=None):
question = post.question
reputation = Repute(user=author,
- positive=settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION,
+ positive=forum_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION,
question=question,
reputed_at=timestamp,
reputation_type=4,
@@ -417,11 +417,11 @@ def onDownVotedCanceled(vote, post, user, timestamp=None):
reputation.save()
user.reputation = calculate_reputation(user.reputation,
- settings.REP_GAIN_FOR_CANCELING_DOWNVOTE)
+ forum_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE)
user.save()
reputation = Repute(user=user,
- positive=settings.REP_GAIN_FOR_CANCELING_DOWNVOTE,
+ positive=forum_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE,
question=question,
reputed_at=timestamp,
reputation_type=5,