diff --git a/frappe/__init__.py b/frappe/__init__.py index a03f049e4a..dddc6f2a17 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -1042,7 +1042,7 @@ def compare(val1, condition, val2): def respond_as_web_page(title, html, success=None, http_status_code=None, context=None, indicator_color=None, primary_action='/', primary_label = None, fullpage=False, - width=None): + width=None, template='message'): """Send response as a web page with a message rather than JSON. Used to show permission errors etc. :param title: Page title and heading. @@ -1055,11 +1055,12 @@ def respond_as_web_page(title, html, success=None, http_status_code=None, :param primary_label: label on primary button (defaut is "Home") :param fullpage: hide header / footer :param width: Width of message in pixels + :param template: Optionally pass view template """ local.message_title = title local.message = html local.response['type'] = 'page' - local.response['route'] = 'message' + local.response['route'] = template if http_status_code: local.response['http_status_code'] = http_status_code diff --git a/frappe/workflow/doctype/workflow_action/workflow_action.py b/frappe/workflow/doctype/workflow_action/workflow_action.py index 0e2c203ff8..e95f25130d 100644 --- a/frappe/workflow/doctype/workflow_action/workflow_action.py +++ b/frappe/workflow/doctype/workflow_action/workflow_action.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe.utils.background_jobs import enqueue -from frappe.utils import get_url +from frappe.utils import get_url, get_datetime from frappe.utils.verified_command import get_signed_params, verify_request from frappe import _ from frappe.model.workflow import apply_workflow, get_workflow_name, \ @@ -55,7 +55,7 @@ def process_workflow_actions(doc, state): @frappe.whitelist(allow_guest=True) -def apply_action(action, doctype, docname, current_state, user): +def apply_action(action, doctype, docname, current_state, user, last_modified=None): if not verify_request(): return @@ -67,14 +67,28 @@ def apply_action(action, doctype, docname, current_state, user): doc_workflow_state = get_doc_workflow_state(doc) if doc_workflow_state == current_state: - newdoc = apply_workflow(doc, action) - frappe.db.commit() - frappe.respond_as_web_page(_("Success"), - _("{0}: {1} is set to state {2}".format( - doctype, - frappe.bold(newdoc.get('name')), - frappe.bold(get_doc_workflow_state(newdoc)) - )), indicator_color='green') + if not last_modified or get_datetime(doc.modified) == get_datetime(last_modified): + newdoc = apply_workflow(doc, action) + frappe.db.commit() + frappe.respond_as_web_page(_("Success"), + _("{0}: {1} is set to state {2}".format( + doctype, + frappe.bold(newdoc.get('name')), + frappe.bold(get_doc_workflow_state(newdoc)) + )), indicator_color='green') + else: + response_html_params = { + 'title': _("Document has been modified!"), + 'message': "Please review the document before approval", + 'print_format': frappe.get_print(doc.get('doctype'), doc.get('name')), + 'action': { + 'label': action, + 'link': get_workflow_action_url(action, doc, user) + } + } + frappe.respond_as_web_page(None, None, + template="modified_doc_alert", + context=response_html_params) else: frappe.respond_as_web_page(_("Link Expired"), _("Document {0} has been set to state {1} by {2}" @@ -161,7 +175,8 @@ def get_workflow_action_url(action, doc, user): "docname": doc.get('name'), "action": action, "current_state": get_doc_workflow_state(doc), - "user": user + "user": user, + "last_modified": doc.get('modified') } return get_url(apply_action_method + "?" + get_signed_params(params)) diff --git a/frappe/www/modified_doc_alert.html b/frappe/www/modified_doc_alert.html new file mode 100644 index 0000000000..7f01d307ad --- /dev/null +++ b/frappe/www/modified_doc_alert.html @@ -0,0 +1,19 @@ +{% extends "templates/web.html" %} +{% block page_content %} +