Commit 80fc64b9 authored by Aurel's avatar Aurel

initial upload of archive tool


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16126 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ff86adcc
......@@ -50,7 +50,7 @@ from MethodObject import Method
from Products.ERP5Security.ERP5UserManager import SUPER_USER
import os, time, urllib, warnings
from zLOG import LOG, PROBLEM
from zLOG import LOG, PROBLEM, INFO
SECURITY_USING_NUX_USER_GROUPS, SECURITY_USING_PAS = range(2)
try:
......@@ -74,6 +74,9 @@ try:
except ImportError:
pass
from Persistence import Persistent
from Acquisition import Implicit
def getSecurityProduct(acl_users):
"""returns the security used by the user folder passed.
(NuxUserGroup, ERP5Security, or None if anything else).
......@@ -83,6 +86,7 @@ def getSecurityProduct(acl_users):
elif acl_users.meta_type == NUG_meta_type:
return SECURITY_USING_NUX_USER_GROUPS
class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
def __setattr__(self, name, value):
......@@ -187,6 +191,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
id = 'portal_catalog'
meta_type = 'ERP5 Catalog'
security = ClassSecurityInfo()
default_result_limit = 1000
manage_options = ( { 'label' : 'Overview', 'action' : 'manage_overview' },
......@@ -204,6 +209,29 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
, 'manage_schema' )
manage_schema = DTMLFile( 'dtml/manageSchema', globals() )
def getPreferredSQLCatalogId(self, id=None):
"""
Get the SQL Catalog from preference.
"""
if id is None:
# Check if we want to use an archive
#if getattr(aq_base(self.portal_preferences), 'uid', None) is not None:
archive_path = self.portal_preferences.getPreferredArchive(sql_catalog_id=self.default_sql_catalog_id)
if archive_path not in ('', None):
try:
archive = self.restrictedTraverse(archive_path)
except KeyError:
# Do not fail if archive object has been removed,
# but preference is not up to date
return None
if archive is not None:
catalog_id = archive.getCatalogId()
if catalog_id not in ('', None):
return catalog_id
return None
else:
return id
security.declareProtected( 'Import/Export objects', 'addDefaultSQLMethods' )
def addDefaultSQLMethods(self, config_id='erp5'):
"""
......@@ -401,7 +429,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
security.declarePublic( 'getAllowedRolesAndUsers' )
def getAllowedRolesAndUsers(self, **kw):
def getAllowedRolesAndUsers(self, sql_catalog_id=None, **kw):
"""
Return allowed roles and users.
......@@ -419,7 +447,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
user_is_superuser = (user_str == SUPER_USER)
allowedRolesAndUsers = self._listAllowedRolesAndUsers(user)
role_column_dict = {}
column_map = self.getSQLCatalog().getColumnMap()
column_map = self.getSQLCatalog(sql_catalog_id).getColumnMap()
# Patch for ERP5 by JP Smets in order
# to implement worklists and search of local roles
......@@ -464,7 +492,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
return allowedRolesAndUsers, role_column_dict
def getSecurityUidListAndRoleColumnDict(self, **kw):
def getSecurityUidListAndRoleColumnDict(self, sql_catalog_id=None, **kw):
"""
Return a list of security Uids and a dictionnary containing available
role columns.
......@@ -474,7 +502,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
catalogs.
"""
allowedRolesAndUsers, role_column_dict = self.getAllowedRolesAndUsers(**kw)
catalog = self.getSQLCatalog()
catalog = self.getSQLCatalog(sql_catalog_id)
method = getattr(catalog, catalog.sql_search_security, None)
if method is None:
raise DeprecationWarning, "The usage of allowedRolesAndUsers is "\
......@@ -501,7 +529,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
return security_uid_list, role_column_dict
security.declarePublic( 'getSecurityQuery' )
def getSecurityQuery(self, query=None, **kw):
def getSecurityQuery(self, query=None, sql_catalog_id=None, **kw):
"""
Build a query based on allowed roles or on a list of security_uid
values. The query takes into account the fact that some roles are
......@@ -509,10 +537,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
"""
original_query = query
try:
security_uid_list, role_column_dict = self.getSecurityUidListAndRoleColumnDict(**kw)
security_uid_list, role_column_dict = self.getSecurityUidListAndRoleColumnDict(sql_catalog_id=sql_catalog_id, **kw)
except DeprecationWarning, message:
warnings.warn(message, DeprecationWarning)
allowedRolesAndUsers, role_column_dict = self.getAllowedRolesAndUsers(**kw)
allowedRolesAndUsers, role_column_dict = self.getAllowedRolesAndUsers(sql_catalog_id=sql_catalog_id, **kw)
if role_column_dict:
query_list = []
for key, value in role_column_dict.items():
......@@ -557,9 +585,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
kw[ 'effective' ] = { 'query' : now, 'range' : 'max' }
kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
query = self.getSecurityQuery(query=query, **kw)
catalog_id = self.getPreferredSQLCatalogId(kw.pop("sql_catalog_id", None))
query = self.getSecurityQuery(query=query, sql_catalog_id=catalog_id, **kw)
kw.setdefault('limit', self.default_result_limit)
return ZCatalog.searchResults(self, query=query, **kw)
# get catalog from preference
#LOG("searchResult", INFO, catalog_id)
# LOG("searchResult", INFO, ZCatalog.searchResults(self, query=query, sql_catalog_id=catalog_id, src__=1, **kw))
return ZCatalog.searchResults(self, query=query, sql_catalog_id=catalog_id, **kw)
__call__ = searchResults
......@@ -609,10 +641,11 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# now = DateTime()
# #kw[ 'effective' ] = { 'query' : now, 'range' : 'max' }
# #kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
query = self.getSecurityQuery(query=query, **kw)
catalog_id = self.getPreferredSQLCatalogId(kw.pop("sql_catalog_id", None))
query = self.getSecurityQuery(query=query, sql_catalog_id=catalog_id, **kw)
kw.setdefault('limit', self.default_result_limit)
return ZCatalog.countResults(self, query=query, **kw)
# get catalog from preference
return ZCatalog.countResults(self, query=query, sql_catalog_id=catalog_id, **kw)
security.declarePrivate('unrestrictedCountResults')
def unrestrictedCountResults(self, REQUEST=None, **kw):
......@@ -824,4 +857,6 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
InitializeClass(CatalogTool)
##############################################################################
#
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
# Aurélien Calonne <aurel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import PropertySheet, Permissions, Interface
from Globals import InitializeClass
from Products.ERP5.Document.Predicate import Predicate
class Archive(Predicate):
"""
A Catalog Archive object
It defines the date of the archive and the catalog to use
"""
meta_type = 'ERP5 Archive'
portal_type = 'Archive'
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative interfaces
__implements__ = ( Interface.Predicate, )
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.Archive
)
isIndexable = 1
InitializeClass(Archive)
##############################################################################
#
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
# Aurélien Calonne <aurel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
class Archive:
"""
"""
_properties = (
{ 'id' : 'catalog_id',
'description' : 'The id of the catalog used by the archive',
'type' : 'string',
'mode' : 'w' },
{ 'id' : 'connection_id',
'description' : 'The id of the connection used by the archive',
'type' : 'string',
'mode' : 'w' },
{ 'id' : 'deferred_connection_id',
'description' : 'The id of the deferred connection used by the archive',
'type' : 'string',
'mode' : 'w' },
{ 'id' : 'priority',
'description' : 'Priority of activity use to index object into the archive',
'type' : 'int',
'mode' : 'w' ,
'default' : 5},
{ 'id' : 'stop_date',
'description' : 'The stop date at which we archive document',
'type' : 'date',
'range' : True,
'default' : None,
'mode' : 'w' },
{ 'id' : 'inventory_method_id',
'description' : 'The method that will be used to create inventory when creating archive',
'type' : 'string',
'mode' : 'w' },
)
#############################################################################
#
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
# Aurélien Calonne <aurel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
class CatalogPreference:
"""
This property sheet defines the user preference for catalog.
"""
_properties = (
{ 'id' : 'preferred_archive',
'description' : 'The archive the user want to use',
'type' : 'string',
'preference' : 1,
'mode' : '' },
)
This diff is collapsed.
......@@ -37,9 +37,11 @@ this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
from Tool import ArchiveTool
import CatalogTool
object_classes = ()
portal_tools = (CatalogTool.CatalogTool,)
portal_tools = (CatalogTool.CatalogTool,
ArchiveTool.ArchiveTool)
content_classes = ()
content_constructors = ()
......
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<h3> <code>portal_archives</code> Tool </h3>
<p> This tool is used to stored archives object which are predicate
that tells in which catalog an object must go.
</p>
<dtml-var manage_page_footer>
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment