diff --git a/modules/bibindex/web/admin/bibindexadmin.py b/modules/bibindex/web/admin/bibindexadmin.py index 038656d44..639530ef6 100644 --- a/modules/bibindex/web/admin/bibindexadmin.py +++ b/modules/bibindex/web/admin/bibindexadmin.py @@ -1,445 +1,445 @@ ## Administrator interface for WebSearch ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware BibIndex Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.bibindexadminlib as bic reload(bic) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def deletetag(req, fldID, ln=cdslang, tagID=-1, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_deletetag(fldID=fldID, ln=ln, tagID=tagID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addtag(req, fldID, ln=cdslang, value=['',-1], name='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_addtag(fldID=fldID, ln=ln, value=value, name=name, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfieldtags(req, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showfieldtags(fldID=fldID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetailsfieldtag(req, fldID, tagID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showdetailsfieldtag(fldID=fldID, tagID=tagID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetailsfield(req, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showdetailsfield(fldID=fldID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfield(req, fldID, ln=cdslang, code='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifyfield(fldID=fldID, ln=ln, code=code, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytag(req, fldID, tagID, ln=cdslang, name='', value='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifytag(fldID=fldID, tagID=tagID, ln=ln, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deletefield(req, fldID, ln=cdslang, confirm=0): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_deletefield(fldID=fldID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetails(req, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_showdetails(ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfields(req, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_showfields(ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfield(req, fldID, ln=cdslang, mtype='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showfield(fldID=fldID, ln=ln, mtype=mtype, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, fldID, ln=cdslang, sel_type='', trans = [], confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifytranslations(fldID=fldID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addfield(req, ln=cdslang, fldNAME='', code='', callback="yes", confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_addfield(ln=cdslang, fldNAME=fldNAME, code=code, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchtagscore(req, fldID, id_1, id_2, ln=cdslang): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_switchtagscore(fldID=fldID, id_1=id_1, id_2=id_2, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefieldtag(req, fldID, tagID, ln=cdslang, callback="yes", confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_removefieldtag(fldID=fldID, tagID=tagID, ln=cdslang, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def index(req, ln=cdslang, mtype='', content=''): navtrail_previous_links = bic.getnavtrail() try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_index(ln=ln, mtype=mtype, content=content), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=bic.adderrorbox('Not logged in', + body=bic.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) diff --git a/modules/bibindex/web/admin/bibindexadmin.py.wml b/modules/bibindex/web/admin/bibindexadmin.py.wml index 038656d44..639530ef6 100644 --- a/modules/bibindex/web/admin/bibindexadmin.py.wml +++ b/modules/bibindex/web/admin/bibindexadmin.py.wml @@ -1,445 +1,445 @@ ## Administrator interface for WebSearch ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware BibIndex Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.bibindexadminlib as bic reload(bic) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def deletetag(req, fldID, ln=cdslang, tagID=-1, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_deletetag(fldID=fldID, ln=ln, tagID=tagID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addtag(req, fldID, ln=cdslang, value=['',-1], name='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_addtag(fldID=fldID, ln=ln, value=value, name=name, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfieldtags(req, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showfieldtags(fldID=fldID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetailsfieldtag(req, fldID, tagID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showdetailsfieldtag(fldID=fldID, tagID=tagID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetailsfield(req, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showdetailsfield(fldID=fldID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfield(req, fldID, ln=cdslang, code='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifyfield(fldID=fldID, ln=ln, code=code, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytag(req, fldID, tagID, ln=cdslang, name='', value='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifytag(fldID=fldID, tagID=tagID, ln=ln, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deletefield(req, fldID, ln=cdslang, confirm=0): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_deletefield(fldID=fldID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showdetails(req, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_showdetails(ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfields(req, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_showfields(ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showfield(req, fldID, ln=cdslang, mtype='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_showfield(fldID=fldID, ln=ln, mtype=mtype, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, fldID, ln=cdslang, sel_type='', trans = [], confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_modifytranslations(fldID=fldID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addfield(req, ln=cdslang, fldNAME='', code='', callback="yes", confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_addfield(ln=cdslang, fldNAME=fldNAME, code=code, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchtagscore(req, fldID, id_1, id_2, ln=cdslang): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_switchtagscore(fldID=fldID, id_1=id_1, id_2=id_2, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefieldtag(req, fldID, tagID, ln=cdslang, callback="yes", confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> BibIndex Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_removefieldtag(fldID=fldID, tagID=tagID, ln=cdslang, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def index(req, ln=cdslang, mtype='', content=''): navtrail_previous_links = bic.getnavtrail() try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = bic.check_user(uid,'cfgbibindex') if not auth[0]: return page(title="BibIndex Interface", body=bic.perform_index(ln=ln, mtype=mtype, content=content), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=bic.adderrorbox('Not logged in', + body=bic.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) diff --git a/modules/bibrank/web/admin/bibrankadmin.py b/modules/bibrank/web/admin/bibrankadmin.py index 0c3e20b1b..4e8c56fd5 100644 --- a/modules/bibrank/web/admin/bibrankadmin.py +++ b/modules/bibrank/web/admin/bibrankadmin.py @@ -1,215 +1,215 @@ ## Administrator interface for BibRank ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware BibRank Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.bibrankadminlib as brc #reload(brc) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def index(req, ln=cdslang): navtrail_previous_links = brc.getnavtrail() # + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="BibRank Admin Interface", body=brc.perform_index(ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, urlargs=req.args) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addrankarea(req, ln=cdslang, rnkcode='', template='', confirm=-1): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Add new rank method", body=brc.perform_addrankarea(rnkcode=rnkcode, ln=cdslang, template=template, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, rnkID='', ln=cdslang, sel_type='', trans = [], confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify translations", body=brc.perform_modifytranslations(rnkID=rnkID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifycollection(req, ln=cdslang, rnkID='', func='', colID='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify visibility toward collections", body=brc.perform_modifycollection(rnkID=rnkID, ln=ln, func=func, colID=colID, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deleterank(req, ln=cdslang, rnkID='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Delete rank method", body=brc.perform_deleterank(rnkID=rnkID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrank(req, ln=cdslang, rnkID='', rnkcode='', template='', cfgfile='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify rank method", body=brc.perform_modifyrank(rnkID=rnkID, ln=ln, rnkcode=rnkcode, cfgfile=cfgfile, template=template, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showrankdetails(req, ln=cdslang, rnkID=''): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Rank method details", body=brc.perform_showrankdetails(rnkID=rnkID, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=brc.adderrorbox('Not logged in', + body=brc.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) diff --git a/modules/bibrank/web/admin/bibrankadmin.py.wml b/modules/bibrank/web/admin/bibrankadmin.py.wml index 0c3e20b1b..4e8c56fd5 100644 --- a/modules/bibrank/web/admin/bibrankadmin.py.wml +++ b/modules/bibrank/web/admin/bibrankadmin.py.wml @@ -1,215 +1,215 @@ ## Administrator interface for BibRank ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware BibRank Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.bibrankadminlib as brc #reload(brc) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def index(req, ln=cdslang): navtrail_previous_links = brc.getnavtrail() # + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="BibRank Admin Interface", body=brc.perform_index(ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, urlargs=req.args) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addrankarea(req, ln=cdslang, rnkcode='', template='', confirm=-1): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Add new rank method", body=brc.perform_addrankarea(rnkcode=rnkcode, ln=cdslang, template=template, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, rnkID='', ln=cdslang, sel_type='', trans = [], confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify translations", body=brc.perform_modifytranslations(rnkID=rnkID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifycollection(req, ln=cdslang, rnkID='', func='', colID='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify visibility toward collections", body=brc.perform_modifycollection(rnkID=rnkID, ln=ln, func=func, colID=colID, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deleterank(req, ln=cdslang, rnkID='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Delete rank method", body=brc.perform_deleterank(rnkID=rnkID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrank(req, ln=cdslang, rnkID='', rnkcode='', template='', cfgfile='', confirm=0): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Modify rank method", body=brc.perform_modifyrank(rnkID=rnkID, ln=ln, rnkcode=rnkcode, cfgfile=cfgfile, template=template, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showrankdetails(req, ln=cdslang, rnkID=''): navtrail_previous_links = brc.getnavtrail() + """> BibRank Admin Interface """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = brc.check_user(uid,'cfgbibrank') if not auth[0]: return page(title="Rank method details", body=brc.perform_showrankdetails(rnkID=rnkID, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=brc.adderrorbox('Not logged in', + body=brc.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) diff --git a/modules/webaccess/lib/webaccessadmin_lib.py b/modules/webaccess/lib/webaccessadmin_lib.py index b18a04cda..f3d43f5ad 100644 --- a/modules/webaccess/lib/webaccessadmin_lib.py +++ b/modules/webaccess/lib/webaccessadmin_lib.py @@ -1,2677 +1,2677 @@ ## $Id$ ## Administrator interface for WebAccess ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware WebAccess Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: import access_control_engine as acce import access_control_admin as acca # reload(acce) # reload(acca) import cgi import re from bibrankadminlib import adderrorbox,addadminbox,tupletotable,tupletotable_onlyselected,addcheckboxes,createhiddenform from access_control_config import * from dbquery import run_sql from config import * from webpage import page, pageheaderonly, pagefooteronly from webuser import getUid, get_email from mod_python import apache __version__ = "$Id$" def index(req, title='', body='', subtitle='', adminarea=2, authorized=0): """main function to show pages for webaccessadmin. 1. if user not logged in and administrator, show the mustlogin page 2. if used without body argument, show the startpage 3. show admin page with title, body, subtitle and navtrail. adminarea - number codes that tell what extra info to put in the navtrail 0 - nothing extra 1 - add Delegate Rights 2 - add Manage WebAccess maybe add: 3: role admin 4: action admin 5: user area 6: reset area authorized - if 1, don't check if the user is allowed to be webadmin """ navtrail_previous_links = """Admin Area > WebAccess Admin """ % (weburl, weburl) if body: if adminarea == 1: navtrail_previous_links += '> Delegate Rights ' % (weburl, ) if adminarea >= 2: navtrail_previous_links += '> Manage WebAccess ' % (weburl, ) if adminarea == 3: navtrail_previous_links += '> Role Administration ' % (weburl, ) elif adminarea == 4: navtrail_previous_links += '> Action Administration ' % (weburl, ) elif adminarea == 5: navtrail_previous_links += '> User Administration ' % (weburl, ) elif adminarea == 6: navtrail_previous_links += '> Reset Authorizations ' % (weburl, ) id_user = getUid(req) (auth_code, auth_message) = is_adminuser(req) if not authorized and auth_code != 0: return mustloginpage(req, auth_message) elif not body: title = 'Manage WebAccess' body = startpage() elif type(body) != str: body = addadminbox(subtitle, datalist=body) return page(title=title, uid=id_user, body=body, navtrail=navtrail_previous_links, lastupdated=__lastupdated__) def mustloginpage(req, message): """show a page asking the user to login.""" navtrail_previous_links = """Admin Area > WebAccess Admin """ % (weburl, weburl) return page(title='Authorization failure', uid=getUid(req), - body=adderrorbox('Not logged in', + body=adderrorbox('Reason:', datalist=[message]), navtrail=navtrail_previous_links, lastupdated=__lastupdated__) def is_adminuser(req): """check if user is a registered administrator. """ id_user = getUid(req) return acce.acc_authorize_action(id_user, WEBACCESSACTION) def perform_rolearea(req): """create the role area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) header = ['id', 'name', 'description', 'users', 'authorizations / actions', 'role', ''] roles = acca.acc_getAllRoles() roles2 = [] for (id, name, desc) in roles: if len(desc) > 30: desc = desc[:30] + '...' roles2.append([id, name, desc]) for col in [(('add', 'adduserrole'), ('remove', 'deleteuserrole')), (('add', 'addauthorization'), ('modify', 'modifyauthorizations'), ('remove', 'deleteroleaction')), (('delete', 'deleterole'), ), (('show details', 'showroledetails'), )]: roles2[-1].append('%s' % (col[0][1], id, col[0][0])) for (str, function) in col[1:]: roles2[-1][-1] += ' / %s' % (function, id, str) output = """
Users:
add or remove users from the access to a role and its priviliges.
Authorizations/Actions:
these terms means almost the same, but an authorization is a
connection between a role and an action (possibly) containing arguments.
Roles:
see all the information attached to a role and decide if you want to
delete it.
""" output += tupletotable(header=header, tuple=roles2) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" return index(req=req, title='Role Administration', subtitle='administration with roles as access point', body=[output, extra], adminarea=2) def perform_actionarea(req): """create the action area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) header = ['id', 'name', 'authorizations/roles', 'action', ''] actions = acca.acc_getAllActions() actions2 = [] roles2 = [] for (id, name, dontcare) in actions: actions2.append([id, name]) for col in [(('add', 'addauthorization'), ('modify', 'modifyauthorizations'), ('remove', 'deleteroleaction')), (('delete', 'deleteaction'), ), (('show details', 'showactiondetails'), )]: actions2[-1].append('%s' % (col[0][1], id, col[0][0])) for (str, function) in col[1:]: actions2[-1][-1] += ' / %s' % (function, id, str) output = """
Authorizations/Roles:
these terms means almost the same, but an authorization is a
connection between a role and an action (possibly) containing arguments.
Actions:
see all the information attached to an action and decide if you want to
delete it.
""" output += tupletotable(header=header, tuple=actions2) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" return index(req=req, title='Action Administration', subtitle='administration with actions as access point', body=[output, extra], adminarea=2) def perform_userarea(req, email_user_pattern=''): """create area to show info about users. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) subtitle = 'step 1 - search for users' output = """

search for users to display.

""" # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 1. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="userarea", text=text, button="search for users") if email_user_pattern: users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email LIMIT %s""" % (email_user_pattern, MAXPAGEUSERS+1)) if not users1: output += '

no matching users

' else: subtitle = 'step 2 - select what to do with user' users = [] for (id, email) in users1[:MAXPAGEUSERS]: users.append([id, email]) for col in [(('add', 'addroleuser'), ('remove', 'deleteuserrole')), (('show details', 'showuserdetails'), )]: users[-1].append('%s' % (col[0][1], email_user_pattern, id, col[0][0])) for (str, function) in col[1:]: users[-1][-1] += ' / %s' % (function, email_user_pattern, id, str) output += '

found %s matching users:

' % (len(users1), ) output += tupletotable(header=['id', 'email', 'roles', ''], tuple=users) if len(users1) > MAXPAGEUSERS: output += '

only showing the first %s users, narrow your search...

' % (MAXPAGEUSERS, ) return index(req=req, title='User Administration', subtitle=subtitle, body=[output], adminarea=2) def perform_resetarea(req): """create the reset area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = """
Reset to Default Authorizations
remove all changes that has been done to the roles and
add only the default authorization settings.
Add Default Authorizations
keep all changes and add the default authorization settings.
""" return index(req=req, title='Reset Authorizations', subtitle='reseting to or adding default authorizations', body=[output], adminarea=2) def perform_resetdefaultsettings(req, superusers=[], confirm=0): """delete all roles, actions and authorizations presently in the database and add only the default roles. only selected users will be added to superadmin, rest is blank """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # cleaning input if type(superusers) == str: superusers = [superusers] # remove not valid e-mails for email in superusers: if not check_email(email): superusers.remove(email) # instructions output = """

before you reset the settings, we need some users
to connect to %s.
enter as many e-mail adresses you want and press reset.
confirm reset settings when you have added enough e-mails.
is added as default.

""" % (SUPERADMINROLE, ) # add more superusers output += """

enter user e-mail addresses:

""" for email in superusers: output += ' ' % (email, ) output += """ e-mail
""" if superusers: # remove emails output += """
have you entered wrong data?
""" # superusers confirm table start = '
' extra = ' ' for email in superusers: extra += '' % (email, ) extra += ' ' end = '
' output += '

reset default settings with the users below?

' output += tupletotable(header=['e-mail address'], tuple=superusers, start=start, extracolumn=extra, end=end) if confirm in [1, "1"]: res = acca.acc_reset_default_settings(superusers) if res: output += '

successfully reset default settings

' else: output += '

sorry, could not reset default settings

' return index(req=req, title='Reset Default Settings', subtitle='reset settings', body=[output], adminarea=6) def perform_adddefaultsettings(req, superusers=[], confirm=0): """add the default settings, and keep everything else. probably nothing will be deleted, except if there has been made changes to the defaults.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # cleaning input if type(superusers) == str: superusers = [superusers] # remove not valid e-mails for email in superusers: if not check_email(email): superusers.remove(email) # instructions output = """

before you add the settings, we need some users
to connect to %s.
enter as many e-mail adresses you want and press add.
confirm add settings when you have added enough e-mails.
is added as default.

""" % (SUPERADMINROLE, ) # add more superusers output += """

enter user e-mail addresses:

""" for email in superusers: output += ' ' % (email, ) output += """ e-mail
""" if superusers: # remove emails output += """
have you entered wrong data?
""" # superusers confirm table start = '
' extra = ' ' for email in superusers: extra += '' % (email, ) extra += ' ' end = '
' output += '

add default settings with the users below?

' output += tupletotable(header=['e-mail address'], tuple=superusers, start=start, extracolumn=extra, end=end) if confirm in [1, "1"]: res = acca.acc_add_default_settings(superusers) if res: output += '

successfully added default settings

' else: output += '

sorry, could not add default settings

' return index(req=req, title='Add Default Settings', subtitle='add settings', body=[output], adminarea=6) def perform_delegate_startarea(req): """start area for lower level delegation of rights.""" subtitle = 'select what to do' output = '' if is_adminuser(req)[0] == 0: output += """

You are also allowed to be in the Main Admin Area which gives you
the access to the full functionality of WebAccess.

""" output += """
Connect users to roles
add users to the roles you have delegation rights to.
Remove users from roles
remove users from the roles you have delegation rights to.
Set up delegation rights
spesialized area to set up the delegation rights used in the areas above.
you need to be a web administrator to access the area.
""" return index(req=req, title='Delegate Rights', subtitle=subtitle, body=[output], adminarea=0, authorized=1) def perform_delegate_adminsetup(req, id_role_admin=0, id_role_delegate=0, confirm=0): """lets the webadmins set up the delegation rights for the other roles id_role_admin - the role to be given delegation rights id_role_delegate - the role over which the delegation rights are given confirm - make the connection happen """ subtitle = 'step 1 - select admin role' admin_roles = acca.acc_getAllRoles() output = """

This is a specialized area to handle a task that also can be handled
from the "add authorization" interface.

By handling the delegation rights here you get the advantage of
not having to select the correct action (%s) or
remembering the names of available roles.

""" % (DELEGATEADDUSERROLE, ) output += createroleselect(id_role=id_role_admin, step=1, button='select admin role', name='id_role_admin', action='delegate_adminsetup', roles=admin_roles) if str(id_role_admin) != '0': subtitle = 'step 2 - select delegate role' name_role_admin = acca.acc_getRoleName(id_role=id_role_admin) delegate_roles_old = acca.acc_find_delegated_roles(id_role_admin=id_role_admin) delegate_roles = [] delegate_roles_old_names = [] for role in admin_roles: if (role,) not in delegate_roles_old: delegate_roles.append(role) else: delegate_roles_old_names.append(role[1]) if delegate_roles_old_names: delegate_roles_old_names.sort() names_str = '' for name in delegate_roles_old_names: if names_str: names_str += ', ' names_str += name output += '

previously selected roles: %s.

' % (names_str, ) extra = """
Remove delegated roles
use the standard administration area to remove delegation rights you no longer want to be available.
""" % (id_role_admin, acca.acc_getActionId(name_action=DELEGATEADDUSERROLE)) else: output += '

no previously selected roles.

' output += createroleselect(id_role=id_role_delegate, step=2, button='select delegate role', name='id_role_delegate', action='delegate_adminsetup', roles=delegate_roles, id_role_admin=id_role_admin) if str(id_role_delegate) != '0': subtitle = 'step 3 - confirm to add delegation right' name_role_delegate = acca.acc_getRoleName(id_role=id_role_delegate) output += """

Warning: don't hand out delegation rights that can harm the system (e.g. delegating superrole).

""" output += createhiddenform(action="delegate_adminsetup", text='let role %s delegate rights over role %s?' % (name_role_admin, name_role_delegate), id_role_admin=id_role_admin, id_role_delegate=id_role_delegate, confirm=1) if int(confirm): subtitle = 'step 4 - confirm delegation right added' # res1 = acca.acc_addRoleActionArguments_names(name_role=name_role_admin, # name_action=DELEGATEADDUSERROLE, # arglistid=-1, # optional=0, # role=name_role_delegate) res1 = acca.acc_addAuthorization(name_role=name_role_admin, name_action=DELEGATEADDUSERROLE, optional=0, role=name_role_delegate) if res1: output += '

confirm: role %s delegates role %s.' % (name_role_admin, name_role_delegate) else: output += '

sorry, delegation right could not be added,
it probably already exists.

' # see if right hand menu is available try: body = [output, extra] except NameError: body = [output] return index(req=req, title='Delegate Rights', subtitle=subtitle, body=body, adminarea=1) def perform_delegate_adduserrole(req, id_role=0, email_user_pattern='', id_user=0, confirm=0): """let a lower level web admin add users to a limited set of roles. id_role - the role to connect to a user id_user - the user to connect to a role confirm - make the connection happen """ # finding the allowed roles for this user id_admin = getUid(req) id_action = acca.acc_getActionId(name_action=DELEGATEADDUSERROLE) actions = acca.acc_findPossibleActionsUser(id_user=id_admin, id_action=id_action) allowed_roles = [] allowed_id_roles = [] for (id, arglistid, name_role_help) in actions[1:]: id_role_help = acca.acc_getRoleId(name_role=name_role_help) if id_role_help and [id_role_help, name_role_help, ''] not in allowed_roles: allowed_roles.append([id_role_help, name_role_help, '']) allowed_id_roles.append(str(id_role_help)) output = '' if not allowed_roles: subtitle = 'no delegation rights' output += """

You do not have the delegation rights over any roles.
If you think you should have such rights, contact a WebAccess Administrator.

""" extra = '' else: subtitle = 'step 1 - select role' output += """

Lower level delegation of access rights to roles.
An administrator with all rights have to give you these rights.

""" email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) output += createroleselect(id_role=id_role, step=1, name='id_role', action='delegate_adduserrole', roles=allowed_roles) if str(id_role) != '0' and str(id_role) in allowed_id_roles: subtitle = 'step 2 - search for users' # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 2. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="delegate_adduserrole", text=text, button="search for users", id_role=id_role) # pattern is entered if email_user_pattern: # users with matching email-address users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) # users that are connected users2 = run_sql("""SELECT DISTINCT u.id, u.email FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE = '%s' AND u.email RLIKE '%s' ORDER BY u.email """ % (id_role, email_user_pattern)) # no users that match the pattern if not (users1 or users2): output += '

no qualified users, try new search.

' # too many matching users elif len(users1) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users1), MAXSELECTUSERS) # show matching users else: subtitle = 'step 3 - select a user' users = [] extrausers = [] for (id, email) in users1: if (id, email) not in users2: users.append([id,email,'']) for (id, email) in users2: extrausers.append([-id, email,'']) output += createuserselect(id_user=id_user, action="delegate_adduserrole", step=3, users=users, extrausers=extrausers, button="add this user", id_role=id_role, email_user_pattern=email_user_pattern) try: id_user = int(id_user) except ValueError: pass # user selected already connected to role if id_user < 0: output += '

users in brackets are already attached to the role, try another one...

' # a user is selected elif email_out: subtitle = "step 4 - confirm to add user" output += createhiddenform(action="delegate_adduserrole", text='add user %s to role %s?' % (email_out, name_role), id_role=id_role, email_user_pattern=email_user_pattern, id_user=id_user, confirm=1) # it is confirmed that this user should be added if confirm: # add user result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm user added' output += '

confirm: user %s added to role %s.

' % (email_out, name_role) else: subtitle = 'step 5 - user could not be added' output += '

sorry, but user could not be added.

' extra = """
Remove users from role
remove users from the roles you have delegating rights to.
""" % (id_role, ) return index(req=req, title='Connect users to roles', subtitle=subtitle, body=[output, extra], adminarea=1, authorized=1) def perform_delegate_deleteuserrole(req, id_role=0, id_user=0, confirm=0): """let a lower level web admin remove users from a limited set of roles. id_role - the role to connect to a user id_user - the user to connect to a role confirm - make the connection happen """ subtitle = 'in progress...' output = '

in progress...

' # finding the allowed roles for this user id_admin = getUid(req) id_action = acca.acc_getActionId(name_action=DELEGATEADDUSERROLE) actions = acca.acc_findPossibleActionsUser(id_user=id_admin, id_action=id_action) output = '' if not actions: subtitle = 'no delegation rights' output += """

You do not have the delegation rights over any roles.
If you think you should have such rights, contact a WebAccess Administrator.

""" extra = '' else: subtitle = 'step 1 - select role' output += """

Lower level delegation of access rights to roles.
An administrator with all rights have to give you these rights.

""" email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) # create list of allowed roles allowed_roles = [] allowed_id_roles = [] for (id, arglistid, name_role_help) in actions[1:]: id_role_help = acca.acc_getRoleId(name_role=name_role_help) if id_role_help and [id_role_help, name_role_help, ''] not in allowed_roles: allowed_roles.append([id_role_help, name_role_help, '']) allowed_id_roles.append(str(id_role_help)) output += createroleselect(id_role=id_role, step=1, action='delegate_deleteuserrole', roles=allowed_roles) if str(id_role) != '0' and str(id_role) in allowed_id_roles: subtitle = 'step 2 - select user' users = acca.acc_getRoleUsers(id_role) output += createuserselect(id_user=id_user, step=2, action='delegate_deleteuserrole', users=users, id_role=id_role) if str(id_user) != '0': subtitle = 'step 3 - confirm delete of user' email_user = acca.acc_getUserEmail(id_user=id_user) output += createhiddenform(action="delegate_deleteuserrole", text='delete user %s from %s?' % (headerstrong(user=id_user), headerstrong(role=id_role)), id_role=id_role, id_user=id_user, confirm=1) if confirm: res = acca.acc_deleteUserRole(id_user=id_user, id_role=id_role) if res: subtitle = 'step 4 - confirm user deleted from role' output += '

confirm: deleted user %s from role %s.

' % (email_user, name_role) else: subtitle = 'step 4 - user could not be deleted' output += 'sorry, but user could not be deleted
user is probably already deleted.' extra = """
Connect users to role
add users to the roles you have delegating rights to.
""" % (id_role, ) return index(req=req, title='Remove users from roles', subtitle=subtitle, body=[output, extra], adminarea=1, authorized=1) def perform_addaction(req, name_action='', arguments='', optional='no', description='put description here.', confirm=0): """form to add a new action with these values: name_action - name of the new action arguments - allowedkeywords, separated by whitespace description - optional description of the action""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_action = cleanstring(name_action) arguments = cleanstring(arguments, comma=1) title = 'Add Action' subtitle = 'step 1 - give values to the requested fields' output = """
action name
arguments keywords for arguments, separate with comma, no whitespace.
optional arguments
description
""" % (name_action, arguments, optional == 'yes' and 'selected="selected"' or '', description) if name_action: # description must be changed before it is submitted if description == 'put description here.': internaldesc = '' else: internaldesc = description if arguments: subtitle = 'step 2 - confirm to add action with %s arguments' % (optional == 'yes' and 'optional' or '', ) arguments = arguments.replace(' ', '') text = 'add action with:
\n' text += 'name: %s
\n' % (name_action, ) if internaldesc: text += 'description: %s
\n' % (description, ) text += '%sarguments: %s
' % (optional == 'yes' and 'optional ' or '', arguments) text += 'optional: %s?' % (optional, ) else: optional = 'no' subtitle = 'step 2 - confirm to add action without arguments' text = 'add action %s without arguments' % (name_action, ) if internaldesc: text += '
\nand description: %s?\n' % (description, ) else: text += '?\n' output += createhiddenform(action="addaction", text=text, name_action=name_action, arguments=arguments, optional=optional, description=description, confirm=1) if confirm not in ["0", 0]: arguments = arguments.split(',') result = acca.acc_addAction(name_action, internaldesc, optional, *arguments) if result: subtitle = 'step 3 - action added' output += '

action added:

' output += tupletotable(header=['id', 'action name', 'description', 'allowedkeywords', 'optional'], tuple=[result]) else: subtitle = 'step 3 - action could not be added' output += '

sorry, could not add action,
action with the same name probably exists.

' extra = """
Add authorization
start adding new authorizations to action %s.
""" % (acca.acc_getActionId(name_action=name_action), name_action) try: body = [output, extra] except NameError: body = [output] return index(req=req, title=title, body=body, subtitle=subtitle, adminarea=4) def perform_deleteaction(req, id_action="0", confirm=0): """show all roles connected, and ask for confirmation. id_action - id of action to delete """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title='Delete action' subtitle='step 1 - select action to delete' name_action = acca.acc_getActionName(id_action=id_action) output = createactionselect(id_action=id_action, action="deleteaction", step=1, actions=acca.acc_getAllActions(), button="delete action") if id_action != "0" and name_action: subtitle = 'step 2 - confirm the delete' output += actiondetails(id_action=id_action) if acca.acc_getActionRoles(id_action=id_action): output += createhiddenform(action="deleteroleaction", text="""rather delete only connection between action %s and a selected role?""" % (name_action, ), id_action=id_action, reverse=1, button='go there') output += createhiddenform(action="deleteaction", text=' delete action %s and all connections?' % (name_action, ), confirm=1, id_action=id_action) if confirm: subtitle = 'step 3 - confirm delete of action' res = acca.acc_deleteAction(id_action=id_action) if res: output += '

confirm: action %s deleted.
\n' % (name_action, ) output += '%s entries deleted all in all.

\n' % (res, ) else: output += '

sorry, action could not be deleted.

\n' elif id_action != "0": output += '

the action has been deleted...

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=4) def perform_showactiondetails(req, id_action): """show the details of an action. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = createactionselect(id_action=id_action, action="showactiondetails", step=1, actions=acca.acc_getAllActions(), button="select action") if id_action not in [0, '0']: output += actiondetails(id_action=id_action) extra = """
Add new authorization
add an authorization.
Modify authorizations
modify existing authorizations.
Remove role
remove all authorizations from action and a role.
""" % (id_action, id_action, id_action) body = [output, extra] else: output += '

no details to show

' body = [output] return index(req=req, title='Show Action Details', subtitle='show action details', body=body, adminarea=4) def actiondetails(id_action=0): """show details of given action. """ output = '' if id_action not in [0, '0']: name_action = acca.acc_getActionName(id_action=id_action) output += '

action details:

' output += tupletotable(header=['id', 'name', 'description', 'allowedkeywords', 'optional'], tuple=[acca.acc_getActionDetails(id_action=id_action)]) roleshlp = acca.acc_getActionRoles(id_action=id_action) if roleshlp: roles = [] for (id, name, dontcare) in roleshlp: roles.append([id, name, 'show authorization details' % (id, id_action), 'show connected users' % (id, )]) roletable = tupletotable(header=['id', 'name', '', ''], tuple=roles) output += '

roles connected to %s:

\n' % (headerstrong(action=name_action, query=0), ) output += roletable else: output += '

no roles connected to %s.

\n' % (headerstrong(action=name_action, query=0), ) else: output += '

no details to show

' return output def perform_addrole(req, name_role='', description='put description here.', confirm=0): """form to add a new role with these values: name_role - name of the new role description - optional description of the role """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_role = cleanstring(name_role) title='Add Role' subtitle = 'step 1 - give values to the requested fields' output = """
role name
description
""" % (name_role, description) if name_role: # description must be changed before submitting subtitle = 'step 2 - confirm to add role' internaldesc = '' if description != 'put description here.': internaldesc = description text = """ add role with:
\n name: %s
""" % (name_role, ) if internaldesc: text += 'description: %s?\n' % (description, ) output += createhiddenform(action="addrole", text=text, name_role=name_role, description=description, confirm=1) if confirm not in ["0", 0]: result = acca.acc_addRole(name_role=name_role, description=internaldesc) if result: subtitle = 'step 3 - role added' output += '

role added:

' output += tupletotable(header=['id', 'action name', 'description', 'allowedkeywords'], tuple=[result]) else: subtitle = 'step 3 - role could not be added' output += '

sorry, could not add role,
role with the same name probably exists.

' id_role = acca.acc_getRoleId(name_role=name_role) extra = """
Add authorization
start adding new authorizations to role %s.
Connect user
connect a user to role %s.
""" % (id_role, name_role, id_role, name_role) try: body = [output, extra] except NameError: body = [output] return index(req=req, title=title, body=body, subtitle=subtitle, adminarea=3) def perform_deleterole(req, id_role="0", confirm=0): """select a role and show all connected information, users - users that can access the role. actions - actions with possible authorizations.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Delete role' subtitle = 'step 1 - select role to delete' name_role = acca.acc_getRoleName(id_role=id_role) output = createroleselect(id_role=id_role, action="deleterole", step=1, roles=acca.acc_getAllRoles(), button="delete role") if id_role != "0" and name_role: subtitle = 'step 2 - confirm delete of role' output += roledetails(id_role=id_role) output += createhiddenform(action="deleterole", text='delete role %s and all connections?' % (name_role, ), id_role=id_role, confirm=1) if confirm: res = acca.acc_deleteRole(id_role=id_role) subtitle = 'step 3 - confirm role deleted' if res: output += "

