From: gfawcett Date: Tue, 28 Dec 2010 00:40:52 +0000 (+0000) Subject: site permissions: add class list by section number, or by external group code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d5c14fcd5d4d626ddde73ebeee9cc438a7e0c171;p=syrup%2Fmasslnc.git site permissions: add class list by section number, or by external group code If you provide a hook function, 'derive_group_code_from_section', mapping section numbers onto external group/class-list codes (in the context of a given site), then users can easily add sections to course sites, just by providing the section number(s). If not, then the part of the UI related to section numbers is not displayed. Note that external group members are loaded lazily: we don't know who belongs to an external group until they log into Syrup, and their external memberships are updated. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1122 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/integration/uwindsor.py b/conifer/integration/uwindsor.py index e57b9c1..ae511a9 100644 --- a/conifer/integration/uwindsor.py +++ b/conifer/integration/uwindsor.py @@ -265,6 +265,24 @@ if os.path.isfile(FUZZY_LOOKUP_BIN): return out +def derive_group_code_from_section(site, section): + """ + This function is used to simplify common-case permission setting + on course sites. It takes a site and a section number/code, and + returns the most likely external group code. (This function will + probably check the site's term and course codes, and merge those + with the section code, to derive the group code.) Return None if a + valid, unambiguous group code cannot be generated. + """ + try: + section = int(section) + except: + return None + + return '%s-%s-%s' % (site.course.code.replace('-', ''), + section, + site.start_term.code) + #-------------------------------------------------- # proxy server integration diff --git a/conifer/syrup/integration.py b/conifer/syrup/integration.py index 540a35e..8c5161f 100644 --- a/conifer/syrup/integration.py +++ b/conifer/syrup/integration.py @@ -132,6 +132,17 @@ def user_needs_decoration(user_obj): """ @disable +def derive_group_code_from_section(site, section): + """ + This function is used to simplify common-case permission setting + on course sites. It takes a site and a section number/code, and + returns the most likely external group code. (This function will + probably check the site's term and course codes, and merge those + with the section code, to derive the group code.) Return None if a + valid, unambiguous group code cannot be generated. + """ + +@disable def proxify_url(url): """ Given a URL, determine whether the URL needs to be passed through diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index e8c4c96..6807806 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -94,15 +94,35 @@ def edit_site_permissions(request, site_id): choose_access = django.forms.RadioSelect(choices=choices) + show_add_section_panel = gethook('derive_group_code_from_section') + if request.method != 'POST': return g.render('edit_site_permissions.xhtml', **locals()) else: POST = request.POST - access = POST.get('access') - site.access = access + message = 'Changes saved.' # default + + if 'action_access_level' in POST: + access = POST.get('access') + site.access = access + + elif 'action_add_group' in POST: + section = POST.get('section', '').strip() + groupcode = None + if section: + groupcode = callhook('derive_group_code_from_section', + site, section) + if not groupcode: + groupcode = POST.get('groupcode','').strip() + + if not groupcode: + message = 'No group code or section number provided.' + else: + group, created = models.Group.objects.get_or_create( + site=site, external_id=groupcode) + site.save() - - return HttpResponseRedirect('../../') + return g.render('edit_site_permissions.xhtml', **locals()) @instructors_only def delete_site(request, site_id): diff --git a/conifer/templates/edit_site_permissions.xhtml b/conifer/templates/edit_site_permissions.xhtml index 9ce6469..8979498 100644 --- a/conifer/templates/edit_site_permissions.xhtml +++ b/conifer/templates/edit_site_permissions.xhtml @@ -1,8 +1,9 @@ ${site_banner(site)}

${title}

+
${message}
-

Who has permission to view resources in this site?

-
${Markup(choose_access.render('access', site.access, {'id':'id_access'}, []))}
-

- ${go_back_link()}

+
+

Security level

+
Who has permission to view resources in this site?
+
${Markup(choose_access.render('access', site.access, {'id':'id_access'}, []))}
+

+ ${go_back_link()}

+
-

Current Membership

+
+

Class lists and groups

+
No external lists are currently associated.
+ + + + + + + + + + + +
Class/group codeKnown members
${eg.external_id}${eg.membership__count}
+
+

+ +
+ +
+
+

Current membership

@@ -38,39 +75,7 @@ extgroups = site.group_set.filter(external_id__isnull=False)
NameRoleUser IDGroup
${member.group.external_id or '(internal)'}
-
-

External Groups

-

${eg.external_id}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - +