Skip to content
This repository

[DS-1193] fix problem A #74

Merged
merged 1 commit into from over 1 year ago

3 participants

helix84 Tim Donohue João Melo
helix84
Owner

[DS-1193] display bitstream read access permissions on item page

This displays the bitstream READ rights information at the item page
in Mirage, but doesn't indicate whether currently logged in user
has READ access.

Tim Donohue
Owner

Hi Helix84,

A few comments on this work.

First off, the code seems to only work for Mirage / dri2xhtml-alt. It looks like we'd have to replicate that same idea to dri2xhtml and other themes?

Second, I'm actually (very slightly) concerned about hard-coding the name of the "METSRIGHTS" crosswalk into the XSLT. This is potentially "fragile", as it must match exactly the name of the crosswalk in dspace.cfg.

Alternatively, I actually wonder if this should instead be an update to the XMLUI ItemAdapter (which generates the METS in the first place), so that the METSRIGHTS crosswalk is just always called by default (if it's found to exist & be enabled).

This change could be made in the 'renderAdministrativeSection()' function of the ItemAdapter -- and look something like this:

if(amdTypes.size==0) this.setRightsMDTypes("METSRIGHTS");

See: https://github.com/DSpace/DSpace/blob/master/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/objectmanager/ItemAdapter.java#L466

This same sort of concept happens in the 'renderDescriptiveSection()' function, which by default always renders the "DIM" metadata section. See: https://github.com/DSpace/DSpace/blob/master/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/objectmanager/ItemAdapter.java#L222

This is just an idea. There may be reasons why you decided to do this in XSLT that I'm unaware of. I just wanted to note that it may be cleaner to just change the ItemAdapter code directly.

helix84
Owner

First off, the code seems to only work for Mirage / dri2xhtml-alt. It looks like we'd have to replicate that same idea to dri2xhtml and other themes?

Tim, that was intentional at the time I opened the pull request, because I wanted to get feedback if this is fine before doing it for all the themes (actually just dri2xhtml, which would trickle down to Reference). It's just copy-paste.

hard-coding the name of the "METSRIGHTS" crosswalk into the XSLT

This is the default and normal users don't change it, so I'm not worried. If anyone happens to change it, it will just revert to the old behaviour. One solution would be to get the config property name from XSL, but according to mdiggory's comments, it would be good to separate the rights from mets.xml into separate XML document (so that people can enforce access-restrictions on it if needed). I wasn't able to do such change, so he told me to go ahead with the current solution. We can change this at any time, but I think it would be a pity to postpone the whole feature.

tl;dr - METSRIGHTS endpoint will likely change later, no reason to do an intermediate change

Regarding enabling METSRIGHTS crosswalk by default - I intentionally didn't want to do that:
1) it works just fine like this
2) it would change status quo, i.e. rights exposed by default -> someone could have a problem with that
3) as I wrote above, I consider this temporary before METSRIGHTS can generate its own XML document

For reasons why I wanted this in XSL as opposed to Aspect, see Jira. I have another use for this information in XSL.

Thanks Tim for a review. Would you happen to know how create a separate document for METSRIGHTS?

Tim Donohue
Owner

Hi helix84,

Regarding enabling METSRIGHTS crosswalk by default - I intentionally didn't want to do that:

I'm not sure I fully understand this statement. By adding "?rightsMDTypes=METSRIGHTS" into the default XSLT, you actually are causing the METSRIGHTS crosswalk to be "enabled by default" as long as it is defined in the dspace.cfg file. The only way to stop the METSRIGHTS crosswalk from being run in the XMLUI would be to either (a) remove it from the dspace.cfg or (b) modify the XSLT in your theme to override that default "?rightsMDTypes=METSRIGHTS" setting.

After saying that, I can now see the one advantage of enabling METSRIGHTS in the Theme XSLT is that it may be easier to disable in your own custom theme than if it was defined in a Java class (like I had suggested above).

Thanks Tim for a review. Would you happen to know how create a separate document for METSRIGHTS?

Off the top of my head, I'm not sure of an easy way to generate a separate document for METSRIGHTS. It could be something to look into post-3.0 obviously.

João Melo
Owner

(Developer appreciation) +1 Code is fine.

helix84 [DS-1193] display bitstream read access permissions on item page (squ…
…ashed)

This displays the bitstream READ rights information at the item page
in Mirage, but doesn't indicate whether the currently logged in user
has READ access.
2499436
helix84
Owner

Tim, both of your concerns have been resolved:
1) all distributed themes now have this feature
2) I'm checking for presence of the METSRIGHTS crosswalk in dspace.cfg and if it's not present, fall back to the old behaviour