confirm: role %s deleted.
" % (name_role, ) output += "%s entries were removed.

" % (res, ) else: output += "

sorry, the role could not be deleted.

" elif id_role != "0": output += '

the role has been deleted...

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=3) def perform_showroledetails(req, id_role): """show the details of a role.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = createroleselect(id_role=id_role, action="showroledetails", step=1, roles=acca.acc_getAllRoles(), button="select role") if id_role not in [0, '0']: name_role = acca.acc_getRoleName(id_role=id_role) output += roledetails(id_role=id_role) extra = """
Add new authorization
add an authorization.
Modify authorizations
modify existing authorizations.
Connect user
connect a user to role %s.
Remove user
remove a user from role %s.
""" % (id_role, id_role, id_role, name_role, id_role, name_role) body = [output, extra] else: output += '

no details to show

' body = [output] return index(req=req, title='Show Role Details', subtitle='show role details', body=body, adminarea=3) def roledetails(id_role=0): """create the string to show details about a role. """ name_role = acca.acc_getRoleName(id_role=id_role) usershlp = acca.acc_getRoleUsers(id_role) users = [] for (id, email, dontcare) in usershlp: users.append([id, email, 'show user details' % (id, )]) usertable = tupletotable(header=['id', 'email'], tuple=users) actionshlp = acca.acc_getRoleActions(id_role) actions = [] for (id, name, dontcare) in actionshlp: actions.append([id, name, 'show action details' % (id_role, id), 'show authorization details' % (id_role, id)]) actiontable = tupletotable(header=['id', 'name', '', ''], tuple=actions) # show role details details = '

role details:

' details += tupletotable(header=['id', 'name', 'description'], tuple=[acca.acc_getRoleDetails(id_role=id_role)]) # show connected users details += '

users connected to %s:

' % (headerstrong(role=name_role, query=0), ) if users: details += usertable else: details += '

no users connected.

' # show connected authorizations details += '

authorizations for %s:

' % (headerstrong(role=name_role, query=0), ) if actions: details += actiontable else: details += '

no authorizations connected

' return details def perform_adduserrole(req, id_role='0', email_user_pattern='', id_user='0', confirm=0): """create connection between user and role. id_role - id of the role to add user to email_user_pattern - search for users using this pattern id_user - id of user to add to the role. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) title = 'Connect user to role ' subtitle = 'step 1 - select a role' output = createroleselect(id_role=id_role, action="adduserrole", step=1, roles=acca.acc_getAllRoles()) # role is selected if id_role != "0": title += name_role subtitle = 'step 2 - search for users' # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 2. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="adduserrole", text=text, button="search for users", id_role=id_role) # pattern is entered if email_user_pattern: # users with matching email-address users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) # users that are connected users2 = run_sql("""SELECT DISTINCT u.id, u.email FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE = '%s' AND u.email RLIKE '%s' ORDER BY u.email """ % (id_role, email_user_pattern)) # no users that match the pattern if not (users1 or users2): output += '

no qualified users, try new search.

' elif len(users1) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users1), MAXSELECTUSERS) # show matching users else: subtitle = 'step 3 - select a user' users = [] extrausers = [] for (id, email) in users1: if (id, email) not in users2: users.append([id,email,'']) for (id, email) in users2: extrausers.append([-id, email,'']) output += createuserselect(id_user=id_user, action="adduserrole", step=3, users=users, extrausers=extrausers, button="add this user", id_role=id_role, email_user_pattern=email_user_pattern) try: id_user = int(id_user) except ValueError: pass # user selected already connected to role if id_user < 0: output += '

users in brackets are already attached to the role, try another one...

' # a user is selected elif email_out: subtitle = "step 4 - confirm to add user" output += createhiddenform(action="adduserrole", text='add user %s to role %s?' % (email_out, name_role), id_role=id_role, email_user_pattern=email_user_pattern, id_user=id_user, confirm=1) # it is confirmed that this user should be added if confirm: # add user result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm user added' output += '

confirm: user %s added to role %s.

' % (email_out, name_role) else: subtitle = 'step 5 - user could not be added' output += '

sorry, but user could not be added.

' extra = """
Create new role
go here to add a new role.
""" if str(id_role) != "0": extra += """
Remove users
remove users from role %s.
Connected users
show all users connected to role %s.
Add authorization
start adding new authorizations to role %s.
""" % (id_role, name_role, id_role, name_role, id_role, name_role) return index(req=req, title=title, subtitle=subtitle, body=[output, extra], adminarea=3) def perform_addroleuser(req, email_user_pattern='', id_user='0', id_role='0', confirm=0): """delete connection between role and user. id_role - id of role to disconnect id_user - id of user to disconnect. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) # used to sort roles, and also to determine right side links con_roles = [] not_roles = [] title = 'Connect user to roles' subtitle = 'step 1 - search for users' # clean email search string email_user_pattern = cleanstring_email(email_user_pattern) text = ' 1. search pattern \n' text += ' \n' % (email_user_pattern, ) output = createhiddenform(action='addroleuser', text=text, button='search for users', id_role=id_role) if email_user_pattern: subtitle = 'step 2 - select user' users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) users = [] for (id, email) in users1: users.append([id, email, '']) # no users if not users: output += '

no qualified users, try new search.

' # too many users elif len(users) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users), MAXSELECTUSERS) # ok number of users else: output += createuserselect(id_user=id_user, action='addroleuser', step=2, users=users, button='select user', email_user_pattern=email_user_pattern) if int(id_user): subtitle = 'step 3 - select role' # roles the user is connected to role_ids = acca.acc_getUserRoles(id_user=id_user) # all the roles, lists are sorted on the background of these... all_roles = acca.acc_getAllRoles() # sort the roles in connected and not connected roles for (id, name, description) in all_roles: if (id, ) in role_ids: con_roles.append([-id, name, description]) else: not_roles.append([id, name, description]) # create roleselect output += createroleselect(id_role=id_role, action='addroleuser', step=3, roles=not_roles, extraroles=con_roles, extrastamp='(connected)', button='add this role', email_user_pattern=email_user_pattern, id_user=id_user) if int(id_role) < 0: name_role = acca.acc_getRoleName(id_role=-int(id_role)) output += '

role %s already connected to the user, try another one...

' % (name_role, ) elif int(id_role): subtitle = 'step 4 - confirm to add role to user' output += createhiddenform(action='addroleuser', text='add role %s to user %s?' % (name_role, email_out), email_user_pattern=email_user_pattern, id_user=id_user, id_role=id_role, confirm=1) if confirm: # add role result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm role added' output += '

confirm: role %s added to user %s.

' % (name_role, email_out) else: subtitle = 'step 5 - role could not be added' output += '

sorry, but role could not be added

' extra = """
Create new role
go here to add a new role.
""" if int(id_user) and con_roles: extra += """
Remove roles
disconnect roles from user %s.
""" % (id_user, email_out) if int(id_role): if int(id_role) < 0: id_role = -int(id_role) extra += """
Remove users
disconnect users from role %s.
""" % (id_role, name_role) return index(req=req, title=title, subtitle=subtitle, body=[output, extra], adminarea=5) def perform_deleteuserrole(req, id_role='0', id_user='0', reverse=0, confirm=0): """delete connection between role and user. id_role - id of role to disconnect id_user - id of user to disconnect. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Remove user from role' email_user = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) output = '' if reverse in [0, '0']: adminarea = 3 subtitle = 'step 1 - select the role' output += createroleselect(id_role=id_role, action="deleteuserrole", step=1, roles=acca.acc_getAllRoles()) if id_role != "0": subtitle = 'step 2 - select the user' output += createuserselect(id_user=id_user, action="deleteuserrole", step=2, users=acca.acc_getRoleUsers(id_role=id_role), id_role=id_role) else: adminarea = 5 # show only if user is connected to a role, get users connected to roles users = run_sql("""SELECT DISTINCT(u.id), u.email, u.note FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE != 'NULL' AND u.email != '' ORDER BY u.email """) has_roles = 1 # check if the user is connected to any roles for (id, email, note) in users: if str(id) == str(id_user): break # user not connected to a role else: subtitle = 'step 1 - user not connected' output += '

no need to remove roles from user %s,
user is not connected to any roles.

' % (email_user, ) has_roles, id_user = 0, '0' # stop the rest of the output below... # user connected to roles if has_roles: output += createuserselect(id_user=id_user, action="deleteuserrole", step=1, users=users, reverse=reverse) if id_user != "0": subtitle = 'step 2 - select the role' role_ids = acca.acc_getUserRoles(id_user=id_user) all_roles = acca.acc_getAllRoles() roles = [] for (id, name, desc) in all_roles: if (id, ) in role_ids: roles.append([id, name, desc]) output += createroleselect(id_role=id_role, action="deleteuserrole", step=2, roles=roles, id_user=id_user, reverse=reverse) if id_role != '0' and id_user != '0': subtitle = 'step 3 - confirm delete of user' output += createhiddenform(action="deleteuserrole", text='delete user %s from %s?' % (headerstrong(user=id_user), headerstrong(role=id_role)), id_role=id_role, id_user=id_user, reverse=reverse, confirm=1) if confirm: res = acca.acc_deleteUserRole(id_user=id_user, id_role=id_role) if res: subtitle = 'step 4 - confirm delete of user' output += '

confirm: deleted user %s from role %s.

