2013-12-27 12:00:24 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-02-14 10:17:51 +00:00
|
|
|
import frappe
|
|
|
|
import frappe.permissions
|
|
|
|
import frappe.defaults
|
2013-12-27 12:00:24 +00:00
|
|
|
|
|
|
|
def execute():
|
2014-05-28 13:19:13 +00:00
|
|
|
frappe.reload_doc("core", "doctype", "docfield")
|
2014-05-10 16:46:39 +00:00
|
|
|
frappe.reload_doc("hr", "doctype", "employee")
|
2014-05-28 13:19:13 +00:00
|
|
|
|
|
|
|
set_print_email_permissions()
|
|
|
|
migrate_user_properties_to_user_permissions()
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.clear_cache()
|
2013-12-27 12:00:24 +00:00
|
|
|
|
2014-05-28 13:19:13 +00:00
|
|
|
def migrate_user_properties_to_user_permissions():
|
2014-02-26 07:05:33 +00:00
|
|
|
for d in frappe.db.sql("""select parent, defkey, defvalue from tabDefaultValue
|
2014-04-04 06:30:36 +00:00
|
|
|
where parent not in ('__global', '__default')""", as_dict=True):
|
2014-02-26 07:05:33 +00:00
|
|
|
df = frappe.db.sql("""select options from tabDocField
|
2013-12-27 12:00:24 +00:00
|
|
|
where fieldname=%s and fieldtype='Link'""", d.defkey, as_dict=True)
|
2014-05-28 13:19:13 +00:00
|
|
|
|
2013-12-27 12:00:24 +00:00
|
|
|
if df:
|
2014-02-26 07:05:33 +00:00
|
|
|
frappe.db.sql("""update tabDefaultValue
|
2014-05-27 03:09:35 +00:00
|
|
|
set defkey=%s, parenttype='User Permission'
|
2013-12-27 12:00:24 +00:00
|
|
|
where defkey=%s and
|
2014-04-04 06:30:36 +00:00
|
|
|
parent not in ('__global', '__default')""", (df[0].options, d.defkey))
|
2013-12-27 12:00:24 +00:00
|
|
|
|
2014-05-28 13:19:13 +00:00
|
|
|
def set_print_email_permissions():
|
|
|
|
# reset Page perms
|
|
|
|
from frappe.core.page.permission_manager.permission_manager import reset
|
|
|
|
reset("Page")
|
|
|
|
reset("Report")
|
2014-01-24 05:40:01 +00:00
|
|
|
|
2014-05-28 13:19:13 +00:00
|
|
|
if "allow_print" not in frappe.db.get_table_columns("DocType"):
|
|
|
|
return
|
|
|
|
|
|
|
|
# patch to move print, email into DocPerm
|
|
|
|
# NOTE: allow_print and allow_email are misnamed. They were used to hide print / hide email
|
|
|
|
for doctype, hide_print, hide_email in frappe.db.sql("""select name, ifnull(allow_print, 0), ifnull(allow_email, 0)
|
|
|
|
from `tabDocType` where ifnull(issingle, 0)=0 and ifnull(istable, 0)=0 and
|
|
|
|
(ifnull(allow_print, 0)=0 or ifnull(allow_email, 0)=0)"""):
|
2013-12-27 12:00:24 +00:00
|
|
|
|
2014-05-28 13:19:13 +00:00
|
|
|
if not hide_print:
|
|
|
|
frappe.db.sql("""update `tabDocPerm` set `print`=1
|
|
|
|
where permlevel=0 and `read`=1 and parent=%s""", doctype)
|
2013-12-27 12:00:24 +00:00
|
|
|
|
2014-05-28 13:19:13 +00:00
|
|
|
if not hide_email:
|
|
|
|
frappe.db.sql("""update `tabDocPerm` set `email`=1
|
|
|
|
where permlevel=0 and `read`=1 and parent=%s""", doctype)
|