File: ConfigurationMethods.py

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (383 lines) | stat: -rw-r--r-- 15,761 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
from OFS.PropertyManager import PropertyManager
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.permissions import AccessInactivePortalContent, \
        AddPortalContent, ListFolderContents, ManagePortal, \
        ModifyPortalContent, View
from Products.CMFCore.Expression import Expression
from Products.CMFPlone.migrations.migration_util import safeEditProperty
from Products.CMFPlone.utils import log_deprecated
from Acquisition import aq_get
from AccessControl import Permissions
from Products.SiteErrorLog.SiteErrorLog import manage_addErrorLog
from DateTime import DateTime
from Products.GroupUserFolder.GroupsToolPermissions import ViewGroups

from zLOG import INFO
from SetupBase import SetupWidget

def addErrorLog(self, portal):
    log_deprecated("addErrorLog is deprecated and will be removed in Plone 3.0")
    if "error_log" not in portal.objectIds():
        manage_addErrorLog(portal)
        portal.error_log.copy_to_zlog = 1

def installPortalTools(self,portal):
    ''' This should be done in Products/CMFPlone/Portal.py in setupTools '''
    log_deprecated("installPortalTools is deprecated and will be removed in "
                   "Plone 3.0")
    pass

def addSiteProperties(self, portal):
    """ adds site_properties in portal_properties """
    log_deprecated("addSiteProperties is deprecated and will be removed in "
                   "Plone 3.0")
    id = 'site_properties'
    title = 'Site wide properties'
    year = DateTime().year()
    p=PropertyManager('id')
    if id not in portal.portal_properties.objectIds():
        portal.portal_properties.addPropertySheet(id, title, p)
    p=getattr(portal.portal_properties, id)

    if not hasattr(p,'allowAnonymousViewAbout'):
        safeEditProperty(p, 'allowAnonymousViewAbout', 1, 'boolean')
    if not hasattr(p,'localTimeFormat'):
        safeEditProperty(p, 'localTimeFormat', '%Y-%m-%d', 'string')
    if not hasattr(p,'localLongTimeFormat'):
        safeEditProperty(p, 'localLongTimeFormat', '%Y-%m-%d %H:%M', 'string')
    if not hasattr(p,'default_language'):
        safeEditProperty(p, 'default_language', 'en', 'string')
    if not hasattr(p,'default_charset'):
        safeEditProperty(p, 'default_charset', 'utf-8', 'string')
    if not hasattr(p,'use_folder_tabs'):
        safeEditProperty(p, 'use_folder_tabs',('Folder',), 'lines')
    if not hasattr(p,'use_folder_contents'):
        safeEditProperty(p, 'use_folder_contents',[], 'lines')
    if not hasattr(p,'ext_editor'):
        safeEditProperty(p, 'ext_editor', 0, 'boolean')
    if not hasattr(p, 'available_editors'):
        safeEditProperty(p, 'available_editors', ('None', ), 'lines')
    if not hasattr(p, 'allowRolesToAddKeywords'):
        safeEditProperty(p, 'allowRolesToAddKeywords', ['Manager', 'Reviewer'], 'lines')
    if not hasattr(p, 'auth_cookie_length'):
        safeEditProperty(p, 'auth_cookie_length', 0, 'int')
    if not hasattr(p, 'calendar_starting_year'):
        safeEditProperty(p, 'calendar_starting_year', 1999, 'int')
    if not hasattr(p, 'calendar_future_years_available'):
        safeEditProperty(p, 'calendar_future_years_available', 5, 'int')

def setupDefaultLeftRightSlots(self, portal):
    """ sets up the slots on objectmanagers """
    log_deprecated("setupDefaultLeftRightSlots is deprecated and will be "
                   "removed in Plone 3.0")
    left_slots=( 'here/portlet_navigation/macros/portlet'
               , 'here/portlet_login/macros/portlet'
               , 'here/portlet_recent/macros/portlet'
               , 'here/portlet_related/macros/portlet' )
    right_slots=( 'here/portlet_review/macros/portlet'
                , 'here/portlet_news/macros/portlet'
                , 'here/portlet_events/macros/portlet' )
    safeEditProperty(portal, 'left_slots', left_slots, 'lines')
    safeEditProperty(portal, 'right_slots', right_slots, 'lines')
    safeEditProperty(portal.Members, 'right_slots', (), 'lines')

def setupDefaultItemActionSlots(self, portal):
    """ Sets up the default action item slots """
    'These are now document_actions ActionInformation object in portal_actiosn'
    log_deprecated("setupDefaultItemActionSlots is deprecated and will be "
                   "removed in Plone 3.0")
    pass