' % (email_user, name_role) else: subtitle = 'step 4 - user could not be deleted' output += 'sorry, but user could not be deleted
user is probably already deleted.' extra = '' if str(id_role) != "0": extra += """
Connect user
add users to role %s.
""" % (id_role, name_role) if int(reverse): extra += """
Remove user
remove users from role %s.
""" % (id_role, name_role) extra += '
' if str(id_user) != "0": extra += """
Connect role
add roles to user %s.
""" % (email_user, id_user, email_user) if not int(reverse): extra += """
Remove role
remove roles from user %s.
""" % (id_user, email_user, email_user) extra += '
' if extra: body = [output, extra] else: body = [output] return index(req=req, title=title, subtitle=subtitle, body=body, adminarea=adminarea) def perform_showuserdetails(req, id_user=0): """show the details of a user. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) if id_user not in [0, '0']: output = userdetails(id_user=id_user) email_user = acca.acc_getUserEmail(id_user=id_user) extra = """
Connect role
connect a role to user %s.
Remove role
remove a role from user %s.
""" % (id_user, email_user, email_user, id_user, email_user) body = [output, extra] else: body = ['

no details to show

'] return index(req=req, title='Show User Details', subtitle='show user details', body=body, adminarea=5) def userdetails(id_user=0): """create the string to show details about a user. """ # find necessary details email_user = acca.acc_getUserEmail(id_user=id_user) userroles = acca.acc_getUserRoles(id_user=id_user) conn_roles = [] # find connected roles for (id, name, desc) in acca.acc_getAllRoles(): if (id, ) in userroles: conn_roles.append([id, name, desc]) conn_roles[-1].append('show details' % (id, )) if conn_roles: # print details details = '

roles connected to user %s

' % (email_user, ) details += tupletotable(header=['id', 'name', 'description', ''], tuple=conn_roles) else: details = '

no roles connected to user %s.

' % (email_user, ) return details def perform_addauthorization(req, id_role="0", id_action="0", optional=0, reverse="0", confirm=0, **keywords): """ form to add new connection between user and role: id_role - role to connect id_action - action to connect reverse - role or action first? """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # values that might get used name_role = acca.acc_getRoleName(id_role=id_role) or id_role name_action = acca.acc_getActionName(id_action=id_action) or id_action optional = optional == 'on' and 1 or int(optional) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" # create the page according to which step the user is on # role -> action -> arguments if reverse in ["0", 0]: adminarea = 3 subtitle = 'step 1 - select role' output = createroleselect(id_role=id_role, action="addauthorization", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if str(id_role) != "0": subtitle = 'step 2 - select action' rolacts = acca.acc_getRoleActions(id_role) allhelp = acca.acc_getAllActions() allacts = [] for r in allhelp: if r not in rolacts: allacts.append(r) output += createactionselect(id_action=id_action, action="addauthorization", step=2, actions=rolacts, extraactions=allacts, id_role=id_role, reverse=reverse) # action -> role -> arguments else: adminarea = 4 subtitle = 'step 1 - select action' output = createactionselect(id_action=id_action, action="addauthorization", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if str(id_action) != "0": subtitle = 'step 2 - select role' actroles = acca.acc_getActionRoles(id_action) allhelp = acca.acc_getAllRoles() allroles = [] for r in allhelp: if r not in actroles: allroles.append(r) output += createroleselect(id_role=id_role, action="addauthorization", step=2, roles=actroles, extraroles=allroles, id_action=id_action, reverse=reverse) # ready for step 3 no matter which direction we took to get here if id_action != "0" and id_role != "0": # links to adding authorizations in the other direction if str(reverse) == "0": extra += """
Add authorization
add authorizations to action %s.
""" % (id_action, name_action) else: extra += """
Add authorization
add authorizations to role %s.
""" % (id_role, name_role) subtitle = 'step 3 - enter values for the keywords\n' output += """
""" % (id_role, id_action, reverse) # the actions argument keywords res_keys = acca.acc_getActionKeywords(id_action=id_action) # res used to display existing authorizations # res used to determine if showing "create connection without arguments" res_auths = acca.acc_findPossibleActions(id_role, id_action) if not res_keys: # action without arguments if not res_auths: output += """ create connection between %s?
""" % (headerstrong(role=name_role, action=name_action, query=0), ) else: output += '

connection without arguments is already created.

' else: # action with arguments optionalargs = acca.acc_getActionIsOptional(id_action=id_action) output += '3. authorized arguments
' if optionalargs: # optional arguments output += """

connect %s to %s for any arguments
connect %s to %s for only these argument cases:

""" % (optional and 'checked="checked"' or '', name_role, name_action, not optional and 'checked="checked"' or '', name_role, name_action) # list the arguments allkeys = 1 for key in res_keys: output += '%s \n \n' output += '\n' # ask for confirmation if str(allkeys) != "0" or optional: keys = keywords.keys() keys.reverse() subtitle = 'step 4 - confirm add of authorization\n' text = """ create connection between
%s
""" % (headerstrong(role=name_role, action=name_action, query=0), ) if optional: text += 'withouth arguments' keywords = {} else: for key in keys: text += '%s: %s \n' % (key, keywords[key]) output += createhiddenform(action="addauthorization", text=text, id_role=id_role, id_action=id_action, reverse=reverse, confirm=1, optional=optional, **keywords) # show existing authorizations, found authorizations further up in the code... # res_auths = acca.acc_findPossibleActions(id_role, id_action) output += '

existing authorizations:

' if res_auths: output += tupletotable(header=res_auths[0], tuple=res_auths[1:]) # shortcut to modifying authorizations extra += """
Modify authorizations
modify the existing authorizations.
""" % (id_role, id_action, reverse) else: output += '

no details to show

' # user confirmed to add entries if confirm: subtitle = 'step 5 - confirm authorization added' res1 = acca.acc_addAuthorization(name_role=name_role, name_action=name_action, optional=optional, **keywords) if res1: res2 = acca.acc_findPossibleActions(id_role, id_action) arg = res1[0][3] # the arglistid new = [res2[0]] for row in res2[1:]: if int(row[0]) == int(arg): new.append(row) newauths = tupletotable(header=new[0], tuple=new[1:]) newentries = tupletotable(header=['role id', 'action id', 'argument id', '#'], tuple=res1) st = 'style="vertical-align: top"' output += """

new authorization and entries:

%s %s
""" % (st, newauths, st, newentries) else: output += '

sorry, authorization could not be added,
it probably already exists

' # trying to put extra link on the right side try: body = [output, extra] except NameError: body = [output] return index(req=req, title = 'Create entry for new authorization', subtitle=subtitle, body=body, adminarea=adminarea) def perform_deleteroleaction(req, id_role="0", id_action="0", reverse=0, confirm=0): """delete all connections between a role and an action. id_role - id of the role id_action - id of the action reverse - 0: ask for role first 1: ask for action first""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Remove action from role ' if reverse in ["0", 0]: # select role -> action adminarea = 3 subtitle = 'step 1 - select a role' output = createroleselect(id_role=id_role, action="deleteroleaction", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if id_role != "0": rolacts = acca.acc_getRoleActions(id_role=id_role) subtitle = 'step 2 - select the action' output += createactionselect(id_action=id_action, action="deleteroleaction", step=2, actions=rolacts, reverse=reverse, id_role=id_role, button="remove connection and all authorizations") else: # select action -> role adminarea = 4 subtitle = 'step 1 - select an action' output = createactionselect(id_action=id_action, action="deleteroleaction", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if id_action != "0": actroles = acca.acc_getActionRoles(id_action=id_action) subtitle = 'step 2 - select the role' output += createroleselect(id_role=id_role, action="deleteroleaction", step=2, roles=actroles, button="remove connection and all authorizations", id_action=id_action, reverse=reverse) if id_action != "0" and id_role != "0": subtitle = 'step 3 - confirm to remove authorizations' # ask for confirmation res = acca.acc_findPossibleActions(id_role, id_action) if res: output += '

authorizations that will be deleted:

' output += tupletotable(header=res[0], tuple=res[1:]) output += createhiddenform(action="deleteroleaction", text='remove %s from %s' % (headerstrong(action=id_action), headerstrong(role=id_role)), confirm=1, id_role=id_role, id_action=id_action, reverse=reverse) else: output += 'no authorizations' # confirmation is given if confirm: subtitle = 'step 4 - confirm authorizations removed ' res = acca.acc_deleteRoleAction(id_role=id_role, id_action=id_action) if res: output += '

confirm: removed %s from %s
' % (headerstrong(action=id_action), headerstrong(role=id_role)) output += '%s entries were removed.

' % (res, ) else: output += '

sorry, no entries could be removed.

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=adminarea) def perform_modifyauthorizations(req, id_role="0", id_action="0", reverse=0, confirm=0, errortext='', sel='', authids=[]): """given ids of a role and an action, show all possible action combinations with checkboxes and allow user to access other functions. id_role - id of the role id_action - id of the action reverse - 0: ask for role first 1: ask for action first sel - which button and modification that is selected errortext - text to print when no connection exist between role and action authids - ids of checked checkboxes """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_role = acca.acc_getRoleName(id_role) name_action = acca.acc_getActionName(id_action) output = '' try: id_role, id_action, reverse = int(id_role), int(id_action), int(reverse) except ValueError: pass extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" if id_role or id_action: extra += '\n
\n' if id_role and id_action: extra += """
Add authorizations
add an authorization to the existing ones.
""" % (id_role, id_action, reverse) if id_role: extra += """
Add authorizations
add to role %s.
""" % (id_role, name_role) if id_action: extra += """
Add authorizations
add to action %s.
""" % (id_action, name_action) extra += '\n
\n' if not reverse: # role -> action adminarea = 3 subtitle = 'step 1 - select the role' output += createroleselect(id_role=str(id_role), action="modifyauthorizations", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if id_role: rolacts = acca.acc_getRoleActions(id_role=id_role) subtitle = 'step 2 - select the action' output += createactionselect(id_action=str(id_action), action="modifyauthorizations", step=2, actions=rolacts, id_role=id_role, reverse=reverse) else: adminarea = 4 # action -> role subtitle = 'step 1 - select the action' output += createactionselect(id_action=str(id_action), action="modifyauthorizations", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if id_action: actroles = acca.acc_getActionRoles(id_action=id_action) subtitle = 'step 2 - select the role' output += createroleselect(id_role=str(id_role), action="modifyauthorizations", step=2, roles=actroles, id_action=id_action, reverse=reverse) if errortext: output += '

%s

' % (errortext, ) if id_role and id_action: # adding to main area if type(authids) is not list: authids = [authids] subtitle = 'step 3 - select groups and modification' # get info res = acca.acc_findPossibleActions(id_role, id_action) # clean the authids hiddenids = [] if sel in ['delete selected']: hiddenids = authids[:] elif sel in ['split groups', 'merge groups']: for authid in authids: arghlp = res[int(authid)][0] if authid not in hiddenids and arghlp not in [-1, '-1', 0, '0']: hiddenids.append(authid) authids = hiddenids[:] if confirm: # do selected modification and output with new authorizations if sel == 'split groups': res = splitgroups(id_role, id_action, authids) elif sel == 'merge groups': res = mergegroups(id_role, id_action, authids) elif sel == 'delete selected': res = deleteselected(id_role, id_action, authids) authids = [] res = acca.acc_findPossibleActions(id_role, id_action) output += 'authorizations after %s.
\n' % (sel, ) elif sel and authids: output += 'confirm choice of authorizations and modification.
\n' else: output += 'select authorizations and perform modification.
\n' if not res: errortext='all connections deleted, try different ' if reverse in ["0", 0]: return perform_modifyauthorizations(req=req, id_role=id_role, errortext=errortext + 'action.') else: return perform_modifyauthorizations(req=req, id_action=id_action, reverse=reverse, errortext=errortext + 'role.') # display output += modifyauthorizationsmenu(id_role, id_action, header=res[0], tuple=res[1:], checked=authids, reverse=reverse) if sel and authids: subtitle = 'step 4 - confirm to perform modification' # form with hidden authids output += '
\n' % ('modifyauthorizations', ) for hiddenid in hiddenids: output += '\n' % (hiddenid, ) # choose what to do if sel == 'split groups': output += '

split groups containing:

' elif sel == 'merge groups': output += '

merge groups containing:

' elif sel == 'delete selected': output += '

delete selected entries:

' extracolumn = '\n' extracolumn += '\n' # show the entries here... output += tupletotable_onlyselected(header=res[0], tuple=res[1:], selected=hiddenids, extracolumn=extracolumn) output += '\n' % (id_role, ) output += '\n' % (id_action, ) output += '\n' % (sel, ) output += '\n' % (reverse, ) output += '
' # tried to perform modification without something selected elif sel and not authids and not confirm: output += '

no valid groups selected

' # trying to put extra link on the right side try: body = [output, extra] except NameError: body = [output] # Display the page return index(req=req, title='Modify Authorizations', subtitle=subtitle, body=body, adminarea=adminarea) def modifyauthorizationsmenu(id_role, id_action, tuple=[], header=[], checked=[], reverse=0): """create table with header and checkboxes, used for multiple choice. makes use of tupletotable to add the actual table id_role - selected role, hidden value in the form id_action - selected action, hidden value in the form tuple - all rows to be put in the table (with checkboxes) header - column headers, empty strings added at start and end checked - ids of rows to be checked """ if not tuple: return 'no authorisations...' argnum = len(acca.acc_getActionKeywords(id_action=id_action)) tuple2 = [] for t in tuple: tuple2.append(t[:]) tuple2 = addcheckboxes(datalist=tuple2, name='authids', startindex=1, checked=checked) hidden = ' \n' % (id_role, ) hidden += ' \n' % (id_action, ) hidden += ' \n' % (reverse, ) button = '\n' if argnum > 1: button += '\n' button += '\n' hdrstr = '' for h in [''] + header + ['']: hdrstr += ' %s\n' % (h, ) if hdrstr: hdrstr = ' \n%s\n \n' % (hdrstr, ) output = '
\n' output += ' \n' output += hdrstr output += '\n' % (hidden, ) align = ['admintdleft'] * len(tuple2[0]) try: align[1] = 'admintdright' except IndexError: pass output += '' for i in range(len(tuple2[0])): output += '\n' % (align[i], tuple2[0][i]) output += '\n' % (len(tuple2), button) output += '\n' for row in tuple2[1:]: output += ' \n' for i in range(len(row)): output += '\n' % (align[i], row[i]) output += ' \n' output += '
%s
%s\n%s\n
%s
\n
\n' return output def splitgroups(id_role=0, id_action=0, authids=[]): """get all the old ones, gather up the arglistids find a list of arglistidgroups to be split, unique get all actions in groups outside of the old ones, (old arglistid is allowed). show them like in showselect. """ if not id_role or not id_action or not authids: return 0 # find all the actions datalist = acca.acc_findPossibleActions(id_role, id_action) if type(authids) is str: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) # argumentlistids of groups to be split splitgrps = [] for authid in authids: hlp = datalist[authid][0] if hlp not in splitgrps and authid in range(1,len(datalist)): splitgrps.append(hlp) # split groups and return success or failure result = 1 for splitgroup in splitgrps: result = 1 and acca.acc_splitArgumentGroup(id_role, id_action, splitgroup) return result def mergegroups(id_role=0, id_action=0, authids=[]): """get all the old ones, gather up the argauthids find a list of arglistidgroups to be split, unique get all actions in groups outside of the old ones, (old arglistid is allowed). show them like in showselect.""" if not id_role or not id_action or not authids: return 0 datalist = acca.acc_findPossibleActions(id_role, id_action) if type(authids) is str: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) # argumentlistids of groups to be merged mergegroups = [] for authid in authids: hlp = datalist[authid][0] if hlp not in mergegroups and authid in range(1, len(datalist)): mergegroups.append(hlp) # merge groups and return success or failure if acca.acc_mergeArgumentGroups(id_role, id_action, mergegroups): return 1 else: return 0 def deleteselected(id_role=0, id_action=0, authids=[]): """delete checked authorizations/possible actions, ids in authids. id_role - role to delete from id_action - action to delete from authids - listids for which possible actions to delete.""" if not id_role or not id_action or not authids: return 0 if type(authids) in [str, int]: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) result = acca.acc_deletePossibleActions(id_role=id_role, id_action=id_action, authids=authids) return result def headeritalic(**ids): """transform keyword=value pairs to string with value in italics. **ids - a dictionary of pairs to create string from """ output = '' value = '' table = '' for key in ids.keys(): if key in ['User', 'user']: value, table = 'email', 'user' elif key in ['Role', 'role']: value, table = 'name', 'accROLE' elif key in ['Action', 'action']: value, table = 'name', 'accACTION' else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) continue res = run_sql("""SELECT %s FROM %s WHERE id = %s""" % (value, table, ids[key])) if res: if output: output += ' and ' output += ' %s %s' % (key, res[0][0]) return output def headerstrong(query=1, **ids): """transform keyword=value pairs to string with value in strong text. **ids - a dictionary of pairs to create string from query - 1 -> try to find names to ids of role, user and action. 0 -> do not try to find names, use the value passed on """ output = '' value = '' table = '' for key in ids.keys(): if key in ['User', 'user']: value, table = 'email', 'user' elif key in ['Role', 'role']: value, table = 'name', 'accROLE' elif key in ['Action', 'action']: value, table = 'name', 'accACTION' else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) continue if query: res = run_sql("""SELECT %s FROM %s WHERE id = %s""" % (value, table, ids[key])) if res: if output: output += ' and ' output += ' %s %s' % (key, res[0][0]) else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) return output def startpage(): """create the menu for the startpage""" body = """
selection for WebAccess Admin
Role Area
main area to configure administration rights and authorization rules.
Action Area
configure administration rights with the actions as starting point.
User Area
configure administration rights with the users as starting point.
Reset Area
reset roles, actions and authorizations.
""" return body def rankarea(): return "Rankmethod area" def perform_simpleauthorization(req, id_role=0, id_action=0): """show a page with simple overview of authorizations between a connected role and action. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) res = acca.acc_findPossibleActions(id_role, id_action) if res: extra = createhiddenform(action='modifyauthorizations', button='modify authorizations', id_role=id_role, id_action=id_action) output = '

authorizations for %s:

' % (headerstrong(action=id_action, role=id_role), ) output += tupletotable(header=res[0], tuple=res[1:], extracolumn=extra) else: output = 'no details to show' return index(req=req, title='Simple authorization details', subtitle='simple authorization details', body=[output], adminarea=3) def perform_showroleusers(req, id_role=0): """show a page with simple overview of a role and connected users. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) res = acca.acc_getRoleUsers(id_role=id_role) name_role = acca.acc_getRoleName(id_role=id_role) if res: users = [] for (id, name, dontcare) in res: users.append([id, name, 'show user details' % (id, )]) output = '

users connected to %s:

' % (headerstrong(role=id_role), ) output += tupletotable(header=['id', 'name', ''], tuple=users) else: output = 'no users connected to role %s' % (name_role, ) extra = """
Connect user
connect users to the role.
""" % (id_role, ) return index(req=req, title='Users connected to role %s' % (name_role, ), subtitle='simple details', body=[output, extra], adminarea=3) def createselect(id_input="0", label="", step=0, name="", action="", list=[], extralist=[], extrastamp='', button="", **hidden): """create form with select and hidden values id - the one to choose as selected if exists label - label shown to the left of the select name - the name of the select on which to reference it list - primary list to select from extralist - list of options to be put in paranthesis extrastamp - stamp extralist entries with this if not '' usually paranthesis around the entry button - the value/text to be put on the button **hidden - name=value pairs to be put as hidden in the form. """ step = step and '%s. ' % step or '' output = '
\n' % (action, ) output += ' %s\n' % (step + label, ) output += ' \n' for key in hidden.keys(): output += ' \n' % (key, hidden[key]) output += ' \n' % (button, ) output += '
\n' return output def createactionselect(id_action="0", label="select action", step=0, name="id_action", action="", actions=[], extraactions=[], extrastamp='', button="select action", **hidden): """create a select for roles in a form. see createselect.""" return createselect(id_input=id_action, label=label, step=step, name=name, action=action, list=actions, extralist=extraactions, extrastamp=extrastamp, button=button, **hidden) def createroleselect(id_role="0", label="select role", step=0, name="id_role", action="", roles=[], extraroles=[], extrastamp='', button="select role", **hidden): """create a select for roles in a form. see createselect.""" return createselect(id_input=id_role, label=label, step=step, name=name, action=action, list=roles, extralist=extraroles, extrastamp=extrastamp, button=button, **hidden) def createuserselect(id_user="0", label="select user", step=0, name="id_user", action="", users=[], extrausers=[], extrastamp='(connected)', button="select user", **hidden): """create a select for users in a form.see createselect.""" return createselect(id_input=id_user, label=label, step=step, name=name, action=action, list=users, extralist=extrausers, extrastamp=extrastamp, button=button, **hidden) def cleanstring(str='', comma=0): """clean all the strings before submitting to access control admin. remove characters not letter, number or underscore, also remove leading underscores and numbers. return cleaned string. str - string to be cleaned comma - 1 -> allow the comma to divide multiple arguments 0 -> wash commas as well """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_,]', '', str) # split string on commas items = str.split(',') str = '' for item in items: if not item: continue if comma and str: str += ',' # create valid variable names str += re.sub(r'^([0-9_])*', '', item) return str def cleanstring_argumentvalue(str=''): """clean the value of an argument before submitting it. allowed characters: a-z A-Z 0-9 _ and space str - string to be cleaned """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_ .]', '', str) # trim leading and ending spaces str = re.sub(r'^ *| *$', '', str) return str def cleanstring_email(str=''): """clean the string and return a valid email address. str - string to be cleaned """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_.@-]', '', str) return str def check_email(str=''): """control that submitted emails are correct. this little check is not very good, but better than nothing. """ r = re.compile(r'(.)+\@(.)+\.(.)+') return r.match(str) and 1 or 0 diff --git a/modules/webaccess/lib/webaccessadmin_lib.py.wml b/modules/webaccess/lib/webaccessadmin_lib.py.wml index b18a04cda..f3d43f5ad 100644 --- a/modules/webaccess/lib/webaccessadmin_lib.py.wml +++ b/modules/webaccess/lib/webaccessadmin_lib.py.wml @@ -1,2677 +1,2677 @@ ## $Id$ ## Administrator interface for WebAccess ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware WebAccess Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: import access_control_engine as acce import access_control_admin as acca # reload(acce) # reload(acca) import cgi import re from bibrankadminlib import adderrorbox,addadminbox,tupletotable,tupletotable_onlyselected,addcheckboxes,createhiddenform from access_control_config import * from dbquery import run_sql from config import * from webpage import page, pageheaderonly, pagefooteronly from webuser import getUid, get_email from mod_python import apache __version__ = "$Id$" def index(req, title='', body='', subtitle='', adminarea=2, authorized=0): """main function to show pages for webaccessadmin. 1. if user not logged in and administrator, show the mustlogin page 2. if used without body argument, show the startpage 3. show admin page with title, body, subtitle and navtrail. adminarea - number codes that tell what extra info to put in the navtrail 0 - nothing extra 1 - add Delegate Rights 2 - add Manage WebAccess maybe add: 3: role admin 4: action admin 5: user area 6: reset area authorized - if 1, don't check if the user is allowed to be webadmin """ navtrail_previous_links = """Admin Area > WebAccess Admin """ % (weburl, weburl) if body: if adminarea == 1: navtrail_previous_links += '> Delegate Rights ' % (weburl, ) if adminarea >= 2: navtrail_previous_links += '> Manage WebAccess ' % (weburl, ) if adminarea == 3: navtrail_previous_links += '> Role Administration ' % (weburl, ) elif adminarea == 4: navtrail_previous_links += '> Action Administration ' % (weburl, ) elif adminarea == 5: navtrail_previous_links += '> User Administration ' % (weburl, ) elif adminarea == 6: navtrail_previous_links += '> Reset Authorizations ' % (weburl, ) id_user = getUid(req) (auth_code, auth_message) = is_adminuser(req) if not authorized and auth_code != 0: return mustloginpage(req, auth_message) elif not body: title = 'Manage WebAccess' body = startpage() elif type(body) != str: body = addadminbox(subtitle, datalist=body) return page(title=title, uid=id_user, body=body, navtrail=navtrail_previous_links, lastupdated=__lastupdated__) def mustloginpage(req, message): """show a page asking the user to login.""" navtrail_previous_links = """Admin Area > WebAccess Admin """ % (weburl, weburl) return page(title='Authorization failure', uid=getUid(req), - body=adderrorbox('Not logged in', + body=adderrorbox('Reason:', datalist=[message]), navtrail=navtrail_previous_links, lastupdated=__lastupdated__) def is_adminuser(req): """check if user is a registered administrator. """ id_user = getUid(req) return acce.acc_authorize_action(id_user, WEBACCESSACTION) def perform_rolearea(req): """create the role area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) header = ['id', 'name', 'description', 'users', 'authorizations / actions', 'role', ''] roles = acca.acc_getAllRoles() roles2 = [] for (id, name, desc) in roles: if len(desc) > 30: desc = desc[:30] + '...' roles2.append([id, name, desc]) for col in [(('add', 'adduserrole'), ('remove', 'deleteuserrole')), (('add', 'addauthorization'), ('modify', 'modifyauthorizations'), ('remove', 'deleteroleaction')), (('delete', 'deleterole'), ), (('show details', 'showroledetails'), )]: roles2[-1].append('%s' % (col[0][1], id, col[0][0])) for (str, function) in col[1:]: roles2[-1][-1] += ' / %s' % (function, id, str) output = """
Users:
add or remove users from the access to a role and its priviliges.
Authorizations/Actions:
these terms means almost the same, but an authorization is a
connection between a role and an action (possibly) containing arguments.
Roles:
see all the information attached to a role and decide if you want to
delete it.
""" output += tupletotable(header=header, tuple=roles2) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" return index(req=req, title='Role Administration', subtitle='administration with roles as access point', body=[output, extra], adminarea=2) def perform_actionarea(req): """create the action area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) header = ['id', 'name', 'authorizations/roles', 'action', ''] actions = acca.acc_getAllActions() actions2 = [] roles2 = [] for (id, name, dontcare) in actions: actions2.append([id, name]) for col in [(('add', 'addauthorization'), ('modify', 'modifyauthorizations'), ('remove', 'deleteroleaction')), (('delete', 'deleteaction'), ), (('show details', 'showactiondetails'), )]: actions2[-1].append('%s' % (col[0][1], id, col[0][0])) for (str, function) in col[1:]: actions2[-1][-1] += ' / %s' % (function, id, str) output = """
Authorizations/Roles:
these terms means almost the same, but an authorization is a
connection between a role and an action (possibly) containing arguments.
Actions:
see all the information attached to an action and decide if you want to
delete it.
""" output += tupletotable(header=header, tuple=actions2) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" return index(req=req, title='Action Administration', subtitle='administration with actions as access point', body=[output, extra], adminarea=2) def perform_userarea(req, email_user_pattern=''): """create area to show info about users. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) subtitle = 'step 1 - search for users' output = """

search for users to display.

""" # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 1. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="userarea", text=text, button="search for users") if email_user_pattern: users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email LIMIT %s""" % (email_user_pattern, MAXPAGEUSERS+1)) if not users1: output += '

