def get_users_and_links(): webnotes.only_for(("System Manager", "Administrator")) links, all_fields = [], [] for l in webnotes.conn.sql("""select tabDocField.fieldname, tabDocField.options from tabDocField, tabDocType where tabDocField.fieldtype='Link' and tabDocField.parent = tabDocType.name and ifnull(tabDocType.istable,0)=0 and ifnull(tabDocType.issingle,0)=0 and tabDocField.parent not in ('[Select]', 'DocType', 'Module Def') """) + webnotes.conn.sql("""select fieldname, options from `tabCustom Field` where fieldtype='Link'"""): if not l[0] in all_fields: links.append([l[0], l[1]]) all_fields.append(l[0]) links.sort() return { "users": [d[0] for d in webnotes.conn.sql("""select name from tabProfile where ifnull(enabled,0)=1 and name not in ("Administrator", "Guest")""")], "link_fields": links }
def get_permissions(doctype=None, role=None): webnotes.only_for(("System Manager", "Administrator")) return webnotes.conn.sql("""select * from tabDocPerm where %s%s order by parent, permlevel, role""" % (\ doctype and (" parent='%s'" % doctype) or "", role and ((doctype and " and " or "") + " role='%s'" % role) or "", ), as_dict=True)
def get_users_and_links(): webnotes.only_for(("System Manager", "Administrator")) links, all_fields = [], [] for l in webnotes.conn.sql( """select tabDocField.fieldname, tabDocField.options from tabDocField, tabDocType where tabDocField.fieldtype='Link' and tabDocField.parent = tabDocType.name and ifnull(tabDocType.istable,0)=0 and ifnull(tabDocType.issingle,0)=0 and tabDocField.parent not in ('[Select]', 'DocType', 'Module Def') """) + webnotes.conn.sql("""select fieldname, options from `tabCustom Field` where fieldtype='Link'"""): if not l[0] in all_fields: links.append([l[0], l[1]]) all_fields.append(l[0]) links.sort() return { "users": [ d[0] for d in webnotes.conn.sql("""select name from tabProfile where ifnull(enabled,0)=1 and name not in ("Administrator", "Guest")""") ], "link_fields": links }
def get_users_with_role(role): webnotes.only_for(("System Manager", "Administrator")) return [p[0] for p in webnotes.conn.sql("""select distinct tabProfile.name from tabUserRole, tabProfile where tabUserRole.role=%s and tabProfile.name != "Administrator" and tabUserRole.parent = tabProfile.name and ifnull(tabProfile.enabled,0)=1""", role)]
def update(name, doctype, ptype, value=0): webnotes.only_for(("System Manager", "Administrator")) webnotes.conn.sql("""update tabDocPerm set `%s`=%s where name=%s"""\ % (ptype, '%s', '%s'), (value, name)) validate_and_reset(doctype) if ptype == "read" and webnotes.conn.get_value("DocPerm", name, "`match`"): webnotes.defaults.clear_cache()
def remove(doctype, name): webnotes.only_for(("System Manager", "Administrator")) match = webnotes.conn.get_value("DocPerm", name, "`match`") webnotes.conn.sql("""delete from tabDocPerm where name=%s""", name) validate_and_reset(doctype, for_remove=True) if match: webnotes.defaults.clear_cache()
def get_properties(user=None, key=None): webnotes.only_for(("System Manager", "Administrator")) return webnotes.conn.sql("""select name, parent, defkey, defvalue from tabDefaultValue where parent!='Control Panel' and substr(defkey,1,1)!='_' %s%s order by parent, defkey""" % (\ user and (" and parent='%s'" % user) or "", key and (" and defkey='%s'" % key) or ""), as_dict=True)
def get_roles_and_doctypes(): webnotes.only_for(("System Manager", "Administrator")) return { "doctypes": [d[0] for d in webnotes.conn.sql("""select name from `tabDocType` dt where ifnull(istable,0)=0 and name not in ('DocType', 'Control Panel') and exists(select * from `tabDocField` where parent=dt.name)""")], "roles": [d[0] for d in webnotes.conn.sql("""select name from tabRole where name not in ('Guest', 'Administrator')""")] }
def get_users_with_role(role): webnotes.only_for(("System Manager", "Administrator")) return [ p[0] for p in webnotes.conn.sql( """select distinct tabProfile.name from tabUserRole, tabProfile where tabUserRole.role=%s and tabProfile.name != "Administrator" and tabUserRole.parent = tabProfile.name and ifnull(tabProfile.enabled,0)=1""", role) ]
def get(): webnotes.only_for("System Manager") for item in items: if item.get("type") == "Section": continue set_count(item) if item.get("dependencies"): for d in item["dependencies"]: set_count(d) return items
def get(): webnotes.only_for("System Manager") for item in items: if item.get("type")=="Section": continue set_count(item) if item.get("dependencies"): for d in item["dependencies"]: set_count(d) return items
def add(parent, role, permlevel): webnotes.only_for(("System Manager", "Administrator")) webnotes.doc(fielddata={ "doctype":"DocPerm", "__islocal": 1, "parent": parent, "parenttype": "DocType", "parentfield": "permissions", "role": role, "permlevel": permlevel, "read": 1 }).save() validate_and_reset(parent)
def add(parent, role, permlevel): webnotes.only_for(("System Manager", "Administrator")) webnotes.doc( fielddata={ "doctype": "DocPerm", "__islocal": 1, "parent": parent, "parenttype": "DocType", "parentfield": "permissions", "role": role, "permlevel": permlevel, "read": 1 }).save() validate_and_reset(parent)
def get_roles_and_doctypes(): webnotes.only_for(("System Manager", "Administrator")) return { "doctypes": [ d[0] for d in webnotes.conn.sql( """select name from `tabDocType` dt where ifnull(istable,0)=0 and name not in ('DocType', 'Control Panel') and exists(select * from `tabDocField` where parent=dt.name)""") ], "roles": [ d[0] for d in webnotes.conn.sql( """select name from tabRole where name not in ('Guest', 'Administrator')""") ] }
def remove(user, name): webnotes.only_for(("System Manager", "Administrator")) webnotes.defaults.clear_default(name=name)
def reset(doctype): webnotes.only_for(("System Manager", "Administrator")) webnotes.reset_perms(doctype) clear_doctype_cache(doctype) webnotes.defaults.clear_cache()
def add(parent, defkey, defvalue): webnotes.only_for(("System Manager", "Administrator")) webnotes.defaults.add_user_default(defkey, defvalue, parent)
def update_match(name, doctype, match=""): webnotes.only_for(("System Manager", "Administrator")) webnotes.conn.sql("""update tabDocPerm set `match`=%s where name=%s""", (match, name)) validate_and_reset(doctype) webnotes.defaults.clear_cache()
def reset(doctype): webnotes.only_for("System Manager") webnotes.reset_perms(doctype) clear_doctype_cache(doctype)
def update(name, doctype, ptype, value=0): webnotes.only_for("System Manager") webnotes.conn.sql("""update tabDocPerm set `%s`=%s where name=%s"""\ % (ptype, '%s', '%s'), (value, name)) validate_and_reset(doctype)
def remove(doctype, name): webnotes.only_for("System Manager") webnotes.conn.sql("""delete from tabDocPerm where name=%s""", name) validate_and_reset(doctype, for_remove=True)