mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-21 13:49:23 +00:00
Flesh out and enable the Reddit gargoyle switch
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
{% load naturaltimediff %}
|
||||
{% load installed %}
|
||||
{% load gargoyle_tags %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@@ -108,6 +109,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if "reddit"|installed %}
|
||||
{% ifswitch reddit %}
|
||||
<br/>
|
||||
<h2>Reddit Accounts</h2>
|
||||
{% if user.redditaccount_set.all %}
|
||||
@@ -125,6 +127,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endifswitch %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
{% load naturaltimediff %}
|
||||
{% load installed %}
|
||||
{% load gargoyle_tags %}
|
||||
|
||||
{% block title %}Your Profile{% endblock %}
|
||||
|
||||
@@ -125,6 +126,7 @@ setup.</p>
|
||||
<br/>
|
||||
|
||||
{% if "reddit"|installed %}
|
||||
{% ifswitch reddit %}
|
||||
<h2>Reddit Accounts</h2>
|
||||
<p>This is a list of all your current linked Reddit accounts</p>
|
||||
{% if user.redditaccount_set.all %}
|
||||
@@ -144,6 +146,7 @@ setup.</p>
|
||||
</p>
|
||||
<p>
|
||||
Reddit account tagging is {% if user.get_profile.tag_reddit_accounts %}Enabled{% else %}Disabled{% endif %}. <a href="{% url sso.views.toggle_reddit_tagging %}">{% if user.get_profile.tag_reddit_accounts %}Disable{% else %}Enable{% endif %}</a>
|
||||
{% endifswitch %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user