def installExternalEditor(self, portal):
    ''' responsible for doing whats necessary if external editor is found '''
    log_deprecated("installExternalEditor is deprecated and will be removed in "
                   "Plone 3.0")
    try:
        from Products.ExternalEditor.ExternalEditor import ExternalEditorPermission
    except ImportError:
        pass
    else:
        types_tool=getToolByName(portal, 'portal_types')
        methods=('PUT', 'manage_FTPget')
        exclude=('Topic', 'Event', 'Folder')
        for ctype in types_tool.objectValues():
            if ctype.getId() not in exclude:
                ctype.addAction( 'external_edit',
                                name='External Edit',
                                action='string:$object_url/external_edit',
                                condition='',
                                permission=ModifyPortalContent,
                                category='object',
                                visible=0 )
        portal.manage_permission(ExternalEditorPermission,
                                 ('Manager', 'Authenticated'), acquire=0)

def assignTitles(self, portal):
    titles={'portal_actions':'Contains custom tabs and buttons',
     'portal_membership':'Handles membership policies',
     'portal_memberdata':'Handles the available properties on members',
     'portal_undo':'Defines actions and functionality related to undo',
     'portal_types':'Controls the available content types in your portal',
     'plone_utils':'Various utility methods',
     'portal_metadata':'Controls metadata like keywords, copyrights, etc',
     'portal_migration':'Handles migrations to newer Plone versions',
     'portal_registration':'Handles registration of new users',
     'portal_skins':'Controls skin behaviour (search order etc)',
     'portal_syndication':'Generates RSS for folders',
     'portal_workflow':'Contains workflow definitions for your portal',
     'portal_url':'Methods to anchor you to the root of your Plone site',
     'portal_discussion':'Controls how discussions are stored',
     'portal_catalog':'Indexes all content in the site',
     'portal_factory':'Responsible for the creation of content objects',
     'portal_calendar':'Controls how events are shown',
     'portal_quickinstaller':'Allows to install/uninstall products',
     'portal_interface':'Allows to query object interfaces',
     'portal_actionicons':'Associates actions with icons',
     'portal_groupdata':'Handles properties on groups',
     'portal_groups':'Handles group related functionality',
     'translation_service': 'Provides access to the translation machinery',
     'mimetypes_registry': 'MIME types recognized by Plone',
     'portal_transforms': 'Handles data conversion between MIME types',
     }

    for oid in portal.objectIds():
        title=titles.get(oid, None)
        if title:
            setattr(aq_get(portal, oid), 'title', title)

def addMemberdata(self, portal):
    log_deprecated("addMemberdata is deprecated and will be removed in "
                   "Plone 3.0")
    md=getToolByName(portal, 'portal_memberdata')
    if not hasattr(md,'wysiwyg_editor'):
        safeEditProperty(md, 'wysiwyg_editor', '', 'string')

    if not hasattr(md,'ext_editor'):
        safeEditProperty(md, 'ext_editor', 0, 'boolean')
    else:
        safeEditProperty(md, 'ext_editor', 0)
        
    if not hasattr(md,'listed'):
        safeEditProperty(md, 'listed', '1', 'boolean')
    else:
        safeEditProperty(md, 'listed','1')
        
    if not hasattr(md, 'fullname'):
        safeEditProperty(md, 'fullname', '', 'string')
    if not hasattr(md, 'error_log_update'):
        safeEditProperty(md, 'error_log_update', 0.0, 'float')

def modifyActionProviders(self, portal):
    log_deprecated("modifyActionProviders is deprecated and will be removed in "
                   "Plone 3.0")
    mt=getToolByName(portal, 'portal_properties')
    _actions=mt._cloneActions()
    for action in _actions:
        if action.id=='configPortal':
            action.visible=0
    mt._actions=_actions

    ut=getToolByName(portal, 'portal_undo')
    _actions=ut._cloneActions()
    for action in _actions:
        if action.id=='undo':
            action.category='user'
    ut._actions=_actions

    at=getToolByName(portal, 'portal_actions')
    correctFolderContentsAction(at)

    dt=getToolByName(portal, 'portal_discussion')
    _actions=dt._cloneActions()
    for action in _actions:
        if action.id=='reply':
            action.visible=0
    dt._actions=_actions

def correctFolderContentsAction(actionTool):
    log_deprecated("correctFolderContentsAction is deprecated and will be "
                   "removed in Plone 3.0")
    _actions=actionTool._cloneActions()
    for action in _actions:
        if action.id=='folderContents':
            action.name=action.title='Contents'
            action.condition=Expression('object/displayContentsTab')
            action.permissions=(ListFolderContents,)
    actionTool._actions=_actions

def modifyMembershipTool(self, portal):
    log_deprecated("modifyMembershipTool is deprecated and will be removed in "
                   "Plone 3.0")
    mt=getToolByName(portal, 'portal_membership')
    mt.addAction('myworkspace'
                ,'Workspace'
                ,'python: portal.portal_membership.getHomeUrl()+"/workspace"'
                ,'python: member and portal.portal_membership.getHomeFolder() is not None'
                ,View
                ,'user'
                , visible=0)
    new_actions=[]
    for a in mt._cloneActions():
        if a.id=='login':
            a.title='Log in'
        if a.id=='logout':
            a.title='Log out'
        if a.id=='preferences':
            a.title='Preferences'
            a.action=Expression('string:${portal_url}/plone_memberprefs_panel')
            new_actions.insert(0, a)
        elif a.id in ('addFavorite', 'favorites'):
            a.visible=0
            new_actions.insert(1,a)
        elif a.id=='mystuff':
            a.title='My Folder'
            new_actions.insert(0, a)
        elif a.id=='myworkspace':
            new_actions.insert(1, a)
        elif a.id=='logout':
            new_actions.append(a)
        else:
            new_actions.insert(len(new_actions)-1,a)
    mt._actions=new_actions