helix84 helix84 merged commit 91b4927 into from September 17, 2012
helix84 helix84 closed this September 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 17, 2012
helix84 [DS-1193] display bitstream read access permissions on item page (squ…
…ashed)

This displays the bitstream READ rights information at the item page
in Mirage, but doesn't indicate whether the currently logged in user
has READ access.
2499436
This page is out of date. Refresh to see the latest.
BIN  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/Classic/images/Crystal_Clear_action_lock3_64px.png
BIN  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/Kubrick/images/Crystal_Clear_action_lock3_64px.png
BIN  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/Mirage/images/Crystal_Clear_action_lock3_64px.png
57  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/Mirage/lib/xsl/aspect/artifactbrowser/item-view.xsl
@@ -31,7 +31,9 @@
31 31
     xmlns:xalan="http://xml.apache.org/xalan"
32 32
     xmlns:encoder="xalan://java.net.URLEncoder"
33 33
     xmlns:util="org.dspace.app.xmlui.utils.XSLUtils"
34  
-    exclude-result-prefixes="xalan encoder i18n dri mets dim xlink xsl util">
  34
+    xmlns:jstring="java.lang.String"
  35
+    xmlns:rights="http://cosimo.stanford.edu/sdr/metsrights/"
  36
+    exclude-result-prefixes="xalan encoder i18n dri mets dim xlink xsl util jstring rights">
35 37
 
36 38
     <xsl:output indent="yes"/>
37 39
 
@@ -481,16 +483,57 @@
481 483
                 </xsl:if>
482 484
             </div>
483 485
             <div class="file-link" style="height: {$thumbnail.maxheight}px;">
484  
-                <a>
485  
-                    <xsl:attribute name="href">
486  
-                        <xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
487  
-                    </xsl:attribute>
488  
-                    <i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
489  
-                </a>
  486
+                <xsl:choose>
  487
+                    <xsl:when test="@ADMID">
  488
+                        <xsl:call-template name="display-rights"/>
  489
+                    </xsl:when>
  490
+                    <xsl:otherwise>
  491
+                        <xsl:call-template name="view-open"/>
  492
+                    </xsl:otherwise>
  493
+                </xsl:choose>
490 494
             </div>
491 495
         </div>
  496
+    </xsl:template>
  497
+
  498
+    <xsl:template name="view-open">
  499
+        <a>
  500
+            <xsl:attribute name="href">
  501
+                <xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
  502
+            </xsl:attribute>
  503
+            <i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
  504
+        </a>
  505
+    </xsl:template>
492 506
 
  507
+    <xsl:template name="display-rights">
  508
+        <xsl:variable name="file_id" select="jstring:replaceAll(jstring:replaceAll(string(@ADMID), '_METSRIGHTS', ''), 'rightsMD_', '')"/>
  509
+        <xsl:variable name="rights_declaration" select="../../../mets:amdSec/mets:rightsMD[@ID = concat('rightsMD_', $file_id, '_METSRIGHTS')]/mets:mdWrap/mets:xmlData/rights:RightsDeclarationMD"/>
  510
+        <xsl:variable name="rights_context" select="$rights_declaration/rights:Context"/>
  511
+        <xsl:variable name="users">
  512
+            <xsl:for-each select="$rights_declaration/*">
  513
+                <xsl:value-of select="rights:UserName"/>
  514
+                <xsl:choose>
  515
+                    <xsl:when test="rights:UserName/@USERTYPE = 'GROUP'">
  516
+                       <xsl:text> (group)</xsl:text>
  517
+                    </xsl:when>
  518
+                    <xsl:when test="rights:UserName/@USERTYPE = 'INDIVIDUAL'">
  519
+                       <xsl:text> (individual)</xsl:text>
  520
+                    </xsl:when>
  521
+                </xsl:choose>
  522
+                <xsl:if test="position() != last()">, </xsl:if>
  523
+            </xsl:for-each>
  524
+        </xsl:variable>
493 525
 
  526
+        <xsl:choose>
  527
+            <xsl:when test="not ($rights_context/@CONTEXTCLASS = 'GENERAL PUBLIC') and ($rights_context/rights:Permissions/@DISPLAY = 'true')">
  528
+                <a href="{mets:FLocat[@LOCTYPE='URL']/@xlink:href}">
  529
+                    <img width="64" height="64" src="{concat($theme-path,'/images/Crystal_Clear_action_lock3_64px.png')}" title="Read access available for {$users}"/>
  530
+                    <!-- icon source: http://commons.wikimedia.org/wiki/File:Crystal_Clear_action_lock3.png -->
  531
+                </a>
  532
+            </xsl:when>
  533
+            <xsl:otherwise>
  534
+                <xsl:call-template name="view-open"/>
  535
+            </xsl:otherwise>
  536
+        </xsl:choose>
494 537
     </xsl:template>
495 538
 
496 539
 </xsl:stylesheet>
BIN  ...ce-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/Reference/images/Crystal_Clear_action_lock3_64px.png
13  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/dri2xhtml-alt/aspect/artifactbrowser/common.xsl
@@ -32,7 +32,8 @@
32 32
     xmlns="http://www.w3.org/1999/xhtml"
33 33
     xmlns:xalan="http://xml.apache.org/xalan"
34 34
     xmlns:encoder="xalan://java.net.URLEncoder"
35  
-    exclude-result-prefixes="xalan encoder i18n dri mets dim  xlink xsl">
  35
+    xmlns:confman="org.dspace.core.ConfigurationManager"
  36
+    exclude-result-prefixes="i18n dri mets dim xlink xsl xalan encoder confman">
36 37
 
37 38
     <xsl:output indent="yes"/>
38 39
 
@@ -187,11 +188,19 @@
187 188
     </xsl:template>
188 189
 
189 190
     <xsl:template match="dri:reference" mode="summaryView">
  191
+        <!-- simplified check to verify whether access rights are available in METS -->
  192
+        <xsl:variable name='METSRIGHTS-enabled' select="contains(confman:getProperty('plugin.named.org.dspace.content.crosswalk.DisseminationCrosswalk'), 'METSRIGHTS')" />
190 193
         <xsl:variable name="externalMetadataURL">
191 194
             <xsl:text>cocoon:/</xsl:text>
192 195
             <xsl:value-of select="@url"/>
193  
-            <!-- No options selected, render the full METS document -->
  196
+            <!-- If this is an Item, display the METSRIGHTS section, so we
  197
+                 know which files have access restrictions.
  198
+                 This requires the METSRightsCrosswalk to be enabled! -->
  199
+            <xsl:if test="@type='DSpace Item' and $METSRIGHTS-enabled">
  200
+                <xsl:text>?rightsMDTypes=METSRIGHTS</xsl:text>
  201
+            </xsl:if>
194 202
         </xsl:variable>
  203
+        <!-- This comment just displays the full URL in an HTML comment, for easy reference. -->
195 204
         <xsl:comment> External Metadata URL: <xsl:value-of select="$externalMetadataURL"/> </xsl:comment>
196 205
         <xsl:apply-templates select="document($externalMetadataURL)" mode="summaryView"/>
197 206
         <xsl:apply-templates />
60  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/dri2xhtml/General-Handler.xsl
@@ -22,7 +22,9 @@
22 22
     xmlns:xlink="http://www.w3.org/TR/xlink/"
23 23
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
24 24
     xmlns="http://www.w3.org/1999/xhtml"
25  
-    exclude-result-prefixes="i18n dri mets xlink xsl">
  25
+    xmlns:jstring="java.lang.String"
  26
+    xmlns:rights="http://cosimo.stanford.edu/sdr/metsrights/"
  27
+    exclude-result-prefixes="i18n dri mets xlink xsl jstring rights">
26 28
     
27 29
     <xsl:output indent="yes"/>
28 30
     
@@ -162,12 +164,14 @@
162 164
                         </a>
163 165
                     </xsl:when>
164 166
                     <xsl:otherwise>
165  
-                        <a>
166  
-                            <xsl:attribute name="href">
167  
-                                <xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
168  
-                            </xsl:attribute>
169  
-                            <i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
170  
-                        </a>
  167
+                        <xsl:choose>
  168
+                            <xsl:when test="@ADMID">
  169
+                                <xsl:call-template name="display-rights"/>
  170
+                            </xsl:when>
  171
+                            <xsl:otherwise>
  172
+                                <xsl:call-template name="view-open"/>
  173
+                            </xsl:otherwise>
  174
+                        </xsl:choose>
171 175
                     </xsl:otherwise>
172 176
                 </xsl:choose>                        
173 177
             </td>
@@ -181,6 +185,48 @@
181 185
         </tr>
182 186
     </xsl:template>
183 187
     
  188
+    <xsl:template name="view-open">
  189
+        <a>
  190
+            <xsl:attribute name="href">
  191
+                <xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
  192
+            </xsl:attribute>
  193
+            <i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
  194
+        </a>
  195
