blob: 9582146cebc4c92660fc57ecceb6dc8ed2758cfd [file] [log] [blame]
Rushabh Mehta3daa49a2014-10-21 16:16:30 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import frappe
6from frappe import _
7from frappe.utils import today
8
9no_cache = 1
10no_sitemap = 1
11
12def get_context(context):
13 doc = frappe.get_doc("Support Ticket", frappe.form_dict.name)
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()
25def add_reply(ticket, message):
26 if not message:
27 raise frappe.throw(_("Please write something"))
28
29 doc = frappe.get_doc("Support Ticket", ticket)
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