From 91fa8a82f7430c868dc00dc1737ea4d6bdb63ace Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 3 Apr 2011 01:52:58 +0000 Subject: [PATCH] tidy up some UWindsor and Sakai stuff. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1314 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/integration/auth_linktool.py | 61 ---------------------- .../{linktool => sakai_linktool}/__init__.py | 0 .../{linktool => sakai_linktool}/app.py | 0 .../{linktool => sakai_linktool}/backend.py | 0 .../templates/associate.xhtml | 0 .../templates/index.xhtml | 0 .../templates/linktoolmaster.xhtml | 0 .../templates/new_site_cannot.xhtml | 0 .../templates/whichsite.xhtml | 0 conifer/integration/uwindsor.py | 12 +++-- conifer/integration/uwindsor_campus_info.py | 12 ----- conifer/local_settings.py.example | 4 +- conifer/settings.py | 6 +-- conifer/urls.py | 4 +- 14 files changed, 16 insertions(+), 83 deletions(-) delete mode 100644 conifer/integration/auth_linktool.py rename conifer/integration/{linktool => sakai_linktool}/__init__.py (100%) rename conifer/integration/{linktool => sakai_linktool}/app.py (100%) rename conifer/integration/{linktool => sakai_linktool}/backend.py (100%) rename conifer/integration/{linktool => sakai_linktool}/templates/associate.xhtml (100%) rename conifer/integration/{linktool => sakai_linktool}/templates/index.xhtml (100%) rename conifer/integration/{linktool => sakai_linktool}/templates/linktoolmaster.xhtml (100%) rename conifer/integration/{linktool => sakai_linktool}/templates/new_site_cannot.xhtml (100%) rename conifer/integration/{linktool => sakai_linktool}/templates/whichsite.xhtml (100%) delete mode 100644 conifer/integration/uwindsor_campus_info.py diff --git a/conifer/integration/auth_linktool.py b/conifer/integration/auth_linktool.py deleted file mode 100644 index 6983285..0000000 --- a/conifer/integration/auth_linktool.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.contrib.auth.models import User -from django.conf import settings -from urllib import quote -from urllib2 import urlopen - -def testsign(query_string): - url = '%s?data=%s' % (settings.LINKTOOL_AUTH_URL, quote(query_string)) - result = urlopen(url).read() - return (result == 'true') - -class LinktoolAuthBackend(object): - - def __init__(self): - assert settings.LINKTOOL_AUTH_URL, \ - 'LinktoolAuthBackend requires settings.LINKTOOL_AUTH_URL' - - def authenticate(self, request=None): - valid = testsign(request.META['QUERY_STRING']) - if valid: - username = request.GET['user'] - return self.maybe_initialize_user(username) - return None - - def get_user(self, user_id): - try: - return User.objects.get(pk=user_id) - except User.DoesNotExist: - return None - - def maybe_initialize_user(self, username, look_local=True): - """Look up user in Django db; if not found, fetch user detail - from backend and set up a local user object. Return None if no - such user exists in either Django or the backend. - - Setting look_local=False skips the Django search and heads - straight to the backend; this shaves a database call when - walking a set of backends to initialize a user. Skipping - look_local on a username that already exists in Django will - certainly lead to an integrity error. - - This method is NOT part of the Django backend interface. - """ - user = None - if look_local: - try: - user = User.objects.get(username=username) - except User.DoesNotExist: - pass - if user is None: - u = self.lookup(username) - if u: # user found in LDAP or whatever. - user = User(username=username, - first_name = u['first_name'], - last_name = u['last_name'], - email = u['email']) - user.set_unusable_password() - user.save() - return user - - def lookup(self, username): - return None # fixme diff --git a/conifer/integration/linktool/__init__.py b/conifer/integration/sakai_linktool/__init__.py similarity index 100% rename from conifer/integration/linktool/__init__.py rename to conifer/integration/sakai_linktool/__init__.py diff --git a/conifer/integration/linktool/app.py b/conifer/integration/sakai_linktool/app.py similarity index 100% rename from conifer/integration/linktool/app.py rename to conifer/integration/sakai_linktool/app.py diff --git a/conifer/integration/linktool/backend.py b/conifer/integration/sakai_linktool/backend.py similarity index 100% rename from conifer/integration/linktool/backend.py rename to conifer/integration/sakai_linktool/backend.py diff --git a/conifer/integration/linktool/templates/associate.xhtml b/conifer/integration/sakai_linktool/templates/associate.xhtml similarity index 100% rename from conifer/integration/linktool/templates/associate.xhtml rename to conifer/integration/sakai_linktool/templates/associate.xhtml diff --git a/conifer/integration/linktool/templates/index.xhtml b/conifer/integration/sakai_linktool/templates/index.xhtml similarity index 100% rename from conifer/integration/linktool/templates/index.xhtml rename to conifer/integration/sakai_linktool/templates/index.xhtml diff --git a/conifer/integration/linktool/templates/linktoolmaster.xhtml b/conifer/integration/sakai_linktool/templates/linktoolmaster.xhtml similarity index 100% rename from conifer/integration/linktool/templates/linktoolmaster.xhtml rename to conifer/integration/sakai_linktool/templates/linktoolmaster.xhtml diff --git a/conifer/integration/linktool/templates/new_site_cannot.xhtml b/conifer/integration/sakai_linktool/templates/new_site_cannot.xhtml similarity index 100% rename from conifer/integration/linktool/templates/new_site_cannot.xhtml rename to conifer/integration/sakai_linktool/templates/new_site_cannot.xhtml diff --git a/conifer/integration/linktool/templates/whichsite.xhtml b/conifer/integration/sakai_linktool/templates/whichsite.xhtml similarity index 100% rename from conifer/integration/linktool/templates/whichsite.xhtml rename to conifer/integration/sakai_linktool/templates/whichsite.xhtml diff --git a/conifer/integration/uwindsor.py b/conifer/integration/uwindsor.py index db5fd78..e49f7b3 100644 --- a/conifer/integration/uwindsor.py +++ b/conifer/integration/uwindsor.py @@ -3,9 +3,10 @@ from datetime import date from evergreen_site import EvergreenIntegration import csv import subprocess -import uwindsor_campus_info import uwindsor_fuzzy_lookup from django.conf import settings +from urllib2 import urlopen +from django.utils import simplejson class UWindsorIntegration(EvergreenIntegration): @@ -59,6 +60,11 @@ class UWindsorIntegration(EvergreenIntegration): ('2011F', '2011 Fall', date(2011,9,1), date(2011,12,31)), ] + def _campus_info(name, *args): + url = '%s%s?%s' % (settings.CAMPUS_INFO_SERVICE, name, simplejson.dumps(args)) + raw = urlopen(url).read() + return simplejson.loads(raw) + def external_person_lookup(self, userid): """ Given a userid, return either None (if the user cannot be found), @@ -67,7 +73,7 @@ class UWindsorIntegration(EvergreenIntegration): an email address is known, and 'patron_id' if a library-system ID is known. """ - return uwindsor_campus_info.call('person_lookup', userid) + return self._campus_info('person_lookup', userid) def external_memberships(self, userid): @@ -78,7 +84,7 @@ class UWindsorIntegration(EvergreenIntegration): 'group': a group-code, externally defined; 'role': the user's role in that group, one of (INSTR, ASSIST, STUDT). """ - memberships = uwindsor_campus_info.call('membership_ids', userid) + memberships = self._campus_info('membership_ids', userid) for m in memberships: m['role'] = self._decode_role(m['role']) return memberships diff --git a/conifer/integration/uwindsor_campus_info.py b/conifer/integration/uwindsor_campus_info.py deleted file mode 100644 index 9a85ce2..0000000 --- a/conifer/integration/uwindsor_campus_info.py +++ /dev/null @@ -1,12 +0,0 @@ -from urllib2 import * -from django.utils import simplejson -from django.conf import settings - -def call(name, *args): - url = '%s%s?%s' % (settings.CAMPUS_INFO_SERVICE, name, simplejson.dumps(args)) - raw = urlopen(url).read() - return simplejson.loads(raw) - -if __name__ == '__main__': - print call('methods_supported') - print call('person_lookup', 'fawcett') diff --git a/conifer/local_settings.py.example b/conifer/local_settings.py.example index 622cec4..e296f4c 100644 --- a/conifer/local_settings.py.example +++ b/conifer/local_settings.py.example @@ -34,8 +34,8 @@ SECRET_KEY = 'replace-with-your-own-super-random-key-@vv(tuvt2+yu2r-$dxs$s7=iqjz # Authentication systems EVERGREEN_AUTHENTICATION = False # Evergreen ILS authentication -LINKTOOL_AUTHENTICATION = False # Sakai LMS Linktool authentication -LINKTOOL_AUTH_URL = 'https://...' # fixme, add documentation +SAKAI_LINKTOOL_AUTHENTICATION = False # Sakai LMS Linktool authentication +SAKAI_LINKTOOL_AUTH_URL = 'https://...' # fixme, add documentation # CAS authentication. See conifer/integration/cas.py, or # http://code.google.com/p/django-cas/ . diff --git a/conifer/settings.py b/conifer/settings.py index 07c6f16..3cc2101 100644 --- a/conifer/settings.py +++ b/conifer/settings.py @@ -97,7 +97,7 @@ AUTHENTICATION_BACKENDS = [ ] EVERGREEN_AUTHENTICATION = False -LINKTOOL_AUTHENTICATION = False +SAKAI_LINKTOOL_AUTHENTICATION = False # CAS authentication requires 'django-cas', # http://code.google.com/p/django-cas/ @@ -129,9 +129,9 @@ if EVERGREEN_AUTHENTICATION: AUTHENTICATION_BACKENDS.append( 'conifer.integration.auth_evergreen.django.EvergreenAuthBackend') -if LINKTOOL_AUTHENTICATION: +if SAKAI_LINKTOOL_AUTHENTICATION: AUTHENTICATION_BACKENDS.append( - 'conifer.integration.linktool.backend.LinktoolAuthBackend') + 'conifer.integration.sakai_linktool.backend.LinktoolAuthBackend') if CAS_AUTHENTICATION: AUTHENTICATION_BACKENDS.append('conifer.integration.cas.CASBackend') diff --git a/conifer/urls.py b/conifer/urls.py index 4ee3e13..5440fb4 100644 --- a/conifer/urls.py +++ b/conifer/urls.py @@ -39,9 +39,9 @@ if not settings.DEBUG: handler404b = 'conifer.syrup.views.custom_400_handler' -if settings.LINKTOOL_AUTHENTICATION: +if settings.SAKAI_LINKTOOL_AUTHENTICATION: urlpatterns += patterns( - 'conifer.integration.linktool.app', + 'conifer.integration.sakai_linktool.app', (r'^linktool-welcome/$', 'linktool_welcome'), (r'^linktool-welcome/new_site$', 'linktool_new_site'), (r'^linktool-welcome/copy_old$', 'linktool_copy_old'), -- 2.11.0