-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
417 additions
and
16 deletions.
There are no files selected for viewing
Binary file modified
BIN
+29.1 KB
(120%)
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
BIN
+4.92 KB
(100%)
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.