@@ -102,21 +102,12 @@ def set_lead_and_contact(d): | |||||
email_addr = email.utils.parseaddr(d.sender) | email_addr = email.utils.parseaddr(d.sender) | ||||
# set contact | # set contact | ||||
if not d.contact: | if not d.contact: | ||||
d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]}, "name") or None | |||||
d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]}, | |||||
"name") or None | |||||
if not d.lead: | if not d.lead: | ||||
d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]}, "name") or None | |||||
if not (d.lead or d.contact): | |||||
d.lead = make_lead(d, email_addr[0], email_addr[1]) | |||||
def make_lead(d, real_name, email_id): | |||||
lead = webnotes.doc("Lead") | |||||
lead.lead_name = real_name or email_id | |||||
lead.email_id = email_id | |||||
lead.source = "Email" | |||||
lead.save(1) | |||||
return lead.name | |||||
d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]}, | |||||
"name") or None | |||||
class DocType(): | class DocType(): | ||||
def __init__(self, doc, doclist=[]): | def __init__(self, doc, doclist=[]): | ||||
@@ -53,10 +53,6 @@ class CustomDocType(DocType): | |||||
''' | ''' | ||||
#================================================================================= | |||||
# execute a script with a lot of globals - deprecated | |||||
#================================================================================= | |||||
def execute(code, doc=None, doclist=[]): | def execute(code, doc=None, doclist=[]): | ||||
""" | """ | ||||
Execute the code, if doc is given, then return the instance of the `DocType` class created | Execute the code, if doc is given, then return the instance of the `DocType` class created | ||||
@@ -91,10 +87,6 @@ def execute(code, doc=None, doclist=[]): | |||||
if locals().get('out'): | if locals().get('out'): | ||||
return out | return out | ||||
#================================================================================= | |||||
# load the DocType class from module & return an instance | |||||
#================================================================================= | |||||
def get_custom_script(doctype, script_type): | def get_custom_script(doctype, script_type): | ||||
""" | """ | ||||
Returns custom script if set in doctype `Custom Script` | Returns custom script if set in doctype `Custom Script` | ||||
@@ -148,10 +140,6 @@ def get_server_obj(doc, doclist = [], basedoctype = ''): | |||||
else: | else: | ||||
return DocType(doc, doclist) | return DocType(doc, doclist) | ||||
#================================================================================= | |||||
# get object (from dt and/or dn or doclist) | |||||
#================================================================================= | |||||
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0): | def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0): | ||||
""" | """ | ||||
Returns the instantiated `DocType` object. Here you can pass the DocType and name (ID) to get the object. | Returns the instantiated `DocType` object. Here you can pass the DocType and name (ID) to get the object. | ||||
@@ -163,17 +151,13 @@ def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0): | |||||
if not dn: | if not dn: | ||||
dn = dt | dn = dt | ||||
if with_children: | if with_children: | ||||
doclist = webnotes.model.doc.get(dt, dn, from_get_obj=1) | |||||
doclist = webnotes.model.doc.get(dt, dn, from_controller=1) | |||||
else: | else: | ||||
doclist = webnotes.model.doc.get(dt, dn, with_children = 0, from_get_obj=1) | |||||
doclist = webnotes.model.doc.get(dt, dn, with_children = 0, from_controller=1) | |||||
return get_server_obj(doclist[0], doclist) | return get_server_obj(doclist[0], doclist) | ||||
else: | else: | ||||
return get_server_obj(doc, doclist) | return get_server_obj(doc, doclist) | ||||
#================================================================================= | |||||
# get object and run method | |||||
#================================================================================= | |||||
def run_server_obj(server_obj, method_name, arg=None): | def run_server_obj(server_obj, method_name, arg=None): | ||||
""" | """ | ||||
Executes a method (`method_name`) from the given object (`server_obj`) | Executes a method (`method_name`) from the given object (`server_obj`) | ||||
@@ -186,17 +170,6 @@ def run_server_obj(server_obj, method_name, arg=None): | |||||
else: | else: | ||||
raise Exception, 'No method %s' % method_name | raise Exception, 'No method %s' % method_name | ||||
#================================================================================= | |||||
# deprecated methods to keep v160 apps happy | |||||
#================================================================================= | |||||
def updatedb(doctype, userfields = [], args = {}): | |||||
pass | |||||
def check_syntax(code): | |||||
return '' | |||||
#=================================================================================== | |||||
def get_code(module, dt, dn, extn, fieldname=None): | def get_code(module, dt, dn, extn, fieldname=None): | ||||
from webnotes.modules import scrub, get_module_path | from webnotes.modules import scrub, get_module_path | ||||
import os, webnotes | import os, webnotes | ||||
@@ -670,12 +670,7 @@ def get_report_builder_code(doc): | |||||
doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js') | doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js') | ||||
doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql') | doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql') | ||||
# called from everywhere | |||||
# load a record and its child records and bundle it in a list - doclist | |||||
# --------------------------------------------------------------------- | |||||
def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'): | |||||
def get(dt, dn='', with_children = 1, from_controller = 0, prefix = 'tab'): | |||||
""" | """ | ||||
Returns a doclist containing the main record and all child records | Returns a doclist containing the main record and all child records | ||||
""" | """ | ||||
@@ -688,14 +683,8 @@ def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'): | |||||
# load the main doc | # load the main doc | ||||
doc = Document(dt, dn, prefix=prefix) | doc = Document(dt, dn, prefix=prefix) | ||||
# check permission - for doctypes, pages | |||||
if (dt in ('DocType', 'Page', 'Control Panel', 'Search Criteria')) or (from_get_obj and webnotes.session.get('user') != 'Guest'): | |||||
if dt=='Page' and webnotes.session['user'] == 'Guest': | |||||
check_page_perm(doc) | |||||
else: | |||||
if not webnotes.has_permission(dt, "read", doc): | |||||
webnotes.response['403'] = 1 | |||||
raise webnotes.ValidationError, '[WNF] No read permission for %s %s' % (dt, dn) | |||||
if dt=='Page' and webnotes.session['user'] == 'Guest': | |||||
check_page_perm(doc) | |||||
if not with_children: | if not with_children: | ||||
# done | # done | ||||
@@ -710,7 +699,7 @@ def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'): | |||||
doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix) | doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix) | ||||
# import report_builder code | # import report_builder code | ||||
if not from_get_obj: | |||||
if not from_controller: | |||||
get_report_builder_code(doc) | get_report_builder_code(doc) | ||||
return doclist | return doclist | ||||
@@ -240,6 +240,9 @@ class ModelWrapper: | |||||
self.doc.fields["__islocal"] = 1 | self.doc.fields["__islocal"] = 1 | ||||
return self.save() | return self.save() | ||||
def has_read_perm(self): | |||||
return webnotes.has_permission(self.doc.doctype, "read", self.doc) | |||||
def save(self, check_links=1): | def save(self, check_links=1): | ||||
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | ||||
self.prepare_for_save(check_links) | self.prepare_for_save(check_links) | ||||
@@ -22,6 +22,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import webnotes | import webnotes | ||||
from webnotes import _ | |||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def runserverobj(): | def runserverobj(): | ||||
@@ -45,6 +46,8 @@ def runserverobj(): | |||||
else: | else: | ||||
wrapper = ModelWrapper() | wrapper = ModelWrapper() | ||||
wrapper.from_compressed(webnotes.form_dict.get('docs'), dn) | wrapper.from_compressed(webnotes.form_dict.get('docs'), dn) | ||||
if not wrapper.has_read_perm(): | |||||
webnotes.msgprint(_("No Permission"), raise_exception = True) | |||||
so = wrapper.make_obj() | so = wrapper.make_obj() | ||||
wrapper.check_if_latest() | wrapper.check_if_latest() | ||||