|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from AccessControl import ClassSecurityInfo |
|
4
|
|
|
from bika.lims import api |
|
5
|
|
|
from plone.app.textfield import IRichTextValue |
|
6
|
|
|
from plone.app.textfield.widget import RichTextFieldWidget # TBD: port to core |
|
7
|
|
|
from plone.autoform import directives |
|
8
|
|
|
from plone.supermodel import model |
|
9
|
|
|
from Products.CMFCore import permissions |
|
10
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
|
11
|
|
|
from senaite.core.catalog import AUDITLOG_CATALOG |
|
12
|
|
|
from senaite.core.content.base import Container |
|
13
|
|
|
from senaite.core.interfaces import IHideActionsMenu |
|
14
|
|
|
from senaite.core.interfaces import ISetup |
|
15
|
|
|
from senaite.core.schema import RichTextField |
|
16
|
|
|
from senaite.impress import senaiteMessageFactory as _ |
|
17
|
|
|
from zope import schema |
|
18
|
|
|
from zope.interface import implementer |
|
19
|
|
|
from zope.interface import provider |
|
20
|
|
|
from zope.schema.interfaces import IContextAwareDefaultFactory |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
@provider(IContextAwareDefaultFactory) |
|
24
|
|
|
def default_email_body_sample_publication(context): |
|
25
|
|
|
"""Returns the default body text for publication emails |
|
26
|
|
|
""" |
|
27
|
|
|
view = api.get_view("senaite_view", context=api.get_setup()) |
|
28
|
|
|
if view is None: |
|
29
|
|
|
# Test fixture |
|
30
|
|
|
return u"" |
|
31
|
|
|
tpl = ViewPageTemplateFile( |
|
32
|
|
|
"../browser/setup/templates/email_body_sample_publication.pt") |
|
33
|
|
|
return tpl(view) |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
class ISetupSchema(model.Schema): |
|
37
|
|
|
"""Schema and marker interface |
|
38
|
|
|
""" |
|
39
|
|
|
|
|
40
|
|
|
directives.widget("email_body_sample_publication", RichTextFieldWidget) |
|
41
|
|
|
email_body_sample_publication = RichTextField( |
|
42
|
|
|
title=_(u"Publication Email Text"), |
|
43
|
|
|
description=_( |
|
44
|
|
|
"The default text that is used for the publication email."), |
|
45
|
|
|
defaultFactory=default_email_body_sample_publication, |
|
46
|
|
|
required=False, |
|
47
|
|
|
) |
|
48
|
|
|
|
|
49
|
|
|
enable_global_auditlog = schema.Bool( |
|
50
|
|
|
title=_(u"Enable global Auditlog"), |
|
51
|
|
|
description=_( |
|
52
|
|
|
"The global Auditlog shows all modifications of the system. " |
|
53
|
|
|
"When enabled, all entities will be indexed in a separate " |
|
54
|
|
|
"catalog. This will increase the time when objects are " |
|
55
|
|
|
"created or modified." |
|
56
|
|
|
), |
|
57
|
|
|
default=False, |
|
58
|
|
|
) |
|
59
|
|
|
|
|
60
|
|
|
### |
|
61
|
|
|
# Fieldsets |
|
62
|
|
|
### |
|
63
|
|
|
|
|
64
|
|
|
# model.fieldset( |
|
65
|
|
|
# "notifications", |
|
66
|
|
|
# label=_(u"Notifications"), |
|
67
|
|
|
# fields=[ |
|
68
|
|
|
# "email_body_sample_publication", |
|
69
|
|
|
# ] |
|
70
|
|
|
# ) |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
@implementer(ISetup, ISetupSchema, IHideActionsMenu) |
|
74
|
|
|
class Setup(Container): |
|
75
|
|
|
"""SENAITE Setup Folder |
|
76
|
|
|
""" |
|
77
|
|
|
security = ClassSecurityInfo() |
|
78
|
|
|
|
|
79
|
|
|
@security.protected(permissions.View) |
|
80
|
|
|
def getEmailBodySamplePublication(self): |
|
81
|
|
|
"""Returns the transformed email body text for publication emails |
|
82
|
|
|
""" |
|
83
|
|
|
accessor = self.accessor("email_body_sample_publication") |
|
84
|
|
|
value = accessor(self) |
|
85
|
|
|
if IRichTextValue.providedBy(value): |
|
86
|
|
|
# Transforms the raw value to the output mimetype |
|
87
|
|
|
value = value.output_relative_to(self) |
|
88
|
|
|
if not value: |
|
89
|
|
|
# Always fallback to default value |
|
90
|
|
|
value = default_email_body_sample_publication(self) |
|
91
|
|
|
return value |
|
92
|
|
|
|
|
93
|
|
|
@security.protected(permissions.ModifyPortalContent) |
|
94
|
|
|
def setEmailBodySamplePublication(self, value): |
|
95
|
|
|
"""Set email body text for publication emails |
|
96
|
|
|
""" |
|
97
|
|
|
mutator = self.mutator("email_body_sample_publication") |
|
98
|
|
|
return mutator(self, value) |
|
99
|
|
|
|
|
100
|
|
|
@security.protected(permissions.View) |
|
101
|
|
|
def getEnableGlobalAuditlog(self): |
|
102
|
|
|
"""Returns if the global Auditlog is enabled |
|
103
|
|
|
""" |
|
104
|
|
|
accessor = self.accessor("enable_global_auditlog") |
|
105
|
|
|
return accessor(self) |
|
106
|
|
|
|
|
107
|
|
|
@security.protected(permissions.ModifyPortalContent) |
|
108
|
|
|
def setEnableGlobalAuditlog(self, value): |
|
109
|
|
|
"""Enable/Disable global Auditlogging |
|
110
|
|
|
""" |
|
111
|
|
|
if value is False: |
|
112
|
|
|
# clear the auditlog catalog |
|
113
|
|
|
catalog = api.get_tool(AUDITLOG_CATALOG) |
|
114
|
|
|
catalog.manage_catalogClear() |
|
115
|
|
|
mutator = self.mutator("enable_global_auditlog") |
|
116
|
|
|
return mutator(self, value) |
|
117
|
|
|
|