no matching users

' else: subtitle = 'step 2 - select what to do with user' users = [] for (id, email) in users1[:MAXPAGEUSERS]: users.append([id, email]) for col in [(('add', 'addroleuser'), ('remove', 'deleteuserrole')), (('show details', 'showuserdetails'), )]: users[-1].append('%s' % (col[0][1], email_user_pattern, id, col[0][0])) for (str, function) in col[1:]: users[-1][-1] += ' / %s' % (function, email_user_pattern, id, str) output += '

found %s matching users:

' % (len(users1), ) output += tupletotable(header=['id', 'email', 'roles', ''], tuple=users) if len(users1) > MAXPAGEUSERS: output += '

only showing the first %s users, narrow your search...

' % (MAXPAGEUSERS, ) return index(req=req, title='User Administration', subtitle=subtitle, body=[output], adminarea=2) def perform_resetarea(req): """create the reset area menu page.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = """
Reset to Default Authorizations
remove all changes that has been done to the roles and
add only the default authorization settings.
Add Default Authorizations
keep all changes and add the default authorization settings.
""" return index(req=req, title='Reset Authorizations', subtitle='reseting to or adding default authorizations', body=[output], adminarea=2) def perform_resetdefaultsettings(req, superusers=[], confirm=0): """delete all roles, actions and authorizations presently in the database and add only the default roles. only selected users will be added to superadmin, rest is blank """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # cleaning input if type(superusers) == str: superusers = [superusers] # remove not valid e-mails for email in superusers: if not check_email(email): superusers.remove(email) # instructions output = """

before you reset the settings, we need some users
to connect to %s.
enter as many e-mail adresses you want and press reset.
confirm reset settings when you have added enough e-mails.
is added as default.

""" % (SUPERADMINROLE, ) # add more superusers output += """

enter user e-mail addresses:

""" for email in superusers: output += ' ' % (email, ) output += """ e-mail
""" if superusers: # remove emails output += """
have you entered wrong data?
""" # superusers confirm table start = '
' extra = ' ' for email in superusers: extra += '' % (email, ) extra += ' ' end = '
' output += '

reset default settings with the users below?

' output += tupletotable(header=['e-mail address'], tuple=superusers, start=start, extracolumn=extra, end=end) if confirm in [1, "1"]: res = acca.acc_reset_default_settings(superusers) if res: output += '

successfully reset default settings

' else: output += '

sorry, could not reset default settings

' return index(req=req, title='Reset Default Settings', subtitle='reset settings', body=[output], adminarea=6) def perform_adddefaultsettings(req, superusers=[], confirm=0): """add the default settings, and keep everything else. probably nothing will be deleted, except if there has been made changes to the defaults.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # cleaning input if type(superusers) == str: superusers = [superusers] # remove not valid e-mails for email in superusers: if not check_email(email): superusers.remove(email) # instructions output = """

before you add the settings, we need some users
to connect to %s.
enter as many e-mail adresses you want and press add.
confirm add settings when you have added enough e-mails.
is added as default.

""" % (SUPERADMINROLE, ) # add more superusers output += """

enter user e-mail addresses:

""" for email in superusers: output += ' ' % (email, ) output += """ e-mail
""" if superusers: # remove emails output += """
have you entered wrong data?
""" # superusers confirm table start = '
' extra = ' ' for email in superusers: extra += '' % (email, ) extra += ' ' end = '
' output += '

add default settings with the users below?

' output += tupletotable(header=['e-mail address'], tuple=superusers, start=start, extracolumn=extra, end=end) if confirm in [1, "1"]: res = acca.acc_add_default_settings(superusers) if res: output += '

successfully added default settings

' else: output += '

sorry, could not add default settings

' return index(req=req, title='Add Default Settings', subtitle='add settings', body=[output], adminarea=6) def perform_delegate_startarea(req): """start area for lower level delegation of rights.""" subtitle = 'select what to do' output = '' if is_adminuser(req)[0] == 0: output += """

You are also allowed to be in the Main Admin Area which gives you
the access to the full functionality of WebAccess.

""" output += """
Connect users to roles
add users to the roles you have delegation rights to.
Remove users from roles
remove users from the roles you have delegation rights to.
Set up delegation rights
spesialized area to set up the delegation rights used in the areas above.
you need to be a web administrator to access the area.
""" return index(req=req, title='Delegate Rights', subtitle=subtitle, body=[output], adminarea=0, authorized=1) def perform_delegate_adminsetup(req, id_role_admin=0, id_role_delegate=0, confirm=0): """lets the webadmins set up the delegation rights for the other roles id_role_admin - the role to be given delegation rights id_role_delegate - the role over which the delegation rights are given confirm - make the connection happen """ subtitle = 'step 1 - select admin role' admin_roles = acca.acc_getAllRoles() output = """

This is a specialized area to handle a task that also can be handled
from the "add authorization" interface.

By handling the delegation rights here you get the advantage of
not having to select the correct action (%s) or
remembering the names of available roles.

""" % (DELEGATEADDUSERROLE, ) output += createroleselect(id_role=id_role_admin, step=1, button='select admin role', name='id_role_admin', action='delegate_adminsetup', roles=admin_roles) if str(id_role_admin) != '0': subtitle = 'step 2 - select delegate role' name_role_admin = acca.acc_getRoleName(id_role=id_role_admin) delegate_roles_old = acca.acc_find_delegated_roles(id_role_admin=id_role_admin) delegate_roles = [] delegate_roles_old_names = [] for role in admin_roles: if (role,) not in delegate_roles_old: delegate_roles.append(role) else: delegate_roles_old_names.append(role[1]) if delegate_roles_old_names: delegate_roles_old_names.sort() names_str = '' for name in delegate_roles_old_names: if names_str: names_str += ', ' names_str += name output += '

previously selected roles: %s.

' % (names_str, ) extra = """
Remove delegated roles
use the standard administration area to remove delegation rights you no longer want to be available.
""" % (id_role_admin, acca.acc_getActionId(name_action=DELEGATEADDUSERROLE)) else: output += '

no previously selected roles.

' output += createroleselect(id_role=id_role_delegate, step=2, button='select delegate role', name='id_role_delegate', action='delegate_adminsetup', roles=delegate_roles, id_role_admin=id_role_admin) if str(id_role_delegate) != '0': subtitle = 'step 3 - confirm to add delegation right' name_role_delegate = acca.acc_getRoleName(id_role=id_role_delegate) output += """

Warning: don't hand out delegation rights that can harm the system (e.g. delegating superrole).

""" output += createhiddenform(action="delegate_adminsetup", text='let role %s delegate rights over role %s?' % (name_role_admin, name_role_delegate), id_role_admin=id_role_admin, id_role_delegate=id_role_delegate, confirm=1) if int(confirm): subtitle = 'step 4 - confirm delegation right added' # res1 = acca.acc_addRoleActionArguments_names(name_role=name_role_admin, # name_action=DELEGATEADDUSERROLE, # arglistid=-1, # optional=0, # role=name_role_delegate) res1 = acca.acc_addAuthorization(name_role=name_role_admin, name_action=DELEGATEADDUSERROLE, optional=0, role=name_role_delegate) if res1: output += '

confirm: role %s delegates role %s.' % (name_role_admin, name_role_delegate) else: output += '

sorry, delegation right could not be added,
it probably already exists.

' # see if right hand menu is available try: body = [output, extra] except NameError: body = [output] return index(req=req, title='Delegate Rights', subtitle=subtitle, body=body, adminarea=1) def perform_delegate_adduserrole(req, id_role=0, email_user_pattern='', id_user=0, confirm=0): """let a lower level web admin add users to a limited set of roles. id_role - the role to connect to a user id_user - the user to connect to a role confirm - make the connection happen """ # finding the allowed roles for this user id_admin = getUid(req) id_action = acca.acc_getActionId(name_action=DELEGATEADDUSERROLE) actions = acca.acc_findPossibleActionsUser(id_user=id_admin, id_action=id_action) allowed_roles = [] allowed_id_roles = [] for (id, arglistid, name_role_help) in actions[1:]: id_role_help = acca.acc_getRoleId(name_role=name_role_help) if id_role_help and [id_role_help, name_role_help, ''] not in allowed_roles: allowed_roles.append([id_role_help, name_role_help, '']) allowed_id_roles.append(str(id_role_help)) output = '' if not allowed_roles: subtitle = 'no delegation rights' output += """

You do not have the delegation rights over any roles.
If you think you should have such rights, contact a WebAccess Administrator.

""" extra = '' else: subtitle = 'step 1 - select role' output += """

Lower level delegation of access rights to roles.
An administrator with all rights have to give you these rights.

""" email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) output += createroleselect(id_role=id_role, step=1, name='id_role', action='delegate_adduserrole', roles=allowed_roles) if str(id_role) != '0' and str(id_role) in allowed_id_roles: subtitle = 'step 2 - search for users' # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 2. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="delegate_adduserrole", text=text, button="search for users", id_role=id_role) # pattern is entered if email_user_pattern: # users with matching email-address users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) # users that are connected users2 = run_sql("""SELECT DISTINCT u.id, u.email FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE = '%s' AND u.email RLIKE '%s' ORDER BY u.email """ % (id_role, email_user_pattern)) # no users that match the pattern if not (users1 or users2): output += '

no qualified users, try new search.

' # too many matching users elif len(users1) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users1), MAXSELECTUSERS) # show matching users else: subtitle = 'step 3 - select a user' users = [] extrausers = [] for (id, email) in users1: if (id, email) not in users2: users.append([id,email,'']) for (id, email) in users2: extrausers.append([-id, email,'']) output += createuserselect(id_user=id_user, action="delegate_adduserrole", step=3, users=users, extrausers=extrausers, button="add this user", id_role=id_role, email_user_pattern=email_user_pattern) try: id_user = int(id_user) except ValueError: pass # user selected already connected to role if id_user < 0: output += '

users in brackets are already attached to the role, try another one...

' # a user is selected elif email_out: subtitle = "step 4 - confirm to add user" output += createhiddenform(action="delegate_adduserrole", text='add user %s to role %s?' % (email_out, name_role), id_role=id_role, email_user_pattern=email_user_pattern, id_user=id_user, confirm=1) # it is confirmed that this user should be added if confirm: # add user result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm user added' output += '

confirm: user %s added to role %s.

' % (email_out, name_role) else: subtitle = 'step 5 - user could not be added' output += '

sorry, but user could not be added.

' extra = """
Remove users from role
remove users from the roles you have delegating rights to.
""" % (id_role, ) return index(req=req, title='Connect users to roles', subtitle=subtitle, body=[output, extra], adminarea=1, authorized=1) def perform_delegate_deleteuserrole(req, id_role=0, id_user=0, confirm=0): """let a lower level web admin remove users from a limited set of roles. id_role - the role to connect to a user id_user - the user to connect to a role confirm - make the connection happen """ subtitle = 'in progress...' output = '

in progress...

' # finding the allowed roles for this user id_admin = getUid(req) id_action = acca.acc_getActionId(name_action=DELEGATEADDUSERROLE) actions = acca.acc_findPossibleActionsUser(id_user=id_admin, id_action=id_action) output = '' if not actions: subtitle = 'no delegation rights' output += """

You do not have the delegation rights over any roles.
If you think you should have such rights, contact a WebAccess Administrator.

""" extra = '' else: subtitle = 'step 1 - select role' output += """

Lower level delegation of access rights to roles.
An administrator with all rights have to give you these rights.

""" email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) # create list of allowed roles allowed_roles = [] allowed_id_roles = [] for (id, arglistid, name_role_help) in actions[1:]: id_role_help = acca.acc_getRoleId(name_role=name_role_help) if id_role_help and [id_role_help, name_role_help, ''] not in allowed_roles: allowed_roles.append([id_role_help, name_role_help, '']) allowed_id_roles.append(str(id_role_help)) output += createroleselect(id_role=id_role, step=1, action='delegate_deleteuserrole', roles=allowed_roles) if str(id_role) != '0' and str(id_role) in allowed_id_roles: subtitle = 'step 2 - select user' users = acca.acc_getRoleUsers(id_role) output += createuserselect(id_user=id_user, step=2, action='delegate_deleteuserrole', users=users, id_role=id_role) if str(id_user) != '0': subtitle = 'step 3 - confirm delete of user' email_user = acca.acc_getUserEmail(id_user=id_user) output += createhiddenform(action="delegate_deleteuserrole", text='delete user %s from %s?' % (headerstrong(user=id_user), headerstrong(role=id_role)), id_role=id_role, id_user=id_user, confirm=1) if confirm: res = acca.acc_deleteUserRole(id_user=id_user, id_role=id_role) if res: subtitle = 'step 4 - confirm user deleted from role' output += '

confirm: deleted user %s from role %s.

' % (email_user, name_role) else: subtitle = 'step 4 - user could not be deleted' output += 'sorry, but user could not be deleted
user is probably already deleted.' extra = """
Connect users to role
add users to the roles you have delegating rights to.
""" % (id_role, ) return index(req=req, title='Remove users from roles', subtitle=subtitle, body=[output, extra], adminarea=1, authorized=1) def perform_addaction(req, name_action='', arguments='', optional='no', description='put description here.', confirm=0): """form to add a new action with these values: name_action - name of the new action arguments - allowedkeywords, separated by whitespace description - optional description of the action""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_action = cleanstring(name_action) arguments = cleanstring(arguments, comma=1) title = 'Add Action' subtitle = 'step 1 - give values to the requested fields' output = """
action name
arguments keywords for arguments, separate with comma, no whitespace.
optional arguments
description
""" % (name_action, arguments, optional == 'yes' and 'selected="selected"' or '', description) if name_action: # description must be changed before it is submitted if description == 'put description here.': internaldesc = '' else: internaldesc = description if arguments: subtitle = 'step 2 - confirm to add action with %s arguments' % (optional == 'yes' and 'optional' or '', ) arguments = arguments.replace(' ', '') text = 'add action with:
\n' text += 'name: %s
\n' % (name_action, ) if internaldesc: text += 'description: %s
\n' % (description, ) text += '%sarguments: %s
' % (optional == 'yes' and 'optional ' or '', arguments) text += 'optional: %s?' % (optional, ) else: optional = 'no' subtitle = 'step 2 - confirm to add action without arguments' text = 'add action %s without arguments' % (name_action, ) if internaldesc: text += '
\nand description: %s?\n' % (description, ) else: text += '?\n' output += createhiddenform(action="addaction", text=text, name_action=name_action, arguments=arguments, optional=optional, description=description, confirm=1) if confirm not in ["0", 0]: arguments = arguments.split(',') result = acca.acc_addAction(name_action, internaldesc, optional, *arguments) if result: subtitle = 'step 3 - action added' output += '

