From: qw3rty Date: Fri, 16 Jul 2010 23:05:44 +0000 (+0000) Subject: now superusers and staff can unsubscribe users subscription. X-Git-Tag: live~588 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/094acc5f44c3a7779f42b3d84c86213ba6a1003c now superusers and staff can unsubscribe users subscription. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@546 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/user.py b/forum/models/user.py index cabaabb..7772bc9 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -321,6 +321,10 @@ class User(BaseModel, DjangoUser): def can_upload_files(self): return self.reputation >= int(settings.REP_TO_UPLOAD) + @true_if_is_super_or_staff + def is_a_super_user_or_staff(self): + return False + def email_valid_and_can_ask(self): return 'ask' not in settings.REQUIRE_EMAIL_VALIDATION_TO or self.email_isvalid diff --git a/forum/skins/default/templates/question_list/subscription_item.html b/forum/skins/default/templates/question_list/subscription_item.html index 2087392..3f1f688 100644 --- a/forum/skins/default/templates/question_list/subscription_item.html +++ b/forum/skins/default/templates/question_list/subscription_item.html @@ -1,9 +1,10 @@ {% load i18n humanize extra_filters extra_tags user_tags %}
-
+
{% trans "Unsubscribe" %}
{% trans "Last checked" %} {% diff_date subscription.last_view %}
-
\ No newline at end of file +
+ diff --git a/forum/urls.py b/forum/urls.py index 5cb6594..9d3c4d6 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -84,7 +84,7 @@ urlpatterns += patterns('', , url(r'^%s(?P\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'), url(r'^%s(?P\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'), - url(r'^%s(?P\d+)/$' % _('subscribe/'), app.commands.subscribe, name="subscribe"), + url(r'^%s(?P\d+)/(?P\d+)?/$' % _('subscribe/'), app.commands.subscribe, name="subscribe"), url(r'^%s' % _('matching_tags/'), app.commands.matching_tags, name='matching_tags'), url(r'^%s(?P\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'), url(r'^%s(?P\d+)/' % _('convert/'), app.commands.convert_to_comment, diff --git a/forum/views/commands.py b/forum/views/commands.py index 956463a..74bbe5a 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -436,23 +436,31 @@ def convert_to_comment(request, id): return RefreshPageCommand() @decorate.withfn(command) -def subscribe(request, id): +def subscribe(request, id, user=0): + if user: + user = User.objects.filter(id=user)[0] + if user.is_a_super_user_or_staff(): + raise CommandException(_("You do not have the correct credentials to preform this action.")) + + else: + user = request.user + question = get_object_or_404(Question, id=id) try: - subscription = QuestionSubscription.objects.get(question=question, user=request.user) + subscription = QuestionSubscription.objects.get(question=question, user=user) subscription.delete() subscribed = False except: - subscription = QuestionSubscription(question=question, user=request.user, auto_subscription=False) + subscription = QuestionSubscription(question=question, user=user, auto_subscription=False) subscription.save() subscribed = True return { - 'commands': { - 'set_subscription_button': [subscribed and _('unsubscribe me') or _('subscribe me')], - 'set_subscription_status': [''] - } + 'commands': { + 'set_subscription_button': [subscribed and _('unsubscribe me') or _('subscribe me')], + 'set_subscription_status': [''] + } } #internally grouped views - used by the tagging system