44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/dao"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/contexts"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func appAccessConfigured(ctx context.Context) (bool, error) {
|
|
return appAccessConfiguredForTenant(ctx, contexts.GetTenantId(ctx))
|
|
}
|
|
|
|
func appAccessConfiguredForTenant(ctx context.Context, tenantId string) (bool, error) {
|
|
perms := appMenuPermCandidates()
|
|
if len(perms) == 0 {
|
|
return false, nil
|
|
}
|
|
mod := dao.SysMenu.Ctx(ctx).
|
|
Where(dao.SysMenu.Columns().Status, consts.SysMenuStatusNormal).
|
|
WhereIn(dao.SysMenu.Columns().Perms, perms)
|
|
count, err := mod.Count()
|
|
if err != nil {
|
|
g.Log().Errorf(ctx, "appAccessConfiguredForTenant count failed: %v", err)
|
|
return false, err
|
|
}
|
|
return count > 0, nil
|
|
}
|
|
|
|
func appendUniqueString(values []string, value string) []string {
|
|
if value == "" {
|
|
return values
|
|
}
|
|
for _, existing := range values {
|
|
if existing == value {
|
|
return values
|
|
}
|
|
}
|
|
return append(values, value)
|
|
}
|