From: Art Rhyno Date: Thu, 23 Jun 2011 19:45:17 +0000 (-0400) Subject: OpenSRF lookup integrated, added slightly different X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=899ed2404488be505631778574b9ea8fda3c4ea1;p=Syrup.git OpenSRF lookup integrated, added slightly different scoping than LDAP. Signed-off-by: Art Rhyno --- diff --git a/conifer/integration/evergreen_example.py b/conifer/integration/evergreen_example.py new file mode 100644 index 0000000..a050565 --- /dev/null +++ b/conifer/integration/evergreen_example.py @@ -0,0 +1,60 @@ +from datetime import date +from evergreen_site import EvergreenIntegration +import csv +import subprocess +from django.conf import settings +from urllib2 import urlopen +from django.utils import simplejson +from conifer.libsystems.evergreen import opensrf + + +class EvergreenExampleIntegration(EvergreenIntegration): + + OSRF_CAT_SEARCH_ORG_UNIT = 28 + + OPAC_LANG = 'en-US' + OPAC_SKIN = 'default' + + RESERVES_DESK_NAME = 'Reserves' + SITE_DEFAULT_ACCESS_LEVEL = 'RESTR' + + def external_person_lookup(self, userid): + """ + Given a userid, return either None (if the user cannot be found), + or a dictionary representing the user. The dictionary must contain + the keys ('given_name', 'surname') and should contain 'email' if + an email address is known, and 'patron_id' if a library-system ID + is known. + """ + return opensrf.ils_patron_details(userid) + + + def fuzzy_person_lookup(self, query, include_students=False, level='STAFF'): + patrons = [] + + if level == 'USERNAME': + patrons = opensrf.ils_patron_lookup(query,False,True,True) + elif level == 'EVERYONE': + patrons = opensrf.ils_patron_lookup(query,False,False,True) + else: + patrons = opensrf.ils_patron_lookup(query) + + return patrons + + #--------------------------------------------------------------------------- + # copyright/permissions + + def download_declaration(self): + """ + Returns a string. The declaration to which students must agree when + downloading electronic documents. If not customized, a generic message + will be used. + """ + # based on U. of Windsor + return ("I warrant that I am a student of this university " + "enrolled in a course of instruction. By pressing the " + "'Request' button below, I am requesting a digital copy of a " + "reserve reading for research, private study, review or criticism " + "and that I will not use the copy for any other purpose, nor " + "will I transmit the copy to any third party.") + diff --git a/conifer/libsystems/evergreen/opensrf.py b/conifer/libsystems/evergreen/opensrf.py index 83207e3..a6a29bf 100644 --- a/conifer/libsystems/evergreen/opensrf.py +++ b/conifer/libsystems/evergreen/opensrf.py @@ -112,6 +112,50 @@ def ils_item_info(barcode): return None, None, None +def ils_patron_details(usrname): + dir_entry = {} + + try: + authtoken = auth_token(settings.OPENSRF_STAFF_USERID, + settings.OPENSRF_STAFF_PW, + settings.OPENSRF_STAFF_WORKSTATION) + + if auth_token: + patrons = [] + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, {'usrname':{'value':usrname.strip(),'group':0}}) + patron_info = req.send() + if patron_info: + patrons = patron_info + for patron in patrons[0:1]: + req = request('open-ils.actor', + 'open-ils.actor.user.fleshed.retrieve', + authtoken, patron, + ["first_given_name","family_name","email","cards"]) + patron_info = req.send() + if patron_info: + dir_entry['given_name'] = patron_info.first_given_name() + dir_entry['surname'] = patron_info.family_name() + dir_entry['email'] = patron_info.email() + + cards = patron_info.cards() + if cards: + barcode = None + for card in cards: + barcode = card.barcode() + dir_entry['barcode'] = barcode + + #clean up session + session_cleanup(authtoken) + except: + print "item update problem" + print "*** print_exc:" + traceback.print_exc() + pass # fail silently in production + + return dir_entry + def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False): """ This is the barebones of a fuzzy lookup using opensrf @@ -148,7 +192,7 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False): if not is_barcode and is_number(name): return out is_email = False - if name.find('@') > 0: + if not is_usrname and name.find('@') > 0: is_email = True try: @@ -182,6 +226,13 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False): 'open-ils.actor.patron.search.advanced', authtoken, {'card':{'value':name.strip(),'group':3}}) patrons = req.send() + elif is_usrname: + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, {'usrname':{'value':name.strip(),'group':0}}) + patron_info = req.send() + if patron_info: + patrons = patron_info elif is_staff: patrons.extend(group_search(query,authtoken,patrons)) if (len(patrons) < RESULT_LIMIT and default_query): @@ -216,9 +267,9 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False): authtoken, patron, ["first_given_name","family_name","email","usrname"]) patron_info = req.send() - display = ('%s %s. %s, ' - '%s. <%s>. [%s]') % (patron_info.first_given_name(), - patron_info.family_name(), 'Test', 'FACULTY/STAFF', + display = ('%s %s, ' + '<%s>. [%s]') % (patron_info.first_given_name(), + patron_info.family_name(), patron_info.email(), patron_info.usrname()) out.append((patron_info.usrname(), display)) diff --git a/conifer/local_settings.py.example b/conifer/local_settings.py.example index 87b7c40..1f8d092 100644 --- a/conifer/local_settings.py.example +++ b/conifer/local_settings.py.example @@ -69,7 +69,7 @@ Z3950_CONFIG = ('zed.concat.ca', 210, 'OWA') #OWA,OSUL,CONIFER # other late initializations. See the 'conifer.syrup.integration' module for # more information. -#INTEGRATION_CLASS = 'conifer.integration.uwindsor.UWindsorIntegration' +#INTEGRATION_CLASS = 'conifer.integration.evergreen_example.EvergreenExampleIntegration' #GATEWAY_SERVER = 'windsor.concat.ca' #GATEWAY_URL = 'osrf-gateway-v1' #OPENSRF_STAFF_USERID = 'staff@projectconifer.ca' diff --git a/conifer/static/fuzzyFinder.js b/conifer/static/fuzzyFinder.js index f83a198..e39991b 100644 --- a/conifer/static/fuzzyFinder.js +++ b/conifer/static/fuzzyFinder.js @@ -31,8 +31,12 @@ function fuzzyFinder(Search, Matches, EditPanel, ViewPanel, ViewName, Change, Ow here.waiting = true; $(Search).css({backgroundColor: 'yellow'}); // debugging + var search=''; + var search_level = document.getElementById('search_level'); + if (search_level) + search = search_level.value; $.post(ROOT + '/fuzzy_user_lookup', {'q': here.lastText, - includeStudents: here.includeStudents}, + includeStudents: here.includeStudents, level: search}, function(data) { here.waiting = false; here.lastPress = null; diff --git a/conifer/syrup/views/admin.py b/conifer/syrup/views/admin.py index 457a8a4..993e775 100644 --- a/conifer/syrup/views/admin.py +++ b/conifer/syrup/views/admin.py @@ -156,13 +156,18 @@ def admin_staff_add(request): return g.render('admin/staff_add.xhtml', **locals()) else: userid = request.POST.get('userid','').strip() + print "userid", userid message_continue = True try: user = User.objects.get(username=userid) except User.DoesNotExist: + print "about to create" user = User.objects.create(username=userid) + print "created", user + print "1" user.maybe_decorate() + print "2" user.is_staff = True user.is_superuser = True # TODO: are we sure they should be superuser? diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index 2f92ba2..ad342c8 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -254,8 +254,9 @@ def site_join(request, site_id): @admin_only def site_fuzzy_user_lookup(request): query = request.REQUEST.get('q').lower().strip() + level = request.REQUEST.get('level').strip() include_students = (request.REQUEST.get('includeStudents') == 'true') - results = callhook('fuzzy_person_lookup', query, include_students) or [] + results = callhook('fuzzy_person_lookup', query, include_students, level) or [] limit = 10 resp = {'results': results[:limit], 'notshown': max(0, len(results) - limit)} diff --git a/conifer/templates/admin/staff_add.xhtml b/conifer/templates/admin/staff_add.xhtml index 3463456..2387059 100644 --- a/conifer/templates/admin/staff_add.xhtml +++ b/conifer/templates/admin/staff_add.xhtml @@ -31,8 +31,15 @@ title = _('Add new staff user')

-
Type a partial name or userid into the box; then select one of the matches.
+
For fuzzy matches, type a partial name or username into the box, then select one of the matches.
+ + +
@@ -49,4 +56,4 @@ title = _('Add new staff user')

Go back

- \ No newline at end of file + diff --git a/conifer/templates/edit_site_permissions.xhtml b/conifer/templates/edit_site_permissions.xhtml index 24edff7..5f2d461 100644 --- a/conifer/templates/edit_site_permissions.xhtml +++ b/conifer/templates/edit_site_permissions.xhtml @@ -106,6 +106,13 @@ extgroups = site.group_set.filter(external_id__isnull=False).annotate(Count('mem Type a partial name or userid into the box; then select one of the matches. + + +