Skip to content

Commit

Permalink
Merge 60d58f5 into cb9d181
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriyanshagro committed Jul 10, 2018
2 parents cb9d181 + 60d58f5 commit d0b5765
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 16 deletions.
Binary file modified docs/_static/images/add_ifttt_content_trigger/fill_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/images/add_ifttt_content_trigger/select_actions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/content_trigger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Content Trigger

This document will guide admins to
add an IFTTT "Content Trigger" to any folder on their site
that will send a trigger to IFTTT when content at or below the current path is published.
that will send a trigger to IFTTT when content at or
below the current path is published.
This will allow them to create IFTTT applets to,
for example, email, tweet, or Facebook post about the content.

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ so you can create more customized applets.
Configuring_Your_IFTTT_Secret_Key
Trigger_IFTTT_Action
content_trigger
user_trigger



66 changes: 66 additions & 0 deletions docs/user_trigger.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Content and User Trigger
========================

This document will guide admins to
add an IFTTT "Content and User Trigger" to any folder on their site
that will send a trigger to IFTTT when content at or below the
current path is edited, including the information of who changed it.
This will allow them to create IFTTT applets to, for example,
log the edit information to Slack or a Google spreadsheet.

Follow the steps given below to Add an IFTTT User Trigger onto any folder.

1. Traverse to folder on which you desire to apply IFTTT content trigger.

2. From actions menu select ``Add Ifttt User Trigger``

.. image:: _static/images/add_ifttt_content_trigger/select_actions.png

3. Fill the given form with required values and click ``Add``

.. image:: _static/images/add_ifttt_user_trigger/fill_form.png

4. Tada, trigger has been applied on your folder!!

.. image:: _static/images/add_ifttt_user_trigger/success.png


Behind the Scenes
-----------------

This section details all jobs performed behind the scenes
after form gets filled.

1. A new Content Rule is dynamically created and assigned with requested
conditions and IFTTT event name for this folder and it's sub-folder.

To know more about content rules, follow this
`link <https://docs.plone.org/working-with-content/managing-content/contentrules.html>`_.

2. ``Rules`` menu on left bar will show you all content rules applied on this folder.

.. image:: _static/images/add_ifttt_content_trigger/rule_tab.png


Default Settings
-----------------

Following are the default settings which are configured during
creation of content rule.

Conditions
^^^^^^^^^^

Default Trigger condition for this content rule is: ``Object Modified``


Data sent to IFTTT applet
^^^^^^^^^^^^^^^^^^^^^^^^^

In the data sent to IFTTT, following values will be dynamically included
(for which content on the site this content rule triggers):

- Title
- Absolute_url
- Username who modified the content

7 changes: 7 additions & 0 deletions src/collective/ifttt/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
permission="collective.ifttt.manageSettings"
/>

<browser:page
for="*"
name="ifttt_user_trigger"
class=".user_trigger.UserTrigger"
permission="collective.ifttt.manageSettings"
/>

</configure>


21 changes: 17 additions & 4 deletions src/collective/ifttt/browser/content_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collective.ifttt.utils import Rules
from plone import api
from plone.autoform.form import AutoExtensibleForm
from Products.CMFCore.interfaces._events import IActionSucceededEvent
from z3c.form import button
from z3c.form import form
from zope import schema
Expand Down Expand Up @@ -68,8 +69,12 @@ class ContentTrigger(AutoExtensibleForm, form.Form):
ignoreContext = True
form_name = 'add_ifttt_rule'

label = _(u'Add new IFTTT trigger')
description = _(u'This will add new IFTTT Trigger')
label = _(u'Add new Content Trigger')
description = _(
u'This will send a trigger to IFTTT '
u'when content at or below the current path is published, '
u'including the description of content'
)

def update(self):
# disable Plone's editable border
Expand All @@ -88,12 +93,20 @@ def handleApply(self, action):
try:
# all the backend magic goes here
'''
data should have keys
ifttt_event_name, content_types, workflow_transitions and payload
available keys for data
ifttt_event_name, content_types, workflow_transitions,
payload, workflow_states
and trigger event
'''

data['payload'] = PAYLOAD_DESCRIPTION

data['event'] = IActionSucceededEvent

data['workflow_states'] = [
'published',
]

rule = Rules(self.context, self.request)

rule.add_rule(data)
Expand Down
139 changes: 139 additions & 0 deletions src/collective/ifttt/browser/user_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*-

