Esempio n. 1
0
def get_highest_role(user):
	# return highest role of user
	from frappe.utils.user import get_roles
	usr_roles = [role for role in get_roles(user)]
	
	highest_role = None
	query = "SELECT role, priority FROM `tabRole Priority` ORDER BY priority DESC"
	records = frappe.db.sql(query, as_dict=True)
	for rec in records:
		if rec.get("role") in usr_roles:
			return rec.get("role")

	if not highest_role:
		frappe.throw("You can not assign Ticket to any other user")
Esempio n. 2
0
def get_highest_role(user):
    # return highest role of user
    from frappe.utils.user import get_roles
    usr_roles = [role for role in get_roles(user)]

    highest_role = None
    query = "SELECT role, priority FROM `tabRole Priority` ORDER BY priority DESC"
    records = frappe.db.sql(query, as_dict=True)
    for rec in records:
        if rec.get("role") in usr_roles:
            return rec.get("role")

    if not highest_role:
        frappe.throw("You can not assign Ticket to any other user")
Esempio n. 3
0
def validate_assigned_by(doc):
	"""Do not allow low authority user to assign ticket to higher authority"""
	from frappe.utils.user import get_roles
	query = """	SELECT
				    MAX(rp.priority)
				FROM
				    `tabRole Priority` rp
				WHERE
				    rp.role IN (%s)"""%(",".join(["'%s'"%(role) for role in get_roles(doc.assigned_by)]))
	
	assigned_by_priority = frappe.db.sql(query, as_list=True)[0][0]
	owner_role_priority = get_role_priority(get_highest_role(doc.owner))

	if owner_role_priority.get("priority") > assigned_by_priority:
		frappe.throw("Can not assign the ToDo to higher authority")
Esempio n. 4
0
def validate_assigned_by(doc):
    """Do not allow low authority user to assign ticket to higher authority"""
    from frappe.utils.user import get_roles
    query = """	SELECT
				    MAX(rp.priority)
				FROM
				    `tabRole Priority` rp
				WHERE
				    rp.role IN (%s)""" % (",".join(
        ["'%s'" % (role) for role in get_roles(doc.assigned_by)]))

    assigned_by_priority = frappe.db.sql(query, as_list=True)[0][0]
    owner_role_priority = get_role_priority(get_highest_role(doc.owner))

    if owner_role_priority.get("priority") > assigned_by_priority:
        frappe.throw("Can not assign the ToDo to higher authority")