Skip to content

Commit

Permalink
Merge cb9d181 into 2931ddc
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriyanshagro committed Jul 10, 2018
2 parents 2931ddc + cb9d181 commit dfb359e
Show file tree
Hide file tree
Showing 17 changed files with 536 additions and 18 deletions.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions docs/content_trigger.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.
This will allow them to create IFTTT applets to,
for example, email, tweet, or Facebook post about the content.

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

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

2. From actions menu select ``Add Ifttt Content 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_content_trigger/fill_form.png

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

.. image:: _static/images/add_ifttt_content_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
^^^^^^^^^^

1. Default Trigger condition for this content rule is: ``Workflow state changed``

2. Default contition for this content rule is: Workflow State as
``published``

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
- Description

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



4 changes: 2 additions & 2 deletions src/collective/ifttt/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

<browser:page
for="*"
name="add_ifttt_trigger"
class=".ifttt_trigger.AddRule"
name="ifttt_content_trigger"
class=".content_trigger.ContentTrigger"
permission="collective.ifttt.manageSettings"
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

from collective.ifttt import _
from collective.ifttt.actions.ifttt import PAYLOAD_DESCRIPTION
from collective.ifttt.utils import Rules
from plone import api
from plone.autoform.form import AutoExtensibleForm
from z3c.form import button
Expand All @@ -9,8 +11,13 @@
from zope.globalrequest import getRequest
from zope.interface import Interface

import logging

class AddRuleSchema(Interface):

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


class ContentTriggerSchema(Interface):
'''
Define schema for add rule form
'''
Expand All @@ -24,9 +31,10 @@ class AddRuleSchema(Interface):
)

content_types = schema.Tuple(
title=_(u'Restrict Content Types'),
title=_(u'Content Types'),
description=_(
u'Select certain content types which should be restricted'
u'Select certain content types which should be restricted '
u'to this event'
),
required=False,
missing_value=None,
Expand All @@ -37,9 +45,10 @@ class AddRuleSchema(Interface):
)

workflow_transitions = schema.Tuple(
title=_(u'Restrict Workflow Transitions'),
title=_(u'Workflow Transitions'),
description=_(
u'Select certain workflow transitions which should be restricted'
u' to this event'
),
required=False,
missing_value=None,
Expand All @@ -50,12 +59,12 @@ class AddRuleSchema(Interface):
)


class AddRule(AutoExtensibleForm, form.Form):
class ContentTrigger(AutoExtensibleForm, form.Form):
'''
Define Form
'''

schema = AddRuleSchema
schema = ContentTriggerSchema
ignoreContext = True
form_name = 'add_ifttt_rule'

Expand All @@ -67,7 +76,7 @@ def update(self):
self.request.set('disable_border', True)

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