from collective.ifttt import _
from collective.ifttt.actions.ifttt import PAYLOAD_USERNAME
from collective.ifttt.utils import Rules
from plone import api
from plone.autoform.form import AutoExtensibleForm
from z3c.form import button
from z3c.form import form
from zope import schema
from zope.globalrequest import getRequest
from zope.interface import Interface
from zope.lifecycleevent.interfaces import IObjectModifiedEvent

import logging


logger = logging.getLogger('collective.ifttt')


class UserTriggerSchema(Interface):
'''
Define schema for add rule form
'''

ifttt_event_name = schema.TextLine(
title=_(u'IFTTT event name'),
description=_(
u'Give the name of IFTTT event which you want to trigger'
),
required=True,
)

content_types = schema.Tuple(
title=_(u'Content Types'),
description=_(
u'Select certain content types which should be restricted '
u'to this event'
),
required=False,
missing_value=None,
default=(),
value_type=schema.Choice(
vocabulary='plone.app.vocabularies.ReallyUserFriendlyTypes'
)
)


class UserTrigger(AutoExtensibleForm, form.Form):
'''
Define Form
'''

schema = UserTriggerSchema
ignoreContext = True
form_name = 'user_content_trigger'

label = _(u'Add new Content and User Trigger')
description = _(
u'This will send a trigger to IFTTT when content '
u'at or below the current path is edited, including '
u'the information of who changed it. '
)

def update(self):
# disable Plone's editable border
self.request.set('disable_border', True)

# call the base class version - this is very important!
super(UserTrigger, self).update()

@button.buttonAndHandler(_(u'Add'))
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return

try:
# all the backend magic goes here
'''
available keys for data
ifttt_event_name, content_types, workflow_transitions,
payload, workflow_states
and trigger event
'''

data['payload'] = PAYLOAD_USERNAME

data['event'] = IObjectModifiedEvent

rule = Rules(self.context, self.request)

rule.add_rule(data)

rule.configure_rule(data)

rule.apply_rule()

# Redirect back to the front page with a status message

api.portal.show_message(
message=_(
u'Successfully applied the IFTTT event '
u'${ifttt_event_name} to ${title}',
mapping=dict(
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
),
),
request=getRequest(),
type='info'
)

except Exception as er:

logger.exception(
u'Unexpected exception: {0:s}'.format(er),
) # noqa

# Redirect back to the front page with a status message

api.portal.show_message(
message=_(u'Error calling IFTTT Trigger'),
request=getRequest(),
type='info'
)

finally:

contextURL = self.context.absolute_url()
self.request.response.redirect(contextURL)

@button.buttonAndHandler(_(u'Cancel'))
def handleCancel(self, action):
"""User cancelled. Redirect back to the front page.
"""
contextURL = self.context.absolute_url()
self.request.response.redirect(contextURL)
12 changes: 12 additions & 0 deletions src/collective/ifttt/profiles/default/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@
</property>
<property name="visible">True</property>
</object>
<object name="Add IFTTT User Trigger" meta_type="CMF Action" i18n:domain="collective.ifttt">
<property name="title" i18n:translate="">Add IFTTT User Trigger</property>
<property name="description" i18n:translate="">Add new IFTTT User Trigger</property>
<property name="url_expr">string:$object_url/@@ifttt_user_trigger</property>
<property name="icon_expr"></property>
<property name="available_expr">python:path('object/@@checkifttt').check_iftttconfig()</property>
<property name="permissions">
<element value="Content rules: Manage rules"/>
<element value="Plone Site Setup: IFTTT"/>
</property>
<property name="visible">True</property>
</object>
</object>
</object>
2 changes: 1 addition & 1 deletion src/collective/ifttt/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1007</version>
<version>1008</version>
<dependencies>
<!--<dependency>profile-plone.app.dexterity:default</dependency></dependencies>-->
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Scenario: As a site administrator I can see Content Trigger actions form
And I fill secret key
And I goto home page
When I trigger the 'Add IFTTT Content Trigger' action menu item
Then check 'This will add new IFTTT Trigger' on pagecontent
Then check 'including the description of content' on pagecontent

Scenario: As a site administrator I can configure Content Trigger action
Given I'm logged in as a Site Administrator
Expand Down
Loading

0 comments on commit d0b5765

Please sign in to comment.