Hi, You're right, it's very time consuming and in order to make the process simpler, I send you the files directly. Theses files has been moved : websubmit/web/yoursubmissions -> websubmit/lib/websubmit_yoursubmissions websubmit/web/publiline -> websubmit/lib/websubmit_publiline websubmit/web/yourapprovals -> websubmit/lib/websubmit_yourapprovals
This files has been remove and integrate into websumit_webinterface : websubmit/web/approve The others files are in attachement and I removed the EPFL specific stuff as far as I known. Sorry for the heavy process but since I cannot directly commit to the cvs repository, it's quite harder. For the future changes, a better way would be to make very little changes and send you patches more often maybe. On 6/30/06, Tibor Simko <[email protected]> wrote:
Hello Seb: On Thu, 29 Jun 2006, Tibor Simko wrote: > It would be great if you manage to prepare a clean patch before > Friday 10:00 to have at least minimal time for testing. FYI, we are going to release with the old .py style for now. Best regards -- Tibor Simko ** CERN IT-UDS ** Bldg 31-S-014 ** Voice: +41-22-7673527 CERN Document Server ** <http://cds.cern.ch/> ** <[email protected]>
-- Sebastien Hugues Directeur associé EasyBox Technologies Sàrl Open Source & Web Solutions http://www.easybox.ch/ Rue des Terreaux 7 CH-1003 Lausanne Switzerland Tel: + 41 21 312 58 66 Fax: + 41 21 312 58 65
Makefile.am.in.websubmit.web
Description: Binary data
## $Id: publiline.py,v 1.19 2006/06/20 09:19:44 tibor Exp $
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## import interesting modules:
import string
import os
import sys
import time
import types
import re
import shutil
from invenio.config import cdsname,cdslang,supportemail,pylibdir, sweburl
from invenio.dbquery import run_sql, Error
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_admin import *
from invenio.webpage import page, create_error_box
from invenio.webuser import getUid, get_email, list_registered_users,
page_not_authorized
from invenio.messages import gettext_set_language, wash_language
from invenio.websubmit_config import *
from invenio.search_engine import search_pattern
from invenio.access_control_config import CFG_ACCESS_CONTROL_LEVEL_SITE
execfile("%s/invenio/websubmit_functions/Retrieve_Data.py" % pylibdir)
execfile("%s/invenio/websubmit_functions/mail.py" % pylibdir)
import invenio.template
websubmit_templates = invenio.template.load('websubmit')
def selectDoctype(ln = cdslang):
res = run_sql("select DISTINCT doctype from sbmAPPROVAL")
docs = []
for row in res:
res2 = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s",
(row[0],))
docs.append({
'doctype' : row[0],
'docname' : res2[0][0],
})
t = websubmit_templates.tmpl_publiline_selectdoctype(
ln = ln,
docs = docs,
)
return t
def selectCateg(doctype, ln = cdslang):
t=""
res = run_sql("select ldocname from sbmDOCTYPE where
sdocname=%s",(doctype,))
title = res[0][0]
sth = run_sql("select * from sbmCATEGORIES where doctype=%s order by
lname",(doctype,))
if len(sth) == 0:
categ = "unknown"
return selectDocument(doctype,categ, ln = ln)
categories = []
for arr in sth:
waiting = 0
rejected = 0
approved = 0
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and
categ=%s and status='waiting'", (doctype,arr[1],))
waiting = sth2[0][0]
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and
categ=%s and status='approved'",(doctype,arr[1],))
approved = sth2[0][0]
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and
categ=%s and status='rejected'",(doctype,arr[1],))
rejected = sth2[0][0]
categories.append({
'waiting' : waiting,
'approved' : approved,
'rejected' : rejected,
'id' : arr[1],
})
t = websubmit_templates.tmpl_publiline_selectcateg(
ln = ln,
categories = categories,
doctype = doctype,
title = title,
images = images,
)
return t
def selectDocument(doctype,categ, ln = cdslang):
t=""
res = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s",
(doctype,))
title = res[0][0]
if categ == "":
categ == "unknown"
docs = []
sth = run_sql("select rn,status from sbmAPPROVAL where doctype=%s and
categ=%s order by status DESC,rn DESC",(doctype,categ))
for arr in sth:
docs.append({
'RN' : arr[0],
'status' : arr[1],
})
t = websubmit_templates.tmpl_publiline_selectdocument(
ln = ln,
doctype = doctype,
title = title,
categ = categ,
images = images,
docs = docs,
)
return t
def displayDocument(doctype,categ,RN,send, ln = cdslang):
# load the right message language
_ = gettext_set_language(ln)
t=""
res = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s",
(doctype,))
docname = res[0][0]
if categ == "":
categ = "unknown"
sth = run_sql("select rn,status,dFirstReq,dLastReq,dAction,access from
sbmAPPROVAL where rn=%s",(RN,))
if len(sth) > 0:
arr = sth[0]
rn = arr[0]
status = arr[1]
dFirstReq = arr[2]
dLastReq = arr[3]
dAction = arr[4]
access = arr[5]
else:
return warningMsg(_("This document has never been requested for
approval!") + "<BR> ", ln = ln)
(authors,title,sysno,newrn) = getInfo(doctype,categ,RN)
confirm_send = 0
if send == _("Send Again"):
if authors == "unknown" or title == "unknown":
SendWarning(doctype,categ,RN,title,authors,access, ln = ln)
else:
# @todo - send in different languages
SendEnglish(doctype,categ,RN,title,authors,access,sysno)
run_sql("update sbmAPPROVAL set dLastReq=NOW() where rn=%s",(RN,))
confirm_send = 1
if status == "waiting":
(auth_code, auth_message) = acc_authorize_action(uid,
"referee",verbose=0,doctype=doctype, categ=categ)
else:
(auth_code, auth_message) = (None, None)
t = websubmit_templates.tmpl_publiline_displaydoc(
ln = ln,
docname = docname,
doctype = doctype,
categ = categ,
rn = rn,
status = status,
dFirstReq = dFirstReq,
dLastReq = dLastReq,
dAction = dAction,
access = access,
images = images,
accessurl = accessurl,
confirm_send = confirm_send,
auth_code = auth_code,
auth_message = auth_message,
authors = authors,
title = title,
sysno = sysno,
newrn = newrn,
)
return t
# Retrieve info about document
def getInfo(doctype,categ,RN):
result = getInPending(doctype,categ,RN)
if not result:
result = getInAlice(doctype,categ,RN)
return result
#seek info in pending directory
def getInPending(doctype,categ,RN):
PENDIR="%s/pending" % storage
if os.path.exists("%s/%s/%s/AU" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/AU" % (PENDIR,doctype,RN),"r")
authors=fp.read()
fp.close()
else:
authors = ""
if os.path.exists("%s/%s/%s/TI" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/TI" % (PENDIR,doctype,RN),"r")
title=fp.read()
fp.close()
else:
title = ""
if os.path.exists("%s/%s/%s/SN" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/SN" % (PENDIR,doctype,RN),"r")
sysno=fp.read()
fp.close()
else:
sysno = ""
if title == "" and os.path.exists("%s/%s/%s/TIF" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/TIF" % (PENDIR,doctype,RN),"r")
title=fp.read()
fp.close()
if title == "":
return 0
else:
return (authors,title,sysno,"")
#seek info in Alice database
def getInAlice(doctype,categ,RN):
# initialize sysno variable
sysno = ""
searchresults = search_pattern(req=None, p=RN,
f="reportnumber").items().tolist()
if len(searchresults) == 0:
return 0
sysno = searchresults[0]
if sysno != "":
title = Get_Field('245__a',sysno)
emailvalue = Get_Field('8560_f',sysno)
authors = Get_Field('100__a',sysno)
authors += "\n%s" % Get_Field('700__a',sysno)
newrn = Get_Field('037__a',sysno)
return (authors,title,sysno,newrn)
else:
return 0
def SendEnglish(doctype,categ,RN,title,authors,access,sysno):
FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail)
# retrieve useful information from webSubmit configuration
res = run_sql("select value from sbmPARAMETERS where name='categformatDAM'
and doctype=%s", (doctype,))
categformat = res[0][0]
categformat = re.sub("<CATEG>","([^-]*)",categformat)
categs = re.match(categformat,RN)
if categs != None:
categ = categs.group(1)
else:
categ = "unknown"
res = run_sql("select value from sbmPARAMETERS where name='addressesDAM'
and doctype=%s",(doctype,))
if len(res) > 0:
otheraddresses = res[0][0]
otheraddresses = otheraddresses.replace("<CATEG>",categ)
else:
otheraddresses = ""
# Build referee's email address
refereeaddress = ""
# Try to retrieve the referee's email from the referee's database
for user in acc_getRoleUsers(acc_getRoleId("referee_%s_%s" %
(doctype,categ))):
refereeaddress += user[1] + ","
# And if there are general referees
for user in acc_getRoleUsers(acc_getRoleId("referee_%s_*" % doctype)):
refereeaddress += user[1] + ","
refereeaddress = re.sub(",$","",refereeaddress)
# Creation of the mail for the referee
addresses = ""
if refereeaddress != "":
addresses = refereeaddress + ","
if otheraddresses != "":
addresses += otheraddresses
else:
addresses = re.sub(",$","",addresses)
if addresses=="":
SendWarning(doctype,categ,RN,title,authors,access)
return 0
if authors == "":
authors = "-"
res = run_sql("select value from sbmPARAMETERS where name='directory' and
doctype=%s", (doctype,))
directory = res[0][0]
message = """
The document %s has been published as a Communication.
Your approval is requested for it to become an official Note.
Title: %s
Author(s): %s
To access the document(s), select the file(s) from the location:
<%s/getfile.py?recid=%s>
To approve/reject the document, you should go to this URL:
<%s/approve.py?%s>
---------------------------------------------
Best regards.
The submission team.""" % (RN,title,authors,urlpath,sysno,urlpath,access)
# send the mail
body = forge_email(FROMADDR,addresses,adminemail,"Request for Approval of
%s" % RN,message)
send_email(FROMADDR,addresses,body,0)
return ""
def SendWarning(doctype,categ,RN,title,authors,access):
FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail)
message = "Failed sending approval email request for %s" % RN
# send the mail
body = forge_email(FROMADDR,adminemail,"","Failed sending approval email
request",message)
send_email(FROMADDR,adminemail,body,0)
return ""
## $Id: websubmit_webinterface.py,v 1.5 2006/06/20 09:19:42 tibor Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import string
from StringIO import StringIO
import os
import time
import types
import re
from mod_python import apache
import sys
from urllib import quote
from invenio.dbquery import run_sql, Error
from invenio.config import cdsname, cdslang, weburl
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_admin import acc_isRole
from invenio.webpage import page, create_error_box
from invenio.webuser import getUid, get_email, page_not_authorized
from invenio.websubmit_config import *
from invenio.websubmit_publiline import *
from invenio.websubmit_yoursubmissions import *
from invenio.websubmit_yourapprovals import *
from invenio.file import *
from invenio.access_control_config import CFG_ACCESS_CONTROL_LEVEL_SITE
from invenio.webinterface_handler import wash_urlargd, WebInterfaceDirectory
from invenio.urlutils import make_canonical_urlargd, redirect_to_url
from invenio.messages import gettext_set_language
from invenio.search_engine import print_record
import invenio.template
websubmit_templates = invenio.template.load('websubmit')
_valid_ips = {
'restricted': [ ipmask('127.0.0.1/32'),
# EPFL
ipmask('128.178.0.0/16'),
# Google
ipmask('66.249.64.0/20') ],
'private': [ ipmask('127.0.0.1/32'), ]
}
def check_permission(remote, doc, req, ln=cdslang):
_ = gettext_set_language(ln)
dt = doc.getType ()
if dt in ('restricted',):
# check client IP to restrict access to the EPFL
for ip in _valid_ips[dt]:
if ipmatch(remote, ip):
valid = True
break
else:
valid = False
if not valid:
recid = doc.getRecid()
body = _("""\
<h2>Restricted access</h2>
Sorry, access to this fulltext document is <em>restricted</em> to the
EPFL.
To obtain a copy of this document, you can either:
<ul>
<li> consult its detailed record below to find out where it has been
published. </li>
<li>Alternatively, the <b>More info</b> field in the detailed record
below will lead you to the laboratory or library that provided the
document.</li>
</ul>
""")
body += '<div style="border-left: 1px solid black; margin-left:
1em; padding-left: 1em">'
body += print_record (recid, format = 'hd')
body += "</div>"
return False, page(title = _("Restricted access"),
body = body,
description = "%s - Warning" % cdsname,
keywords="%s, Invenio, Warning" % cdsname,
language=ln,
req=req)
elif dt in ('private', ):
# check client login info to limit the access to the corresponding lab
recid = doc.getRecid()
# get user ID and credentials
try:
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
units = []
else:
uid_email = get_email (uid)
units = email_to_units(uid_email)
except Error, e:
return False, errorMsg(str(e), req)
xml = print_record(recid, format='xm')
db, junk = MARC.parse(StringIO(xml))
try:
rec = list(db.entries.itervalues())[0]
doc_units = rec['unit']
except IndexError:
doc_units = []
for unit in doc_units:
if unit in units:
valid = True
break
else:
valid = False
if not valid:
body = _("""\
<h2>Private document</h2>
Sorry, this fulltext document is <em>private</em> and can only be read
by members of the laboratory that created it. To obtain a copy of this
document, you can either:
<ul>
<li> consult its detailed record below to find out where it has been
published. </li>
<li>Alternatively, the <b>More info</b> field in the detailed record
below will lead you to the laboratory or library that provided the
document.</li>
</ul>
""")
body += '<div style="border-left: 1px solid black; margin-left:
1em; padding-left: 1em">'
body += print_record (recid, format = 'hd')
body += "</div>"
return False, page(title = _("Private document"),
body = body,
description = "%s - Warning" % cdsname,
keywords="%s, Invenio, Warning" % cdsname,
language=ln,
req=req)
return True, ''
# Errors pages
def errorMsg(title, req, c=cdsname, ln=cdslang):
_ = gettext_set_language(ln)
return page(title=_("Error"),
body = create_error_box(req, title=title,verbose=0, ln=ln),
description=_("Internal Error"),
keywords="CDS Invenio, Internal Error",
language=ln,
req=req)
def warningMsg(title, req, c=cdsname, ln=cdslang):
_ = gettext_set_language(ln)
return page(title=_("Warning"),
body = title,
description=_("Internal Error"),
keywords="CDS Invenio, Internal Error",
language=ln,
req=req)
class WebInterfaceApprovePages(WebInterfaceDirectory):
# Only the index function is public
_exports = ['']
def index(self, req, form):
# Check user rights
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../approve/index")
# Sanitize args
args = wash_urlargd(form, {'access': (str, '')})
ln = args['ln']
access = args['access']
if access == "":
return errorMsg("approve: cannot determine document reference", req)
res = run_sql("select doctype,rn from sbmAPPROVAL where access=%s",
(access,))
if len(res) == 0:
return errorMsg("approve: cannot find document in database", req)
else:
doctype = res[0][0]
rn = res[0][1]
res = run_sql("select value from sbmPARAMETERS where name='edsrn' and
doctype=%s", (doctype,))
edsrn = res[0][0]
url = "%s/sub.py?%s=%s&password=%s@APP%s" % (urlpath, edsrn, rn,
access, doctype)
req.err_headers_out.add("Location", url)
raise apache.SERVER_RETURN, apache.HTTP_MOVED_PERMANENTLY
return ""
class WebInterfaceYourApprovalsPages(WebInterfaceDirectory):
# Only the index function is public
_exports = ['']
def index(self, req, form):
# Sanitize args
args = wash_urlargd(form, {'order': (str, ''), 'doctype': (str, ''),
'deletedId': (str, ''), 'deletedAction': (str,
''),
'deletedDoctype': (str, '')})
ln = args['ln']
order = args['order']
doctype = args['doctype']
deletedId = args['deletedId']
deletedAction = args['deletedAction']
deletedDoctype = args['deletedDoctype']
# load the right message language
_ = gettext_set_language(ln)
t = ""
# get user ID:
try:
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../yourapprovals/index")
u_email = get_email(uid)
except Error, e:
return errorMsg(str(e), req, ln = ln)
res = run_sql("select sdocname,ldocname from sbmDOCTYPE")
referees = []
for row in res:
doctype = row[0]
docname = row[1]
reftext = ""
if isReferee(uid, doctype, "*"):
referees.append ({'doctype': doctype,
'docname': docname,
'categories': None})
else:
res2 = run_sql("select sname,lname from sbmCATEGORIES where
doctype=%s", (doctype,))
categories = []
for row2 in res2:
category = row2[0]
categname = row2[1]
if isReferee(uid, doctype, category):
categories.append({
'id' : category,
'name' : categname,
})
referees.append({
'doctype' : doctype,
'docname' : docname,
'categories' : categories
})
t = websubmit_templates.tmpl_yourapprovals(
ln = ln,
referees = referees
)
return page(title=_("Your Approvals"),
navtrail= """<a class="navtrail"
href="%(sweburl)s/youraccount/display">%(account)s</a>""" % {
'sweburl' : sweburl,
'account' : _("Your Account"),
},
body=t,
description="",
keywords="",
uid=uid,
language=ln,
req=req)
class WebInterfaceYourSubmissionsPages(WebInterfaceDirectory):
# Only the index function is public
_exports = ['']
def index(self, req, form):
# Sanitize args
args = wash_urlargd(form, {'order': (str, ''), 'doctype': (str, ''),
'deletedId': (str, ''), 'deletedAction':
(str, ''),
'deletedDoctype': (str, '')})
ln = args['ln']
order = args['order']
doctype = args['doctype']
deletedId = args['deletedId']
deletedAction = args['deletedAction']
deletedDoctype = args['deletedDoctype']
# load the right message language
_ = gettext_set_language(ln)
t = ""
# get user ID:
try:
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../yoursubmissions/index")
u_email = get_email(uid)
except Error, e:
return errorMsg(str(e), req, ln)
if u_email == "guest" or u_email == "":
return warningMsg(websubmit_templates.tmpl_warning_message(
ln = ln,
msg = _("You first have to login before using this feature. Use
the left menu to log in."),
),req, ln = ln)
if deletedId != "":
t += deleteSubmission(deletedId, deletedAction, deletedDoctype,
u_email)
# doctypes
res = run_sql("select ldocname,sdocname from sbmDOCTYPE order by
ldocname")
doctypes = []
for row in res:
doctypes.append({
'id' : row[1],
'name' : row[0],
'selected' : (doctype == row[1]),
})
# submissions
# request order default value
reqorder = "sbmSUBMISSIONS.md DESC, lactname"
# requested value
if order == "actiondown":
reqorder = "lactname ASC, sbmSUBMISSIONS.md DESC"
elif order == "actionup":
reqorder = "lactname DESC, sbmSUBMISSIONS.md DESC"
elif order == "refdown":
reqorder = "reference ASC, sbmSUBMISSIONS.md DESC, lactname DESC"
elif order == "refup":
reqorder = "reference DESC, sbmSUBMISSIONS.md DESC, lactname DESC"
elif order == "cddown":
reqorder = "sbmSUBMISSIONS.cd DESC, lactname"
elif order == "cdup":
reqorder = "sbmSUBMISSIONS.cd ASC, lactname"
elif order == "mddown":
reqorder = "sbmSUBMISSIONS.md DESC, lactname"
elif order == "mdup":
reqorder = "sbmSUBMISSIONS.md ASC, lactname"
elif order == "statusdown":
reqorder = "sbmSUBMISSIONS.status DESC, lactname"
elif order == "statusup":
reqorder = "sbmSUBMISSIONS.status ASC, lactname"
if doctype != "":
docselect = " and doctype='%s' " % doctype
else:
docselect = ""
res = run_sql("SELECT sbmSUBMISSIONS.* FROM sbmSUBMISSIONS,sbmACTION
WHERE sactname=action and email=%s and id!='' "+docselect+" ORDER BY
doctype,"+reqorder, (u_email,))
currentdoctype = ""
currentaction = ""
currentstatus = ""
submissions = []
for row in res:
if currentdoctype != row[1]:
currentdoctype = row[1]
currentaction = ""
currentstatus = ""
res2 = run_sql("SELECT ldocname FROM sbmDOCTYPE WHERE
sdocname=%s",
(currentdoctype,))
if res2:
ldocname = res2[0][0]
else:
ldocname = """***Unknown Document Type - (%s)""" %
(currentdoctype,)
if currentaction != row[2]:
currentaction = row[2]
res2 = run_sql("SELECT lactname FROM sbmACTION WHERE
sactname=%s", (currentaction,))
if res2:
lactname = res2[0][0]
else:
lactname = "\""
else:
lactname = "\""
if currentstatus != row[3]:
currentstatus = row[3]
status = row[3]
else:
status = "\""
submissions.append({
'docname' : ldocname,
'actname' : lactname,
'status' : status,
'cdate' : row[6],
'mdate' : row[7],
'reference' : row[5],
'id' : row[4],
'act' : currentaction,
'doctype' : currentdoctype,
'pending' : (row[3] == "pending")
})
# display
t += websubmit_templates.tmpl_yoursubmissions(
ln = ln,
weburl = weburl,
images = images,
order = order,
doctypes = doctypes,
submissions = submissions,
)
return page(title="Your Submissions",
navtrail= """<a class="navtrail"
href="%(sweburl)s/youraccount/display">%(account)s</a>""" % {
'sweburl' : sweburl,
'account' : _("Your Account"),
},
body=t,
description="",
keywords="",
uid=uid,
language=ln,
req=req)
class WebInterfacePublilinePages(WebInterfaceDirectory):
# Only the index function is public
_exports = ['']
# default Method
def index(self, req, form):
# Sanitize args
args = wash_urlargd(form, {'doctype': (str, ''), 'categ': (str, ''),
'RN': (str, ''), 'send': (str, '')})
ln = args['ln']
doctype = args['doctype']
categ = args['categ']
RN = args['RN']
send = args['send']
# load the right message language
_ = gettext_set_language(ln)
t = ""
# get user ID:
try:
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../publiline/index")
uid_email = get_email(uid)
except Error, e:
return errorMsg(str(e), req, ln = ln)
if doctype == "":
t = selectDoctype(ln)
elif categ == "":
t = selectCateg(doctype, ln)
elif RN == "":
t = selectDocument(doctype, categ, ln)
else:
t = displayDocument(doctype, categ, RN, send, ln)
return page(title="publication line",
navtrail= """<a class="navtrail"
href="%(sweburl)s/youraccount/display">%(account)s</a>""" % {
'sweburl' : sweburl,
'account' : _("Your Account"),
},
body=t,
description="",
keywords="",
uid=uid,
language=ln,
req=req)
class WebInterfaceFilesPages(WebInterfaceDirectory):
def __init__(self, recid):
self.recid = recid
def _lookup(self, component, path):
# after /record/<recid>/files/ every part is used as the file
# name (with possible path in the case of archives to be
# uncompressed)
filename = component
def getfile(req, form):
args = wash_urlargd(form,
websubmit_templates.files_default_urlargd)
ln = args['ln']
_ = gettext_set_language(ln)
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE > 1:
return page_not_authorized(req, "../getfile.py/index")
uid_email = get_email(uid)
readonly = CFG_ACCESS_CONTROL_LEVEL_SITE == 1
# From now on: either the user provided a specific file
# name (and a possible version), or we return a list of
# all the available files. In no case are the docids
# visible.
bibarchive = BibRecDocs(self.recid)
# "best" mode: try to return the latest public document
if args['mode'] == 'best':
for t in ("public", "retricted"):
docs = bibarchive.listBibDocs(type=t)
if len (docs) == 0:
continue
# More than one document? give the list instead of
returning the first one
if len(docs) > 1:
break
doc = docs[0].listLatestFiles()[0]
ip = str(req.get_remote_host(apache.REMOTE_NOLOOKUP))
can_stream, msg = check_permission(ip, doc, req, ln=ln)
if not can_stream:
return msg
if not readonly:
res = docs[0].registerDownload(ip, doc.version,
doc.format, uid)
return doc.stream(req)
if args['mode'] == 'icon':
docs = bibarchive.listBibDocs(type='icon')
if len (docs) > 0:
doc = docs[0].listLatestFiles()[0]
# Do not count access to the icon files!
return doc.stream(req)
if filename:
# We know the complete file name, guess which docid it
# refers to
name, format = os.path.splitext(filename)
if format and format[0] == '.':
format = format[1:]
# search this filename in the complete list of files
for doc in bibarchive.listBibDocs():
if filename in [f.fullname for f in doc.listAllFiles()]:
docfile = doc.getFile(name, format, args['version'])
if docfile is None:
return warningMsg(_("can't find file..."), req,
cdsname, ln)
ip = str(req.get_remote_host(apache.REMOTE_NOLOOKUP))
can_stream, msg = check_permission(ip, docfile, req,
ln=ln)
if not can_stream:
return msg
if not readonly:
res = doc.registerDownload(ip, version, format, uid)
return docfile.stream(req)
else:
return warningMsg(_("can't find file..."), req, cdsname, ln)
filelist = bibarchive.display("", args['version'], ln=ln)
t = websubmit_templates.tmpl_filelist(
ln=ln,
recid=self.recid,
docid="",
version=args['version'],
filelist=filelist)
return page(title="",
body=t,
navtrail=_("Access to Fulltext"),
description="",
keywords="keywords",
uid=uid,
language=ln,
req=req)
return getfile, []
def websubmit_legacy_getfile(req, form):
""" Handle legacy /getfile.py URLs """
# FIXME: this should _redirect_ to the proper
# /record/.../files/... URL.
args = wash_urlargd(form, {
'c': (str, cdsname),
'recid': (str, ''),
'docid': (str, ''),
'version': (str, ''),
'name': (str, ''),
'format': (str, ''),
# EPFL-specific option ([mode=<best|icon>])
'mode': (str, ''),
})
def _getfile_py(req, c=cdsname, ln=cdslang, recid="", docid="", version="",
name="", format="", mode=""):
_ = gettext_set_language(ln)
# get user ID:
try:
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../getfile.py/index")
uid_email = get_email(uid)
except Error, e:
return errorMsg(str(e), req)
filelist = ""
# redirect to a canonical URL as far as it is possible (what
# if we only have a docid, and no file supplied?)
if name != "":
if docid == "":
return errorMsg(_("Parameter docid missing"), req, c, ln)
doc = BibDoc(bibdocid=docid)
docfile = doc.getFile(name, format, version)
if docfile == None:
return warningMsg(_("can't find file..."), req, c, ln)
# redirect to this specific file, possibly dropping
# the version if we are referring to the latest one.
target = '%s/record/%d/files/%s.%s' % (
weburl, doc.recid, docfile.name, docfile.format)
if version and int(version) == int(doc.getLatestVersion()):
version = ''
target += make_canonical_urlargd({
'version': version}, websubmit_templates.files_default_urlargd)
return redirect_to_url(req, target)
# all files attached to a record
elif recid!="":
target = '%s/record/%s/files/' % (weburl, recid)
target += make_canonical_urlargd({
'version': version, 'mode': mode},
websubmit_templates.files_default_urlargd)
return redirect_to_url(req, target)
# a precise filename
elif docid!="":
bibdoc = BibDoc(bibdocid=docid)
recid = bibdoc.getRecid()
filelist = bibdoc.display(version, ln=ln)
t = websubmit_templates.tmpl_filelist(
ln = ln,
recid = recid,
docid = docid,
version = version,
filelist = filelist,
)
p_navtrail = _("Access to Fulltext")
return page(title="",
body=t,
navtrail = p_navtrail,
description="",
keywords="keywords",
uid=uid,
language=ln,
req=req)
return _getfile_py(req, **args)
# --------------------------------------------------
from invenio.websubmit_engine import home, action, interface, endaction
class WebInterfaceSubmitPages(WebInterfaceDirectory):
_exports = ['summary', 'sub', 'direct', '']
def direct(self, req, form):
args = wash_urlargd(form, {'sub': (str, '')})
sub = args['sub']
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../direct.py/index")
myQuery = req.args
if sub == "":
return errorMsg("Sorry parameter missing...", req)
res = run_sql("select docname,actname from sbmIMPLEMENT where
subname=%s", (sub,))
if len(res)==0:
return errorMsg("Sorry. Can't analyse parameter", req)
else:
# get document type
doctype = res[0][0]
# get action name
action = res[0][1]
# retrieve other parameter values
params = re.sub("sub=[^&]*", "", myQuery)
# find existing access number
result = re.search("access=([^&]*)", params)
if result != None:
access = result.group(1)
params = re.sub("access=[^&]*", "", params)
else:
# create 'unique' access number
pid = os.getpid()
now = time.time()
access = "%i_%s" % (now, pid)
# retrieve 'dir' value
res = run_sql ("select dir from sbmACTION where sactname=%s", (action,))
dir = res[0][0]
try:
mainmenu = req.headers_in['Referer']
except:
mainmenu = ""
url =
"/submit?doctype=%s&dir=%s&access=%s&act=%s&startPg=1%s&mainmenu=%s" % (
doctype, dir, access, action, params, quote(mainmenu))
req.err_headers_out.add("Location", url)
raise apache.SERVER_RETURN, apache.HTTP_MOVED_PERMANENTLY
return ""
def sub(self, req, form):
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../sub.py/index")
myQuery = req.args
if myQuery:
if re.search("@", myQuery):
param = re.sub("@.*", "", myQuery)
IN = re.sub(".*@", "", myQuery)
else:
IN = myQuery
url = "%s/submit/direct?sub=%s&%s" % (urlpath, IN, param)
req.err_headers_out.add("Location", url)
raise apache.SERVER_RETURN, apache.HTTP_MOVED_PERMANENTLY
return ""
else:
return "<html>Illegal page access</html>"
def summary(self, req, form):
args = wash_urlargd(form, {
'doctype': (str, ''),
'act': (str, ''),
'access': (str, ''),
'indir': (str, '')})
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../summary.py/index")
t = ""
curdir = "%s/%s/%s/%s" % (storage, args['indir'], args['doctype'],
args['access'])
subname = "%s%s" % (args['act'], args['doctype'])
res = run_sql("select sdesc,fidesc,pagenb,level from sbmFIELD where
subname=%s "
"order by pagenb,fieldnb", (subname,))
nbFields = 0
values = []
for arr in res:
if arr[0] != "":
val = {
'mandatory' : (arr[3] == 'M'),
'value' : '',
'page' : arr[2],
'name' : arr[0],
}
if os.path.exists("%s/%s" % (curdir, arr[1])):
fd = open("%s/%s" % (curdir, arr[1]), "r")
value = fd.read()
fd.close()
value = value.replace("\n", " ")
value = value.replace("Select:", "")
else:
value = ""
val['value'] = value
values.append(val)
return websubmit_templates.tmpl_submit_summary(
ln = args['ln'],
values = values,
images = images,
)
def index(self, req, form):
args = wash_urlargd(form, {
'c': (str, cdsname),
'doctype': (str, ''),
'act': (str, ''),
'startPg': (str, "1"),
'indir': (str, ''),
'access': (str, ''),
'mainmenu': (str, ''),
'fromdir': (str, ''),
'file': (str, ''),
'nextPg': (str, ''),
'nbPg': (str, ''),
'curpage': (str, '1'),
'step': (str, '0'),
'mode': (str, 'U'),
})
req.form = form
def _index(req, c, ln, doctype, act, startPg, indir, access,
mainmenu, fromdir, file, nextPg, nbPg, curpage, step,
mode):
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../submit")
if doctype == "":
return home(req, c, ln)
elif act == "":
return action(req, c, ln, doctype)
elif int(step)==0:
return interface(req, c, ln, doctype, act, startPg, indir,
access, mainmenu, fromdir, file, nextPg,
nbPg, curpage)
else:
return endaction(req, c, ln, doctype, act, startPg, indir,
access,mainmenu, fromdir, file, nextPg,
nbPg, curpage, step, mode)
return _index(req, **args)
# Answer to both /submit/ and /submit
__call__ = index
## $Id: yourapprovals.py,v 1.16 2006/06/20 09:19:44 tibor Exp $
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## import interesting modules:
import os
import sys
from invenio.config import weburl, sweburl, cdsname, cdslang
from invenio.dbquery import run_sql, Error
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_admin import *
from invenio.webpage import page, create_error_box
from invenio.webuser import getUid, get_email, list_registered_users,
page_not_authorized
from invenio.messages import gettext_set_language, wash_language
from invenio.websubmit_config import *
from invenio.search_engine import search_pattern
from invenio.access_control_config import CFG_ACCESS_CONTROL_LEVEL_SITE
import invenio.template
websubmit_templates = invenio.template.load('websubmit')
def isReferee(uid,doctype="",categ=""):
(auth_code, auth_message) = acc_authorize_action(uid,
"referee",verbose=0,doctype=doctype, categ=categ)
if auth_code == 0:
return 1
else:
return 0
## $Id: yoursubmissions.py,v 1.19 2006/06/20 09:19:44 tibor Exp $
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## import interesting modules:
import string
import os
import sys
import time
import types
import re
import shutil
import operator
from invenio.config import weburl, sweburl, cdsname, cdslang
from invenio.dbquery import run_sql, Error
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_admin import *
from invenio.webpage import page, create_error_box
from invenio.webuser import getUid, get_email, list_registered_users,
page_not_authorized
from invenio.messages import gettext_set_language, wash_language
from invenio.websubmit_config import *
from invenio.search_engine import search_pattern
from invenio.access_control_config import CFG_ACCESS_CONTROL_LEVEL_SITE
import invenio.template
websubmit_templates = invenio.template.load('websubmit')
def deleteSubmission(id, action, doctype, u_email):
global storage
run_sql("delete from sbmSUBMISSIONS WHERE doctype=%s and action=%s and
email=%s and status='pending' and id=%s",(doctype,action,u_email,id,))
res = run_sql("select dir from sbmACTION where sactname=%s",(action,))
dir = res[0][0]
if not ('..' in doctype or '..' in id) and id != "":
full = os.path.join(storage, dir, doctype, id)
if os.path.isdir(full):
shutil.rmtree(full)
return ""
# -*- coding: utf-8 -*-
## $Id: webinterface_layout.py,v 1.11 2006/06/16 12:17:12 gobry Exp $
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
Global organisation of the application's URLs.
This module binds together CDS Invenio's modules and maps them to
their corresponding URLs (ie, /search to the websearch modules,...)
"""
from invenio.config import webdir
from invenio.webinterface_handler import create_handler, WebInterfaceDirectory
from invenio.websearch_webinterface import WebInterfaceSearchInterfacePages
from invenio.websubmit_webinterface import websubmit_legacy_getfile
from invenio.websubmit_webinterface import WebInterfaceSubmitPages
from invenio.websubmit_webinterface import WebInterfacePublilinePages
from invenio.websubmit_webinterface import WebInterfaceYourSubmissionsPages
from invenio.websubmit_webinterface import WebInterfaceYourApprovalsPages
from invenio.websubmit_webinterface import WebInterfaceApprovePages
from invenio.websession_webinterface import WebInterfaceYourAccountPages
from invenio.webalert_webinterface import WebInterfaceYourAlertsPages
from invenio.webbasket_webinterface import WebInterfaceYourBasketsPages
from invenio.webcomment_webinterface import WebInterfaceCommentsPages
from invenio.webmessage_webinterface import WebInterfaceYourMessagesPages
from invenio.errorlib_webinterface import WebInterfaceErrorPages
from invenio.oai_repository_webinterface import WebInterfaceOAIProviderPages
from invenio.urlutils import redirect_to_url
class WebInterfaceInvenio(WebInterfaceSearchInterfacePages):
""" The global URL layout is composed of the search API plus all
the other modules."""
_exports = WebInterfaceSearchInterfacePages._exports + [
'youraccount',
'youralerts',
'yourbaskets',
'yourmessages',
'comments',
'error',
'oai2d', ('oai2d.py', 'oai2d'),
('getfile.py', 'getfile'),
'publiline',
'yoursubmissions',
'yourapprovals',
'approve',
'submit',
]
def __init__(self):
self.getfile = websubmit_legacy_getfile
return
submit = WebInterfaceSubmitPages()
publiline = WebInterfacePublilinePages()
yoursubmissions = WebInterfaceYourSubmissionsPages()
yourapprovals = WebInterfaceYourApprovalsPages()
approve = WebInterfaceApprovePages()
youraccount = WebInterfaceYourAccountPages()
youralerts = WebInterfaceYourAlertsPages()
yourbaskets = WebInterfaceYourBasketsPages()
yourmessages = WebInterfaceYourMessagesPages()
comments = WebInterfaceCommentsPages()
error = WebInterfaceErrorPages()
oai2d = WebInterfaceOAIProviderPages()
# This creates the 'handler' function, which will be invoked directly
# by mod_python.
handler = create_handler(WebInterfaceInvenio())
