def is_watching(self):
     """
     Determine if the current user is watching this task or not.
     """
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     return watchers.isWatching()
示例#2
0
def mail_issue_add(object, event):
    """Send an email when a new issue is created
    """
    if object.modified() != object.created():
        return
    if object.getReviewState()['state'] == 'unconfirmed':
        watchers = IWatcherList(object)
        watchers.send('new-issue-mail')
示例#3
0
 def setTechnicians(self, technicians):
     """Set the list of technicians, and give them the
     Technician local role.
     """
     self._updateRolesField('technicians', technicians)
     #Customizando set do collective.watchers para enviar e-mails dos usuarios setados no campo "Técnicos do Gerenciador"
     watchers = IWatcherList(self, None)
     watchers._WatcherList__set_watchers(technicians)
示例#4
0
 def __call__(self):
     context = aq_inner(self.context)
     # Old style
     # context.toggleWatching()
     # New style
     watchers = IWatcherList(context)
     watchers.toggle_watching()
     self.request.RESPONSE.redirect(context.absolute_url())
def mail_i18n(object, event):
    """Send an i18n email when an object gets 'i18n' in the title.

    A bit silly perhaps, but this tests mails in a different encoding.
    """
    if 'i18n' in object.Title():
        watchers = IWatcherList(object)
        watchers.send('i18n-mail')
示例#6
0
def mail_issue_add(object, event):
    """Send an email when a new issue is created
    """
    if object.modified() != object.created():
        return
    if object.getReviewState()['state'] == 'unconfirmed':
        watchers = IWatcherList(object)
        watchers.send('new-issue-mail')
示例#7
0
 def setManagers(self, managers):
     """Set the list of tracker managers, and give them the
     TrackerManager local role.
     """
     self._updateRolesField('managers', managers)
     #Customizando set do collective.watchers para enviar e-mails dos usuarios setados no campo "Administradores do Gerenciador"
     watchers = IWatcherList(self, None)
     watchers._WatcherList__set_watchers(managers)
示例#8
0
 def __call__(self):
     context = aq_inner(self.context)
     # Old style
     # context.toggleWatching()
     # New style
     watchers = IWatcherList(context)
     watchers.toggle_watching()
     self.request.RESPONSE.redirect(context.absolute_url())
示例#9
0
文件: browser.py 项目: CGTIC/Plone_SP
 def __call__(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     email = self.request.form.get('email')
     if email:
         watchers.watchers.append(email)
     if self.request.form.get('toggle'):
         watchers.toggle_watching()
     # Return the rendered form.
     return self.index()
示例#10
0
 def __call__(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     email = self.request.form.get('email')
     if email:
         watchers.watchers.append(email)
     if self.request.form.get('toggle'):
         watchers.toggle_watching()
     # Return the rendered form.
     return self.index()
示例#11
0
def mail_issue_change(object, event):
    """Send an email when an issue is resolved
    """
    if event.new_state.id == 'resolved':
        watchers = IWatcherList(object)
        # Only mail the original poster, if available.
        address = object.getContactEmail()
        if address:
            watchers.send('resolved-issue-mail',
                          only_these_addresses=[address])
示例#12
0
def mail_issue_change(object, event):
    """Send an email when an issue is resolved
    """
    if event.new_state.id == 'resolved':
        watchers = IWatcherList(object)
        # Only mail the original poster, if available.
        address = object.getContactEmail()
        if address:
            watchers.send('resolved-issue-mail',
                          only_these_addresses=[address])
def set_task_initial_date(task, event):
    ''' This subscriber will set the initial date
        for the task and send email for the
        author and for the responsible for the task.
        And create a local role enable responsible to
        add tasks
    '''
    watchers = IWatcherList(task)
    watchers.toggle_watching()
    if task.responsible:
        watchers.watchers.append(task.responsible)
        task.manage_setLocalRoles(task.responsible, ['Manager'],)
    task.initial_date = date.today()
    send_task_notification_mail(task)
示例#14
0
 def is_watching(self):
     site_url = api.portal.get().absolute_url()
     referrer = self.request.environ.get('HTTP_REFERER')
     if referrer:
         if referrer.startswith(site_url + '/'):
             alsoProvides(self.request, IDisableCSRFProtection)
     else:
         origin = self.request.environ.get('HTTP_ORIGIN')
         if origin and origin == site_url:
             alsoProvides(self.request, IDisableCSRFProtection)
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     if watchers:
         return watchers.isWatching()
     return False
示例#15
0
def migrate_tracker_watchers(context):
    """Migrate tracker watchers.

    Watchers of a tracker were first stored in annotations, but should
    now be stored in a LinesField.
    """
    logger.info("Starting update of tracker watchers.")
    catalog = getToolByName(context, 'portal_catalog')
    tracker_brains = catalog.searchResults(
        portal_type=('PoiTracker', 'PoiPscTracker'))
    logger.info("Found %s PoiTrackers.", len(tracker_brains))
    for brain in tracker_brains:
        try:
            tracker = brain.getObject()
        except (AttributeError, KeyError):
            logger.warn("AttributeError or KeyError getting tracker object at "
                        "%s", brain.getURL())
            continue

        watchers = IWatcherList(tracker)
        # We would want to check watchers.__mapping, but that fails.
        # watchers._WatcherList__mapping would work, but it looks
        # suspicious to me.  So let's get the annotations.
        annotations = IAnnotations(tracker)
        mapping = annotations.get(watchers.ANNO_KEY, None)
        if not mapping:
            continue
        try:
            old_value = mapping['watchers']
        except KeyError:
            continue
        logger.info("Setting watchers of tracker at %s: %r",
                    tracker.absolute_url(), old_value)
        tracker.setWatchers(old_value)
        del mapping['watchers']
def added_response(claim, event):
    """Send message to people involved in the claim when it is created or
    modified.
    """
    ombudsoffice = aq_parent(claim)
    watchers = IWatcherList(claim)
    # clear the list of watchers to deal with any change
    watchers.watchers = []

    # add the email for the responsible area, if exists
    emails = ombudsoffice.get_emails_for_areas()
    email = emails.get(claim.area)
    if email:
        watchers.watchers.append(email)

    # add the email of the owner of the claim
    watchers.watchers.append(claim.email)

    watchers.send('claim-mail')
示例#17
0
    def test_add_claim(self):
        claim = api.content.create(self.office,
                                   'Claim',
                                   title='My claim',
                                   area='area1',
                                   email='*****@*****.**')

        watchers = IWatcherList(claim)
        self.assertEqual(len(watchers.watchers), 2)
        self.assertIn('*****@*****.**', watchers.watchers)
        self.assertIn('*****@*****.**', watchers.watchers)
示例#18
0
 def testGetAddressesOnNewResponse(self):
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=[u'member1', u'member3'],
                              assignee=u'member2')
     addresses = IWatcherList(issue).addresses
     self.assertEqual(len(addresses), 5)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
示例#19
0
 def testGetAddressesOnNewResponse(self):
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=('member2', 'member3'))
     addresses = IWatcherList(issue).addresses
     self.assertEqual(len(addresses), 4)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     # A mail is sent immediately on creation of this issue.
     self.assertEqual(len(self.portal.MailHost.messages), 4)
示例#20
0
 def testGetAddressesWithNotificationsOff(self):
     self.tracker.setSendNotificationEmails(False)
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=('member2', 'member3'))
     watcherlist = IWatcherList(issue)
     # We have two watchers directly on this issue, plus the submitter:
     watchers = watcherlist.watchers
     self.assertEqual(len(watchers), 3)
     # But since emails are not sent, we have zero addresses:
     addresses = watcherlist.addresses
     self.assertEqual(len(addresses), 0)
示例#21
0
def mail_issue_change(object, event):
    """Send an email on some transitions of an issue.

    Specifically: new issue and resolved issue.
    """
    if event.transition and event.transition.id == 'post':
        watchers = IWatcherList(object)
        watchers.send('new-issue-mail')
    elif event.new_state.id == 'resolved':
        watchers = IWatcherList(object)
        # Only mail the original poster, if available.
        address = object.getContactEmail()
        if address:
            watchers.send('resolved-issue-mail',
                          only_these_addresses=[address])
示例#22
0
 def testGetAddressesOnNewIssue(self):
     self.tracker.mailing_list = None
     assignees = self.tracker.assignees
     self.assertEqual(len(assignees), 2)
     self.failUnless('member1' in assignees)
     self.failUnless('member2' in assignees)
     # issue creator should be a watcher
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=None,
                              assignee=u'member2')
     addresses = IWatcherList(issue).addresses
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
示例#23
0
    def test_modify_claim(self):
        claim = api.content.create(self.office,
                                   'Claim',
                                   title='My claim',
                                   area='area1',
                                   email='*****@*****.**')

        claim.email = '*****@*****.**'
        notify(ObjectModifiedEvent(claim))

        watchers = IWatcherList(claim)
        self.assertEqual(len(watchers.watchers), 2)
        self.assertIn('*****@*****.**', watchers.watchers)
        self.assertNotIn('*****@*****.**', watchers.watchers)
        self.assertIn('*****@*****.**', watchers.watchers)
示例#24
0
 def testGetAddressesOnNewResponseWithList(self):
     self.tracker.mailing_list = '*****@*****.**'
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=[u'member1', u'member3'],
                              assignee=u'member2')
     addresses = IWatcherList(issue).addresses
     self.assertEqual(len(addresses), 5)
     # mailing list:
     self.failUnless('*****@*****.**' in addresses)
     # submitter:
     self.failUnless('*****@*****.**' in addresses)
     # tracker assignee:
     self.failUnless('*****@*****.**' in addresses)
     # direct subscribers:
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
示例#25
0
 def testGetAddressesOnNewResponseWithList(self):
     self.tracker.setMailingList('*****@*****.**')
     issue = self.createIssue(self.tracker,
                              contactEmail='*****@*****.**',
                              watchers=('member2', 'member3'))
     addresses = IWatcherList(issue).addresses
     self.assertEqual(len(addresses), 5)
     # mailing list:
     self.failUnless('*****@*****.**' in addresses)
     # submitter:
     self.failUnless('*****@*****.**' in addresses)
     # tracker manager:
     self.failUnless('*****@*****.**' in addresses)
     # direct subscribers:
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)
     # A mail is sent immediately on creation of this issue.
     self.assertEqual(len(self.portal.MailHost.messages), 5)
