Skip to content

Commit 209372f

Browse files
committed
BibDocFile: addition of files redirect
* Adds redirection on files that their record has been merged. Signed-off-by: Harris Tzovanakis <me@drjova.com>
1 parent bd691cd commit 209372f

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

modules/bibdocfile/lib/bibdocfile_webinterface.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is part of Invenio.
2-
# Copyright (C) 2012, 2013 CERN.
2+
# Copyright (C) 2012, 2013, 2015, 2016 CERN.
33
#
44
# Invenio is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU General Public License as
@@ -46,10 +46,16 @@
4646
from invenio.webinterface_handler import wash_urlargd, WebInterfaceDirectory
4747
from invenio.urlutils import make_canonical_urlargd, redirect_to_url
4848
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+
)
5359
from invenio.bibdocfile import BibRecDocs, normalize_format, file_strip_ext, \
5460
stream_restricted_icon, BibDoc, InvenioBibDocFileError, \
5561
get_subformat_from_format
@@ -105,6 +111,21 @@ def getfile(req, form):
105111
navmenuid='submit')
106112

107113
if record_exists(self.recid) < 1:
114+
# Check if the record of the file has been merged
115+
# if the /record/1 has been merged to /record/2 then
116+
# /record/1/files/foo.pdf will redirect to /record/2/files/foo.pdf
117+
merged_recid = get_merged_recid(self.recid)
118+
if merged_recid:
119+
# Build the url for the file in merged record
120+
url = "{0}/{1}/{2}/files/{3}".format(
121+
CFG_SITE_URL,
122+
CFG_SITE_RECORD,
123+
merged_recid,
124+
filename
125+
)
126+
return redirect_to_url(
127+
req, url, redirection_type=apache.HTTP_MOVED_PERMANENTLY
128+
)
108129
msg = "<p>%s</p>" % _("Requested record does not seem to exist.")
109130
return warning_page(msg, req, ln)
110131

0 commit comments

Comments
 (0)