mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-16 15:07:59 +08:00
Merge pull request #2051 from swordqiu/hotfix/qj-quota-list-adjust-for-non-default-domain-projects
fix: 1. project quota-list not include domain quota 2. do not check
This commit is contained in:
@@ -253,58 +253,61 @@ func (manager *SQuotaBaseManager) setQuotaHanlder(ctx context.Context, w http.Re
|
||||
oquota.Update(quota)
|
||||
}
|
||||
|
||||
if scope == rbacutils.ScopeProject {
|
||||
total, err := manager.getDomainTotalQuota(ctx, ownerId.GetProjectDomainId(), []string{ownerId.GetProjectId()})
|
||||
if err != nil {
|
||||
log.Errorf("get total quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
domainQuota := manager.newQuota()
|
||||
err = manager.GetQuota(ctx, rbacutils.ScopeDomain, ownerId, nil, domainQuota)
|
||||
if err != nil {
|
||||
log.Errorf("GetQuota for domain %s fail %s", ownerId.GetProjectDomainId(), err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
total.Add(oquota)
|
||||
err = total.Exceed(quota, domainQuota)
|
||||
if err != nil {
|
||||
// exeed domain quota
|
||||
cascade, _ := body.Bool(manager.KeywordPlural(), "cascade")
|
||||
if !cascade {
|
||||
log.Errorf("project quota exeed domain quota: %s", err)
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota")
|
||||
if consts.GetNonDefaultDomainProjects() {
|
||||
// only if non-default-domain-project is turned ON, check the conformance between project quotas and domain quotas
|
||||
if scope == rbacutils.ScopeProject {
|
||||
total, err := manager.getDomainTotalQuota(ctx, ownerId.GetProjectDomainId(), []string{ownerId.GetProjectId()})
|
||||
if err != nil {
|
||||
log.Errorf("get total quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
} else {
|
||||
if allowScope != rbacutils.ScopeSystem {
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota, no previlige to cascade set")
|
||||
}
|
||||
|
||||
domainQuota := manager.newQuota()
|
||||
err = manager.GetQuota(ctx, rbacutils.ScopeDomain, ownerId, nil, domainQuota)
|
||||
if err != nil {
|
||||
log.Errorf("GetQuota for domain %s fail %s", ownerId.GetProjectDomainId(), err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
total.Add(oquota)
|
||||
err = total.Exceed(quota, domainQuota)
|
||||
if err != nil {
|
||||
// exeed domain quota
|
||||
cascade, _ := body.Bool(manager.KeywordPlural(), "cascade")
|
||||
if !cascade {
|
||||
log.Errorf("project quota exeed domain quota: %s", err)
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota")
|
||||
return
|
||||
} else {
|
||||
// cascade set domain quota
|
||||
err = manager.SetQuota(ctx, userCred, rbacutils.ScopeDomain, ownerId, nil, total)
|
||||
if err != nil {
|
||||
log.Errorf("cascade set quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
if allowScope != rbacutils.ScopeSystem {
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota, no previlige to cascade set")
|
||||
return
|
||||
} else {
|
||||
// cascade set domain quota
|
||||
err = manager.SetQuota(ctx, userCred, rbacutils.ScopeDomain, ownerId, nil, total)
|
||||
if err != nil {
|
||||
log.Errorf("cascade set quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
total, err := manager.getDomainTotalQuota(ctx, ownerId.GetProjectDomainId(), nil)
|
||||
if err != nil {
|
||||
log.Errorf("get total quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
err = total.Exceed(quota, oquota)
|
||||
if err != nil {
|
||||
log.Errorf("project quota exeed domain quota: %s", err)
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota")
|
||||
return
|
||||
} else {
|
||||
total, err := manager.getDomainTotalQuota(ctx, ownerId.GetProjectDomainId(), nil)
|
||||
if err != nil {
|
||||
log.Errorf("get total quota fail %s", err)
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
err = total.Exceed(quota, oquota)
|
||||
if err != nil {
|
||||
log.Errorf("project quota exeed domain quota: %s", err)
|
||||
httperrors.OutOfQuotaError(w, "project quota exeed domain quota")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,6 +432,11 @@ func (manager *SQuotaBaseManager) listQuotas(ctx context.Context, targetDomainId
|
||||
// domain only
|
||||
q = q.IsNullOrEmpty("tenant_id")
|
||||
}
|
||||
// if tuen OFF NonDefaultDOmainProjects
|
||||
// no domain quota should return
|
||||
if !consts.GetNonDefaultDomainProjects() {
|
||||
q = q.IsNotEmpty("tenant_id")
|
||||
}
|
||||
// dsable platform
|
||||
q = q.IsNullOrEmpty("platform")
|
||||
rows, err := q.Rows()
|
||||
@@ -460,9 +468,6 @@ func (manager *SQuotaBaseManager) listQuotas(ctx context.Context, targetDomainId
|
||||
log.Errorf("query quota for %s fail %s", getMemoryStoreKey(scope, &owner, platform), err)
|
||||
continue
|
||||
}
|
||||
// if usage.IsEmpty() {
|
||||
// continue
|
||||
// }
|
||||
if len(projectId) > 0 {
|
||||
quota.Set("tenant_id", jsonutils.NewString(projectId))
|
||||
quota.Set("domain_id", jsonutils.NewString(domainId))
|
||||
@@ -487,7 +492,8 @@ func (manager *SQuotaBaseManager) listQuotas(ctx context.Context, targetDomainId
|
||||
}
|
||||
ret = append(ret, quota)
|
||||
}
|
||||
if len(ret) == 0 && len(targetDomainId) > 0 {
|
||||
// if no projects for a domain and NonDefaultDomainProjects is turned ON
|
||||
if len(ret) == 0 && len(targetDomainId) > 0 && consts.GetNonDefaultDomainProjects() {
|
||||
// return the initial quota of targetDomainId
|
||||
scope := rbacutils.ScopeDomain
|
||||
owner := db.SOwnerId{
|
||||
|
||||
@@ -110,9 +110,6 @@ func (manager *SPolicyManager) ValidateCreateData(ctx context.Context, userCred
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("fail to decode policy data")
|
||||
}
|
||||
/*if policy.IsSystemWidePolicy() && policyman.PolicyManager.Allow(rbacutils.ScopeSystem, userCred, consts.GetServiceType(), manager.KeywordPlural(), policyman.PolicyActionCreate) == rbacutils.Deny {
|
||||
return nil, httperrors.NewNotSufficientPrivilegeError("not allow to create system-wide policy")
|
||||
}*/
|
||||
err = db.ValidateCreateDomainId(ownerId.GetProjectDomainId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user