@button.buttonAndHandler(_(u'Add'))
def handleApply(self, action):
Expand All @@ -78,6 +87,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
'''

data['payload'] = PAYLOAD_DESCRIPTION

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

Expand All @@ -86,15 +109,19 @@ def handleApply(self, action):
u'Successfully applied the IFTTT event '
u'${ifttt_event_name} to ${title}',
mapping=dict(
ifttt_event_name=data['ifttt_event_name'],
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
),
),
request=getRequest(),
type='info'
)

except TypeError:
except Exception as er:

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

# Redirect back to the front page with a status message

Expand All @@ -104,8 +131,10 @@ def handleApply(self, action):
type='info'
)

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

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

@button.buttonAndHandler(_(u'Cancel'))
def handleCancel(self, action):
Expand Down
4 changes: 2 additions & 2 deletions src/collective/ifttt/profiles/default/actions.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0"?>
<object name="portal_actions" meta_type="Plone Actions Tool"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<object name="object" meta_type="CMF Action Category">
<object name="object_buttons" meta_type="CMF Action Category">
<object name="Add IFTTT Content Trigger" meta_type="CMF Action" i18n:domain="collective.ifttt">
<property name="title" i18n:translate="">Add IFTTT Content Trigger</property>
<property name="description" i18n:translate="">Add new IFTTT Content Trigger</property>
<property name="url_expr">string:$object_url/@@add_ifttt_trigger</property>
<property name="url_expr">string:$object_url/@@ifttt_content_trigger</property>
<property name="icon_expr"></property>
<property name="available_expr">python:path('object/@@checkifttt').check_iftttconfig()</property>
<property name="permissions">
Expand Down
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>1004</version>
<version>1007</version>
<dependencies>
<!--<dependency>profile-plone.app.dexterity:default</dependency></dependencies>-->
</dependencies>
Expand Down
143 changes: 143 additions & 0 deletions src/collective/ifttt/tests/robot/test_content_trigger.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

# ============================================================================
# CONTENT TRIGGER ROBOT TESTS
# ============================================================================
#
# Run this robot test stand-alone:
#
# $ bin/test -s collective.ifttt -t test_content_trigger.robot --all
#
# Run this robot test with robot server (which is faster):
#
# 1) Start robot server:
#
# $ bin/robot-server --reload-path src collective.ifttt.testing.COLLECTIVE_IFTTT_ACCEPTANCE_TESTING
#
# 2) Run robot tests:
#
# $ bin/robot src/collective/ifttt/tests/robot/test_content_trigger.robot
#
# for debug mode
# $ bin/robot-debug src/collective/ifttt/tests/robot/test_content_trigger.robot

# See the http://docs.plone.org for further details (search for robot
# framework).
#
# ============================================================================

*** Settings ***

Resource plone/app/robotframework/selenium.robot
Resource plone/app/robotframework/keywords.robot
Resource Selenium2Screenshots/keywords.robot

Library Remote ${PLONE_URL}/RobotRemote
Library Selenium2Screenshots

Test Setup Test Setup
Test Teardown Close all browsers

*** Variables ***

${SELENIUM2LIBRARY_RUN_ON_FAILURE} Capture page screenshot
${SCREENSHOTS} false


*** Test Cases ***

Scenario: As a site administrator I cannot see Content Trigger actions form if secret key is not filled
Given I'm logged in as a Site Administrator
And I goto home page
Then I check the 'Add IFTTT Content Trigger' action menu item

Scenario: As a site administrator I can see Content Trigger actions form
Given I'm logged in as a Site Administrator
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

Scenario: As a site administrator I can configure Content Trigger action
Given I'm logged in as a Site Administrator
And I fill secret key
And I goto home page
And I trigger the 'Add IFTTT Content Trigger' action menu item
When I fill Content Trigger form
Then I see 'Successfully applied the IFTTT event test_event to Plone site' on success

*** Keywords ***

# --- Given ------------------------------------------------------------------

I'm logged in as a Site Administrator
Enable autologin as Site Administrator

I fill secret key
Goto ${PLONE_URL}/@@collectiveifttt-controlpanel
check 'IFTTT Settings' on pagecontent
input 'secret' into 'form.widgets.ifttt_secret_key' textinput
press 'Save' clickbutton
check 'Changes' on pagecontent

I goto home page
GOTO ${PLONE_URL}/

# --- WHEN -------------------------------------------------------------------

I check the 'Add IFTTT Content Trigger' action menu item
Element should not be visible xpath=//li[@id='plone-contentmenu-actions']/a

I trigger the '${action}' action menu item
Element should be visible xpath=//li[@id='plone-contentmenu-actions']/a
Click link xpath=//li[@id='plone-contentmenu-actions']/a
Wait until element is visible id=plone-contentmenu-actions-${action}
Click link id=plone-contentmenu-actions-${action}

I fill Content Trigger form
input 'test_event' into 'form-widgets-ifttt_event_name' textinput
select 'Collection' into 'form-widgets-content_types-from' selectbox
press 'from2toButton' clickbutton
select 'Event' into 'form-widgets-content_types-from' selectbox
press 'from2toButton' clickbutton
select 'File' into 'form-widgets-content_types-from' selectbox
press 'from2toButton' clickbutton
press 'form.buttons.add' clickbutton

# --- THEN -------------------------------------------------------------------

I see '${sucess_message}' on success
Page should contain ${sucess_message}

Test Setup
Open test browser
# Set Window Size 1280 720


# --- selenium library keywords -------------------------------------------------------------------

select '${select}' into '${id}' selectbox
Select from list by value id=${id} ${select}

press '${value}' clickbutton
Click button ${value}

input '${value}' into '${field}' textinput
Input text ${field} ${value}

press '${value}' into '${id}' clickoverlaybutton
Click button ${id} ${value}

check '${text}' on pagecontent
Wait until page contains ${text}

check element '${text}' on pagecsscontent
Wait until page contains element ${text}

check '${text}' on instantpage
Page should contain ${text}

check element '${text}' on instantpagecss
Page should contain element ${text}

sleep for '${duration}'
Sleep time_=${duration}
2 changes: 1 addition & 1 deletion src/collective/ifttt/tests/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.request = self.layer['request']
self.view = getMultiAdapter(
(self.layer['portal'], self.layer['request']),
name='add_ifttt_trigger'
name='ifttt_content_trigger'
)

def test_view(self):
Expand Down
Loading

0 comments on commit dfb359e

Please sign in to comment.