Skip to content

Commit

Permalink
fix: clouduser can_delete always be false
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jul 3, 2020
1 parent 1ace096 commit a54a9c0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/climc/shell/cloudid/cloudgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func init() {

ClouduserId string `json:"clouduser_id"`
CloudpolicyId string `json:"cloudpolicy_id"`
Usable bool `json:"usable"`
}
R(&CloudgroupListOptions{}, "cloud-group-list", "List cloud groups", func(s *mcclient.ClientSession, opts *CloudgroupListOptions) error {
params, err := options.ListStructToParams(opts)
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/cloudid/cloudgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type CloudgroupListInput struct {

// 根据权限过滤权限组
CloudpolicyId string `json:"cloudpolicy_id"`

// 是否可用
Usable *bool `json:"usable"`
}

type SCloudIdBaseResource struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ type MetadataResourceInfo struct {
type StatusDomainLevelUserResourceDetails struct {
StatusDomainLevelResourceDetails

UserResourceDetails
// 用户名称
OwnerName string `json:"owner_name"`
}

type UserResourceDetails struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloudid/models/cloudgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (manager *SCloudgroupManager) ListItemFilter(ctx context.Context, q *sqlche
q = q.In("id", sq.SubQuery())
}

if query.Usable != nil && *query.Usable {
sq := CloudaccountManager.Query("provider").SubQuery()
q = q.In("provider", sq)
}

return q, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/multicloud/qcloud/cloudgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (self *SQcloudClient) ListGroups(keyword string, page int, rp int) ([]SClou
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return groups, int(total), nil
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (self *SQcloudClient) ListAttachedGroupPolicies(groupId int, page int, rp i
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return policies, int(total), nil
}

Expand All @@ -269,7 +269,7 @@ func (self *SQcloudClient) ListGroupUsers(groupId int, page int, rp int) ([]SClo
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return users, int(total), nil
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/multicloud/qcloud/clouduser.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (self *SQcloudClient) ListGroupsForUser(uin string, rp, page int) ([]SCloud
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return groups, int(total), nil
}

Expand Down Expand Up @@ -271,11 +271,15 @@ func (policy *SClouduserPolicy) GetPolicyType() string {
}

func (policy *SClouduserPolicy) GetDescription() string {
if len(policy.Description) > 0 {
return policy.Description
}
p, err := policy.client.GetPolicy(policy.GetGlobalId())
if err != nil {
log.Errorf("failed to get policy %s description: %v", policy.PolicyName, err)
return p.Description
}
return ""
return p.Description
}

func (self *SQcloudClient) ListAttachedUserPolicies(uin string, page int, rp int) ([]SClouduserPolicy, int, error) {
Expand All @@ -299,7 +303,7 @@ func (self *SQcloudClient) ListAttachedUserPolicies(uin string, page int, rp int
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return policies, int(total), nil
}

Expand Down Expand Up @@ -348,7 +352,7 @@ func (self *SQcloudClient) ListPolicies(keyword, scope string, page int, rp int)
if err != nil {
return nil, 0, errors.Wrap(err, "resp.Unmarshal")
}
total, _ := resp.Int("TotalNum")
total, _ := resp.Float("TotalNum")
return policies, int(total), nil
}

Expand Down

0 comments on commit a54a9c0

Please sign in to comment.