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 import _
|
8
|
from qommon.publisher import get_publisher_class
|
9
|
|
10
|
import wcs.backoffice.management
|
11
|
import wcs.root
|
12
|
from wcs.categories import Category
|
13
|
from wcs.formdef import FormDef
|
14
|
|
15
|
from qommon import get_cfg, errors
|
16
|
from qommon.form import *
|
17
|
|
18
|
CURRENT_USER = object()
|
19
|
|
20
|
def check_visibility(target, user=CURRENT_USER):
|
21
|
if user is CURRENT_USER:
|
22
|
user = get_request().user
|
23
|
if not user:
|
24
|
return False
|
25
|
target = target.strip('/')
|
26
|
if target == 'management':
|
27
|
target = 'forms'
|
28
|
if target == 'strongbox':
|
29
|
if not get_publisher().has_site_option(target):
|
30
|
# strongbox disabled in site-options.cfg
|
31
|
return False
|
32
|
if not get_cfg('misc', {}).get('aq-strongbox'):
|
33
|
# strongbox disabled in settings panel
|
34
|
return False
|
35
|
admin_role = get_cfg('aq-permissions', {}).get(target, None)
|
36
|
if not admin_role:
|
37
|
return False
|
38
|
if not (user.is_admin or admin_role in (user.roles or [])):
|
39
|
return False
|
40
|
return True
|
41
|
|
42
|
|
43
|
class BackofficeRootDirectory(wcs.backoffice.root.RootDirectory):
|
44
|
def get_intro_text(self):
|
45
|
return _('Welcome on Publik back office interface')
|
46
|
|
47
|
def _q_index(self):
|
48
|
if len(self.get_menu_items()) == 1:
|
49
|
return redirect(self.get_menu_items()[0]['url'])
|
50
|
return wcs.backoffice.root.RootDirectory._q_index(self)
|
51
|
|
52
|
def home(self):
|
53
|
return redirect('management/')
|
54
|
|
55
|
get_publisher_class().backoffice_directory_class = BackofficeRootDirectory
|