Permissions and other minor fixes for GSTversion-14
@@ -12,6 +12,7 @@ | |||||
"editable_grid": 0, | "editable_grid": 0, | ||||
"fields": [ | "fields": [ | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -41,11 +42,12 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
"columns": 0, | "columns": 0, | ||||
"description": "Name of person or organization that this address belongs to.", | |||||
"description": "", | |||||
"fieldname": "address_title", | "fieldname": "address_title", | ||||
"fieldtype": "Data", | "fieldtype": "Data", | ||||
"hidden": 0, | "hidden": 0, | ||||
@@ -70,6 +72,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -99,6 +102,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -127,6 +131,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -155,6 +160,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -183,6 +189,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -212,6 +219,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -240,6 +248,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -269,6 +278,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -297,6 +307,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -325,6 +336,7 @@ | |||||
"width": "50%" | "width": "50%" | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -353,6 +365,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -381,6 +394,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -409,6 +423,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -439,6 +454,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -469,6 +485,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -498,6 +515,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -528,6 +546,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -569,7 +588,7 @@ | |||||
"issingle": 0, | "issingle": 0, | ||||
"istable": 0, | "istable": 0, | ||||
"max_attachments": 0, | "max_attachments": 0, | ||||
"modified": "2017-04-10 13:09:45.030542", | |||||
"modified": "2017-06-21 11:30:20.719590", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Contacts", | "module": "Contacts", | ||||
"name": "Address", | "name": "Address", | ||||
@@ -13,6 +13,7 @@ | |||||
"engine": "InnoDB", | "engine": "InnoDB", | ||||
"fields": [ | "fields": [ | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -42,36 +43,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_on_submit": 0, | |||||
"bold": 0, | |||||
"collapsible": 0, | |||||
"columns": 0, | |||||
"fieldname": "salutation", | |||||
"fieldtype": "Link", | |||||
"hidden": 0, | |||||
"ignore_user_permissions": 0, | |||||
"ignore_xss_filter": 0, | |||||
"in_filter": 0, | |||||
"in_global_search": 0, | |||||
"in_list_view": 0, | |||||
"in_standard_filter": 0, | |||||
"label": "Salutation", | |||||
"length": 0, | |||||
"no_copy": 0, | |||||
"options": "Salutation", | |||||
"permlevel": 0, | |||||
"precision": "", | |||||
"print_hide": 0, | |||||
"print_hide_if_no_value": 0, | |||||
"read_only": 0, | |||||
"remember_last_selected_value": 0, | |||||
"report_hide": 0, | |||||
"reqd": 0, | |||||
"search_index": 0, | |||||
"set_only_once": 0, | |||||
"unique": 0 | |||||
}, | |||||
{ | |||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -102,6 +74,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 1, | "bold": 1, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -132,6 +105,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 1, | "bold": 1, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -163,6 +137,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -193,6 +168,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -220,6 +196,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -250,6 +227,38 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | |||||
"bold": 0, | |||||
"collapsible": 0, | |||||
"columns": 0, | |||||
"fieldname": "salutation", | |||||
"fieldtype": "Link", | |||||
"hidden": 0, | |||||
"ignore_user_permissions": 0, | |||||
"ignore_xss_filter": 0, | |||||
"in_filter": 0, | |||||
"in_global_search": 0, | |||||
"in_list_view": 0, | |||||
"in_standard_filter": 0, | |||||
"label": "Salutation", | |||||
"length": 0, | |||||
"no_copy": 0, | |||||
"options": "Salutation", | |||||
"permlevel": 0, | |||||
"precision": "", | |||||
"print_hide": 0, | |||||
"print_hide_if_no_value": 0, | |||||
"read_only": 0, | |||||
"remember_last_selected_value": 0, | |||||
"report_hide": 0, | |||||
"reqd": 0, | |||||
"search_index": 0, | |||||
"set_only_once": 0, | |||||
"unique": 0 | |||||
}, | |||||
{ | |||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -280,6 +289,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 1, | "bold": 1, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -310,6 +320,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 1, | "bold": 1, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -340,6 +351,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -369,6 +381,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -398,6 +411,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -430,6 +444,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -460,6 +475,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -489,6 +505,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -518,6 +535,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -547,6 +565,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -575,6 +594,7 @@ | |||||
"unique": 0 | "unique": 0 | ||||
}, | }, | ||||
{ | { | ||||
"allow_bulk_edit": 0, | |||||
"allow_on_submit": 0, | "allow_on_submit": 0, | ||||
"bold": 0, | "bold": 0, | ||||
"collapsible": 0, | "collapsible": 0, | ||||
@@ -615,7 +635,7 @@ | |||||
"issingle": 0, | "issingle": 0, | ||||
"istable": 0, | "istable": 0, | ||||
"max_attachments": 0, | "max_attachments": 0, | ||||
"modified": "2017-04-10 13:09:27.880530", | |||||
"modified": "2017-06-21 17:17:44.694188", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Contacts", | "module": "Contacts", | ||||
"name": "Contact", | "name": "Contact", | ||||
@@ -7,7 +7,9 @@ import frappe | |||||
from frappe.model.document import Document | from frappe.model.document import Document | ||||
class CustomRole(Document): | class CustomRole(Document): | ||||
pass | |||||
def validate(self): | |||||
if self.report and not self.ref_doctype: | |||||
self.ref_doctype = frappe.db.get_value('Report', self.report, 'ref_doctype') | |||||
def get_custom_allowed_roles(field, name): | def get_custom_allowed_roles(field, name): | ||||
allowed_roles = [] | allowed_roles = [] | ||||
@@ -623,10 +623,24 @@ def validate_permissions_for_doctype(doctype, for_remove=False): | |||||
for perm in doctype.get("permissions"): | for perm in doctype.get("permissions"): | ||||
perm.db_update() | perm.db_update() | ||||
clear_permissions_cache(doctype.name) | |||||
def clear_permissions_cache(doctype): | |||||
frappe.clear_cache(doctype=doctype) | |||||
delete_notification_count_for(doctype) | |||||
for user in frappe.db.sql_list("""select | |||||
distinct `tabHas Role`.parent | |||||
from | |||||
`tabHas Role`, | |||||
tabDocPerm | |||||
where tabDocPerm.parent = %s | |||||
and tabDocPerm.role = `tabHas Role`.role""", doctype): | |||||
frappe.clear_cache(user=user) | |||||
def validate_permissions(doctype, for_remove=False): | def validate_permissions(doctype, for_remove=False): | ||||
permissions = doctype.get("permissions") | permissions = doctype.get("permissions") | ||||
if not permissions: | if not permissions: | ||||
frappe.throw(_('Enter at least one permission row'), frappe.MandatoryError) | |||||
frappe.msgprint(_('No Permissions Specified'), alert=True, indicator='orange') | |||||
issingle = issubmittable = isimportable = False | issingle = issubmittable = isimportable = False | ||||
if doctype: | if doctype: | ||||
issingle = cint(doctype.issingle) | issingle = cint(doctype.issingle) | ||||
@@ -39,6 +39,7 @@ class Report(Document): | |||||
if self.report_type == "Report Builder": | if self.report_type == "Report Builder": | ||||
self.update_report_json() | self.update_report_json() | ||||
def before_insert(self): | |||||
self.set_doctype_roles() | self.set_doctype_roles() | ||||
def on_update(self): | def on_update(self): | ||||
@@ -48,11 +49,10 @@ class Report(Document): | |||||
delete_custom_role('report', self.name) | delete_custom_role('report', self.name) | ||||
def set_doctype_roles(self): | def set_doctype_roles(self): | ||||
if self.get('roles'): return | |||||
doc = frappe.get_meta(self.ref_doctype) | |||||
roles = [{'role': d.role} for d in doc.permissions if d.permlevel==0] | |||||
self.set('roles', roles) | |||||
if not self.get('roles'): | |||||
meta = frappe.get_meta(self.ref_doctype) | |||||
roles = [{'role': d.role} for d in meta.permissions if d.permlevel==0] | |||||
self.set('roles', roles) | |||||
def is_permitted(self): | def is_permitted(self): | ||||
"""Returns true if Has Role is not set or the user is allowed.""" | """Returns true if Has Role is not set or the user is allowed.""" | ||||
@@ -153,7 +153,7 @@ class Report(Document): | |||||
for c in columns] | for c in columns] | ||||
out = out + [list(d) for d in result] | out = out + [list(d) for d in result] | ||||
if as_dict: | if as_dict: | ||||
data = [] | data = [] | ||||
for row in out: | for row in out: | ||||
@@ -6,8 +6,10 @@ import frappe | |||||
import frappe.defaults | import frappe.defaults | ||||
from frappe.modules.import_file import get_file_path, read_doc_from_file | from frappe.modules.import_file import get_file_path, read_doc_from_file | ||||
from frappe.translate import send_translations | from frappe.translate import send_translations | ||||
from frappe.desk.notifications import delete_notification_count_for | |||||
from frappe.permissions import reset_perms, get_linked_doctypes, get_all_perms, setup_custom_perms | |||||
from frappe.permissions import (reset_perms, get_linked_doctypes, get_all_perms, | |||||
setup_custom_perms, add_permission) | |||||
from frappe.core.doctype.doctype.doctype import (clear_permissions_cache, | |||||
validate_permissions_for_doctype) | |||||
from frappe import _ | from frappe import _ | ||||
@frappe.whitelist() | @frappe.whitelist() | ||||
@@ -61,20 +63,7 @@ def get_permissions(doctype=None, role=None): | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def add(parent, role, permlevel): | def add(parent, role, permlevel): | ||||
frappe.only_for("System Manager") | frappe.only_for("System Manager") | ||||
setup_custom_perms(parent) | |||||
frappe.get_doc({ | |||||
"doctype":"Custom DocPerm", | |||||
"__islocal": 1, | |||||
"parent": parent, | |||||
"parenttype": "DocType", | |||||
"parentfield": "permissions", | |||||
"role": role, | |||||
"permlevel": permlevel, | |||||
"read": 1 | |||||
}).save() | |||||
validate_and_reset(parent) | |||||
add_permission(parent, role, permlevel) | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def update(doctype, role, permlevel, ptype, value=None): | def update(doctype, role, permlevel, ptype, value=None): | ||||
@@ -88,7 +77,7 @@ def update(doctype, role, permlevel, ptype, value=None): | |||||
frappe.db.sql("""update `tabCustom DocPerm` set `%s`=%s where name=%s"""\ | frappe.db.sql("""update `tabCustom DocPerm` set `%s`=%s where name=%s"""\ | ||||
% (frappe.db.escape(ptype), '%s', '%s'), (value, name)) | % (frappe.db.escape(ptype), '%s', '%s'), (value, name)) | ||||
validate_and_reset(doctype) | |||||
validate_permissions_for_doctype(doctype) | |||||
return out | return out | ||||
@@ -103,27 +92,14 @@ def remove(doctype, role, permlevel): | |||||
if not frappe.get_all('Custom DocPerm', dict(parent=doctype)): | if not frappe.get_all('Custom DocPerm', dict(parent=doctype)): | ||||
frappe.throw(_('There must be atleast one permission rule.'), title=_('Cannot Remove')) | frappe.throw(_('There must be atleast one permission rule.'), title=_('Cannot Remove')) | ||||
validate_and_reset(doctype, for_remove=True) | |||||
def validate_and_reset(doctype, for_remove=False): | |||||
from frappe.core.doctype.doctype.doctype import validate_permissions_for_doctype | |||||
validate_permissions_for_doctype(doctype, for_remove) | |||||
clear_doctype_cache(doctype) | |||||
validate_permissions_for_doctype(doctype, for_remove=True) | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def reset(doctype): | def reset(doctype): | ||||
frappe.only_for("System Manager") | frappe.only_for("System Manager") | ||||
reset_perms(doctype) | reset_perms(doctype) | ||||
clear_doctype_cache(doctype) | |||||
def clear_doctype_cache(doctype): | |||||
frappe.clear_cache(doctype=doctype) | |||||
delete_notification_count_for(doctype) | |||||
for user in frappe.db.sql_list("""select distinct `tabHas Role`.parent from `tabHas Role`, | |||||
tabDocPerm | |||||
where tabDocPerm.parent = %s | |||||
and tabDocPerm.role = `tabHas Role`.role""", doctype): | |||||
frappe.clear_cache(user=user) | |||||
clear_permissions_cache(doctype) | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def get_users_with_role(role): | def get_users_with_role(role): | ||||
@@ -1,3 +0,0 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# MIT License. See license.txt | |||||
@@ -73,7 +73,8 @@ class CustomField(Document): | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def get_fields_label(doctype=None): | def get_fields_label(doctype=None): | ||||
return [{"value": df.fieldname or "", "label": _(df.label or "")} for df in frappe.get_meta(doctype).get("fields")] | |||||
return [{"value": df.fieldname or "", "label": _(df.label or "")} | |||||
for df in frappe.get_meta(doctype).get("fields")] | |||||
def create_custom_field_if_values_exist(doctype, df): | def create_custom_field_if_values_exist(doctype, df): | ||||
df = frappe._dict(df) | df = frappe._dict(df) | ||||
@@ -86,6 +86,11 @@ def update_user_name(args): | |||||
first_name, last_name = first_name.split(' ', 1) | first_name, last_name = first_name.split(' ', 1) | ||||
if args.get("email"): | if args.get("email"): | ||||
if frappe.db.exists('User', args.get('email')): | |||||
# running again | |||||
return | |||||
args['name'] = args.get("email") | args['name'] = args.get("email") | ||||
_mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True | _mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True | ||||
@@ -9,6 +9,7 @@ import os, json | |||||
from frappe import _ | from frappe import _ | ||||
from frappe.modules import scrub, get_module_path | from frappe.modules import scrub, get_module_path | ||||
from frappe.utils import flt, cint, get_html_format, cstr | from frappe.utils import flt, cint, get_html_format, cstr | ||||
from frappe.model.utils import render_include | |||||
from frappe.translate import send_translations | from frappe.translate import send_translations | ||||
import frappe.desk.reportview | import frappe.desk.reportview | ||||
from frappe.permissions import get_role_permissions | from frappe.permissions import get_role_permissions | ||||
@@ -55,7 +56,7 @@ def get_script(report_name): | |||||
send_translations(frappe.get_lang_dict("report", report_name)) | send_translations(frappe.get_lang_dict("report", report_name)) | ||||
return { | return { | ||||
"script": script, | |||||
"script": render_include(script), | |||||
"html_format": html_format | "html_format": html_format | ||||
} | } | ||||
@@ -104,7 +105,7 @@ def run(report_name, filters=None, user=None): | |||||
if cint(report.add_total_row) and result: | if cint(report.add_total_row) and result: | ||||
result = add_total_row(result, columns) | result = add_total_row(result, columns) | ||||
return { | return { | ||||
"result": result, | "result": result, | ||||
"columns": columns, | "columns": columns, | ||||
@@ -145,7 +146,7 @@ def export_query(): | |||||
# add column headings | # add column headings | ||||
for idx in range(len(data.columns)): | for idx in range(len(data.columns)): | ||||
result[0].append(columns[idx]["label"]) | result[0].append(columns[idx]["label"]) | ||||
# build table from dict | # build table from dict | ||||
if isinstance(data.result[0], dict): | if isinstance(data.result[0], dict): | ||||
for i,row in enumerate(data.result): | for i,row in enumerate(data.result): | ||||
@@ -381,4 +382,4 @@ def get_user_match_filters(doctypes, ref_doctype): | |||||
if filter_list: | if filter_list: | ||||
match_filters[dt] = filter_list | match_filters[dt] = filter_list | ||||
return match_filters | |||||
return match_filters |
@@ -1,5 +1,6 @@ | |||||
// Copyright (c) 2016, Frappe Technologies and contributors | // Copyright (c) 2016, Frappe Technologies and contributors | ||||
// For license information, please see license.txt | // For license information, please see license.txt | ||||
/* eslint-disable */ | |||||
frappe.query_reports["ToDo"] = { | frappe.query_reports["ToDo"] = { | ||||
"filters": [ | "filters": [ |
@@ -7,9 +7,9 @@ | |||||
"doctype": "Report", | "doctype": "Report", | ||||
"idx": 3, | "idx": 3, | ||||
"is_standard": "Yes", | "is_standard": "Yes", | ||||
"modified": "2017-02-24 20:13:12.217943", | |||||
"modified": "2017-06-21 18:18:50.748793", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Core", | |||||
"module": "Desk", | |||||
"name": "ToDo", | "name": "ToDo", | ||||
"owner": "Administrator", | "owner": "Administrator", | ||||
"ref_doctype": "ToDo", | "ref_doctype": "ToDo", |
@@ -31,5 +31,4 @@ def execute(filters=None): | |||||
result.append([todo.name, todo.priority, todo.date, todo.description, | result.append([todo.name, todo.priority, todo.date, todo.description, | ||||
todo.owner, todo.assigned_by, todo.reference]) | todo.owner, todo.assigned_by, todo.reference]) | ||||
return columns, result | |||||
return columns, result |
@@ -4,7 +4,6 @@ | |||||
from __future__ import unicode_literals, print_function | from __future__ import unicode_literals, print_function | ||||
import frappe | import frappe | ||||
import time | import time | ||||
import redis | |||||
from frappe import _, msgprint | from frappe import _, msgprint | ||||
from frappe.utils import flt, cstr, now, get_datetime_str, file_lock | from frappe.utils import flt, cstr, now, get_datetime_str, file_lock | ||||
from frappe.utils.background_jobs import enqueue | from frappe.utils.background_jobs import enqueue | ||||
@@ -61,3 +61,20 @@ def render_include(content): | |||||
break | break | ||||
return content | return content | ||||
def get_fetch_values(doctype, fieldname, value): | |||||
'''Returns fetch value dict for the given object | |||||
:param doctype: Target doctype | |||||
:param fieldname: Link fieldname selected | |||||
:param value: Value selected | |||||
''' | |||||
out = {} | |||||
meta = frappe.get_meta(doctype) | |||||
link_df = meta.get_field(fieldname) | |||||
for df in meta.get_fields_to_fetch(fieldname): | |||||
# example shipping_address.gistin | |||||
link_field, source_fieldname = df.options.split('.', 1) | |||||
out[df.fieldname] = frappe.db.get_value(link_df.options, value, source_fieldname) | |||||
return out |
@@ -16,7 +16,7 @@ def get_user_settings(doctype, for_update=False): | |||||
if not for_update: | if not for_update: | ||||
update_user_settings(doctype, user_settings, True) | update_user_settings(doctype, user_settings, True) | ||||
return user_settings or '{}' | return user_settings or '{}' | ||||
def update_user_settings(doctype, user_settings, for_update=False): | def update_user_settings(doctype, user_settings, for_update=False): | ||||
@@ -34,7 +34,6 @@ def get_file_path(module, dt, dn): | |||||
def import_file_by_path(path, force=False, data_import=False, pre_process=None, ignore_version=None, | def import_file_by_path(path, force=False, data_import=False, pre_process=None, ignore_version=None, | ||||
reset_permissions=False): | reset_permissions=False): | ||||
frappe.flags.in_import = True | |||||
try: | try: | ||||
docs = read_doc_from_file(path) | docs = read_doc_from_file(path) | ||||
except IOError: | except IOError: | ||||
@@ -54,8 +53,10 @@ def import_file_by_path(path, force=False, data_import=False, pre_process=None, | |||||
original_modified = doc.get("modified") | original_modified = doc.get("modified") | ||||
frappe.flags.in_import = True | |||||
import_doc(doc, force=force, data_import=data_import, pre_process=pre_process, | import_doc(doc, force=force, data_import=data_import, pre_process=pre_process, | ||||
ignore_version=ignore_version, reset_permissions=reset_permissions) | ignore_version=ignore_version, reset_permissions=reset_permissions) | ||||
frappe.flags.in_import = False | |||||
if original_modified: | if original_modified: | ||||
# since there is a new timestamp on the file, update timestamp in | # since there is a new timestamp on the file, update timestamp in | ||||
@@ -67,7 +68,6 @@ def import_file_by_path(path, force=False, data_import=False, pre_process=None, | |||||
(doc['doctype'], '%s', '%s'), | (doc['doctype'], '%s', '%s'), | ||||
(original_modified, doc['name'])) | (original_modified, doc['name'])) | ||||
frappe.flags.in_import = False | |||||
return True | return True | ||||
def read_doc_from_file(path): | def read_doc_from_file(path): | ||||
@@ -183,4 +183,5 @@ frappe.patches.v8_0.set_currency_field_precision # 2017-05-09 | |||||
frappe.patches.v8_0.rename_print_to_printing | frappe.patches.v8_0.rename_print_to_printing | ||||
frappe.patches.v7_1.disabled_print_settings_for_custom_print_format | frappe.patches.v7_1.disabled_print_settings_for_custom_print_format | ||||
frappe.patches.v8_0.update_desktop_icons | frappe.patches.v8_0.update_desktop_icons | ||||
frappe.patches.v8_0.update_gender_and_salutation | |||||
frappe.patches.v8_0.update_gender_and_salutation | |||||
execute:frappe.db.sql('update tabReport set module="Desk" where name="ToDo"') |
@@ -330,7 +330,7 @@ def get_all_perms(role): | |||||
'''Returns valid permissions for a given role''' | '''Returns valid permissions for a given role''' | ||||
perms = frappe.get_all('DocPerm', fields='*', filters=dict(role=role)) | perms = frappe.get_all('DocPerm', fields='*', filters=dict(role=role)) | ||||
custom_perms = frappe.get_all('Custom DocPerm', fields='*', filters=dict(role=role)) | custom_perms = frappe.get_all('Custom DocPerm', fields='*', filters=dict(role=role)) | ||||
doctypes_with_custom_perms = frappe.db.sql_list("""select distinct parent | |||||
doctypes_with_custom_perms = frappe.db.sql_list("""select distinct parent | |||||
from `tabCustom DocPerm`""") | from `tabCustom DocPerm`""") | ||||
for p in perms: | for p in perms: | ||||
@@ -458,6 +458,31 @@ def setup_custom_perms(parent): | |||||
copy_perms(parent) | copy_perms(parent) | ||||
return True | return True | ||||
def add_permission(doctype, role, permlevel=0): | |||||
'''Add a new permission rule to the given doctype | |||||
for the given Role and Permission Level''' | |||||
from frappe.core.doctype.doctype.doctype import validate_permissions_for_doctype | |||||
setup_custom_perms(doctype) | |||||
if frappe.db.get_value('Custom DocPerm', dict(parent=doctype, role=role, | |||||
permlevel=permlevel)): | |||||
return | |||||
custom_docperm = frappe.get_doc({ | |||||
"doctype":"Custom DocPerm", | |||||
"__islocal": 1, | |||||
"parent": doctype, | |||||
"parenttype": "DocType", | |||||
"parentfield": "permissions", | |||||
"role": role, | |||||
'read': 1, | |||||
"permlevel": permlevel, | |||||
}) | |||||
custom_docperm.save() | |||||
validate_permissions_for_doctype(doctype) | |||||
def copy_perms(parent): | def copy_perms(parent): | ||||
'''Copy all DocPerm in to Custom DocPerm for the given document''' | '''Copy all DocPerm in to Custom DocPerm for the given document''' | ||||
for d in frappe.get_all('DocPerm', fields='*', filters=dict(parent=parent)): | for d in frappe.get_all('DocPerm', fields='*', filters=dict(parent=parent)): | ||||
@@ -480,3 +505,4 @@ def get_linked_doctypes(dt): | |||||
"options": ("!=", "[Select]") | "options": ("!=", "[Select]") | ||||
}) | }) | ||||
])) | ])) | ||||
@@ -223,6 +223,14 @@ h6.uppercase, | |||||
.badge-important { | .badge-important { | ||||
background-color: #e74c3c; | background-color: #e74c3c; | ||||
} | } | ||||
.address-box { | |||||
background-color: #fafbfc; | |||||
padding: 0px 15px; | |||||
margin: 15px 0px; | |||||
border: 1px solid #d1d8dd; | |||||
border-radius: 3px; | |||||
font-size: 12px; | |||||
} | |||||
.timeline { | .timeline { | ||||
margin: 30px 0px; | margin: 30px 0px; | ||||
} | } | ||||
@@ -272,7 +280,7 @@ h6.uppercase, | |||||
} | } | ||||
.timeline-item.user-content .media-body { | .timeline-item.user-content .media-body { | ||||
border: 1px solid #d1d8dd; | border: 1px solid #d1d8dd; | ||||
border-radius: 2px; | |||||
border-radius: 3px; | |||||
margin-left: -7px; | margin-left: -7px; | ||||
position: relative; | position: relative; | ||||
overflow: visible; | overflow: visible; | ||||
@@ -386,7 +394,7 @@ h6.uppercase, | |||||
.timeline-head { | .timeline-head { | ||||
background-color: white; | background-color: white; | ||||
border: 1px solid #d1d8dd; | border: 1px solid #d1d8dd; | ||||
border-radius: 2px; | |||||
border-radius: 3px; | |||||
position: relative; | position: relative; | ||||
z-index: 1; | z-index: 1; | ||||
} | } | ||||
@@ -218,12 +218,15 @@ $.extend(frappe.ui.toolbar, { | |||||
frappe.ui.toolbar.clear_cache = function() { | frappe.ui.toolbar.clear_cache = function() { | ||||
frappe.assets.clear_local_storage(); | frappe.assets.clear_local_storage(); | ||||
$c('frappe.sessions.clear',{},function(r,rt){ | |||||
if(!r.exc) { | |||||
frappe.show_alert(r.message); | |||||
location.reload(true); | |||||
frappe.call({ | |||||
method: 'frappe.sessions.clear', | |||||
callback: function(r) { | |||||
if(!r.exc) { | |||||
frappe.show_alert({message:r.message, indicator:'green'}); | |||||
location.reload(true); | |||||
} | |||||
} | } | ||||
}); | |||||
}) | |||||
return false; | return false; | ||||
} | } | ||||
@@ -293,6 +293,15 @@ h6.uppercase, .h6.uppercase { | |||||
background-color: #e74c3c; | background-color: #e74c3c; | ||||
} | } | ||||
.address-box { | |||||
background-color: @light-bg; | |||||
padding: 0px 15px; | |||||
margin: 15px 0px; | |||||
border: 1px solid @border-color; | |||||
border-radius: 3px; | |||||
font-size: 12px; | |||||
} | |||||
.timeline { | .timeline { | ||||
margin: 30px 0px; | margin: 30px 0px; | ||||
@@ -356,7 +365,7 @@ h6.uppercase, .h6.uppercase { | |||||
.media-body { | .media-body { | ||||
border: 1px solid @border-color; | border: 1px solid @border-color; | ||||
border-radius: 2px; | |||||
border-radius: 3px; | |||||
margin-left: -7px; | margin-left: -7px; | ||||
position: relative; | position: relative; | ||||
@@ -502,7 +511,7 @@ h6.uppercase, .h6.uppercase { | |||||
background-color: white; | background-color: white; | ||||
// padding: 15px 30px; | // padding: 15px 30px; | ||||
border: 1px solid @border-color; | border: 1px solid @border-color; | ||||
border-radius: 2px; | |||||
border-radius: 3px; | |||||
position: relative; | position: relative; | ||||
z-index: 1; | z-index: 1; | ||||