action added:

' output += tupletotable(header=['id', 'action name', 'description', 'allowedkeywords', 'optional'], tuple=[result]) else: subtitle = 'step 3 - action could not be added' output += '

sorry, could not add action,
action with the same name probably exists.

' extra = """
Add authorization
start adding new authorizations to action %s.
""" % (acca.acc_getActionId(name_action=name_action), name_action) try: body = [output, extra] except NameError: body = [output] return index(req=req, title=title, body=body, subtitle=subtitle, adminarea=4) def perform_deleteaction(req, id_action="0", confirm=0): """show all roles connected, and ask for confirmation. id_action - id of action to delete """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title='Delete action' subtitle='step 1 - select action to delete' name_action = acca.acc_getActionName(id_action=id_action) output = createactionselect(id_action=id_action, action="deleteaction", step=1, actions=acca.acc_getAllActions(), button="delete action") if id_action != "0" and name_action: subtitle = 'step 2 - confirm the delete' output += actiondetails(id_action=id_action) if acca.acc_getActionRoles(id_action=id_action): output += createhiddenform(action="deleteroleaction", text="""rather delete only connection between action %s and a selected role?""" % (name_action, ), id_action=id_action, reverse=1, button='go there') output += createhiddenform(action="deleteaction", text=' delete action %s and all connections?' % (name_action, ), confirm=1, id_action=id_action) if confirm: subtitle = 'step 3 - confirm delete of action' res = acca.acc_deleteAction(id_action=id_action) if res: output += '

confirm: action %s deleted.
\n' % (name_action, ) output += '%s entries deleted all in all.

\n' % (res, ) else: output += '

sorry, action could not be deleted.

\n' elif id_action != "0": output += '

the action has been deleted...

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=4) def perform_showactiondetails(req, id_action): """show the details of an action. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = createactionselect(id_action=id_action, action="showactiondetails", step=1, actions=acca.acc_getAllActions(), button="select action") if id_action not in [0, '0']: output += actiondetails(id_action=id_action) extra = """
Add new authorization
add an authorization.
Modify authorizations
modify existing authorizations.
Remove role
remove all authorizations from action and a role.
""" % (id_action, id_action, id_action) body = [output, extra] else: output += '

no details to show

' body = [output] return index(req=req, title='Show Action Details', subtitle='show action details', body=body, adminarea=4) def actiondetails(id_action=0): """show details of given action. """ output = '' if id_action not in [0, '0']: name_action = acca.acc_getActionName(id_action=id_action) output += '

action details:

' output += tupletotable(header=['id', 'name', 'description', 'allowedkeywords', 'optional'], tuple=[acca.acc_getActionDetails(id_action=id_action)]) roleshlp = acca.acc_getActionRoles(id_action=id_action) if roleshlp: roles = [] for (id, name, dontcare) in roleshlp: roles.append([id, name, 'show authorization details' % (id, id_action), 'show connected users' % (id, )]) roletable = tupletotable(header=['id', 'name', '', ''], tuple=roles) output += '

roles connected to %s:

\n' % (headerstrong(action=name_action, query=0), ) output += roletable else: output += '

no roles connected to %s.

\n' % (headerstrong(action=name_action, query=0), ) else: output += '

no details to show

' return output def perform_addrole(req, name_role='', description='put description here.', confirm=0): """form to add a new role with these values: name_role - name of the new role description - optional description of the role """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_role = cleanstring(name_role) title='Add Role' subtitle = 'step 1 - give values to the requested fields' output = """
role name
description
""" % (name_role, description) if name_role: # description must be changed before submitting subtitle = 'step 2 - confirm to add role' internaldesc = '' if description != 'put description here.': internaldesc = description text = """ add role with:
\n name: %s
""" % (name_role, ) if internaldesc: text += 'description: %s?\n' % (description, ) output += createhiddenform(action="addrole", text=text, name_role=name_role, description=description, confirm=1) if confirm not in ["0", 0]: result = acca.acc_addRole(name_role=name_role, description=internaldesc) if result: subtitle = 'step 3 - role added' output += '

role added:

' output += tupletotable(header=['id', 'action name', 'description', 'allowedkeywords'], tuple=[result]) else: subtitle = 'step 3 - role could not be added' output += '

sorry, could not add role,
role with the same name probably exists.

' id_role = acca.acc_getRoleId(name_role=name_role) extra = """
Add authorization
start adding new authorizations to role %s.
Connect user
connect a user to role %s.
""" % (id_role, name_role, id_role, name_role) try: body = [output, extra] except NameError: body = [output] return index(req=req, title=title, body=body, subtitle=subtitle, adminarea=3) def perform_deleterole(req, id_role="0", confirm=0): """select a role and show all connected information, users - users that can access the role. actions - actions with possible authorizations.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Delete role' subtitle = 'step 1 - select role to delete' name_role = acca.acc_getRoleName(id_role=id_role) output = createroleselect(id_role=id_role, action="deleterole", step=1, roles=acca.acc_getAllRoles(), button="delete role") if id_role != "0" and name_role: subtitle = 'step 2 - confirm delete of role' output += roledetails(id_role=id_role) output += createhiddenform(action="deleterole", text='delete role %s and all connections?' % (name_role, ), id_role=id_role, confirm=1) if confirm: res = acca.acc_deleteRole(id_role=id_role) subtitle = 'step 3 - confirm role deleted' if res: output += "

confirm: role %s deleted.
" % (name_role, ) output += "%s entries were removed.

" % (res, ) else: output += "

sorry, the role could not be deleted.

" elif id_role != "0": output += '

the role has been deleted...

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=3) def perform_showroledetails(req, id_role): """show the details of a role.""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) output = createroleselect(id_role=id_role, action="showroledetails", step=1, roles=acca.acc_getAllRoles(), button="select role") if id_role not in [0, '0']: name_role = acca.acc_getRoleName(id_role=id_role) output += roledetails(id_role=id_role) extra = """
Add new authorization
add an authorization.
Modify authorizations
modify existing authorizations.
Connect user
connect a user to role %s.
Remove user
remove a user from role %s.
""" % (id_role, id_role, id_role, name_role, id_role, name_role) body = [output, extra] else: output += '

no details to show

' body = [output] return index(req=req, title='Show Role Details', subtitle='show role details', body=body, adminarea=3) def roledetails(id_role=0): """create the string to show details about a role. """ name_role = acca.acc_getRoleName(id_role=id_role) usershlp = acca.acc_getRoleUsers(id_role) users = [] for (id, email, dontcare) in usershlp: users.append([id, email, 'show user details' % (id, )]) usertable = tupletotable(header=['id', 'email'], tuple=users) actionshlp = acca.acc_getRoleActions(id_role) actions = [] for (id, name, dontcare) in actionshlp: actions.append([id, name, 'show action details' % (id_role, id), 'show authorization details' % (id_role, id)]) actiontable = tupletotable(header=['id', 'name', '', ''], tuple=actions) # show role details details = '

role details:

' details += tupletotable(header=['id', 'name', 'description'], tuple=[acca.acc_getRoleDetails(id_role=id_role)]) # show connected users details += '

users connected to %s:

' % (headerstrong(role=name_role, query=0), ) if users: details += usertable else: details += '

no users connected.

' # show connected authorizations details += '

authorizations for %s:

' % (headerstrong(role=name_role, query=0), ) if actions: details += actiontable else: details += '

no authorizations connected

' return details def perform_adduserrole(req, id_role='0', email_user_pattern='', id_user='0', confirm=0): """create connection between user and role. id_role - id of the role to add user to email_user_pattern - search for users using this pattern id_user - id of user to add to the role. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) title = 'Connect user to role ' subtitle = 'step 1 - select a role' output = createroleselect(id_role=id_role, action="adduserrole", step=1, roles=acca.acc_getAllRoles()) # role is selected if id_role != "0": title += name_role subtitle = 'step 2 - search for users' # remove letters not allowed in an email email_user_pattern = cleanstring_email(email_user_pattern) text = ' 2. search pattern \n' text += ' \n' % (email_user_pattern, ) output += createhiddenform(action="adduserrole", text=text, button="search for users", id_role=id_role) # pattern is entered if email_user_pattern: # users with matching email-address users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) # users that are connected users2 = run_sql("""SELECT DISTINCT u.id, u.email FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE = '%s' AND u.email RLIKE '%s' ORDER BY u.email """ % (id_role, email_user_pattern)) # no users that match the pattern if not (users1 or users2): output += '

no qualified users, try new search.

' elif len(users1) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users1), MAXSELECTUSERS) # show matching users else: subtitle = 'step 3 - select a user' users = [] extrausers = [] for (id, email) in users1: if (id, email) not in users2: users.append([id,email,'']) for (id, email) in users2: extrausers.append([-id, email,'']) output += createuserselect(id_user=id_user, action="adduserrole", step=3, users=users, extrausers=extrausers, button="add this user", id_role=id_role, email_user_pattern=email_user_pattern) try: id_user = int(id_user) except ValueError: pass # user selected already connected to role if id_user < 0: output += '

users in brackets are already attached to the role, try another one...

' # a user is selected elif email_out: subtitle = "step 4 - confirm to add user" output += createhiddenform(action="adduserrole", text='add user %s to role %s?' % (email_out, name_role), id_role=id_role, email_user_pattern=email_user_pattern, id_user=id_user, confirm=1) # it is confirmed that this user should be added if confirm: # add user result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm user added' output += '

confirm: user %s added to role %s.

' % (email_out, name_role) else: subtitle = 'step 5 - user could not be added' output += '

sorry, but user could not be added.

' extra = """
Create new role
go here to add a new role.
""" if str(id_role) != "0": extra += """
Remove users
remove users from role %s.
Connected users
show all users connected to role %s.
Add authorization
start adding new authorizations to role %s.
""" % (id_role, name_role, id_role, name_role, id_role, name_role) return index(req=req, title=title, subtitle=subtitle, body=[output, extra], adminarea=3) def perform_addroleuser(req, email_user_pattern='', id_user='0', id_role='0', confirm=0): """delete connection between role and user. id_role - id of role to disconnect id_user - id of user to disconnect. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) email_out = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) # used to sort roles, and also to determine right side links con_roles = [] not_roles = [] title = 'Connect user to roles' subtitle = 'step 1 - search for users' # clean email search string email_user_pattern = cleanstring_email(email_user_pattern) text = ' 1. search pattern \n' text += ' \n' % (email_user_pattern, ) output = createhiddenform(action='addroleuser', text=text, button='search for users', id_role=id_role) if email_user_pattern: subtitle = 'step 2 - select user' users1 = run_sql("""SELECT id, email FROM user WHERE email RLIKE '%s' ORDER BY email """ % (email_user_pattern, )) users = [] for (id, email) in users1: users.append([id, email, '']) # no users if not users: output += '

no qualified users, try new search.

' # too many users elif len(users) > MAXSELECTUSERS: output += '

%s hits, too many qualified users, specify more narrow search. (limit %s)

' % (len(users), MAXSELECTUSERS) # ok number of users else: output += createuserselect(id_user=id_user, action='addroleuser', step=2, users=users, button='select user', email_user_pattern=email_user_pattern) if int(id_user): subtitle = 'step 3 - select role' # roles the user is connected to role_ids = acca.acc_getUserRoles(id_user=id_user) # all the roles, lists are sorted on the background of these... all_roles = acca.acc_getAllRoles() # sort the roles in connected and not connected roles for (id, name, description) in all_roles: if (id, ) in role_ids: con_roles.append([-id, name, description]) else: not_roles.append([id, name, description]) # create roleselect output += createroleselect(id_role=id_role, action='addroleuser', step=3, roles=not_roles, extraroles=con_roles, extrastamp='(connected)', button='add this role', email_user_pattern=email_user_pattern, id_user=id_user) if int(id_role) < 0: name_role = acca.acc_getRoleName(id_role=-int(id_role)) output += '

role %s already connected to the user, try another one...

' % (name_role, ) elif int(id_role): subtitle = 'step 4 - confirm to add role to user' output += createhiddenform(action='addroleuser', text='add role %s to user %s?' % (name_role, email_out), email_user_pattern=email_user_pattern, id_user=id_user, id_role=id_role, confirm=1) if confirm: # add role result = acca.acc_addUserRole(id_user=id_user, id_role=id_role) if result and result[2]: subtitle = 'step 5 - confirm role added' output += '

confirm: role %s added to user %s.

' % (name_role, email_out) else: subtitle = 'step 5 - role could not be added' output += '

sorry, but role could not be added

' extra = """
Create new role
go here to add a new role.
""" if int(id_user) and con_roles: extra += """
Remove roles
disconnect roles from user %s.
""" % (id_user, email_out) if int(id_role): if int(id_role) < 0: id_role = -int(id_role) extra += """
Remove users
disconnect users from role %s.
""" % (id_role, name_role) return index(req=req, title=title, subtitle=subtitle, body=[output, extra], adminarea=5) def perform_deleteuserrole(req, id_role='0', id_user='0', reverse=0, confirm=0): """delete connection between role and user. id_role - id of role to disconnect id_user - id of user to disconnect. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Remove user from role' email_user = acca.acc_getUserEmail(id_user=id_user) name_role = acca.acc_getRoleName(id_role=id_role) output = '' if reverse in [0, '0']: adminarea = 3 subtitle = 'step 1 - select the role' output += createroleselect(id_role=id_role, action="deleteuserrole", step=1, roles=acca.acc_getAllRoles()) if id_role != "0": subtitle = 'step 2 - select the user' output += createuserselect(id_user=id_user, action="deleteuserrole", step=2, users=acca.acc_getRoleUsers(id_role=id_role), id_role=id_role) else: adminarea = 5 # show only if user is connected to a role, get users connected to roles users = run_sql("""SELECT DISTINCT(u.id), u.email, u.note FROM user u LEFT JOIN user_accROLE ur ON u.id = ur.id_user WHERE ur.id_accROLE != 'NULL' AND u.email != '' ORDER BY u.email """) has_roles = 1 # check if the user is connected to any roles for (id, email, note) in users: if str(id) == str(id_user): break # user not connected to a role else: subtitle = 'step 1 - user not connected' output += '

no need to remove roles from user %s,
user is not connected to any roles.

' % (email_user, ) has_roles, id_user = 0, '0' # stop the rest of the output below... # user connected to roles if has_roles: output += createuserselect(id_user=id_user, action="deleteuserrole", step=1, users=users, reverse=reverse) if id_user != "0": subtitle = 'step 2 - select the role' role_ids = acca.acc_getUserRoles(id_user=id_user) all_roles = acca.acc_getAllRoles() roles = [] for (id, name, desc) in all_roles: if (id, ) in role_ids: roles.append([id, name, desc]) output += createroleselect(id_role=id_role, action="deleteuserrole", step=2, roles=roles, id_user=id_user, reverse=reverse) if id_role != '0' and id_user != '0': subtitle = 'step 3 - confirm delete of user' output += createhiddenform(action="deleteuserrole", text='delete user %s from %s?' % (headerstrong(user=id_user), headerstrong(role=id_role)), id_role=id_role, id_user=id_user, reverse=reverse, confirm=1) if confirm: res = acca.acc_deleteUserRole(id_user=id_user, id_role=id_role) if res: subtitle = 'step 4 - confirm delete of user' output += '

confirm: deleted user %s from role %s.

' % (email_user, name_role) else: subtitle = 'step 4 - user could not be deleted' output += 'sorry, but user could not be deleted
user is probably already deleted.' extra = '' if str(id_role) != "0": extra += """
Connect user
add users to role %s.
""" % (id_role, name_role) if int(reverse): extra += """
Remove user
remove users from role %s.
""" % (id_role, name_role) extra += '
' if str(id_user) != "0": extra += """
Connect role
add roles to user %s.
""" % (email_user, id_user, email_user) if not int(reverse): extra += """
Remove role
remove roles from user %s.
""" % (id_user, email_user, email_user) extra += '
' if extra: body = [output, extra] else: body = [output] return index(req=req, title=title, subtitle=subtitle, body=body, adminarea=adminarea) def perform_showuserdetails(req, id_user=0): """show the details of a user. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) if id_user not in [0, '0']: output = userdetails(id_user=id_user) email_user = acca.acc_getUserEmail(id_user=id_user) extra = """
Connect role
connect a role to user %s.
Remove role
remove a role from user %s.
""" % (id_user, email_user, email_user, id_user, email_user) body = [output, extra] else: body = ['

no details to show

'] return index(req=req, title='Show User Details', subtitle='show user details', body=body, adminarea=5) def userdetails(id_user=0): """create the string to show details about a user. """ # find necessary details email_user = acca.acc_getUserEmail(id_user=id_user) userroles = acca.acc_getUserRoles(id_user=id_user) conn_roles = [] # find connected roles for (id, name, desc) in acca.acc_getAllRoles(): if (id, ) in userroles: conn_roles.append([id, name, desc]) conn_roles[-1].append('show details' % (id, )) if conn_roles: # print details details = '

roles connected to user %s

' % (email_user, ) details += tupletotable(header=['id', 'name', 'description', ''], tuple=conn_roles) else: details = '

no roles connected to user %s.

' % (email_user, ) return details def perform_addauthorization(req, id_role="0", id_action="0", optional=0, reverse="0", confirm=0, **keywords): """ form to add new connection between user and role: id_role - role to connect id_action - action to connect reverse - role or action first? """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) # values that might get used name_role = acca.acc_getRoleName(id_role=id_role) or id_role name_action = acca.acc_getActionName(id_action=id_action) or id_action optional = optional == 'on' and 1 or int(optional) extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" # create the page according to which step the user is on # role -> action -> arguments if reverse in ["0", 0]: adminarea = 3 subtitle = 'step 1 - select role' output = createroleselect(id_role=id_role, action="addauthorization", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if str(id_role) != "0": subtitle = 'step 2 - select action' rolacts = acca.acc_getRoleActions(id_role) allhelp = acca.acc_getAllActions() allacts = [] for r in allhelp: if r not in rolacts: allacts.append(r) output += createactionselect(id_action=id_action, action="addauthorization", step=2, actions=rolacts, extraactions=allacts, id_role=id_role, reverse=reverse) # action -> role -> arguments else: adminarea = 4 subtitle = 'step 1 - select action' output = createactionselect(id_action=id_action, action="addauthorization", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if str(id_action) != "0": subtitle = 'step 2 - select role' actroles = acca.acc_getActionRoles(id_action) allhelp = acca.acc_getAllRoles() allroles = [] for r in allhelp: if r not in actroles: allroles.append(r) output += createroleselect(id_role=id_role, action="addauthorization", step=2, roles=actroles, extraroles=allroles, id_action=id_action, reverse=reverse) # ready for step 3 no matter which direction we took to get here if id_action != "0" and id_role != "0": # links to adding authorizations in the other direction if str(reverse) == "0": extra += """
Add authorization
add authorizations to action %s.
""" % (id_action, name_action) else: extra += """
Add authorization
add authorizations to role %s.
""" % (id_role, name_role) subtitle = 'step 3 - enter values for the keywords\n' output += """
""" % (id_role, id_action, reverse) # the actions argument keywords res_keys = acca.acc_getActionKeywords(id_action=id_action) # res used to display existing authorizations # res used to determine if showing "create connection without arguments" res_auths = acca.acc_findPossibleActions(id_role, id_action) if not res_keys: # action without arguments if not res_auths: output += """ create connection between %s?
""" % (headerstrong(role=name_role, action=name_action, query=0), ) else: output += '

connection without arguments is already created.

' else: # action with arguments optionalargs = acca.acc_getActionIsOptional(id_action=id_action) output += '3. authorized arguments
' if optionalargs: # optional arguments output += """

connect %s to %s for any arguments
connect %s to %s for only these argument cases:

""" % (optional and 'checked="checked"' or '', name_role, name_action, not optional and 'checked="checked"' or '', name_role, name_action) # list the arguments allkeys = 1 for key in res_keys: output += '%s \n \n' output += '\n' # ask for confirmation if str(allkeys) != "0" or optional: keys = keywords.keys() keys.reverse() subtitle = 'step 4 - confirm add of authorization\n' text = """ create connection between
%s
""" % (headerstrong(role=name_role, action=name_action, query=0), ) if optional: text += 'withouth arguments' keywords = {} else: for key in keys: text += '%s: %s \n' % (key, keywords[key]) output += createhiddenform(action="addauthorization", text=text, id_role=id_role, id_action=id_action, reverse=reverse, confirm=1, optional=optional, **keywords) # show existing authorizations, found authorizations further up in the code... # res_auths = acca.acc_findPossibleActions(id_role, id_action) output += '

existing authorizations:

' if res_auths: output += tupletotable(header=res_auths[0], tuple=res_auths[1:]) # shortcut to modifying authorizations extra += """
Modify authorizations
modify the existing authorizations.
""" % (id_role, id_action, reverse) else: output += '

no details to show

' # user confirmed to add entries if confirm: subtitle = 'step 5 - confirm authorization added' res1 = acca.acc_addAuthorization(name_role=name_role, name_action=name_action, optional=optional, **keywords) if res1: res2 = acca.acc_findPossibleActions(id_role, id_action) arg = res1[0][3] # the arglistid new = [res2[0]] for row in res2[1:]: if int(row[0]) == int(arg): new.append(row) newauths = tupletotable(header=new[0], tuple=new[1:]) newentries = tupletotable(header=['role id', 'action id', 'argument id', '#'], tuple=res1) st = 'style="vertical-align: top"' output += """

new authorization and entries:

%s %s
""" % (st, newauths, st, newentries) else: output += '

sorry, authorization could not be added,
it probably already exists

' # trying to put extra link on the right side try: body = [output, extra] except NameError: body = [output] return index(req=req, title = 'Create entry for new authorization', subtitle=subtitle, body=body, adminarea=adminarea) def perform_deleteroleaction(req, id_role="0", id_action="0", reverse=0, confirm=0): """delete all connections between a role and an action. id_role - id of the role id_action - id of the action reverse - 0: ask for role first 1: ask for action first""" (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) title = 'Remove action from role ' if reverse in ["0", 0]: # select role -> action adminarea = 3 subtitle = 'step 1 - select a role' output = createroleselect(id_role=id_role, action="deleteroleaction", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if id_role != "0": rolacts = acca.acc_getRoleActions(id_role=id_role) subtitle = 'step 2 - select the action' output += createactionselect(id_action=id_action, action="deleteroleaction", step=2, actions=rolacts, reverse=reverse, id_role=id_role, button="remove connection and all authorizations") else: # select action -> role adminarea = 4 subtitle = 'step 1 - select an action' output = createactionselect(id_action=id_action, action="deleteroleaction", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if id_action != "0": actroles = acca.acc_getActionRoles(id_action=id_action) subtitle = 'step 2 - select the role' output += createroleselect(id_role=id_role, action="deleteroleaction", step=2, roles=actroles, button="remove connection and all authorizations", id_action=id_action, reverse=reverse) if id_action != "0" and id_role != "0": subtitle = 'step 3 - confirm to remove authorizations' # ask for confirmation res = acca.acc_findPossibleActions(id_role, id_action) if res: output += '

authorizations that will be deleted:

' output += tupletotable(header=res[0], tuple=res[1:]) output += createhiddenform(action="deleteroleaction", text='remove %s from %s' % (headerstrong(action=id_action), headerstrong(role=id_role)), confirm=1, id_role=id_role, id_action=id_action, reverse=reverse) else: output += 'no authorizations' # confirmation is given if confirm: subtitle = 'step 4 - confirm authorizations removed ' res = acca.acc_deleteRoleAction(id_role=id_role, id_action=id_action) if res: output += '

confirm: removed %s from %s
' % (headerstrong(action=id_action), headerstrong(role=id_role)) output += '%s entries were removed.

' % (res, ) else: output += '

sorry, no entries could be removed.

' return index(req=req, title=title, subtitle=subtitle, body=[output], adminarea=adminarea) def perform_modifyauthorizations(req, id_role="0", id_action="0", reverse=0, confirm=0, errortext='', sel='', authids=[]): """given ids of a role and an action, show all possible action combinations with checkboxes and allow user to access other functions. id_role - id of the role id_action - id of the action reverse - 0: ask for role first 1: ask for action first sel - which button and modification that is selected errortext - text to print when no connection exist between role and action authids - ids of checked checkboxes """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) name_role = acca.acc_getRoleName(id_role) name_action = acca.acc_getActionName(id_action) output = '' try: id_role, id_action, reverse = int(id_role), int(id_action), int(reverse) except ValueError: pass extra = """
Create new role
go here to add a new role.
Create new action
go here to add a new action.
""" if id_role or id_action: extra += '\n
\n' if id_role and id_action: extra += """
Add authorizations
add an authorization to the existing ones.
""" % (id_role, id_action, reverse) if id_role: extra += """
Add authorizations
add to role %s.
""" % (id_role, name_role) if id_action: extra += """
Add authorizations
add to action %s.
""" % (id_action, name_action) extra += '\n
\n' if not reverse: # role -> action adminarea = 3 subtitle = 'step 1 - select the role' output += createroleselect(id_role=str(id_role), action="modifyauthorizations", step=1, roles=acca.acc_getAllRoles(), reverse=reverse) if id_role: rolacts = acca.acc_getRoleActions(id_role=id_role) subtitle = 'step 2 - select the action' output += createactionselect(id_action=str(id_action), action="modifyauthorizations", step=2, actions=rolacts, id_role=id_role, reverse=reverse) else: adminarea = 4 # action -> role subtitle = 'step 1 - select the action' output += createactionselect(id_action=str(id_action), action="modifyauthorizations", step=1, actions=acca.acc_getAllActions(), reverse=reverse) if id_action: actroles = acca.acc_getActionRoles(id_action=id_action) subtitle = 'step 2 - select the role' output += createroleselect(id_role=str(id_role), action="modifyauthorizations", step=2, roles=actroles, id_action=id_action, reverse=reverse) if errortext: output += '

%s

' % (errortext, ) if id_role and id_action: # adding to main area if type(authids) is not list: authids = [authids] subtitle = 'step 3 - select groups and modification' # get info res = acca.acc_findPossibleActions(id_role, id_action) # clean the authids hiddenids = [] if sel in ['delete selected']: hiddenids = authids[:] elif sel in ['split groups', 'merge groups']: for authid in authids: arghlp = res[int(authid)][0] if authid not in hiddenids and arghlp not in [-1, '-1', 0, '0']: hiddenids.append(authid) authids = hiddenids[:] if confirm: # do selected modification and output with new authorizations if sel == 'split groups': res = splitgroups(id_role, id_action, authids) elif sel == 'merge groups': res = mergegroups(id_role, id_action, authids) elif sel == 'delete selected': res = deleteselected(id_role, id_action, authids) authids = [] res = acca.acc_findPossibleActions(id_role, id_action) output += 'authorizations after %s.
\n' % (sel, ) elif sel and authids: output += 'confirm choice of authorizations and modification.
\n' else: output += 'select authorizations and perform modification.
\n' if not res: errortext='all connections deleted, try different ' if reverse in ["0", 0]: return perform_modifyauthorizations(req=req, id_role=id_role, errortext=errortext + 'action.') else: return perform_modifyauthorizations(req=req, id_action=id_action, reverse=reverse, errortext=errortext + 'role.') # display output += modifyauthorizationsmenu(id_role, id_action, header=res[0], tuple=res[1:], checked=authids, reverse=reverse) if sel and authids: subtitle = 'step 4 - confirm to perform modification' # form with hidden authids output += '
\n' % ('modifyauthorizations', ) for hiddenid in hiddenids: output += '\n' % (hiddenid, ) # choose what to do if sel == 'split groups': output += '

split groups containing:

' elif sel == 'merge groups': output += '

merge groups containing:

' elif sel == 'delete selected': output += '

delete selected entries:

' extracolumn = '\n' extracolumn += '\n' # show the entries here... output += tupletotable_onlyselected(header=res[0], tuple=res[1:], selected=hiddenids, extracolumn=extracolumn) output += '\n' % (id_role, ) output += '\n' % (id_action, ) output += '\n' % (sel, ) output += '\n' % (reverse, ) output += '
' # tried to perform modification without something selected elif sel and not authids and not confirm: output += '

no valid groups selected

' # trying to put extra link on the right side try: body = [output, extra] except NameError: body = [output] # Display the page return index(req=req, title='Modify Authorizations', subtitle=subtitle, body=body, adminarea=adminarea) def modifyauthorizationsmenu(id_role, id_action, tuple=[], header=[], checked=[], reverse=0): """create table with header and checkboxes, used for multiple choice. makes use of tupletotable to add the actual table id_role - selected role, hidden value in the form id_action - selected action, hidden value in the form tuple - all rows to be put in the table (with checkboxes) header - column headers, empty strings added at start and end checked - ids of rows to be checked """ if not tuple: return 'no authorisations...' argnum = len(acca.acc_getActionKeywords(id_action=id_action)) tuple2 = [] for t in tuple: tuple2.append(t[:]) tuple2 = addcheckboxes(datalist=tuple2, name='authids', startindex=1, checked=checked) hidden = ' \n' % (id_role, ) hidden += ' \n' % (id_action, ) hidden += ' \n' % (reverse, ) button = '\n' if argnum > 1: button += '\n' button += '\n' hdrstr = '' for h in [''] + header + ['']: hdrstr += ' %s\n' % (h, ) if hdrstr: hdrstr = ' \n%s\n \n' % (hdrstr, ) output = '
\n' output += ' \n' output += hdrstr output += '\n' % (hidden, ) align = ['admintdleft'] * len(tuple2[0]) try: align[1] = 'admintdright' except IndexError: pass output += '' for i in range(len(tuple2[0])): output += '\n' % (align[i], tuple2[0][i]) output += '\n' % (len(tuple2), button) output += '\n' for row in tuple2[1:]: output += ' \n' for i in range(len(row)): output += '\n' % (align[i], row[i]) output += ' \n' output += '
%s
%s\n%s\n
%s
\n
\n' return output def splitgroups(id_role=0, id_action=0, authids=[]): """get all the old ones, gather up the arglistids find a list of arglistidgroups to be split, unique get all actions in groups outside of the old ones, (old arglistid is allowed). show them like in showselect. """ if not id_role or not id_action or not authids: return 0 # find all the actions datalist = acca.acc_findPossibleActions(id_role, id_action) if type(authids) is str: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) # argumentlistids of groups to be split splitgrps = [] for authid in authids: hlp = datalist[authid][0] if hlp not in splitgrps and authid in range(1,len(datalist)): splitgrps.append(hlp) # split groups and return success or failure result = 1 for splitgroup in splitgrps: result = 1 and acca.acc_splitArgumentGroup(id_role, id_action, splitgroup) return result def mergegroups(id_role=0, id_action=0, authids=[]): """get all the old ones, gather up the argauthids find a list of arglistidgroups to be split, unique get all actions in groups outside of the old ones, (old arglistid is allowed). show them like in showselect.""" if not id_role or not id_action or not authids: return 0 datalist = acca.acc_findPossibleActions(id_role, id_action) if type(authids) is str: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) # argumentlistids of groups to be merged mergegroups = [] for authid in authids: hlp = datalist[authid][0] if hlp not in mergegroups and authid in range(1, len(datalist)): mergegroups.append(hlp) # merge groups and return success or failure if acca.acc_mergeArgumentGroups(id_role, id_action, mergegroups): return 1 else: return 0 def deleteselected(id_role=0, id_action=0, authids=[]): """delete checked authorizations/possible actions, ids in authids. id_role - role to delete from id_action - action to delete from authids - listids for which possible actions to delete.""" if not id_role or not id_action or not authids: return 0 if type(authids) in [str, int]: authids = [authids] for i in range(len(authids)): authids[i] = int(authids[i]) result = acca.acc_deletePossibleActions(id_role=id_role, id_action=id_action, authids=authids) return result def headeritalic(**ids): """transform keyword=value pairs to string with value in italics. **ids - a dictionary of pairs to create string from """ output = '' value = '' table = '' for key in ids.keys(): if key in ['User', 'user']: value, table = 'email', 'user' elif key in ['Role', 'role']: value, table = 'name', 'accROLE' elif key in ['Action', 'action']: value, table = 'name', 'accACTION' else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) continue res = run_sql("""SELECT %s FROM %s WHERE id = %s""" % (value, table, ids[key])) if res: if output: output += ' and ' output += ' %s %s' % (key, res[0][0]) return output def headerstrong(query=1, **ids): """transform keyword=value pairs to string with value in strong text. **ids - a dictionary of pairs to create string from query - 1 -> try to find names to ids of role, user and action. 0 -> do not try to find names, use the value passed on """ output = '' value = '' table = '' for key in ids.keys(): if key in ['User', 'user']: value, table = 'email', 'user' elif key in ['Role', 'role']: value, table = 'name', 'accROLE' elif key in ['Action', 'action']: value, table = 'name', 'accACTION' else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) continue if query: res = run_sql("""SELECT %s FROM %s WHERE id = %s""" % (value, table, ids[key])) if res: if output: output += ' and ' output += ' %s %s' % (key, res[0][0]) else: if output: output += ' and ' output += ' %s %s' % (key, ids[key]) return output def startpage(): """create the menu for the startpage""" body = """
selection for WebAccess Admin
Role Area
main area to configure administration rights and authorization rules.
Action Area
configure administration rights with the actions as starting point.
User Area
configure administration rights with the users as starting point.
Reset Area
reset roles, actions and authorizations.
""" return body def rankarea(): return "Rankmethod area" def perform_simpleauthorization(req, id_role=0, id_action=0): """show a page with simple overview of authorizations between a connected role and action. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) res = acca.acc_findPossibleActions(id_role, id_action) if res: extra = createhiddenform(action='modifyauthorizations', button='modify authorizations', id_role=id_role, id_action=id_action) output = '

authorizations for %s:

' % (headerstrong(action=id_action, role=id_role), ) output += tupletotable(header=res[0], tuple=res[1:], extracolumn=extra) else: output = 'no details to show' return index(req=req, title='Simple authorization details', subtitle='simple authorization details', body=[output], adminarea=3) def perform_showroleusers(req, id_role=0): """show a page with simple overview of a role and connected users. """ (auth_code, auth_message) = is_adminuser(req) if auth_code != 0: return mustloginpage(req, auth_message) res = acca.acc_getRoleUsers(id_role=id_role) name_role = acca.acc_getRoleName(id_role=id_role) if res: users = [] for (id, name, dontcare) in res: users.append([id, name, 'show user details' % (id, )]) output = '

users connected to %s:

' % (headerstrong(role=id_role), ) output += tupletotable(header=['id', 'name', ''], tuple=users) else: output = 'no users connected to role %s' % (name_role, ) extra = """
Connect user
connect users to the role.
""" % (id_role, ) return index(req=req, title='Users connected to role %s' % (name_role, ), subtitle='simple details', body=[output, extra], adminarea=3) def createselect(id_input="0", label="", step=0, name="", action="", list=[], extralist=[], extrastamp='', button="", **hidden): """create form with select and hidden values id - the one to choose as selected if exists label - label shown to the left of the select name - the name of the select on which to reference it list - primary list to select from extralist - list of options to be put in paranthesis extrastamp - stamp extralist entries with this if not '' usually paranthesis around the entry button - the value/text to be put on the button **hidden - name=value pairs to be put as hidden in the form. """ step = step and '%s. ' % step or '' output = '
\n' % (action, ) output += ' %s\n' % (step + label, ) output += ' \n' for key in hidden.keys(): output += ' \n' % (key, hidden[key]) output += ' \n' % (button, ) output += '
\n' return output def createactionselect(id_action="0", label="select action", step=0, name="id_action", action="", actions=[], extraactions=[], extrastamp='', button="select action", **hidden): """create a select for roles in a form. see createselect.""" return createselect(id_input=id_action, label=label, step=step, name=name, action=action, list=actions, extralist=extraactions, extrastamp=extrastamp, button=button, **hidden) def createroleselect(id_role="0", label="select role", step=0, name="id_role", action="", roles=[], extraroles=[], extrastamp='', button="select role", **hidden): """create a select for roles in a form. see createselect.""" return createselect(id_input=id_role, label=label, step=step, name=name, action=action, list=roles, extralist=extraroles, extrastamp=extrastamp, button=button, **hidden) def createuserselect(id_user="0", label="select user", step=0, name="id_user", action="", users=[], extrausers=[], extrastamp='(connected)', button="select user", **hidden): """create a select for users in a form.see createselect.""" return createselect(id_input=id_user, label=label, step=step, name=name, action=action, list=users, extralist=extrausers, extrastamp=extrastamp, button=button, **hidden) def cleanstring(str='', comma=0): """clean all the strings before submitting to access control admin. remove characters not letter, number or underscore, also remove leading underscores and numbers. return cleaned string. str - string to be cleaned comma - 1 -> allow the comma to divide multiple arguments 0 -> wash commas as well """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_,]', '', str) # split string on commas items = str.split(',') str = '' for item in items: if not item: continue if comma and str: str += ',' # create valid variable names str += re.sub(r'^([0-9_])*', '', item) return str def cleanstring_argumentvalue(str=''): """clean the value of an argument before submitting it. allowed characters: a-z A-Z 0-9 _ and space str - string to be cleaned """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_ .]', '', str) # trim leading and ending spaces str = re.sub(r'^ *| *$', '', str) return str def cleanstring_email(str=''): """clean the string and return a valid email address. str - string to be cleaned """ # remove not allowed characters str = re.sub(r'[^a-zA-Z0-9_.@-]', '', str) return str def check_email(str=''): """control that submitted emails are correct. this little check is not very good, but better than nothing. """ r = re.compile(r'(.)+\@(.)+\.(.)+') return r.match(str) and 1 or 0 diff --git a/modules/websearch/web/admin/websearchadmin.py b/modules/websearch/web/admin/websearchadmin.py index c76a384a2..cf72eec36 100644 --- a/modules/websearch/web/admin/websearchadmin.py +++ b/modules/websearch/web/admin/websearchadmin.py @@ -1,1069 +1,1069 @@ ## Administrator interface for WebSearch ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware WebSearch Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.websearchadminlib as wsc #reload(wsc) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def switchfmtscore(req, colID, type, id_1, id_2, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfmtscore(colID=colID, ln=ln, type=type, id_1=id_1, id_2=id_2), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchfldscore(req, colID, id_1, id_2, fmeth, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfldscore(colID=colID, ln=ln, id_1=id_1, id_2=id_2, fmeth=fmeth), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchfldvaluescore(req, colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfldvaluescore(colID=colID, ln=ln, id_1=id_1, id_fldvalue_1=id_fldvalue_1, id_fldvalue_2=id_fldvalue_2), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def runwebcoll(req, colID, ln=cdslang, confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_runwebcoll(colID=colID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchpbxscore(req, colID, id_1, id_2, sel_ln,ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchpbxscore(colID=colID, ln=ln, id_1=id_1, id_2=id_2, sel_ln=sel_ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifydbquery(req, colID, ln=cdslang, dbquery='', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifydbquery(colID=colID, ln=ln, dbquery=dbquery, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showtree(req, colID, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection tree", body=wsc.perform_showtree(colID=colID, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrestricted(req, colID, ln=cdslang, rest='', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyrestricted(colID=colID, ln=ln, rest=rest, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, colID, ln=cdslang, sel_type='', trans = [], confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifytranslations(colID=colID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addcollectiontotree(req, colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_addcollectiontotree(colID=colID, ln=cdslang, add_dad=add_dad, add_son=add_son, rtype=rtype, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addcollection(req, colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_addcollection(colID=colID, ln=cdslang, colNAME=colNAME, dbquery=dbquery, rest=rest, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrankmethods(req, colID, ln=cdslang, func='', rnkID='', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyrankmethods(colID=colID, ln=ln, func=func, rnkID=rnkID, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deletecollection(req, colID, ln=cdslang, confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deletecollection(colID=colID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def editcollection(req, colID=1, ln=cdslang, mtype=''): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_editcollection(colID=colID, ln=ln, mtype=mtype), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addoutputformat(req, colID, ln=cdslang, code='', name='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addoutputformat(colID=colID, ln=ln, code=code, name=name, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showoutputformats(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showoutputformats(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deleteoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deleteoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removeoutputformat(req, colID, ln=cdslang, fmtID='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removeoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefieldvalue(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removefieldvalue(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefield(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removefield(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfield(req, colID, fldID, fldvID='', ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyfield(colID=colID, fldID=fldID, fldvID=fldvID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyoutputformat(req, colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyoutputformat(colID=colID, ln=ln, fmtID=fmtID, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsearchoptions(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsearchoptions(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingfield(req, colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingfield(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def rearrangefield(req, colID, ln=cdslang, fmeth='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_rearrangefield(colID=colID, ln=ln, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def addexistingfieldvalue(req, colID, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingfieldvalue(colID=colID, ln=ln, fldID=fldID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def rearrangefieldvalue(req, colID, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_rearrangefieldvalue(colID=colID, ln=ln, fldID=fldID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def addnewfieldvalue(req, colID, fldID, ln=cdslang, name='', value='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addnewfieldvalue(colID=colID, fldID=fldID, ln=cdslang, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfieldvalue(req, colID, fldID, fldvID, ln=cdslang, name='', value='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyfieldvalue(colID=colID, fldID=fldID, fldvID=fldvID, ln=cdslang, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsearchfields(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsearchfields(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsortoptions(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsortoptions(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyportalbox(req, colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyportalbox(colID=colID, ln=ln, pbxID=pbxID, score=score, position=position, sel_ln=sel_ln, title=title, body=body, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removeportalbox(req, colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removeportalbox(colID=colID, ln=ln, pbxID=pbxID, sel_ln=sel_ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingportalbox(req, colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingportalbox(colID=colID, ln=ln, pbxID=pbxID, score=score, position=position, sel_ln=sel_ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def deleteportalbox(req, colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deleteportalbox(colID=colID, ln=ln, pbxID=pbxID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showportalboxes(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showportalboxes(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addportalbox(req, colID, ln=cdslang, title='', body='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addportalbox(colID=colID, ln=ln, title=title, body=body, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifycollectiontree(req, colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_modifycollectiontree(colID=colID, ln=ln, move_up=move_up, move_down=move_down, move_from=move_from, move_to=move_to, delete=delete, rtype=rtype, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def index(req, colID=1, ln=cdslang, mtype='', content='', confirm=0): navtrail_previous_links = wsc.getnavtrail() try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_index(colID=colID, ln=ln, mtype=mtype, content=content, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=wsc.adderrorbox('Not logged in', + body=wsc.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) diff --git a/modules/websearch/web/admin/websearchadmin.py.wml b/modules/websearch/web/admin/websearchadmin.py.wml index c76a384a2..cf72eec36 100644 --- a/modules/websearch/web/admin/websearchadmin.py.wml +++ b/modules/websearch/web/admin/websearchadmin.py.wml @@ -1,1069 +1,1069 @@ ## Administrator interface for WebSearch ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware 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. ## ## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """CDSware WebSearch Administrator Interface.""" __lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>""" ## fill config variables: pylibdir = "/python" import sys sys.path.append('%s' % pylibdir) import cdsware.websearchadminlib as wsc #reload(wsc) from cdsware.webpage import page, create_error_box from cdsware.config import weburl,cdslang from cdsware.webuser import getUid __version__ = "$Id$" def switchfmtscore(req, colID, type, id_1, id_2, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfmtscore(colID=colID, ln=ln, type=type, id_1=id_1, id_2=id_2), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchfldscore(req, colID, id_1, id_2, fmeth, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfldscore(colID=colID, ln=ln, id_1=id_1, id_2=id_2, fmeth=fmeth), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchfldvaluescore(req, colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchfldvaluescore(colID=colID, ln=ln, id_1=id_1, id_fldvalue_1=id_fldvalue_1, id_fldvalue_2=id_fldvalue_2), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def runwebcoll(req, colID, ln=cdslang, confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_runwebcoll(colID=colID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def switchpbxscore(req, colID, id_1, id_2, sel_ln,ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_switchpbxscore(colID=colID, ln=ln, id_1=id_1, id_2=id_2, sel_ln=sel_ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifydbquery(req, colID, ln=cdslang, dbquery='', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifydbquery(colID=colID, ln=ln, dbquery=dbquery, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showtree(req, colID, ln=cdslang): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection tree", body=wsc.perform_showtree(colID=colID, ln=ln), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrestricted(req, colID, ln=cdslang, rest='', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyrestricted(colID=colID, ln=ln, rest=rest, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifytranslations(req, colID, ln=cdslang, sel_type='', trans = [], confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifytranslations(colID=colID, ln=ln, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addcollectiontotree(req, colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_addcollectiontotree(colID=colID, ln=cdslang, add_dad=add_dad, add_son=add_son, rtype=rtype, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addcollection(req, colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_addcollection(colID=colID, ln=cdslang, colNAME=colNAME, dbquery=dbquery, rest=rest, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyrankmethods(req, colID, ln=cdslang, func='', rnkID='', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyrankmethods(colID=colID, ln=ln, func=func, rnkID=rnkID, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deletecollection(req, colID, ln=cdslang, confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deletecollection(colID=colID, ln=ln, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def editcollection(req, colID=1, ln=cdslang, mtype=''): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_editcollection(colID=colID, ln=ln, mtype=mtype), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addoutputformat(req, colID, ln=cdslang, code='', name='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addoutputformat(colID=colID, ln=ln, code=code, name=name, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showoutputformats(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showoutputformats(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def deleteoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deleteoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removeoutputformat(req, colID, ln=cdslang, fmtID='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removeoutputformat(colID=colID, ln=ln, fmtID=fmtID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefieldvalue(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removefieldvalue(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removefield(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removefield(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfield(req, colID, fldID, fldvID='', ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyfield(colID=colID, fldID=fldID, fldvID=fldvID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyoutputformat(req, colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyoutputformat(colID=colID, ln=ln, fmtID=fmtID, sel_type=sel_type, trans=trans, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsearchoptions(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsearchoptions(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingfield(req, colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingfield(colID=colID, ln=ln, fldID=fldID, fldvID=fldvID, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def rearrangefield(req, colID, ln=cdslang, fmeth='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_rearrangefield(colID=colID, ln=ln, fmeth=fmeth, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def addexistingfieldvalue(req, colID, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingfieldvalue(colID=colID, ln=ln, fldID=fldID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def rearrangefieldvalue(req, colID, fldID, ln=cdslang, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_rearrangefieldvalue(colID=colID, ln=ln, fldID=fldID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def addnewfieldvalue(req, colID, fldID, ln=cdslang, name='', value='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addnewfieldvalue(colID=colID, fldID=fldID, ln=cdslang, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyfieldvalue(req, colID, fldID, fldvID, ln=cdslang, name='', value='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyfieldvalue(colID=colID, fldID=fldID, fldvID=fldvID, ln=cdslang, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, urlargs=req.args, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsearchfields(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsearchfields(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showsortoptions(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showsortoptions(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifyportalbox(req, colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyportalbox(colID=colID, ln=ln, pbxID=pbxID, score=score, position=position, sel_ln=sel_ln, title=title, body=body, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def removeportalbox(req, colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_removeportalbox(colID=colID, ln=ln, pbxID=pbxID, sel_ln=sel_ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addexistingportalbox(req, colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addexistingportalbox(colID=colID, ln=ln, pbxID=pbxID, score=score, position=position, sel_ln=sel_ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=wsc.adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to login with another account.""" % (weburl, weburl)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__) def deleteportalbox(req, colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_deleteportalbox(colID=colID, ln=ln, pbxID=pbxID, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def showportalboxes(req, colID, ln=cdslang, callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_showportalboxes(colID=colID, ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def addportalbox(req, colID, ln=cdslang, title='', body='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_addportalbox(colID=colID, ln=ln, title=title, body=body, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def modifycollectiontree(req, colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> Collection Management """ % (weburl) try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_modifycollectiontree(colID=colID, ln=ln, move_up=move_up, move_down=move_down, move_from=move_from, move_to=move_to, delete=delete, rtype=rtype, callback=callback, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def index(req, colID=1, ln=cdslang, mtype='', content='', confirm=0): navtrail_previous_links = wsc.getnavtrail() try: uid = getUid(req) except MySQLdb.Error, e: return error_page(req) auth = wsc.check_user(uid,'cfgwebsearch') if not auth[0]: return page(title="Collection Management", body=wsc.perform_index(colID=colID, ln=ln, mtype=mtype, content=content, confirm=confirm), uid=uid, language=ln, urlargs=req.args, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return auth_failed(uid, navtrail_previous_links, auth[1]) def error_page(req): return page(title=msg_internal_error[ln], body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % cdsname, keywords="%s, CDSware, Internal Error" % cdsname, language=ln, urlargs=req.args) def auth_failed(uid, navtrail_previous_links, message=""): return page(title='Authorization failure', uid=uid, - body=wsc.adderrorbox('Not logged in', + body=wsc.adderrorbox('Reason:', datalist=[message]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__)