Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions changedetectionio/conditions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def execute_ruleset_against_all_plugins(current_watch_uuid: str, application_dat
if not jsonLogic(logic=ruleset, data=EXECUTE_DATA, operations=CUSTOM_OPERATIONS):
result = False

return result

return {'executed_data': EXECUTE_DATA, 'result': result}

# Load plugins dynamically
for plugin in plugin_manager.get_plugins():
Expand Down
3 changes: 2 additions & 1 deletion changedetectionio/conditions/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def verify_condition_single_rule(watch_uuid):

return jsonify({
'status': 'success',
'result': result,
'result': result.get('result'),
'data': result.get('executed_data'),
'message': 'Condition passes' if result else 'Condition does not pass'
})

Expand Down
14 changes: 8 additions & 6 deletions changedetectionio/processors/text_json_diff/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,14 @@ def run_changedetection(self, watch):

# And check if 'conditions' will let this pass through
if watch.get('conditions') and watch.get('conditions_match_logic'):
if not execute_ruleset_against_all_plugins(current_watch_uuid=watch.get('uuid'),
application_datastruct=self.datastore.data,
ephemeral_data={
'text': stripped_text_from_html
}
):
conditions_result = execute_ruleset_against_all_plugins(current_watch_uuid=watch.get('uuid'),
application_datastruct=self.datastore.data,
ephemeral_data={
'text': stripped_text_from_html
}
)

if not conditions_result.get('result'):
# Conditions say "Condition not met" so we block it.
blocked = True

Expand Down
6 changes: 5 additions & 1 deletion changedetectionio/static/js/conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $(document).ready(function () {


// Create a rule object
const rule = {
let rule = {
field: field,
operator: operator,
value: value
Expand Down Expand Up @@ -96,6 +96,10 @@ $(document).ready(function () {
contentType: false, // Let the browser set the correct content type
success: function (response) {
if (response.status === "success") {
if(rule['field'] !== "page_filtered_text") {
// A little debug helper for the user
$('#verify-state-text').text(`${rule['field']} was value "${response.data[rule['field']]}"`)
}
if (response.result) {
alert("✅ Condition PASSES verification against current snapshot!");
} else {
Expand Down
4 changes: 2 additions & 2 deletions changedetectionio/templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ <h2 >Click here to Start</h2>
{{ render_field(form.conditions_match_logic) }}
{{ render_fieldlist_of_formfields_as_table(form.conditions) }}
<div class="pure-form-message-inline">
<br>
Use the verify (✓) button to test if a condition passes against the current snapshot.<br><br>

<p id="verify-state-text">Use the verify (✓) button to test if a condition passes against the current snapshot.</p>
Did you know that <strong>conditions</strong> can be extended with your own custom plugin? tutorials coming soon!<br>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion changedetectionio/tests/unit/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_conditions_execution_pass(self):
ephemeral_data={'text': "I saw 500 people at a rock show"})

# @todo - now we can test that 'Extract number' increased more than X since last time
self.assertTrue(result)
self.assertTrue(result.get('result'))


if __name__ == '__main__':
Expand Down