Rushabh Mehta | 3daa49a | 2014-10-21 16:16:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import frappe |
| 6 | from frappe import _ |
| 7 | from frappe.utils import today |
| 8 | |
| 9 | no_cache = 1 |
| 10 | no_sitemap = 1 |
| 11 | |
| 12 | def get_context(context): |
Rushabh Mehta | bd9b62f | 2014-11-28 11:45:02 +0530 | [diff] [blame^] | 13 | doc = frappe.get_doc("Issue", frappe.form_dict.name) |
Rushabh Mehta | 3daa49a | 2014-10-21 16:16:30 +0530 | [diff] [blame] | 14 | if doc.raised_by == frappe.session.user: |
| 15 | ticket_context = { |
| 16 | "title": doc.name, |
| 17 | "doc": doc |
| 18 | } |
| 19 | else: |
| 20 | ticket_context = {"title": "Not Allowed", "doc": {}} |
| 21 | |
| 22 | return ticket_context |
| 23 | |
| 24 | @frappe.whitelist() |
| 25 | def add_reply(ticket, message): |
| 26 | if not message: |
| 27 | raise frappe.throw(_("Please write something")) |
| 28 | |
Rushabh Mehta | bd9b62f | 2014-11-28 11:45:02 +0530 | [diff] [blame^] | 29 | doc = frappe.get_doc("Issue", ticket) |
Rushabh Mehta | 3daa49a | 2014-10-21 16:16:30 +0530 | [diff] [blame] | 30 | if doc.raised_by != frappe.session.user: |
| 31 | raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError) |
| 32 | |
| 33 | comm = frappe.get_doc({ |
| 34 | "doctype":"Communication", |
| 35 | "subject": doc.subject, |
| 36 | "content": message, |
| 37 | "sender": doc.raised_by, |
| 38 | "sent_or_received": "Received" |
| 39 | }) |
| 40 | comm.insert(ignore_permissions=True) |
| 41 | |