[fix] Use User Permission value as default only if the document type is Setup

This commit is contained in:
Anand Doshi 2015-09-14 13:00:24 +05:30
parent 3cfc9a598a
commit ffb8ef29ca
8 changed files with 22 additions and 23 deletions

View file

@ -503,13 +503,6 @@ frappe.PermissionEngine = Class.extend({
get_perm: function(name) {
return $.map(this.perm_list, function(d) { if(d.name==name) return d; })[0];
},
get_user_fields: function(doctype) {
var user_fields = frappe.get_children("DocType", doctype, "fields", {fieldtype:"Link", options:"User"})
user_fields = user_fields.concat(frappe.get_children("DocType", doctype, "fields",
{fieldtype:"Select", link_doctype:"User"}))
return user_fields
},
get_link_fields: function(doctype) {
return frappe.get_children("DocType", doctype, "fields",
{fieldtype:"Link", options:["not in", ["User", '[Select]']]});

View file

@ -33,6 +33,7 @@ class FormMeta(Meta):
def load_assets(self):
self.add_search_fields()
self.add_linked_document_type()
if not self.istable:
self.add_linked_with()
@ -49,7 +50,7 @@ class FormMeta(Meta):
d[k] = self.get(k)
for i, df in enumerate(d.get("fields")):
for k in ("link_doctype", "search_fields", "is_custom_field"):
for k in ("search_fields", "is_custom_field", "linked_document_type"):
df[k] = self.get("fields")[i].get(k)
return d
@ -120,6 +121,11 @@ class FormMeta(Meta):
if search_fields:
df.search_fields = map(lambda sf: sf.strip(), search_fields.split(","))
def add_linked_document_type(self):
for df in self.get("fields", {"fieldtype": "Link"}):
if df.options:
df.linked_document_type = frappe.get_meta(df.options).document_type
def add_linked_with(self):
"""add list of doctypes this doctype is 'linked' with.

View file

@ -8,6 +8,7 @@
"description": "**Currency** Master",
"docstatus": 0,
"doctype": "DocType",
"document_type": "Setup",
"fields": [
{
"allow_on_submit": 0,
@ -152,7 +153,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-09-07 15:51:26",
"modified": "2015-09-14 03:17:04.837607",
"modified_by": "Administrator",
"module": "Geo",
"name": "Currency",

View file

@ -65,8 +65,11 @@ def set_user_and_static_default_values(doc):
def get_user_default_value(df, defaults, user_permissions):
# don't set defaults for "User" link field using User Permissions!
if df.fieldtype == "Link" and df.options != "User":
# 1 - look in user permissions
if user_permissions_exist(df, user_permissions) and len(user_permissions[df.options])==1:
# 1 - look in user permissions only for document_type==Setup
# We don't want to include permissions of transactions to be used for defaults.
if (frappe.get_meta(df.options).document_type=="Setup"
and user_permissions_exist(df, user_permissions)
and len(user_permissions[df.options])==1):
return user_permissions[df.options][0]
# 2 - Look in user defaults

View file

@ -313,12 +313,6 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
if(this.only_input || this.df.label==this._label)
return;
// var icon = frappe.ui.form.fieldtype_icons[this.df.fieldtype];
// if(this.df.fieldtype==="Link") {
// icon = frappe.boot.doctype_icons[this.df.options];
// } else if(this.df.link_doctype) {
// icon = frappe.boot.doctype_icons[this.df.link_doctype];
// }
var icon = "";
this.label_span.innerHTML = (icon ? '<i class="'+icon+'"></i> ' : "") +
__(this.df.label) || "&nbsp;";

View file

@ -82,8 +82,10 @@ $.extend(frappe.model, {
// don't set defaults for "User" link field using User Permissions!
if (df.fieldtype==="Link" && df.options!=="User") {
// 1 - look in user permissions
if (has_user_permissions && user_permissions[df.options].length===1) {
// 1 - look in user permissions for document_type=="Setup".
// We don't want to include permissions of transactions to be used for defaults.
if (df.linked_document_type==="Setup"
&& has_user_permissions && user_permissions[df.options].length===1) {
return user_permissions[df.options][0];
}

View file

@ -7,7 +7,7 @@
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Master",
"document_type": "Setup",
"fields": [
{
"allow_on_submit": 0,
@ -643,7 +643,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-07-27 01:00:32.901851",
"modified": "2015-09-14 02:56:01.143058",
"modified_by": "Administrator",
"module": "Website",
"name": "Website Theme",

View file

@ -8,7 +8,7 @@
"description": "Defines workflow states and rules for a document.",
"docstatus": 0,
"doctype": "DocType",
"document_type": "Transaction",
"document_type": "Document",
"fields": [
{
"allow_on_submit": 0,
@ -199,7 +199,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-07-27 01:00:32.901851",
"modified": "2015-09-14 02:56:01.362929",
"modified_by": "Administrator",
"module": "Workflow",
"name": "Workflow",