示例#26
0
    def addresses(self):
        """
        Upon activity for the given issue, get the list of email
        addresses to which notifications should be sent. May return an
        empty list if notification is turned off. If issue is given, the
        issue poster and any watchers will also be included.

        Taken from PoiTracker.

        Note that we currently return only email addresses, without
        any full names.  That is what Poi has been doing, and it makes
        a few things simpler.
        """
        if not self.send_emails:
            return ()

        # make sure no duplicates are added
        addresses = sets.Set()

        context = aq_inner(self.context)
        memship = getToolByName(context, 'portal_membership', None)
        if memship is None:
            # Okay, either we are in a simple unit test, or someone is
            # using this package outside of CMF/Plone.  We should
            # assume the watchers are simple email addresses.
            addresses.union_update(self.watchers)
        else:
            addresses.union_update([get_member_email(w, memship)
                                    for w in self.watchers])
        addresses.union_update(self.extra_addresses)

        # Discard invalid addresses:
        addresses.discard(None)
        # Discard current user:
        email = get_member_email()
        addresses.discard(email)

        if self.allow_recursive:
            # Get addresses from parent (might be recursive).
            parent_list = IWatcherList(aq_parent(context), None)
            if parent_list is not None:
                addresses.union_update(parent_list.addresses)

        return tuple(addresses)
示例#27
0
def mail_issue_change(object, event):
    """Send an email on some transitions of an issue.

    Specifically: new issue and resolved issue.
    """
    if event.transition and event.transition.id == 'post':
        watchers = IWatcherList(object)
        watchers.send('new-issue-mail')
    elif event.new_state.id == 'resolved':
        watchers = IWatcherList(object)
        # Only mail the original poster, if available.
        address = object.getContactEmail()
        if address:
            watchers.send('resolved-issue-mail',
                          only_these_addresses=[address])
示例#28
0
    def __get_send_emails(self):
        """Should emails be sent?

        The parent of the context may have a setting for this.  In the
        context we may or may not wish to override this.  For example,
        in the case of Poi we only set this on the tracker, not on
        individual issues.
        """
        setting = self.__mapping.get('send_emails', _marker)
        if setting is not _marker:
            # We have an explicit setting.
            return setting
        # The context has no explicit setting, so we ask the parent.
        context = aq_inner(self.context)
        parent_list = IWatcherList(aq_parent(context), None)
        if parent_list is not None:
            return parent_list.send_emails

        # No explicit setting, so we fall back to the default: yes, we
        # send emails.
        return True
示例#29
0
 def __call__(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     return '\n'.join(watchers.addresses)
 def render(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     watchers.toggle_watching()
     self.request.RESPONSE.redirect(context.absolute_url())
def send_closed_task_mail(task):
    watchers = IWatcherList(task)
    watchers.send('closed-task-mail')
def send_task_notification_mail(task):
    watchers = IWatcherList(task)
    watchers.send('new-task-mail')
def send_response_notification_mail(task):
    watchers = IWatcherList(task)
    watchers.send('new-response-mail')
示例#34
0
 def testGetAddressesOnNewIssueWithList(self):
     self.tracker.setMailingList('*****@*****.**')
     addresses = IWatcherList(self.tracker).addresses
     # Addresses are the mailing list and the tracker managers.
     self.assertEqual(len(addresses), 3)
     self.failUnless('*****@*****.**' in addresses)
示例#35
0
def sendResponseNotificationMail(issue):
    # As we take the last response by default, we can keep this simple.
    watchers = IWatcherList(issue)
    watchers.send('new-response-mail')
示例#36
0
 def is_watching(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     return watchers.isWatching()
def mail_news(object, event):
    """Send an email when a news item is published.
    """
    if event.new_state.id == 'published':
        watchers = IWatcherList(object)
        watchers.send('newsitem-mail')
示例#38
0
 def testGetAddressesOnNewIssueWithList(self):
     self.tracker.mailing_list = '*****@*****.**'
     addresses = IWatcherList(self.tracker).addresses
     # Addresses are the mailing list and the tracker assignees.
     self.assertEqual(len(addresses), 1)
     self.failUnless('*****@*****.**' in addresses)
示例#39
0
文件: browser.py 项目: CGTIC/Plone_SP
 def is_watching(self):
     context = aq_inner(self.context)
     watchers = IWatcherList(context)
     return watchers.isWatching()
示例#40
0
def sendResponseNotificationMail(issue):
    # As we take the last response by default, we can keep this simple.
    watchers = IWatcherList(issue)
    watchers.send('new-response-mail')
示例#41
0
 def testGetAddressesOnNewIssue(self):
     addresses = IWatcherList(self.tracker).addresses
     self.assertEqual(len(addresses), 2)
     self.failUnless('*****@*****.**' in addresses)
     self.failUnless('*****@*****.**' in addresses)