|
1 | 1 | # This file is part of Invenio.
|
2 |
| -# Copyright (C) 2012, 2013 CERN. |
| 2 | +# Copyright (C) 2012, 2013, 2015, 2016 CERN. |
3 | 3 | #
|
4 | 4 | # Invenio is free software; you can redistribute it and/or
|
5 | 5 | # modify it under the terms of the GNU General Public License as
|
|
46 | 46 | from invenio.webinterface_handler import wash_urlargd, WebInterfaceDirectory
|
47 | 47 | from invenio.urlutils import make_canonical_urlargd, redirect_to_url
|
48 | 48 | from invenio.messages import gettext_set_language
|
49 |
| -from invenio.search_engine import \ |
50 |
| - guess_primary_collection_of_a_record, get_colID, record_exists, \ |
51 |
| - create_navtrail_links, check_user_can_view_record, record_empty, \ |
52 |
| - is_user_owner_of_record |
| 49 | +from invenio.search_engine import ( |
| 50 | + check_user_can_view_record, |
| 51 | + create_navtrail_links, |
| 52 | + get_colID, |
| 53 | + get_merged_recid, |
| 54 | + guess_primary_collection_of_a_record, |
| 55 | + is_user_owner_of_record, |
| 56 | + record_empty, |
| 57 | + record_exists |
| 58 | +) |
53 | 59 | from invenio.bibdocfile import BibRecDocs, normalize_format, file_strip_ext, \
|
54 | 60 | stream_restricted_icon, BibDoc, InvenioBibDocFileError, \
|
55 | 61 | get_subformat_from_format
|
|
68 | 74 | move_uploaded_files_to_storage
|
69 | 75 |
|
70 | 76 | bibdocfile_templates = invenio.template.load('bibdocfile')
|
| 77 | +from invenio.obelixutils import obelix, clean_user_info |
71 | 78 |
|
72 | 79 |
|
73 | 80 | class WebInterfaceFilesPages(WebInterfaceDirectory):
|
@@ -105,6 +112,21 @@ def getfile(req, form):
|
105 | 112 | navmenuid='submit')
|
106 | 113 |
|
107 | 114 | if record_exists(self.recid) < 1:
|
| 115 | + # Check if the record of the file has been merged |
| 116 | + # if the /record/1 has been merged to /record/2 then |
| 117 | + # /record/1/files/foo.pdf will redirect to /record/2/files/foo.pdf |
| 118 | + merged_recid = get_merged_recid(self.recid) |
| 119 | + if merged_recid: |
| 120 | + # Build the url for the file in merged record |
| 121 | + url = "{0}/{1}/{2}/files/{3}".format( |
| 122 | + CFG_SITE_URL, |
| 123 | + CFG_SITE_RECORD, |
| 124 | + merged_recid, |
| 125 | + filename |
| 126 | + ) |
| 127 | + return redirect_to_url( |
| 128 | + req, url, redirection_type=apache.HTTP_MOVED_PERMANENTLY |
| 129 | + ) |
108 | 130 | msg = "<p>%s</p>" % _("Requested record does not seem to exist.")
|
109 | 131 | return warning_page(msg, req, ln)
|
110 | 132 |
|
@@ -170,6 +192,12 @@ def getfile(req, form):
|
170 | 192 | else:
|
171 | 193 | docname = args['docname']
|
172 | 194 |
|
| 195 | + try: |
| 196 | + obelix.log('download_after_search', |
| 197 | + clean_user_info(user_info), self.recid) |
| 198 | + except Exception: |
| 199 | + register_exception(alert_admin=True) |
| 200 | + |
173 | 201 | if not docformat:
|
174 | 202 | docformat = args['format']
|
175 | 203 | if args['subformat']:
|
@@ -225,7 +253,7 @@ def getfile(req, form):
|
225 | 253 | if not docfile.hidden_p():
|
226 | 254 | if not readonly:
|
227 | 255 | ip = str(req.remote_ip)
|
228 |
| - doc.register_download(ip, docfile.get_version(), docformat, uid, self.recid) |
| 256 | + doc.register_download(ip, docfile.get_version(), docformat, req.headers_in.get('User-Agent'), uid, self.recid) |
229 | 257 | try:
|
230 | 258 | return docfile.stream(req, download=is_download)
|
231 | 259 | except InvenioBibDocFileError, msg:
|
|
0 commit comments