1
|
import os
|
2
|
|
3
|
from quixote import get_publisher, redirect
|
4
|
from quixote.directory import Directory
|
5
|
from quixote.html import TemplateIO, htmltext
|
6
|
|
7
|
from qommon.publisher import get_publisher_class
|
8
|
|
9
|
import wcs.backoffice.management
|
10
|
import wcs.root
|
11
|
from wcs.categories import Category
|
12
|
from wcs.formdef import FormDef
|
13
|
|
14
|
from qommon import get_cfg, errors
|
15
|
from qommon.form import *
|
16
|
|
17
|
CURRENT_USER = object()
|
18
|
|
19
|
def check_visibility(target, user=CURRENT_USER):
|
20
|
if user is CURRENT_USER:
|
21
|
user = get_request().user
|
22
|
if not user:
|
23
|
return False
|
24
|
target = target.strip('/')
|
25
|
if target == 'management':
|
26
|
target = 'forms'
|
27
|
if target == 'strongbox':
|
28
|
if not get_publisher().has_site_option(target):
|
29
|
# strongbox disabled in site-options.cfg
|
30
|
return False
|
31
|
if not get_cfg('misc', {}).get('aq-strongbox'):
|
32
|
# strongbox disabled in settings panel
|
33
|
return False
|
34
|
admin_role = get_cfg('aq-permissions', {}).get(target, None)
|
35
|
if not admin_role:
|
36
|
return False
|
37
|
if not (user.is_admin or admin_role in (user.roles or [])):
|
38
|
return False
|
39
|
return True
|
40
|
|
41
|
|
42
|
class BackofficeRootDirectory(wcs.backoffice.root.RootDirectory):
|
43
|
def _q_access(self):
|
44
|
super(BackofficeRootDirectory, self)._q_access()
|
45
|
portal_agent_url = get_publisher().get_site_option('portal_agent_url', 'variables')
|
46
|
portal_agent_title = get_publisher().get_site_option('portal_agent_title', 'variables')
|
47
|
if not portal_agent_title:
|
48
|
portal_agent_title = _('Portal Agent')
|
49
|
if portal_agent_url:
|
50
|
get_response().breadcrumb.insert(0, (portal_agent_url, portal_agent_title))
|
51
|
|
52
|
def get_intro_text(self):
|
53
|
return _('Welcome on Publik back office interface')
|
54
|
|
55
|
def _q_index(self):
|
56
|
if len(self.get_menu_items()) == 1:
|
57
|
return redirect(self.get_menu_items()[0]['url'])
|
58
|
return wcs.backoffice.root.RootDirectory._q_index(self)
|
59
|
|
60
|
def home(self):
|
61
|
return redirect('management/')
|
62
|
|
63
|
get_publisher_class().backoffice_directory_class = BackofficeRootDirectory
|