From 2428987e53c2ac6feecd48953b35ce99e7de207b Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Fri, 26 Aug 2011 13:36:34 +0100 Subject: [PATCH] Flesh out and enable the Reddit gargoyle switch --- app/hr/templates/hr/applications/view.html | 3 +++ app/hr/views.py | 10 ++++++---- app/reddit/views.py | 4 ++++ app/sso/forms.py | 5 ++++- app/sso/templates/sso/lookup/user.html | 3 +++ app/sso/templates/sso/profile.html | 3 +++ app/sso/views.py | 14 +++++++------- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/hr/templates/hr/applications/view.html b/app/hr/templates/hr/applications/view.html index 3d2f3fe..7920ad4 100644 --- a/app/hr/templates/hr/applications/view.html +++ b/app/hr/templates/hr/applications/view.html @@ -4,6 +4,7 @@ {% load if_extra %} {% load installed %} {% load naturaltimediff %} +{% load gargoyle_tags %} {% block title %}View Application{% endblock %} @@ -128,6 +129,7 @@ {% endfor %} {% if "reddit"|installed %} +{% ifswitch reddit %} {% if app.user.redditaccount_set.all %}

Reddit Accounts

@@ -193,6 +195,7 @@ function handleResponse() {
{% endif %} +{% endifswitch %} {% endif %} {% endif %} {% endblock %} diff --git a/app/hr/views.py b/app/hr/views.py index 90c7c2a..7f38fe8 100644 --- a/app/hr/views.py +++ b/app/hr/views.py @@ -10,8 +10,9 @@ from django.template import RequestContext from django.template.loader import render_to_string from django.conf import settings -from utils import installed, blacklist_values +from gargoyle import gargoyle +from utils import installed, blacklist_values from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerCharacter from hr.forms import CreateRecommendationForm, CreateApplicationForm, NoteForm, BlacklistUserForm, AdminNoteForm from hr.models import Recommendation, Application, Audit, Blacklist, BlacklistSource @@ -95,7 +96,7 @@ def view_application(request, applicationid): # Respond to Reddit Comment Load # TODO: Move to reddit app? - if installed('reddit') and request.GET.has_key('redditxhr') and request.is_ajax(): + if installed('reddit') and gargoyle.is_active('reddit', request) and request.GET.has_key('redditxhr') and request.is_ajax(): posts = [] for acc in app.user.redditaccount_set.all(): try: @@ -330,8 +331,9 @@ def blacklist_user(request, userid): for ea in u.eveaccount_set.all(): blacklist_item(BLACKLIST_TYPE_APIUSERID, ea.api_user_id) - for ra in u.redditaccount_set.all(): - blacklist_item(BLACKLIST_TYPE_REDDIT, ra.username) + if installed('reddit'): + for ra in u.redditaccount_set.all(): + blacklist_item(BLACKLIST_TYPE_REDDIT, ra.username) for char in EVEPlayerCharacter.objects.filter(eveaccount__user=u): blacklist_item(BLACKLIST_TYPE_CHARACTER, char.name) diff --git a/app/reddit/views.py b/app/reddit/views.py index f1c88a3..99c3fa4 100644 --- a/app/reddit/views.py +++ b/app/reddit/views.py @@ -3,10 +3,13 @@ from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.contrib import messages +from gargoyle.decorators import switch_is_active + from reddit.forms import RedditAccountForm from reddit.models import RedditAccount @login_required +@switch_is_active('reddit') def reddit_add(request): """ Add a Reddit account to a user's account """ @@ -32,6 +35,7 @@ def reddit_add(request): return render_to_response('reddit/add_reddit_account.html', locals(), context_instance=RequestContext(request)) @login_required +@switch_is_active('reddit') def reddit_del(request, redditid=0): """ Delete a Reddit account from a user's account """ diff --git a/app/sso/forms.py b/app/sso/forms.py index 7d91851..a4e985f 100644 --- a/app/sso/forms.py +++ b/app/sso/forms.py @@ -4,6 +4,8 @@ from django import forms from django.contrib.auth.models import User from django.conf import settings +from gargoyle import gargoyle + from utils import installed from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation @@ -92,12 +94,13 @@ class UserLookupForm(forms.Form): """ User Lookup Form """ def __init__(self, *args, **kwargs): + request = kwargs.pop('request', None) super(UserLookupForm, self).__init__(*args, **kwargs) choices = [(1, "Auth Username"), (2, "Character"), (4, "Email Address"), (5, "EVE API User ID"), ] - if installed('reddit'): + if installed('reddit') and gargoyle.is_active('reddit', request): choices.append((3, "Reddit ID")) self.fields['type'] = forms.ChoiceField(label=u'Search type', choices=choices) diff --git a/app/sso/templates/sso/lookup/user.html b/app/sso/templates/sso/lookup/user.html index 4c3361a..ce646f5 100644 --- a/app/sso/templates/sso/lookup/user.html +++ b/app/sso/templates/sso/lookup/user.html @@ -2,6 +2,7 @@ {% load naturaltimediff %} {% load installed %} +{% load gargoyle_tags %} {% block content %} @@ -108,6 +109,7 @@ {% endif %} {% if "reddit"|installed %} +{% ifswitch reddit %}

Reddit Accounts

{% if user.redditaccount_set.all %} @@ -125,6 +127,7 @@
{% endif %} +{% endifswitch %} {% endif %} {% endblock %} diff --git a/app/sso/templates/sso/profile.html b/app/sso/templates/sso/profile.html index 46e6b23..261dbe4 100644 --- a/app/sso/templates/sso/profile.html +++ b/app/sso/templates/sso/profile.html @@ -2,6 +2,7 @@ {% load naturaltimediff %} {% load installed %} +{% load gargoyle_tags %} {% block title %}Your Profile{% endblock %} @@ -125,6 +126,7 @@ setup.


{% if "reddit"|installed %} +{% ifswitch reddit %}

Reddit Accounts

This is a list of all your current linked Reddit accounts

{% if user.redditaccount_set.all %} @@ -144,6 +146,7 @@ setup.

Reddit account tagging is {% if user.get_profile.tag_reddit_accounts %}Enabled{% else %}Disabled{% endif %}. {% if user.get_profile.tag_reddit_accounts %}Disable{% else %}Enable{% endif %} +{% endifswitch %} {% endif %} {% endblock %} diff --git a/app/sso/views.py b/app/sso/views.py index 286385b..503f392 100644 --- a/app/sso/views.py +++ b/app/sso/views.py @@ -14,15 +14,14 @@ from django.template import RequestContext from django.core import serializers from django.conf import settings -from utils import installed +from gargoyle import gargoyle +from gargoyle.decorators import switch_is_active +from utils import installed from eve_api.models import EVEAccount, EVEPlayerCharacter from eve_api.tasks import import_apikey, import_apikey_result, update_user_access - from eve_proxy.models import ApiAccessLog - from reddit.tasks import update_user_flair - from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm, EmailChangeForm, PrimaryCharacterForm @@ -182,13 +181,13 @@ def user_view(request, username, template='sso/lookup/user.html'): def user_lookup(request): """ Lookup a user's account by providing a matching criteria """ - form = UserLookupForm() + form = UserLookupForm(request=request) if not request.user.has_perm('sso.can_search_users'): return redirect('sso.views.profile') if request.method == 'POST': - form = UserLookupForm(request.POST) + form = UserLookupForm(request.POST, request=request) if form.is_valid(): users = None uids = [] @@ -200,7 +199,7 @@ def user_lookup(request): for u in uid: uids.append(u['user']) users = User.objects.filter(id__in=uids).only('username') - elif installed('reddit') and form.cleaned_data['type'] == '3': + elif installed('reddit') and gargoyle.is_active('reddit', request) and form.cleaned_data['type'] == '3': from reddit.models import RedditAccount uid = RedditAccount.objects.filter(username__icontains=username).values('user') for u in uid: @@ -291,6 +290,7 @@ def primarychar_change(request): @login_required +@switch_is_active('reddit') def toggle_reddit_tagging(request): profile = request.user.get_profile() if profile.primary_character: