88 lines
2.6 KiB
Plaintext
88 lines
2.6 KiB
Plaintext
import os
|
|
|
|
from quixote import get_session, get_publisher, get_request, get_response
|
|
from quixote.directory import Directory, AccessControlled
|
|
|
|
import settings
|
|
import users
|
|
import logger
|
|
|
|
from qommon import errors
|
|
|
|
def gpl [html] ():
|
|
"""<p>This program 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.</p>
|
|
|
|
<p>This program 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.</p>
|
|
|
|
<p>You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
Place - Suite 330, Boston, MA 02111-1307, USA.</p>
|
|
"""
|
|
|
|
|
|
class RootDirectory(AccessControlled, Directory):
|
|
_q_exports = ['', 'settings', 'users', 'logger']
|
|
|
|
settings = settings.SettingsDirectory()
|
|
users = users.UsersDirectory()
|
|
logger = logger.LoggerDirectory()
|
|
|
|
items = [
|
|
('users/', N_('Users')),
|
|
('logger/', N_('Logs')),
|
|
('settings/', N_('Settings')),
|
|
('/', N_('Lasso Conformance Event Service Provider'))]
|
|
|
|
def _q_access(self):
|
|
get_response().breadcrumb.append( ('admin/', _('Administration')) )
|
|
|
|
if os.path.exists(os.path.join(get_publisher().app_dir, 'ADMIN_FOR_ALL')):
|
|
return
|
|
session = get_session()
|
|
|
|
req = get_request()
|
|
if req.user:
|
|
if users.User.count() == 0:
|
|
# this means user logged in anonymously
|
|
pass
|
|
elif not req.user.is_admin:
|
|
raise errors.AccessForbiddenError()
|
|
else:
|
|
if users.User.count() > 0:
|
|
raise errors.AccessUnauthorizedError()
|
|
|
|
return
|
|
|
|
|
|
def _q_index [html] (self):
|
|
from menu import html_top
|
|
html_top('/')
|
|
'<blockquote>'
|
|
gpl()
|
|
'</blockquote>'
|
|
|
|
|
|
def register_page(url_name, directory = None, label = None):
|
|
first_time = False
|
|
if not url_name in RootDirectory._q_exports:
|
|
RootDirectory._q_exports.append(url_name)
|
|
first_time = True
|
|
|
|
if directory:
|
|
setattr(RootDirectory, url_name, directory)
|
|
if not label:
|
|
label = directory.label
|
|
|
|
if first_time:
|
|
logger_index = RootDirectory.items.index(('logger/', 'Logs'))
|
|
if directory:
|
|
url_name += '/'
|
|
RootDirectory.items.insert(logger_index, (url_name, label))
|
|
|