路由权限可以通过在xml配置中指定roles
<api name="add" func="add" table="sys_user" method="post" roles="X8e6D3y60K" desc="添加用户">
<param name="user" type="$sys_user" desc="用户信息" />
<return>
<success type="$success"/>
<failure type="$fail"/>
</return>
</api>
通过dolphin翻译后 app.auto.go
ctr.Add.Roles = Roles("X8e6D3y60K")
// ...
group.Handle(
instance.Add.Method,
instance.Add.RelativePath,
instance.Add.Auth,
instance.Add.Roles,
instance.Add.Cache,
instance.Add.Interceptor,
instance.Add.Handler)
通过SetRule函数注入TypeQuery
q := ctx.TypeQuery()
q.SetInt("page", 1)
q.SetInt("size", 10)
q.SetString("org_id")
q.SetString("mobile")
q.SetString("name")
q.SetString("cn_org_id")
q.SetRule("sys_user_page")
q.SetString("creater")
q.SetString("updater")
q.SetRange("create_time")
q.SetRange("update_time")
q.SetInt("is_delete", 0)()
q.SetTags()
// ...
func (q *Query) SetRule(rule string) {
var roleRules []types.SysDataPermissionDetail
userID := q.ctx.MustToken().GetUserID()
q.ctx.MustDB().SqlMapClient("get_user_rule_by_code", rule, userID).Find(&roleRules)
for i := range roleRules {
q.m["is_role_rule_"+roleRules[i].Rule.String] = true
}
}
select
sys_user.id,
sys_user.name,
sys_user.nickname,
sys_user.email,
sys_user.mobile,
sys_user.status,
sys_user.org_id,
sys_user.temp_id,
sys_user.temp_value
from
sys_user
where
sys_user.id {{.ne}} ""
and sys_user.is_delete {{.ne}} 1
{{if .is_role_rule_load_sch}}
and sys_user.org_id = "{{.org_id}}"
{{end}}
{{end}}
LIMIT {{.size}} OFFSET {{.offset}}