[open-ils-commits] r1194 - in servres/trunk/conifer: syrup syrup/views templates/components templates/item (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 12 19:49:54 EST 2011


Author: gfawcett
Date: 2011-01-12 19:49:53 -0500 (Wed, 12 Jan 2011)
New Revision: 1194

Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views/items.py
   servres/trunk/conifer/syrup/views/sites.py
   servres/trunk/conifer/templates/components/site.xhtml
   servres/trunk/conifer/templates/item/item_metadata.xhtml
Log:
added "Restricted" access level: auth'd users may browse, but only members can download ELEC documents.

At the request of the Leddy team.

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2011-01-12 17:46:36 UTC (rev 1193)
+++ servres/trunk/conifer/syrup/models.py	2011-01-13 00:49:53 UTC (rev 1194)
@@ -236,6 +236,7 @@
     ACCESS_CHOICES = [
         ('ANON',  _('World-accessible')),
         ('LOGIN', _('Accessible to all logged-in users')),
+        ('RESTR', _('Accessible to all logged-in users, but only course-site members can read electronic documents.')),
         ('MEMBR', _('Accessible to course-site members')),
         ('CLOSE', _('Accessible only to course-site owners'))]
 
@@ -406,7 +407,7 @@
             return True
         if not user.is_authenticated():
             return False
-        if level == 'LOGIN':
+        if level in ('LOGIN', 'RESTR'):
             return True
         memberships = self.members().filter(user=user)
         if not memberships:
@@ -419,6 +420,19 @@
             raise Exception('Cannot determine access level '
                             'for user %s in site %s' % (user, self))
 
+    def allows_downloads_to(self, user):
+        """
+        Return True if this site allows this user to download
+        electronic documents. For 'restricted' sites, we allow any
+        logged-in user to visit, but only members can download
+        documents.
+        """
+        level = self.access
+        if level == 'RESTR':
+            return user.is_staff or self.is_member(user)
+        else:
+            return self.is_open_to(user)
+        
     @classmethod
     def taught_by(cls, user):
         """Return a set of Sites for which this user is an Instructor."""
@@ -439,7 +453,7 @@
         elif user.is_staff:
             return Q()
         else:
-            return (Q(access__in=('LOGIN','ANON')) \
+            return (Q(access__in=('RESTR','LOGIN','ANON')) \
                         | Q(group__membership__user=user))
 
 #------------------------------------------------------------
@@ -817,7 +831,7 @@
         elif user.is_staff:
             return Q()
         else:
-            return (Q(site__access__in=('LOGIN','ANON')) \
+            return (Q(site__access__in=('RESTR','LOGIN','ANON')) \
                         | Q(site__group__membership__user=user))
 
 #------------------------------------------------------------

Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py	2011-01-12 17:46:36 UTC (rev 1193)
+++ servres/trunk/conifer/syrup/views/items.py	2011-01-13 00:49:53 UTC (rev 1194)
@@ -27,10 +27,13 @@
         return _heading_detail(request, item)
     else:
         item_declaration_required = item.needs_declaration_from(request.user)
+        access_forbidden = (item.item_type == 'ELEC' 
+                            and not item.site.allows_downloads_to(request.user))
         custom_declaration = callhook('download_declaration')
         return g.render('item/item_metadata.xhtml', site=item.site,
                         item_declaration_required=item_declaration_required,
                         custom_declaration=custom_declaration,
+                        access_forbidden=access_forbidden,
                         item=item)
 
 @members_only
@@ -362,6 +365,12 @@
     item = get_object_or_404(models.Item, pk=item_id, site__id=site_id)
     assert item.item_type == 'ELEC', _('Can only download ELEC documents!')
 
+    access_forbidden = (item.item_type == 'ELEC' 
+                        and not item.site.allows_downloads_to(request.user))
+    if access_forbidden:
+        return simple_message(_('Access denied.'), 
+                              _('Sorry, but you are not allowed to access this resource.'))
+
     # don't allow download of items that need a declaration.
     item_declaration_required = item.needs_declaration_from(request.user)
     if item_declaration_required:

Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py	2011-01-12 17:46:36 UTC (rev 1193)
+++ servres/trunk/conifer/syrup/views/sites.py	2011-01-13 00:49:53 UTC (rev 1194)
@@ -87,7 +87,8 @@
     # the ones in 'models'.
     choices = [
         (u'ANON',  _(u'Everyone: no login required.')),
-        (u'LOGIN', _(u'Members and non-members: login required.')),
+        (u'LOGIN', _(u'Login required.')),
+        (u'RESTR', _(u'Login required; only members can access electronic documents.')),
         (u'MEMBR', _(u'Members only.')),
         (u'CLOSE', _(u'Instructors only: this site is closed.')),
         ]

Modified: servres/trunk/conifer/templates/components/site.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/site.xhtml	2011-01-12 17:46:36 UTC (rev 1193)
+++ servres/trunk/conifer/templates/components/site.xhtml	2011-01-13 00:49:53 UTC (rev 1194)
@@ -1,5 +1,6 @@
 <?python
 searchtext = _('search this site...')
+downloads_allowed = site.allows_downloads_to(user)
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:py="http://genshi.edgewall.org/"
@@ -69,7 +70,11 @@
       <div class="availability avail_nonphys" py:if="item.item_type != 'PHYS'">
       </div>
       <div class="mainline ${item.item_type=='HEADING' and 'headingmainline' or ''}">
-		<a href="${item.item_url()}" class="mainlink">${item}</a> 
+	<span py:if="item.item_type=='ELEC' and not downloads_allowed">
+	  <img title="Sorry, this document is not available to you."
+	       src="${ROOT}/static/tango/lock.png"/></span>
+	  <a href="${item.item_url()}" class="mainlink"
+	     py:strip="item.item_type=='ELEC' and not downloads_allowed">${item}</a> 
       </div>
       <div class="author_pub" py:if="item.author or item.publisher or item.published">
 	<span py:with="vt=item.video_type()"><span class="videotype" py:if="vt">[${vt}]</span></span>

Modified: servres/trunk/conifer/templates/item/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item/item_metadata.xhtml	2011-01-12 17:46:36 UTC (rev 1193)
+++ servres/trunk/conifer/templates/item/item_metadata.xhtml	2011-01-13 00:49:53 UTC (rev 1194)
@@ -62,7 +62,7 @@
       <tr py:if="item.url"><th>URL</th><td><a href="${item.url}">${item.url}</a></td></tr>
     </table>
 
-    <div py:if="item.item_type=='ELEC'">
+    <div py:if="item.item_type=='ELEC' and not access_forbidden">
       <h2 class="metadata_subhead">Download the document</h2>
       <div class="errors" py:if="not item.copyright_status_ok()">
 	Note: this item is awaiting <a href="edit/">copyright clearance</a>. Only staff and instructors may download it.



More information about the open-ils-commits mailing list