def find_function_user_auth(function_id): context = DBContext() sql_arr = [ "select u.id, u.loginid, u.name, a.id authid from um_user u", "left join (", " select id, grantid from um_auth", " where sourceentity = :functionentity and sourceid = :functionid and grantentity = :userentity", ") a on u.id = a.grantid", "where u.loginid <> 'admin'" ] return context.create_sql_query("\n".join(sql_arr), functionentity="UmFunction", functionid=function_id, userentity="UmUser")
def find_my_menu_db(user_id): context = DBContext() ret = [] user = get_user_byid(user_id) if user is None: return ret if user["loginid"] == "admin": return find_menu() else: sql = [ "select m.* from um_menu m", "right join (", " select * from um_auth where sourceentity = 'UmMenu' and grantentity = 'UmUser' and grantid = :userid", ") a on m.id = a.sourceid" ] return context.create_sql_query("\n".join(sql), userid=user_id)