<s> from __future__ import unicode_literals <EOL> import frappe <EOL> import frappe . defaults <EOL> from frappe . modules . import_file import get_file_path , read_doc_from_file <EOL> from frappe . translate import send_translations <EOL> from frappe . desk . notifications import delete_notification_count_for <EOL> from frappe . permissions import reset_perms , get_linked_doctypes <EOL> @ frappe . whitelist ( ) <EOL> def get_roles_and_doctypes ( ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> send_translations ( frappe . get_lang_dict ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> return { <EOL> "<STR_LIT>" : [ d [ <NUM_LIT:0> ] for d in frappe . db . sql ( """<STR_LIT>""" ) ] , <EOL> "<STR_LIT>" : [ d [ <NUM_LIT:0> ] for d in frappe . db . sql ( """<STR_LIT>""" ) ] <EOL> } <EOL> @ frappe . whitelist ( ) <EOL> def get_permissions ( doctype = None , role = None ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> out = frappe . db . sql ( """<STR_LIT>""" % <EOL> ( doctype and ( "<STR_LIT>" % frappe . db . escape ( doctype ) ) or "<STR_LIT>" , <EOL> role and ( ( doctype and "<STR_LIT>" or "<STR_LIT>" ) + "<STR_LIT>" % frappe . db . escape ( role ) ) or "<STR_LIT>" ) , <EOL> as_dict = True ) <EOL> linked_doctypes = { } <EOL> for d in out : <EOL> d . linked_doctypes = linked_doctypes . setdefault ( d . parent , get_linked_doctypes ( d . parent ) ) <EOL> return out <EOL> @ frappe . whitelist ( ) <EOL> def remove ( doctype , name ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> frappe . db . sql ( """<STR_LIT>""" , name ) <EOL> validate_and_reset ( doctype , for_remove = True ) <EOL> @ frappe . whitelist ( ) <EOL> def add ( parent , role , permlevel ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> frappe . get_doc ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : parent , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : role , <EOL> "<STR_LIT>" : permlevel , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } ) . save ( ) <EOL> validate_and_reset ( parent ) <EOL> @ frappe . whitelist ( ) <EOL> def update ( name , doctype , ptype , value = None ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> frappe . db . sql ( """<STR_LIT>""" % ( frappe . db . escape ( ptype ) , '<STR_LIT:%s>' , '<STR_LIT:%s>' ) , ( value , name ) ) <EOL> validate_and_reset ( doctype ) <EOL> def validate_and_reset ( doctype , for_remove = False ) : <EOL> from frappe . core . doctype . doctype . doctype import validate_permissions_for_doctype <EOL> validate_permissions_for_doctype ( doctype , for_remove ) <EOL> clear_doctype_cache ( doctype ) <EOL> @ frappe . whitelist ( ) <EOL> def reset ( doctype ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> reset_perms ( doctype ) <EOL> clear_doctype_cache ( doctype ) <EOL> def clear_doctype_cache ( doctype ) : <EOL> frappe . clear_cache ( doctype = doctype ) <EOL> delete_notification_count_for ( doctype ) <EOL> for user in frappe . db . sql_list ( """<STR_LIT>""" , doctype ) : <EOL> frappe . clear_cache ( user = user ) <EOL> @ frappe . whitelist ( ) <EOL> def get_users_with_role ( role ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> return [ p [ <NUM_LIT:0> ] for p in frappe . db . sql ( """<STR_LIT>""" , role ) ] <EOL> @ frappe . whitelist ( ) <EOL> def get_standard_permissions ( doctype ) : <EOL> frappe . only_for ( "<STR_LIT>" ) <EOL> module = frappe . db . get_value ( "<STR_LIT>" , doctype , "<STR_LIT>" ) <EOL> path = get_file_path ( module , "<STR_LIT>" , doctype ) <EOL> return read_doc_from_file ( path ) . get ( "<STR_LIT>" ) </s>
