blob: 2d52f3805c94ad9386dfd9eae9d897de0a7252e4 [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):
Rushabh Mehtabd9b62f2014-11-28 11:45:02 +053013 doc = frappe.get_doc("Issue", frappe.form_dict.name)
Rushabh Mehta3daa49a2014-10-21 16:16:30 +053014 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
Rushabh Mehtabd9b62f2014-11-28 11:45:02 +053029 doc = frappe.get_doc("Issue", ticket)
Rushabh Mehta3daa49a2014-10-21 16:16:30 +053030 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