mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-24 02:15:50 +08:00
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright 2019 Yunion
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"context"
|
|
|
|
"yunion.io/x/onecloud/pkg/notify/cache"
|
|
)
|
|
|
|
func GetUserByID(ctx context.Context, id string) (*cache.SUser, error) {
|
|
return cache.UserCacheManager.FetchUserByID(ctx, id, false)
|
|
}
|
|
|
|
func GetUserIdsLikeName(ctx context.Context, name string) ([]string, error) {
|
|
users, err := cache.UserCacheManager.FetchUserLikeName(ctx, name, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ret := make([]string, len(users))
|
|
for i := range users {
|
|
ret[i] = users[i].Id
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
func GetUsersByGroupID(ctx context.Context, gid string) ([]string, error) {
|
|
ret, err := cache.UserGroupCacheManager.FetchByGroupId(ctx, gid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ids := make([]string, len(ret))
|
|
for i := range ret {
|
|
ids[i] = ret[i].UserId
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
func GetUsernameByID(ctx context.Context, id string) (string, error) {
|
|
user, err := GetUserByID(ctx, id)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return user.Name, nil
|
|
}
|