Files
yunzerwebsiteallinone/go/models/admin_role_default.go
T
2026-09-15 10:44:31 +08:00

29 lines
879 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"github.com/beego/beego/v2/client/orm"
)
// GetTenantAdminRole 返回全局「租户管理员」角色(cid=2, tenant_id=0)的 ID。
//
// 角色模型:租户端的「租户管理员 / 租户用户」为全局共用角色(tenant_id=0),
// 所有租户共享同一批记录,由平台端角色管理统一维护;
// 角色数据走 SQL(docs/sql/update_role_system.sql),代码不做自动补建。
//
// 租户的第一个账号即租户管理员,绑定此角色以获得 backend 全权限。
// 任何失败返回 (0, err)。
func GetTenantAdminRole() (uint64, error) {
if Orm == nil {
return 0, orm.ErrNoRows
}
var role AdminRole
if err := Orm.QueryTable(new(AdminRole)).
Filter("cid", 2).
Filter("tenant_id", 0).
Filter("name", "租户管理员").
One(&role); err != nil {
return 0, err
}
return role.ID, nil
}