mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(keystone): support unset project admin user (#19538)
This commit is contained in:
@@ -164,6 +164,9 @@ type ProjectListInput struct {
|
||||
|
||||
// project tags filter imposed by policy
|
||||
PolicyProjectTags tagutils.TTagSetList `json:"policy_project_tags"`
|
||||
|
||||
// 通过项目管理员id过滤
|
||||
AdminId string `json:"admin_id"`
|
||||
}
|
||||
|
||||
type DomainListInput struct {
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/keystone/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -286,6 +287,14 @@ func (manager *SProjectManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
if len(query.AdminId) > 0 {
|
||||
_, err := validators.ValidateModel(ctx, nil, UserManager, &query.AdminId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q = q.Equals("admin_id", query.AdminId)
|
||||
}
|
||||
|
||||
groupStr := query.GroupId
|
||||
if len(groupStr) > 0 {
|
||||
groupObj, err := GroupManager.FetchById(groupStr)
|
||||
@@ -350,6 +359,14 @@ func (manager *SProjectManager) QueryDistinctExtraField(q *sqlchemy.SQuery, fiel
|
||||
return q, nil
|
||||
}
|
||||
|
||||
if field == "admin" {
|
||||
userQuery := UserManager.Query("name", "id").Distinct().SubQuery()
|
||||
q.AppendField(userQuery.Field("name", field))
|
||||
q = q.Join(userQuery, sqlchemy.Equals(q.Field("admin_id"), userQuery.Field("id")))
|
||||
q.GroupBy(userQuery.Field("name"))
|
||||
return q, nil
|
||||
}
|
||||
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -822,6 +839,11 @@ func (project *SProject) PerformSetAdmin(
|
||||
query jsonutils.JSONObject,
|
||||
input api.SProjectSetAdminInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
// unset admin
|
||||
if len(input.UserId) == 0 {
|
||||
return nil, project.setAdminId(ctx, userCred, input.UserId)
|
||||
}
|
||||
|
||||
var user *SUser
|
||||
var role *SRole
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ type ProjectListOptions struct {
|
||||
UserId string `help:"filter by user id"`
|
||||
GroupId string `help:"filter by group id"`
|
||||
IdpId string `help:"filter by idp id"`
|
||||
AdminId string
|
||||
|
||||
OrderByDomain string `help:"order by domain name" choices:"asc|desc"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user