fix(region): more accounts details for project mapping

This commit is contained in:
Qu Xuan
2021-05-18 17:55:38 +08:00
parent 14f3d77bf6
commit 7cb4da8bda
5 changed files with 42 additions and 2 deletions
+2 -1
View File
@@ -479,5 +479,6 @@ type CloudaccountEnableAutoSyncInput struct {
}
type CloudaccountProjectMappingInput struct {
ProjectMappingId string
// 同步策略Id, 若不传此参数则解绑
ProjectMappingId string `json:"project_mapping_id"`
}
+5
View File
@@ -139,6 +139,11 @@ type ProjectMappingDetails struct {
apis.EnabledStatusInfrasResourceBaseDetails
Rules []ProjectMappingRuleInfoDetails
Accounts []struct {
Id string
Name string
}
}
type ProjectMappingCreateInput struct {
+1
View File
@@ -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)
+33
View File
@@ -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{
+1 -1
View File
@@ -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)