diff --git a/ietf/dbtemplate/views.py b/ietf/dbtemplate/views.py index bcfcbd636..95529c378 100644 --- a/ietf/dbtemplate/views.py +++ b/ietf/dbtemplate/views.py @@ -5,7 +5,7 @@ from django.template import RequestContext from ietf.dbtemplate.models import DBTemplate from ietf.dbtemplate.forms import DBTemplateForm from ietf.group.models import Group -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role def template_list(request, acronym): diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index d35db1c4e..b27df3580 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -423,7 +423,7 @@ def startswith(x, y): @register.filter def has_role(user, role_names): - from ietf.ietfauth.decorators import has_role + from ietf.ietfauth.utils import has_role if not user: return False return has_role(user, role_names.split(',')) diff --git a/ietf/doc/views_ballot.py b/ietf/doc/views_ballot.py index 1e8814c52..e24e8aa07 100644 --- a/ietf/doc/views_ballot.py +++ b/ietf/doc/views_ballot.py @@ -16,7 +16,7 @@ from django.conf import settings import debug from ietf.utils.mail import send_mail_text, send_mail_preformatted -from ietf.ietfauth.decorators import has_role, role_required +from ietf.ietfauth.utils import has_role, role_required from ietf.iesg.models import TelechatDate from ietf.ipr.models import IprDetail from ietf.ipr.search import iprs_from_docs diff --git a/ietf/doc/views_conflict_review.py b/ietf/doc/views_conflict_review.py index dfc66ddd8..d4222d97d 100644 --- a/ietf/doc/views_conflict_review.py +++ b/ietf/doc/views_conflict_review.py @@ -12,7 +12,7 @@ from ietf.doc.utils import log_state_changed, update_telechat from ietf.doc.models import save_document_in_history from ietf.doc.utils import create_ballot_if_not_open, close_open_ballots, get_document_content -from ietf.ietfauth.decorators import has_role, role_required +from ietf.ietfauth.utils import has_role, role_required from ietf.utils.textupload import get_cleaned_text_file_content from ietf.utils.mail import send_mail_preformatted from ietf.doc.mails import email_iana diff --git a/ietf/doc/views_draft.py b/ietf/doc/views_draft.py index fe12c7a34..0fc7cc2ec 100644 --- a/ietf/doc/views_draft.py +++ b/ietf/doc/views_draft.py @@ -18,7 +18,7 @@ from django.contrib.auth.decorators import login_required from django.template.defaultfilters import pluralize from ietf.utils.mail import send_mail_text, send_mail_message -from ietf.ietfauth.decorators import role_required +from ietf.ietfauth.utils import role_required from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, user_is_person from ietf.iesg.models import TelechatDate from ietf.doc.mails import * diff --git a/ietf/doc/views_status_change.py b/ietf/doc/views_status_change.py index d83254867..27841f2b2 100644 --- a/ietf/doc/views_status_change.py +++ b/ietf/doc/views_status_change.py @@ -12,7 +12,7 @@ from ietf.doc.utils import log_state_changed, update_telechat from ietf.doc.models import save_document_in_history from ietf.doc.utils import create_ballot_if_not_open, close_open_ballots, get_document_content -from ietf.ietfauth.decorators import has_role, role_required +from ietf.ietfauth.utils import has_role, role_required from ietf.utils.textupload import get_cleaned_text_file_content from ietf.utils.mail import send_mail_preformatted from ietf.doc.models import State, Document, DocHistory, DocAlias diff --git a/ietf/group/ajax.py b/ietf/group/ajax.py index d4c0bd1cd..568420eea 100644 --- a/ietf/group/ajax.py +++ b/ietf/group/ajax.py @@ -1,17 +1,15 @@ -from django.utils import simplejson as json -from dajaxice.core import dajaxice_functions -from dajaxice.decorators import dajaxice_register -from ietf.ietfauth.decorators import group_required -from django.shortcuts import get_object_or_404 -from django.http import HttpResponseRedirect, HttpResponse, Http404 - -from ietf.group.models import Group import datetime import logging import sys -from ietf.settings import LOG_DIR -log = logging.getLogger(__name__) +from django.utils import simplejson as json +from django.shortcuts import get_object_or_404 +from django.http import HttpResponseRedirect, HttpResponse, Http404 + +from dajaxice.core import dajaxice_functions +from dajaxice.decorators import dajaxice_register + +from ietf.group.models import Group def group_json(request, groupname): group = get_object_or_404(Group, acronym=groupname) diff --git a/ietf/ietfauth/__init__.py b/ietf/ietfauth/__init__.py index a4b306690..e69de29bb 100644 --- a/ietf/ietfauth/__init__.py +++ b/ietf/ietfauth/__init__.py @@ -1,2 +0,0 @@ -# Copyright The IETF Trust 2007, All Rights Reserved - diff --git a/ietf/ietfauth/auth.py b/ietf/ietfauth/auth.py deleted file mode 100644 index 029a0b557..000000000 --- a/ietf/ietfauth/auth.py +++ /dev/null @@ -1,115 +0,0 @@ -# Portions Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. Contact: Pasi Eronen -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# * Neither the name of the Nokia Corporation and/or its -# subsidiary(-ies) nor the names of its contributors may be used -# to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# Copyright The IETF Trust 2007, All Rights Reserved - -from django.contrib.auth.backends import RemoteUserBackend -from django.contrib.auth.models import Group -from ietf.idtracker.models import IESGLogin, Role -from ietf.ietfauth.models import IetfUserProfile - -from ietf.utils import log - -AUTOMATIC_GROUPS = ["Area_Director", "Secretariat", "IETF_Chair", - "IAB_Chair", "IRTF_Chair", ] - -class IetfUserBackend(RemoteUserBackend): - - def find_groups(username): - """ - Role/Group: - Area_Director currently sitting AD - IETF_Chair currently sitting IETF Chair - IAB_Chair currently sitting IAB Chair - IRTF_Chair currently sitting IRTF Chair - Secretariat secretariat staff - - Roles/Groups NOT YET IMPLEMENTED - WG_Chair currently sitting chair of some WG - IESG_Liaison non-ADs on iesg@ietf.org and telechats - Session_Chair chairing a non-WG session in IETF meeting - Ex_Area_Director past AD - """ - # Any group name added by this method should be added to the - # AUTOMATIC_GROUPS list - groups = [] - try: - login = IESGLogin.objects.get(login_name=username) - if login.user_level == 1: - groups.append("Area_Director") - elif login.user_level == 0: - groups.append("Secretariat") - if login.person: - for role in login.person.role_set.all(): - if role.id == Role.IETF_CHAIR: - groups.append("IETF_Chair") - elif role.id == Role.IAB_CHAIR: - groups.append("IAB_Chair") - elif role.id == Role.IRTF_CHAIR: - groups.append("IRTF_Chair") - except IESGLogin.DoesNotExist: - pass - # - # Additional sources of group memberships: - # - wg_password table - # - other Roles - # - the /etc/.../*.perms files - return groups - - find_groups = staticmethod(find_groups) - - def authenticate(self, remote_user): - user = RemoteUserBackend.authenticate(self, remote_user) - if not user: - return user - - # Create profile if it doesn't exist - try: - profile = user.get_profile() - except IetfUserProfile.DoesNotExist: - profile = IetfUserProfile(user=user) - profile.save() - - # Remove any automatic groups, the proper ones will be retrieved by - # find_groups - groups = [group for group in user.groups.exclude(name__in=AUTOMATIC_GROUPS)] - - # Update group memberships - group_names = IetfUserBackend.find_groups(user.username) - for group_name in group_names: - # Create groups as needed - group,created = Group.objects.get_or_create(name=group_name) - if created: - log("IetfUserBackend created Group '%s'" % (group_name,)) - groups.append(group) - user.groups = groups - return user diff --git a/ietf/ietfauth/decorators.py b/ietf/ietfauth/decorators.py deleted file mode 100644 index a30cbb01b..000000000 --- a/ietf/ietfauth/decorators.py +++ /dev/null @@ -1,35 +0,0 @@ -# Portion Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. Contact: Pasi Eronen -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# * Neither the name of the Nokia Corporation and/or its -# subsidiary(-ies) nor the names of its contributors may be used -# to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# REDESIGN: backwards compatibility, to be deleted -from ietf.ietfauth.utils import role_required, has_role, passes_test_decorator -group_required = lambda *group_names: role_required(*[n.replace("Area_Director", "Area Director") for n in group_names]) diff --git a/ietf/ietfauth/forms.py b/ietf/ietfauth/forms.py index 0b895efe8..94cc54d1e 100644 --- a/ietf/ietfauth/forms.py +++ b/ietf/ietfauth/forms.py @@ -10,7 +10,8 @@ from django.contrib.sites.models import Site from django.utils.translation import ugettext_lazy as _ from ietf.utils.mail import send_mail -from ietf.person.models import Person, Email +from ietf.person.models import Person, Email, Alias +from ietf.group.models import Role class RegistrationForm(forms.Form): @@ -167,7 +168,6 @@ class PersonForm(ModelForm): request = None new_emails = [] class Meta: - from ietf.person.models import Person model = Person exclude = ('time','user') @@ -193,8 +193,6 @@ class PersonForm(ModelForm): send_mail(self.request, to_email, from_email, subject, 'registration/add_email_email.txt', context) def save(self, force_insert=False, force_update=False, commit=True): - from ietf.group.models import Role - from ietf.person.models import Alias m = super(PersonForm, self).save(commit=False) self.new_emails = [v for k,v in self.data.items() if k[:10] == u'new_email_' and u'@' in v] diff --git a/ietf/ietfauth/models.py b/ietf/ietfauth/models.py index b302d38a6..137941ffa 100644 --- a/ietf/ietfauth/models.py +++ b/ietf/ietfauth/models.py @@ -1,136 +1 @@ -# Portions Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. Contact: Pasi Eronen -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# * Neither the name of the Nokia Corporation and/or its -# subsidiary(-ies) nor the names of its contributors may be used -# to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# Copyright The IETF Trust 2007, All Rights Reserved - from django.db import models -from django.contrib.auth.models import User -from ietf.idtracker.models import PersonOrOrgInfo, IESGLogin -from ietf.utils.admin import admin_link - -def find_person(username): - try: - person = IESGLogin.objects.get(login_name=username).person - return person - except IESGLogin.DoesNotExist, PersonOrOrgInfo.DoesNotExist: - pass - # try LegacyWgPassword next - try: - return LegacyWgPassword.objects.get(login_name=username).person - except LegacyWgPassword.DoesNotExist, PersonOrOrgInfo.DoesNotExist: - pass - # try LegacyLiaisonUser next - try: - return LegacyLiaisonUser.objects.get(login_name=username).person - except LegacyLiaisonUser.DoesNotExist, PersonOrOrgInfo.DoesNotExist: - pass - return None - -class IetfUserProfile(models.Model): - user = models.ForeignKey(User,unique=True) - - def person(self): - return find_person(self.user.username) - - def iesg_login_id(self): - person = self.person() - if not person: - return None - try: - return person.iesglogin_set.all()[0].id - except: - return None - - def email(self): - # quick hack to bind new and old schema together for the time being - try: - l = IESGLogin.objects.get(login_name=self.user.username) - if l.person: - person = l.person - else: - person = PersonOrOrgInfo.objects.get(first_name=l.first_name, - last_name=l.last_name) - except IESGLogin.DoesNotExist, PersonOrOrgInfo.DoesNotExist: - person = None - from ietf.person.models import Email - return Email.objects.get(address=person.email()[1]) - - def __str__(self): - return "IetfUserProfile(%s)" % (self.user,) - - -###################################################### -# legacy per-tool access tables. -# ietf.idtracker.models.IESGLogin is in the same vein. - -class LegacyLiaisonUser(models.Model): - USER_LEVEL_CHOICES = ( - (0, 'Secretariat'), - (1, 'IESG'), - (2, 'ex-IESG'), - (3, 'Level 3'), - (4, 'Comment Only(?)'), - ) - person = models.ForeignKey(PersonOrOrgInfo, db_column='person_or_org_tag', primary_key=True) - login_name = models.CharField(max_length=255) - password = models.CharField(max_length=25, blank=True, editable=False) - user_level = models.IntegerField(null=True, blank=True, choices=USER_LEVEL_CHOICES) - comment = models.TextField(blank=True,null=True) - def __str__(self): - return self.login_name - class Meta: - db_table = 'users' - ordering = ['login_name'] - person_link = admin_link('person') - -class LegacyWgPassword(models.Model): - person = models.ForeignKey(PersonOrOrgInfo, db_column='person_or_org_tag', primary_key=True) - password = models.CharField(blank=True, null=True,max_length=255) - secrete_question_id = models.IntegerField(null=True, blank=True) - secrete_answer = models.CharField(blank=True, null=True, max_length=255) - is_tut_resp = models.IntegerField(null=True, blank=True) - irtf_id = models.IntegerField(null=True, blank=True) - comment = models.TextField(blank=True,null=True) - login_name = models.CharField(blank=True, max_length=100) - def __str__(self): - return self.login_name - class Meta: - db_table = 'wg_password' - ordering = ['login_name'] - person_link = admin_link('person') - -# changes done by convert-096.py:changed maxlength to max_length -# removed core -# removed edit_inline -# removed max_num_in_admin -# removed num_in_admin -# removed raw_id_admin diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index 293949342..3b8deaab4 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -31,12 +31,12 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import unittest -from django.conf import settings +from urlparse import urlsplit + from django.contrib.auth.models import User from django.test.client import Client + from ietf.utils.test_utils import SimpleUrlTestCase, RealDatabaseTest -from ietf.idtracker.models import Role -from urlparse import urlsplit class IetfAuthUrlTestCase(SimpleUrlTestCase): def testUrls(self): @@ -66,40 +66,3 @@ class IetfAuthTestCase(unittest.TestCase,RealDatabaseTest): self.assertEquals(response.status_code, 200) self.assert_("User name" in response.content) return response - - def testLogin(self): - TEST_USERNAME = '__testuser' - print " Testing login with "+TEST_USERNAME - - # Delete test user (if it exists) - try: - testuser = User.objects.get(username=TEST_USERNAME) - testuser.delete() - except User.DoesNotExist: - pass - - self._doLogin(TEST_USERNAME) - - # Delete test user after test - testuser = User.objects.get(username=TEST_USERNAME) - testuser.delete() - print "OK" - - def testGroups(self): - print " Testing group assignment" - username = Role.objects.get(id=Role.IETF_CHAIR).person.iesglogin_set.all()[0].login_name - print " (with username "+str(username)+")" - - self._doLogin(username) - - user = User.objects.get(username=username) - groups = [x.name for x in user.groups.all()] - self.assert_("Area_Director" in groups) - self.assert_("IETF_Chair" in groups) - - print "OK" - -if settings.USE_DB_REDESIGN_PROXY_CLASSES: - del IetfAuthTestCase.testLogin - # this test doesn't make any sense anymore - del IetfAuthTestCase.testGroups diff --git a/ietf/ietfauth/urls.py b/ietf/ietfauth/urls.py index 68d62bebe..4fd239d20 100644 --- a/ietf/ietfauth/urls.py +++ b/ietf/ietfauth/urls.py @@ -1,18 +1,14 @@ # Copyright The IETF Trust 2007, 2009, All Rights Reserved from django.conf.urls.defaults import patterns, url -from ietf.ietfauth import views -urlpatterns = patterns('', - (r'^$', views.index, None, 'account_index'), - (r'^login/$', views.ietf_login), - (r'^loggedin/$', views.ietf_loggedin), - (r'^profile/$', views.profile), -# (r'^login/(?P[a-z0-9.@]+)/(?P.+)$', views.url_login), - (r'^testemail/$', views.test_email), -) - -urlpatterns += patterns('ietf.ietfauth.views', +urlpatterns = patterns('ietf.ietfauth.views', + url(r'^$', 'index', name='account_index'), + url(r'^login/$', 'ietf_login'), + url(r'^loggedin/$', 'ietf_loggedin'), + url(r'^profile/$', 'profile'), +# (r'^login/(?P[a-z0-9.@]+)/(?P.+)$', 'url_login'), + url(r'^testemail/$', 'test_email'), url(r'^create/$', 'create_account', name='create_account'), url(r'^confirm/(?P[\w.@+-]+)/(?P[\d]+)/(?P[\w]+)/(?P[a-f0-9]+)/$', 'confirm_account', name='confirm_account'), url(r'^reset/$', 'password_reset_view', name='password_reset'), diff --git a/ietf/ietfauth/views.py b/ietf/ietfauth/views.py index 141237075..c7c74fc1a 100644 --- a/ietf/ietfauth/views.py +++ b/ietf/ietfauth/views.py @@ -34,6 +34,7 @@ import datetime import hashlib +import json from django.conf import settings from django.template import RequestContext @@ -43,10 +44,12 @@ from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.utils.http import urlquote -from django.utils import simplejson as json from django.utils.translation import ugettext as _ +from django.core.exceptions import ValidationError, NON_FIELD_ERRORS -from ietf.ietfauth.forms import RegistrationForm, PasswordForm, RecoverPasswordForm, TestEmailForm +from ietf.person.models import Person, Email, Alias +from ietf.group.models import Role +from ietf.ietfauth.forms import RegistrationForm, PasswordForm, RecoverPasswordForm, TestEmailForm, PersonForm def index(request): return render_to_response('registration/index.html', context_instance=RequestContext(request)) @@ -62,8 +65,8 @@ def url_login(request, user, passwd): def ietf_login(request): if not request.user.is_authenticated(): - # This probably means an exception occured inside IetfUserBackend return HttpResponse("Not authenticated?", status=500) + redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '') request.session.set_test_cookie() return HttpResponseRedirect('/accounts/loggedin/?%s=%s' % (REDIRECT_FIELD_NAME, urlquote(redirect_to))) @@ -79,10 +82,6 @@ def ietf_loggedin(request): @login_required def profile(request): - from ietf.person.models import Person, Email, Alias - from ietf.group.models import Role - from ietf.ietfauth.forms import PersonForm - roles = [] person = None try: @@ -119,8 +118,6 @@ def profile(request): context_instance=RequestContext(request)) def confirm_new_email(request, username, date, email, hash): - from ietf.person.models import Person, Email, Alias - from django.core.exceptions import ValidationError, NON_FIELD_ERRORS valid = hashlib.md5('%s%s%s%s' % (settings.SECRET_KEY, date, email, username)).hexdigest() == hash if not valid: raise Http404 @@ -233,24 +230,15 @@ def ajax_check_username(request): return HttpResponse(json.dumps({'error': error}), mimetype='text/plain') def test_email(request): + """Set email address to which email generated in the system will be sent.""" if settings.SERVER_MODE == "production": - raise Http404() + raise Http404 - # note that the cookie set here is only used when running in + # Note that the cookie set here is only used when running in # "test" mode, normally you run the server in "development" mode, - # in which case email is sent out as usual; for development, put - # this - # - # EMAIL_HOST = 'localhost' - # EMAIL_PORT = 1025 - # EMAIL_HOST_USER = None - # EMAIL_HOST_PASSWORD = None - # EMAIL_COPY_TO = "" - # - # in your settings.py and start a little debug email server in a - # console with the following (it receives and prints messages) - # - # python -m smtpd -n -c DebuggingServer localhost:1025 + # in which case email is sent out as usual; for development, you + # can easily start a little email debug server with Python, see + # the instructions in utils/mail.py. cookie = None diff --git a/ietf/meeting/ajax.py b/ietf/meeting/ajax.py index 418065160..f9800451f 100644 --- a/ietf/meeting/ajax.py +++ b/ietf/meeting/ajax.py @@ -1,18 +1,14 @@ - from django.utils import simplejson as json -from dajaxice.decorators import dajaxice_register from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404 - -from ietf.ietfauth.decorators import group_required, has_role -from ietf.name.models import TimeSlotTypeName from django.http import HttpResponseRedirect, HttpResponse, QueryDict +from dajaxice.decorators import dajaxice_register +from ietf.ietfauth.utils import role_required, has_role +from ietf.name.models import TimeSlotTypeName + from ietf.meeting.helpers import get_meeting, get_schedule, get_schedule_by_id, agenda_permissions from ietf.meeting.views import edit_timeslots, edit_agenda - - -# New models from ietf.meeting.models import TimeSlot, Session, Schedule, Room, Constraint import debug @@ -50,7 +46,7 @@ def readonly(request, meeting_num, schedule_id): 'owner_href': request.build_absolute_uri(schedule.owner.json_url()), 'read_only': read_only}) -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') @dajaxice_register def update_timeslot_pinned(request, schedule_id, scheduledsession_id, pinned=False): schedule = get_object_or_404(Schedule, pk = int(schedule_id)) @@ -73,7 +69,7 @@ def update_timeslot_pinned(request, schedule_id, scheduledsession_id, pinned=Fal -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') @dajaxice_register def update_timeslot(request, schedule_id, session_id, scheduledsession_id=None, extended_from_id=None, duplicate=False): schedule = get_object_or_404(Schedule, pk = int(schedule_id)) @@ -132,7 +128,7 @@ def update_timeslot(request, schedule_id, session_id, scheduledsession_id=None, return json.dumps({'message':'valid'}) -@group_required('Secretariat') +@role_required('Secretariat') @dajaxice_register def update_timeslot_purpose(request, timeslot_id=None, purpose=None): ts_id = int(timeslot_id) @@ -167,10 +163,8 @@ def timeslot_roomlist(request, mtg): return HttpResponse(json.dumps(json_array), mimetype="application/json") -@group_required('Secretariat') +@role_required('Secretariat') def timeslot_addroom(request, meeting): - # authorization was enforced by the @group_require decorator above. - newroomform = AddRoomForm(request.POST) if not newroomform.is_valid(): return HttpResponse(status=404) @@ -188,9 +182,8 @@ def timeslot_addroom(request, meeting): return HttpResponseRedirect( reverse(edit_timeslots, args=[meeting.number])) -@group_required('Secretariat') +@role_required('Secretariat') def timeslot_delroom(request, meeting, roomid): - # authorization was enforced by the @group_require decorator above. room = get_object_or_404(meeting.room_set, pk=roomid) room.delete_timeslots() @@ -235,10 +228,8 @@ def timeslot_slotlist(request, mtg): return HttpResponse(json.dumps(json_array), mimetype="application/json") -@group_required('Secretariat') +@role_required('Secretariat') def timeslot_addslot(request, meeting): - - # authorization was enforced by the @group_require decorator above. addslotform = AddSlotForm(request.POST) #debug.log("newslot: %u" % ( addslotform.is_valid() )) if not addslotform.is_valid(): @@ -261,9 +252,8 @@ def timeslot_addslot(request, meeting): return HttpResponseRedirect( reverse(edit_timeslots, args=[meeting.number])) -@group_required('Secretariat') +@role_required('Secretariat') def timeslot_delslot(request, meeting, slotid): - # authorization was enforced by the @group_require decorator above. slot = get_object_or_404(meeting.timeslot_set, pk=slotid) # this will delete self as well. @@ -301,7 +291,7 @@ def timeslot_sloturl(request, num=None, slotid=None): AgendaEntryForm = modelform_factory(Schedule, exclude=('meeting','owner')) EditAgendaEntryForm = modelform_factory(Schedule, exclude=('meeting','owner', 'name')) -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') def agenda_list(request, mtg): agendas = mtg.schedule_set.all() json_array=[] @@ -311,10 +301,8 @@ def agenda_list(request, mtg): mimetype="application/json") # duplicates save-as functionality below. -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') def agenda_add(request, meeting): - # authorization was enforced by the @group_require decorator above. - newagendaform = AgendaEntryForm(request.POST) if not newagendaform.is_valid(): return HttpResponse(status=404) @@ -332,10 +320,8 @@ def agenda_add(request, meeting): return HttpResponseRedirect( reverse(edit_agenda, args=[meeting.number, newagenda.name])) -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') def agenda_update(request, meeting, schedule): - # authorization was enforced by the @group_require decorator above. - # forms are completely useless for update actions that want to # accept a subset of values. update_dict = QueryDict(request.raw_post_data, encoding=request._encoding) @@ -380,7 +366,7 @@ def agenda_update(request, meeting, schedule): return HttpResponseRedirect( reverse(edit_agenda, args=[meeting.number, schedule.name])) -@group_required('Secretariat') +@role_required('Secretariat') def agenda_del(request, meeting, schedule): schedule.delete_scheduledsessions() #debug.log("deleting meeting: %s agenda: %s" % (meeting, meeting.agenda)) @@ -427,10 +413,8 @@ def meeting_get(request, meeting): sort_keys=True, indent=2), mimetype="application/json") -@group_required('Secretariat') +@role_required('Secretariat') def meeting_update(request, meeting): - # authorization was enforced by the @group_require decorator above. - # at present, only the official agenda can be updated from this interface. update_dict = QueryDict(request.raw_post_data, encoding=request._encoding) diff --git a/ietf/meeting/helpers.py b/ietf/meeting/helpers.py index 0d0531411..53d78f40a 100644 --- a/ietf/meeting/helpers.py +++ b/ietf/meeting/helpers.py @@ -14,7 +14,7 @@ from django.utils.cache import get_cache_key import debug from django.shortcuts import get_object_or_404 -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.utils.history import find_history_active_at from ietf.doc.models import Document, State diff --git a/ietf/meeting/tests/api.py b/ietf/meeting/tests/api.py index 6d4eaa260..98c0b7516 100644 --- a/ietf/meeting/tests/api.py +++ b/ietf/meeting/tests/api.py @@ -6,7 +6,7 @@ from ietf.utils import TestCase from ietf.person.models import Person from django.contrib.auth.models import User from ietf.meeting.models import TimeSlot, Session, ScheduledSession, Meeting -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from auths import auth_joeblow, auth_wlo, auth_ietfchair, auth_ferrel from django.utils import simplejson as json from ietf.meeting.helpers import get_meeting diff --git a/ietf/meeting/tests/auths.py b/ietf/meeting/tests/auths.py index 3c7ff0fd6..2cebbef5b 100644 --- a/ietf/meeting/tests/auths.py +++ b/ietf/meeting/tests/auths.py @@ -3,7 +3,7 @@ from django.test import Client from ietf.utils import TestCase #from ietf.person.models import Person from django.contrib.auth.models import User -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role # from http://djangosnippets.org/snippets/850/ diff --git a/ietf/meeting/views.py b/ietf/meeting/views.py index 59b0417f3..363ebfc33 100644 --- a/ietf/meeting/views.py +++ b/ietf/meeting/views.py @@ -1,17 +1,17 @@ # Copyright The IETF Trust 2007, All Rights Reserved -#import models import datetime import os import re import tarfile +import debug +import urllib from tempfile import mkstemp from django import forms from django.shortcuts import render_to_response, get_object_or_404 from django.utils import simplejson as json -from ietf.idtracker.models import IETFWG, IRTF, Area from django.http import HttpResponseRedirect, HttpResponse, Http404 from django.core.urlresolvers import reverse from django.db.models import Q @@ -19,16 +19,14 @@ from django.template import RequestContext from django.template.loader import render_to_string from django.conf import settings from django.utils.decorators import decorator_from_middleware -from ietf.ietfauth.decorators import group_required, has_role from django.middleware.gzip import GZipMiddleware from django.db.models import Max from django.forms.models import modelform_factory -import debug -import urllib - from ietf.utils.pipe import pipe from ietf.doc.models import Document, State +from ietf.idtracker.models import IETFWG, IRTF, Area +from ietf.ietfauth.utils import role_required, has_role # Old model -- needs to be removed from ietf.proceedings.models import Meeting as OldMeeting, WgMeetingSession, Proceeding, Switches @@ -46,8 +44,6 @@ from ietf.meeting.helpers import get_modified_from_scheduledsessions from ietf.meeting.helpers import get_wg_list, find_ads_for_meeting from ietf.meeting.helpers import get_meeting, get_schedule, agenda_permissions -import debug - @decorator_from_middleware(GZipMiddleware) def materials(request, meeting_num=None): proceeding = get_object_or_404(Proceeding, meeting_num=meeting_num) @@ -100,7 +96,7 @@ def get_user_agent(request): class SaveAsForm(forms.Form): savename = forms.CharField(max_length=100) -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') def agenda_create(request, num=None, schedule_name=None): meeting = get_meeting(num) schedule = get_schedule(meeting, schedule_name) @@ -203,7 +199,7 @@ def edit_timeslots(request, num=None): RequestContext(request)), mimetype="text/html") ############################################################################## -#@group_required('Area Director','Secretariat') +#@role_required('Area Director','Secretariat') # disable the above security for now, check it below. @decorator_from_middleware(GZipMiddleware) def edit_agenda(request, num=None, schedule_name=None): @@ -293,7 +289,7 @@ def edit_agenda(request, num=None, schedule_name=None): # AgendaPropertiesForm = modelform_factory(Schedule, fields=('name','visible', 'public')) -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') @decorator_from_middleware(GZipMiddleware) def edit_agenda_properties(request, num=None, schedule_name=None): @@ -311,7 +307,7 @@ def edit_agenda_properties(request, num=None, schedule_name=None): # show list of agendas. # -@group_required('Area Director','Secretariat') +@role_required('Area Director','Secretariat') @decorator_from_middleware(GZipMiddleware) def edit_agendas(request, num=None, order=None): diff --git a/ietf/nomcom/decorators.py b/ietf/nomcom/decorators.py index ed0d715c9..89c19e9c5 100644 --- a/ietf/nomcom/decorators.py +++ b/ietf/nomcom/decorators.py @@ -2,7 +2,7 @@ from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.utils.http import urlquote -from ietf.ietfauth.decorators import passes_test_decorator +from ietf.ietfauth.utils import passes_test_decorator from ietf.nomcom.utils import get_nomcom_by_year diff --git a/ietf/nomcom/forms.py b/ietf/nomcom/forms.py index 75f8cac3d..dfdaad59c 100644 --- a/ietf/nomcom/forms.py +++ b/ietf/nomcom/forms.py @@ -11,7 +11,7 @@ from django.template.context import RequestContext from ietf.dbtemplate.forms import DBTemplateForm from ietf.utils.mail import send_mail -from ietf.ietfauth.decorators import role_required +from ietf.ietfauth.utils import role_required from ietf.utils import fields as custom_fields from ietf.group.models import Group, Role from ietf.name.models import RoleName, FeedbackType, NomineePositionState diff --git a/ietf/nomcom/templatetags/nomcom_tags.py b/ietf/nomcom/templatetags/nomcom_tags.py index 97aa4ee67..43f421a6a 100644 --- a/ietf/nomcom/templatetags/nomcom_tags.py +++ b/ietf/nomcom/templatetags/nomcom_tags.py @@ -7,7 +7,7 @@ from django.template.defaultfilters import linebreaksbr, force_escape from ietf.utils.pipe import pipe from ietf.utils.log import log -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.doc.templatetags.ietf_filters import wrap_text from ietf.person.models import Person diff --git a/ietf/person/ajax.py b/ietf/person/ajax.py index 4a10043a0..3db648c25 100644 --- a/ietf/person/ajax.py +++ b/ietf/person/ajax.py @@ -1,17 +1,15 @@ -from django.utils import simplejson as json -from dajaxice.core import dajaxice_functions -from dajaxice.decorators import dajaxice_register -from ietf.ietfauth.decorators import group_required -from django.shortcuts import get_object_or_404 -from django.http import HttpResponseRedirect, HttpResponse, Http404 - -from ietf.person.models import Person import datetime import logging import sys -from ietf.settings import LOG_DIR -log = logging.getLogger(__name__) +from django.utils import simplejson as json +from django.shortcuts import get_object_or_404 +from django.http import HttpResponseRedirect, HttpResponse, Http404 + +from dajaxice.core import dajaxice_functions +from dajaxice.decorators import dajaxice_register + +from ietf.person.models import Person def person_json(request, personid): person = get_object_or_404(Person, pk=personid) diff --git a/ietf/secr/announcement/forms.py b/ietf/secr/announcement/forms.py index 8486ce49f..a22a35e74 100644 --- a/ietf/secr/announcement/forms.py +++ b/ietf/secr/announcement/forms.py @@ -6,7 +6,7 @@ from ietf.secr.utils.mail import MultiEmailField from ietf.secr.utils.group import current_nomcom from ietf.message.models import Message -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role # --------------------------------------------- # Globals diff --git a/ietf/secr/announcement/tests.py b/ietf/secr/announcement/tests.py index 89fcf6c00..7cc984e15 100644 --- a/ietf/secr/announcement/tests.py +++ b/ietf/secr/announcement/tests.py @@ -4,7 +4,7 @@ from ietf.utils import TestCase from django.contrib.auth.models import User from ietf.group.models import Group -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.person.models import Person from ietf.utils.mail import outbox from ietf.utils.test_data import make_test_data diff --git a/ietf/secr/announcement/views.py b/ietf/secr/announcement/views.py index 71810c7fc..61f3e92b3 100644 --- a/ietf/secr/announcement/views.py +++ b/ietf/secr/announcement/views.py @@ -4,7 +4,7 @@ from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidde from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.utils.mail import send_mail_text from ietf.group.models import Group from ietf.secr.utils.group import current_nomcom diff --git a/ietf/secr/areas/tests.py b/ietf/secr/areas/tests.py index cec3b65a8..05f01bb21 100644 --- a/ietf/secr/areas/tests.py +++ b/ietf/secr/areas/tests.py @@ -3,7 +3,7 @@ from ietf.utils import TestCase from django.contrib.auth.models import User from ietf.group.models import Group, GroupEvent -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.person.models import Person from ietf.utils.test_data import make_test_data diff --git a/ietf/secr/middleware/secauth.py b/ietf/secr/middleware/secauth.py index 327080284..99c3ca836 100644 --- a/ietf/secr/middleware/secauth.py +++ b/ietf/secr/middleware/secauth.py @@ -2,7 +2,7 @@ from django.conf import settings from django.http import HttpResponseForbidden from django.shortcuts import render_to_response -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role import re diff --git a/ietf/secr/proceedings/views.py b/ietf/secr/proceedings/views.py index b927de710..6d8f946e2 100644 --- a/ietf/secr/proceedings/views.py +++ b/ietf/secr/proceedings/views.py @@ -26,7 +26,7 @@ from ietf.doc.models import Document, DocAlias, DocEvent, State, NewRevisionDocE from ietf.group.models import Group from ietf.group.proxy import IETFWG from ietf.group.utils import get_charter_text -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.meeting.models import Meeting, Session, TimeSlot, ScheduledSession from ietf.name.models import MeetingTypeName, SessionStatusName from ietf.person.models import Person diff --git a/ietf/secr/sreq/tests.py b/ietf/secr/sreq/tests.py index 7c25962fe..a053c22f8 100644 --- a/ietf/secr/sreq/tests.py +++ b/ietf/secr/sreq/tests.py @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse from ietf.utils import TestCase from django.test.client import Client from ietf.group.models import Group -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.utils.test_data import make_test_data from ietf.utils.test_utils import SimpleUrlTestCase, RealDatabaseTest diff --git a/ietf/secr/sreq/views.py b/ietf/secr/sreq/views.py index 7deb6daee..9e2369fba 100644 --- a/ietf/secr/sreq/views.py +++ b/ietf/secr/sreq/views.py @@ -11,7 +11,7 @@ from ietf.secr.utils.mail import get_ad_email_list, get_chair_email_list, get_cc from ietf.secr.utils.decorators import check_permissions, sec_only from ietf.secr.utils.group import get_my_groups, groups_by_session -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.utils.mail import send_mail from ietf.meeting.models import Meeting, Session, Constraint diff --git a/ietf/secr/utils/decorators.py b/ietf/secr/utils/decorators.py index 168af6efe..0cd7214ef 100644 --- a/ietf/secr/utils/decorators.py +++ b/ietf/secr/utils/decorators.py @@ -3,7 +3,7 @@ from django.http import HttpResponseRedirect from django.shortcuts import render_to_response, get_object_or_404 from functools import wraps -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role from ietf.doc.models import Document from ietf.group.models import Group from ietf.meeting.models import Session diff --git a/ietf/secr/utils/group.py b/ietf/secr/utils/group.py index 0dcf57d2a..ed2771b17 100644 --- a/ietf/secr/utils/group.py +++ b/ietf/secr/utils/group.py @@ -2,7 +2,7 @@ from django.conf import settings from ietf.group.models import Group from ietf.meeting.models import Session -from ietf.ietfauth.decorators import has_role +from ietf.ietfauth.utils import has_role import itertools import os diff --git a/ietf/sync/views.py b/ietf/sync/views.py index d038c0440..892b0250d 100644 --- a/ietf/sync/views.py +++ b/ietf/sync/views.py @@ -9,7 +9,7 @@ from django import forms from django.db.models import Q from django.contrib.auth.models import User -from ietf.ietfauth.decorators import role_required, has_role +from ietf.ietfauth.utils import role_required, has_role from ietf.doc.models import * from ietf.sync import iana, rfceditor from ietf.sync.discrepancies import find_discrepancies diff --git a/ietf/wgcharter/views.py b/ietf/wgcharter/views.py index a9831cf11..095af9592 100644 --- a/ietf/wgcharter/views.py +++ b/ietf/wgcharter/views.py @@ -16,7 +16,7 @@ from django.contrib import messages from ietf.utils.mail import send_mail_preformatted from ietf.utils.textupload import get_cleaned_text_file_content from ietf.utils.history import find_history_active_at -from ietf.ietfauth.decorators import has_role, role_required +from ietf.ietfauth.utils import has_role, role_required from ietf.iesg.models import TelechatDate from ietf.doc.models import * from ietf.doc.utils import * diff --git a/ietf/wginfo/edit.py b/ietf/wginfo/edit.py index b14839c89..94dfb3950 100644 --- a/ietf/wginfo/edit.py +++ b/ietf/wginfo/edit.py @@ -11,7 +11,7 @@ from django.utils.html import mark_safe import debug -from ietf.ietfauth.decorators import role_required, has_role +from ietf.ietfauth.utils import role_required, has_role from ietf.doc.models import * from ietf.name.models import * diff --git a/ietf/wginfo/milestones.py b/ietf/wginfo/milestones.py index a83f2303b..31327caa9 100644 --- a/ietf/wginfo/milestones.py +++ b/ietf/wginfo/milestones.py @@ -11,7 +11,7 @@ from django.utils.html import mark_safe, escape from django.utils.functional import lazy from django.core.urlresolvers import reverse as urlreverse -from ietf.ietfauth.decorators import role_required, has_role +from ietf.ietfauth.utils import role_required, has_role from ietf.doc.models import Document, DocEvent from ietf.doc.utils import get_chartering_type from ietf.group.models import *