X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/87e592dc4c9e0321635350da8c9f1624554a604f..50218f3c76fc43de83da77dda0501b5aabffa4d4:/forum/models/user.py diff --git a/forum/models/user.py b/forum/models/user.py index 3e92e16..62eeac3 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -26,7 +26,7 @@ class UserManager(CachedManager): class AnonymousUser(DjangoAnonymousUser): def get_visible_answers(self, question): - return question.answers.filter(deleted=None) + return question.answers.filter_state(deleted=False) def can_view_deleted_post(self, post): return False @@ -55,12 +55,24 @@ class AnonymousUser(DjangoAnonymousUser): def can_delete_comment(self, comment): return False + def can_convert_to_comment(self, answer): + return False + def can_accept_answer(self, answer): return False + def can_create_tags(self): + return False + def can_edit_post(self, post): return False + def can_wikify(self, post): + return False + + def can_cancel_wiki(self, post): + return False + def can_retag_questions(self): return False @@ -141,7 +153,7 @@ class User(BaseModel, DjangoUser): return mark_safe(profile_link) def get_visible_answers(self, question): - return question.answers.filter(deleted=None, in_moderation=None) + return question.answers.filter_state(deleted=False) def get_vote_count_today(self): today = datetime.date.today() @@ -201,14 +213,29 @@ class User(BaseModel, DjangoUser): def can_delete_comment(self, comment): return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS) + def can_convert_to_comment(self, answer): + return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int(settings.REP_TO_CONVERT_TO_COMMENT)) + @true_if_is_super_or_staff def can_accept_answer(self, answer): return self == answer.question.author + @true_if_is_super_or_staff + def can_create_tags(self): + return self.reputation >= int(settings.REP_TO_CREATE_TAGS) + @true_if_is_super_or_staff def can_edit_post(self, post): return self == post.author or self.reputation >= int(settings.REP_TO_EDIT_OTHERS - ) or (post.wiki and self.reputation >= int(settings.REP_TO_EDIT_WIKI)) + ) or (post.nis.wiki and self.reputation >= int(settings.REP_TO_EDIT_WIKI)) + + @true_if_is_super_or_staff + def can_wikify(self, post): + return self == post.author or self.reputation >= int(settings.REP_TO_WIKIFY) + + @true_if_is_super_or_staff + def can_cancel_wiki(self, post): + return self == post.author @true_if_is_super_or_staff def can_retag_questions(self): @@ -235,6 +262,11 @@ class User(BaseModel, DjangoUser): def can_upload_files(self): return self.reputation >= int(settings.REP_TO_UPLOAD) + def check_password(self, old_passwd): + self.__dict__.update(self.__class__.objects.filter(id=self.id).values('password')[0]) + return DjangoUser.check_password(self, old_passwd) + + class Meta: app_label = 'forum'