mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added the ability to add notes to user's accounts
This commit is contained in:
@@ -9,7 +9,7 @@ from gargoyle import gargoyle
|
||||
from utils import installed
|
||||
|
||||
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
|
||||
from sso.models import ServiceAccount, Service
|
||||
from sso.models import ServiceAccount, Service, SSOUserNote
|
||||
from registration.forms import RegistrationForm
|
||||
|
||||
|
||||
@@ -139,3 +139,18 @@ class PrimaryCharacterForm(forms.Form):
|
||||
if self.user:
|
||||
self.fields['character'].queryset = EVEPlayerCharacter.objects.filter(eveaccount__user=self.user).distinct()
|
||||
|
||||
|
||||
class UserNoteForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = SSOUserNote
|
||||
exclude = ('created_by', 'created_date')
|
||||
widgets = {
|
||||
'user': forms.HiddenInput(),
|
||||
'note': forms.Textarea(),
|
||||
}
|
||||
|
||||
def clean_note(self):
|
||||
data = self.cleaned_data['note']
|
||||
# Clean dodgy text?
|
||||
return data
|
||||
|
||||
24
app/sso/templates/sso/add_usernote.html
Normal file
24
app/sso/templates/sso/add_usernote.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Add User Note{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="page-header">
|
||||
<h1>Add User Note</h1>
|
||||
</div>
|
||||
|
||||
<p>This will add a note to {{ user.username }}'s account that'll be visible to everyone able to view user profiles</p>
|
||||
|
||||
<form action="{% url sso-addusernote user.username %}" method="post">
|
||||
<fieldset>
|
||||
{% include "formtools/formerror.html" %}
|
||||
{% include "formtools/formfield.html" with field=form.user %}
|
||||
{% include "formtools/formfield.html" with field=form.note class="xxlarge" %}
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Add Note" class="btn primary" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -28,8 +28,27 @@
|
||||
<a href="{% url hr-blacklistuser user.id %}" class="btn error">Blacklist User</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if perms.sso.add_ssousernote %}
|
||||
<a href="{% url sso-addusernote user %}" class="btn">Add Note</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
{% if user.notes.count %}
|
||||
<h2>User Notes</h2>
|
||||
|
||||
<table class="zebra-striped">
|
||||
<thead>
|
||||
<tr><th width="600px">Note</th><th>Date</th><th>Added By</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for note in user.notes.all %}
|
||||
<tr><td>{{ note.note|linebreaks }}</td><td>{{ note.date_created|date:"Y/m/d H:i:s" }}</td><td><a href="{% url sso-viewuser note.created_by %}">{{ note.created_by }}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if services %}
|
||||
<section id="services">
|
||||
<h2>Service Accounts</h2>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.views import password_change, password_change_done
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from sso import views
|
||||
|
||||
@@ -19,8 +20,9 @@ urlpatterns = patterns('',
|
||||
(r'^profile/change/email/$', views.email_change),
|
||||
(r'^profile/change/primary/$', views.primarychar_change),
|
||||
(r'^profile/change/reddittag/$', views.toggle_reddit_tagging),
|
||||
(r'^users/(?P<username>.*)/$', views.user_view),
|
||||
(r'^users/$', views.user_lookup),
|
||||
url(r'^users/(?P<username>.*)/addnote/$', login_required(views.AddUserNote.as_view()), name='sso-addusernote'),
|
||||
url(r'^users/(?P<username>.*)/$', views.user_view, name='sso-viewuser'),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('django.views.generic.simple',
|
||||
|
||||
@@ -4,7 +4,7 @@ import re
|
||||
import unicodedata
|
||||
import celery
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
|
||||
from django.shortcuts import render_to_response, get_object_or_404, redirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib import messages
|
||||
@@ -13,6 +13,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.template import RequestContext
|
||||
from django.core import serializers
|
||||
from django.conf import settings
|
||||
from django.views.generic import FormView
|
||||
|
||||
from gargoyle import gargoyle
|
||||
from gargoyle.decorators import switch_is_active
|
||||
@@ -23,7 +24,7 @@ from eve_api.tasks import import_apikey, import_apikey_result, update_user_acces
|
||||
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
|
||||
from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm, EmailChangeForm, PrimaryCharacterForm, UserNoteForm
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
@@ -315,3 +316,41 @@ def toggle_reddit_tagging(request):
|
||||
messages.add_message(request, messages.ERROR, "You need to set a primary character before using this feature!")
|
||||
|
||||
return redirect('sso.views.profile')
|
||||
|
||||
|
||||
class AddUserNote(FormView):
|
||||
|
||||
template_name = 'sso/add_usernote.html'
|
||||
form_class = UserNoteForm
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.has_perm('add_ssousernote'):
|
||||
return HttpResponseForbidden()
|
||||
return super(AddUserNote, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_user(self):
|
||||
if not hasattr(self, 'user'):
|
||||
userid = self.kwargs.get('username', None)
|
||||
self.user = User.objects.get(username=userid)
|
||||
return self.user
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(AddUserNote, self).get_context_data(**kwargs)
|
||||
ctx['user'] = self.get_user()
|
||||
return ctx
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddUserNote, self).get_initial()
|
||||
initial['user'] = self.get_user()
|
||||
return initial
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('sso-viewuser', args=[self.get_user()])
|
||||
|
||||
def form_valid(self, form):
|
||||
|
||||
obj = form.save(commit=False)
|
||||
obj.created_by = self.request.user
|
||||
obj.save()
|
||||
|
||||
return super(AddUserNote, self).form_valid(form)
|
||||
|
||||
Reference in New Issue
Block a user