Event.py 6.45 KB
Newer Older
Jean-Paul Smets's avatar
Jean-Paul Smets committed
1 2 3
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
4
#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
Jean-Paul Smets's avatar
Jean-Paul Smets committed
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
#
# 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

Yusei Tahara's avatar
Yusei Tahara committed
31
from Products.ERP5Type import Permissions, PropertySheet
32
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
33
from Products.ERP5.Document.Movement import Movement
34
from Products.ERP5.Document.EmailDocument import EmailDocument
Jean-Paul Smets's avatar
Jean-Paul Smets committed
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
class AcknowledgeableMixin:
  """
  Mixin class for all documents that we can acknowledge
  """
  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)

  security.declareProtected(Permissions.AccessContentsInformation, 'acknowledge')
  def acknowledge(self, **kw):
    """
      Define what we want to do with acknowledgment.

      Possibilities :
        - do nothing
        - add an Acknowledge document every time someone read
          an event corresponding to this ticket
        - we could even think to move the workflow forward
          when all event have been acknowledge

      Is the name buildAcknowledgement better ???
    """
    method = self._getTypeBasedMethod('acknowledge')
    if method is not None:
      return method(**kw)
    return None

  def hasAcknowledgementActivity(self, user_name=None):
    """
    We will check if there is some current activities running or not
    """
    tag = "%s_%s" % (user_name, self.getRelativeUrl())
    result = False
    # First look at activities, we check if an acknowledgement document
    # is under reindexing
    if self.portal_activities.countMessageWithTag(tag):
      result = True
    return result

  security.declareProtected(Permissions.AccessContentsInformation, 'isAcknowledged')
  def isAcknowledged(self, user_name=None):
    """
    Say if this ticket is already acknowledged or not by this user.
    """
    result = self.hasAcknowledgementActivity(user_name=user_name)
    if not result:
      # Check in the catalog if we can find an acknowledgement
      person_value = self.ERP5Site_getAuthenticatedMemberPersonValue(
                          user_name=user_name)
      if len(self.portal_catalog(portal_type='Acknowledgement',
                causality_relative_url=self.getRelativeUrl(),
                destination_relative_url=person_value.getRelativeUrl())) > 0:
        result = True
    return result

Jérome Perrin's avatar
Jérome Perrin committed
91
class Event(Movement, EmailDocument, AcknowledgeableMixin):
Yusei Tahara's avatar
Yusei Tahara committed
92 93
  """
    Event is the base class for all events in ERP5.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
94

Yusei Tahara's avatar
Yusei Tahara committed
95
    Event objects include emails, phone calls,
Jean-Paul Smets's avatar
Jean-Paul Smets committed
96

Yusei Tahara's avatar
Yusei Tahara committed
97 98
    The purpose of an Event object is to keep track
    of the interface between the ERP and third parties.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
99

Yusei Tahara's avatar
Yusei Tahara committed
100 101
    Events have a start and stop date.
  """
Jean-Paul Smets's avatar
Jean-Paul Smets committed
102

Yusei Tahara's avatar
Yusei Tahara committed
103 104
  meta_type = 'ERP5 Event'
  portal_type = 'Event'
Jérome Perrin's avatar
Jérome Perrin committed
105
  # XXX this is hack so we can search event by delivery.start_date
106
  isDelivery = ConstantGetter('isDelivery', value=True)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
107

Yusei Tahara's avatar
Yusei Tahara committed
108 109 110
  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
111

Yusei Tahara's avatar
Yusei Tahara committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  # Declarative properties
  property_sheets = ( PropertySheet.Base
                    , PropertySheet.XMLObject
                    , PropertySheet.CategoryCore
                    , PropertySheet.Document
                    , PropertySheet.DublinCore
                    , PropertySheet.Task
                    , PropertySheet.Url
                    , PropertySheet.TextDocument
                    , PropertySheet.Arrow
                    , PropertySheet.Movement
                    , PropertySheet.Event
                    , PropertySheet.Delivery
                    , PropertySheet.ItemAggregation
                   )
127

Yusei Tahara's avatar
Yusei Tahara committed
128 129 130
  security.declareProtected(Permissions.AccessContentsInformation,
                            'isAccountable')
  def isAccountable(self):
Jérome Perrin's avatar
Jérome Perrin committed
131
    """Events are accountable 
Yusei Tahara's avatar
Yusei Tahara committed
132 133
    """
    return 1
134

Yusei Tahara's avatar
Yusei Tahara committed
135 136
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getQuantity')
137 138
  def getQuantity(self, default=1.):
    """Quantity is by default 1.0 on events.
Yusei Tahara's avatar
Yusei Tahara committed
139
    """
140
    return self._baseGetQuantity(default)
141

Yusei Tahara's avatar
Yusei Tahara committed
142 143 144 145 146 147 148 149 150 151
  security.declareProtected(Permissions.AccessContentsInformation,
                             'getExplanationValue')
  def getExplanationValue(self):
    """
      An event is it's own explanation
    """
    return self

  security.declareProtected(Permissions.UseMailhostServices, 'send')
  def send(self, from_url=None, to_url=None, reply_url=None, subject=None,
Yusei Tahara's avatar
Yusei Tahara committed
152 153
           body=None, attachment_format=None, attachment_list=None,
           download=False, **kw):
Yusei Tahara's avatar
Yusei Tahara committed
154 155 156 157 158 159 160 161 162 163 164
    """
      Make the send method overridable by typed based script
      so that special kinds of events can use a different gateway
      to send messages. This is useful for example to send
      faxes through fax server or to send letters by printing
      them to the printer or to send SMS through a custom 
      gateway. In the most usual case, sending will only consist
      in changing the destination.
    """
    send_script = self._getTypeBasedMethod('send')
    if send_script is None:
165 166
      raise NotImplementedError("`send` type based method not found. "
                                "Please update erp5_base and erp5_crm")
Yusei Tahara's avatar
Yusei Tahara committed
167
    return send_script(
Yusei Tahara's avatar
Yusei Tahara committed
168 169
        from_url, to_url, reply_url, subject, body, attachment_format, attachment_list,
        download, **kw
Yusei Tahara's avatar
Yusei Tahara committed
170
        )