Merge pull request #8929 from wy65701436/read-only-sync

add read only for quota switcher
This commit is contained in:
Wang Yan 2019-09-03 15:58:13 +08:00 committed by GitHub
commit b844443509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,14 +88,20 @@ func (ia *InternalAPI) SwitchQuota() {
ia.SendBadRequestError(err) ia.SendBadRequestError(err)
return return
} }
cur := config.ReadOnly()
// quota per project from disable to enable, it needs to update the quota usage bases on the DB records. // quota per project from disable to enable, it needs to update the quota usage bases on the DB records.
if !config.QuotaPerProjectEnable() && req.Enabled { if !config.QuotaPerProjectEnable() && req.Enabled {
if !cur {
config.GetCfgManager().Set(common.ReadOnly, true)
config.GetCfgManager().Save()
}
if err := ia.ensureQuota(); err != nil { if err := ia.ensureQuota(); err != nil {
ia.SendInternalServerError(err) ia.SendInternalServerError(err)
return return
} }
} }
defer func() { defer func() {
config.GetCfgManager().Set(common.ReadOnly, cur)
config.GetCfgManager().Set(common.QuotaPerProjectEnable, req.Enabled) config.GetCfgManager().Set(common.QuotaPerProjectEnable, req.Enabled)
config.GetCfgManager().Save() config.GetCfgManager().Save()
}() }()