mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(region): more accounts details for project mapping
This commit is contained in:
@@ -479,5 +479,6 @@ type CloudaccountEnableAutoSyncInput struct {
|
||||
}
|
||||
|
||||
type CloudaccountProjectMappingInput struct {
|
||||
ProjectMappingId string
|
||||
// 同步策略Id, 若不传此参数则解绑
|
||||
ProjectMappingId string `json:"project_mapping_id"`
|
||||
}
|
||||
|
||||
@@ -139,6 +139,11 @@ type ProjectMappingDetails struct {
|
||||
apis.EnabledStatusInfrasResourceBaseDetails
|
||||
|
||||
Rules []ProjectMappingRuleInfoDetails
|
||||
|
||||
Accounts []struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
|
||||
type ProjectMappingCreateInput struct {
|
||||
|
||||
@@ -2863,6 +2863,7 @@ func (self *SCloudaccount) AllowPerformProjectMapping(ctx context.Context, userC
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "project-mapping")
|
||||
}
|
||||
|
||||
// 绑定同步策略
|
||||
func (self *SCloudaccount) PerformProjectMapping(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudaccountProjectMappingInput) (jsonutils.JSONObject, error) {
|
||||
if len(input.ProjectMappingId) > 0 {
|
||||
_, err := validators.ValidateModel(userCred, ProjectMappingManager, &input.ProjectMappingId)
|
||||
|
||||
@@ -175,10 +175,43 @@ func (manager *SProjectMappingManager) FetchCustomizeColumns(
|
||||
for _, proj := range projects {
|
||||
projectMaps[proj.Id] = proj.Name
|
||||
}
|
||||
accounts := []struct {
|
||||
Id string
|
||||
Name string
|
||||
ProjectMappingId string
|
||||
}{}
|
||||
q = CloudaccountManager.Query().In("project_mapping_id", mpIds)
|
||||
err = q.All(&accounts)
|
||||
if err != nil {
|
||||
return rows
|
||||
}
|
||||
accountMapping := map[string][]struct {
|
||||
Id string
|
||||
Name string
|
||||
}{}
|
||||
for i := range accounts {
|
||||
_, ok := accountMapping[accounts[i].ProjectMappingId]
|
||||
if !ok {
|
||||
accountMapping[accounts[i].ProjectMappingId] = []struct {
|
||||
Id string
|
||||
Name string
|
||||
}{}
|
||||
}
|
||||
accountMapping[accounts[i].ProjectMappingId] = append(accountMapping[accounts[i].ProjectMappingId],
|
||||
struct {
|
||||
Id string
|
||||
Name string
|
||||
}{
|
||||
Id: accounts[i].Id,
|
||||
Name: accounts[i].Name,
|
||||
})
|
||||
}
|
||||
|
||||
for i := range rows {
|
||||
mp := objs[i].(*SProjectMapping)
|
||||
if mp.Rules != nil {
|
||||
rows[i].Rules = []api.ProjectMappingRuleInfoDetails{}
|
||||
rows[i].Accounts, _ = accountMapping[mpIds[i]]
|
||||
for i := range *mp.Rules {
|
||||
rules := *mp.Rules
|
||||
rule := api.ProjectMappingRuleInfoDetails{
|
||||
|
||||
@@ -22,7 +22,7 @@ var (
|
||||
|
||||
func init() {
|
||||
ProjectMappings = NewComputeManager("project_mapping", "project_mappings",
|
||||
[]string{"ID", "Name", "Enabled", "Status", "Public_Scope", "Domain_Id", "Domain", "Rules", "Metadata"},
|
||||
[]string{"ID", "Name", "Enabled", "Status", "Public_Scope", "Domain_Id", "Domain", "Rules", "Accounts", "Metadata"},
|
||||
[]string{})
|
||||
|
||||
registerCompute(&ProjectMappings)
|
||||
|
||||
Reference in New Issue
Block a user