def modifySkins(self, portal):
    #remove non Plone skins from skins tool
    #since we implemented the portal_form proxy these skins will no longer work
    log_deprecated("modifySkins is deprecated and will be removed in Plone 3.0")

    # this should be run through the skins setup widget :)
    st=getToolByName(portal, 'portal_skins')
    skins_map=st._getSelections()

    if skins_map.has_key('No CSS'):
        del skins_map['No CSS']
    if skins_map.has_key('Nouvelle'):
        del skins_map['Nouvelle']
    if skins_map.has_key('Basic'):
        del skins_map['Basic']
    st.selections=skins_map

    types=getToolByName(portal, 'portal_types')
    for t in types.objectValues():
        _actions=t._cloneActions()
        for a in _actions:
            if a.id == 'metadata':
                a.name = 'Properties'   #1.3
                a.title = 'Properties'  #1.4
            if a.id == 'local_roles':
                a.name = 'Sharing'
                a.title = 'Sharing'
            if a.id == 'content_status_history':
                a.visible = 0

def addNewActions(self, portal):
    log_deprecated("addNewActions is deprecated and will be removed in "
                   "Plone 3.0")
    at=getToolByName(portal, 'portal_actions')

    at.addAction('index_html',
                 name='Home',
                 action='string:$portal_url',
                 condition='',
                 permission=View,
                 category='portal_tabs')
    at.addAction('change_ownership',
                 name='Ownership',
                 action='string:${object_url}/ownership_form',
                 condition='',
                 permission=ManagePortal,
                 category='object_tabs',
                 visible=0)
    at.addAction('rename',
                 name='Rename',
                 action='string:folder_rename_form:method',
                 condition='',
                 permission=AddPortalContent,
                 category='folder_buttons')
    at.addAction('paste',
                 name='Paste',
                 action='string:folder_paste:method',
                 condition='folder/cb_dataValid',
                 permission=AddPortalContent,
                 category='folder_buttons')
    at.addAction('delete',
                 name='Delete',
                 action='string:folder_delete:method',
                 condition='',
                 permission=Permissions.delete_objects,
                 category='folder_buttons')

    # Move change_state to the bottom
    cloned_actions = at._cloneActions()
    num_actions = len(cloned_actions)
    state_index = 0
    for action in cloned_actions:
        if action.id == 'change_state' and action.category == 'folder_buttons':
            break
        state_index = state_index + 1
    state_action = cloned_actions.pop(state_index)
    cloned_actions.append(state_action)
    at._actions = cloned_actions

def setPortalDefaultPermissions(self, portal):
    log_deprecated("setPortalDefaultPermissions is deprecated and will be "
                   "removed in Plone 3.0")
    portal.manage_permission(AccessInactivePortalContent,
                                                ('Owner',), acquire=1)
    portal.manage_permission(ViewGroups, ('Manager', 'Owner', 'Member'),
                                                            acquire=1)

def enableSiteSyndication(self, portal):
    log_deprecated("enableSiteSyndication is deprecated and will be removed in "
                   "Plone 3.0")
    syn_tool = getToolByName(portal, 'portal_syndication')
    syn_tool.editProperties(isAllowed=True)


functions = {
    'addSiteProperties': addSiteProperties,
    'setupDefaultLeftRightSlots': setupDefaultLeftRightSlots,
    'setupDefaultItemActionSlots': setupDefaultItemActionSlots,
    'installExternalEditor': installExternalEditor,
    'assignTitles': assignTitles,
    'addMemberdata': addMemberdata,
    'modifyMembershipTool': modifyMembershipTool,
    'addNewActions': addNewActions,
    'modifySkins': modifySkins,
    'installPortalTools': installPortalTools,
    'modifyActionProviders': modifyActionProviders,
    'addErrorLog':addErrorLog,
    'setPortalDefaultPermissions':setPortalDefaultPermissions,
    'enableSiteSyndication':enableSiteSyndication,
    }

class GeneralSetup(SetupWidget):
    type = 'General Setup'

    description = """This applies a function to the site. These functions are some of the basic
set up features of a site. The chances are you will not want to apply these again. <b>Please note</b>
these functions do not have a uninstall function."""

    functions = functions

    def setup(self):
        pass

    def delItems(self, fns):
        out = []
        out.append(('Currently there is no way to remove a function', INFO))
        return out

    def addItems(self, fns):
        out = []
        for fn in fns:
            self.functions[fn](self, self.portal)
            out.append(('Function %s has been applied' % fn, INFO))
        return out

    def installed(self):
        return []

    def available(self):
        """ Go get the functions """
        return self.functions.keys()