+    </xsl:template>
  196
+
  197
+    <xsl:template name="display-rights">
  198
+        <xsl:variable name="file_id" select="jstring:replaceAll(jstring:replaceAll(string(@ADMID), '_METSRIGHTS', ''), 'rightsMD_', '')"/>
  199
+        <xsl:variable name="rights_declaration" select="../../../mets:amdSec/mets:rightsMD[@ID = concat('rightsMD_', $file_id, '_METSRIGHTS')]/mets:mdWrap/mets:xmlData/rights:RightsDeclarationMD"/>
  200
+        <xsl:variable name="rights_context" select="$rights_declaration/rights:Context"/>
  201
+        <xsl:variable name="users">
  202
+            <xsl:for-each select="$rights_declaration/*">
  203
+                <xsl:value-of select="rights:UserName"/>
  204
+                <xsl:choose>
  205
+                    <xsl:when test="rights:UserName/@USERTYPE = 'GROUP'">
  206
+                       <xsl:text> (group)</xsl:text>
  207
+                    </xsl:when>
  208
+                    <xsl:when test="rights:UserName/@USERTYPE = 'INDIVIDUAL'">
  209
+                       <xsl:text> (individual)</xsl:text>
  210
+                    </xsl:when>
  211
+                </xsl:choose>
  212
+                <xsl:if test="position() != last()">, </xsl:if>
  213
+            </xsl:for-each>
  214
+        </xsl:variable>
  215
+
  216
+        <xsl:choose>
  217
+            <xsl:when test="not ($rights_context/@CONTEXTCLASS = 'GENERAL PUBLIC') and ($rights_context/rights:Permissions/@DISPLAY = 'true')">
  218
+                <a href="{mets:FLocat[@LOCTYPE='URL']/@xlink:href}">
  219
+                    <img width="64" height="64" src="{concat($theme-path,'/images/Crystal_Clear_action_lock3_64px.png')}" title="Read access available for {$users}"/>
  220
+                    <!-- icon source: http://commons.wikimedia.org/wiki/File:Crystal_Clear_action_lock3.png -->
  221
+                </a>
  222
+            </xsl:when>
  223
+            <xsl:otherwise>
  224
+                <xsl:call-template name="view-open"/>
  225
+            </xsl:otherwise>
  226
+        </xsl:choose>
  227
+    </xsl:template>
  228
+
  229
+
184 230
     <!--
185 231
     File Type Mapping template
186 232
 
11  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/dri2xhtml/structural.xsl
@@ -24,7 +24,8 @@
24 24
         xmlns:mods="http://www.loc.gov/mods/v3"
25 25
         xmlns:dc="http://purl.org/dc/elements/1.1/"
26 26
         xmlns="http://www.w3.org/1999/xhtml"
27  
-        exclude-result-prefixes="mets xlink xsl dim xhtml mods dc">
  27
+        xmlns:confman="org.dspace.core.ConfigurationManager"
  28
+        exclude-result-prefixes="mets xlink xsl dim xhtml mods dc confman">
28 29
     
29 30
     <xsl:output indent="yes"/>
30 31
     
@@ -2954,10 +2955,16 @@
2954 2955
     </xsl:template>
2955 2956
     
2956 2957
     <xsl:template match="dri:reference" mode="summaryView">
  2958
+        <xsl:variable name='METSRIGHTS-enabled' select="contains(confman:getProperty('plugin.named.org.dspace.content.crosswalk.DisseminationCrosswalk'), 'METSRIGHTS')" />
2957 2959
         <xsl:variable name="externalMetadataURL">
2958 2960
             <xsl:text>cocoon:/</xsl:text>
2959 2961
             <xsl:value-of select="@url"/>
2960  
-            <!-- No options selected, render the full METS document -->
  2962
+            <!-- If this is an Item, display the METSRIGHTS section, so we
  2963
+                 know which files have access restrictions.
  2964
+                 This requires the METSRightsCrosswalk to be enabled! -->
  2965
+            <xsl:if test="@type='DSpace Item' and $METSRIGHTS-enabled">
  2966
+                <xsl:text>?rightsMDTypes=METSRIGHTS</xsl:text>
  2967
+            </xsl:if>
2961 2968
         </xsl:variable>
2962 2969
         <xsl:comment> External Metadata URL: <xsl:value-of select="$externalMetadataURL"/> </xsl:comment>
2963 2970
         <xsl:apply-templates select="document($externalMetadataURL)" mode="summaryView"/>
BIN  dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/themes/template/images/Crystal_Clear_action_lock3_64px.png
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.