# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from BaseFunctions import BaseFunctions schema = BaseSchema class Psyhvel(OrderedBaseFolder, BaseFunctions): """ Psyhvel main folder containing testing stuff and all other stuff also""" meta_type = "Psyhvel" archetype_name = "Psyhvel" global_allow = 0 exclude_from_nav = False filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def manage_afterAdd(self,item,container): self.makePsyhvelContent() if not hasattr(item.aq_base, 'right_slots'): self._setProperty('right_slots', [], 'lines') def makePsyhvelContent(self): """ creates all content to psyhvel folder """ #XXX Library folder if not hasattr(self, 'library'): library = Library('library') self._setObject(library.id, library) ob=getattr(self,library.id) ob.setTitle('Library') ob.reindexObject() #XXX Tests folder if not hasattr(self, 'tests'): tests = Tests('tests') self._setObject(tests.id, tests) ob=getattr(self,tests.id) ob.setTitle('Tests') ob.reindexObject() registerType(Psyhvel, PROJECT_NAME) class Library(OrderedBaseFolder, BaseFunctions): """ Psyhvel main folder containing testing stuff and all other stuff also""" meta_type = "Library" archetype_name = "Library" global_allow = 0 exclude_from_nav = False filter_content_types = True allowed_content_types = ('TestFolder',) # 'GameFolder' in test phase, to swich on add 'GameFolder' to list security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/library_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'visible':False, 'permissions': ('Manage Portal',), }, ) def manage_afterAdd(self,item,container): """sets permissions""" self.setupPermissionsHere() security.declareProtected('Manage Portal', 'setupPermissionsHere') def setupPermissionsHere(self): """permissions for library""" self.manage_permission('Add portal content', ('Manager','Owner','Editor') ,0) self.manage_permission('Modify portal content', ('Manager','Owner','Editor') ,0) def isImportable(self): """is exportable""" return True; registerType(Library, PROJECT_NAME) class Tests(OrderedBaseFolder, BaseFunctions): """ Psyhvel tests folder containing testing tests""" meta_type = "Tests" archetype_name = "Tests" global_allow = 0 exclude_from_nav = False filter_content_types = True allowed_content_types = ('Collection') security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/tests_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'visible':False, 'permissions': ('Manage Portal',), }, ) def manage_afterAdd(self,item,container): """sets permissions""" self.setupPermissionsHere() security.declareProtected('Manage Portal', 'setupPermissionsHere') def setupPermissionsHere(self): """permissions for library""" self.manage_permission('Add portal content', ('Manager','Owner','Editor') ,0) self.manage_permission('Modify portal content', ('Manager','Owner','Editor') ,0) def redirectToTest(self): """ redirects user to active test""" for test in self.objectValues('Collection'): if test.getActiveTest(): groupstool = getToolByName(self, 'portal_groups') member = self.REQUEST.AUTHENTICATED_USER for target in test.getTestTarget(): target2 = groupstool.getGroupById(target) target = str(target) for md in target2.getGroupMembers(): if md.id == str(member): return self.REQUEST.RESPONSE.redirect(test.absolute_url()) return False registerType(Tests, PROJECT_NAME)