diff --git a/src/core/api/harborapi_test.go b/src/core/api/harborapi_test.go index ed67e8577..ec9569b9d 100644 --- a/src/core/api/harborapi_test.go +++ b/src/core/api/harborapi_test.go @@ -115,7 +115,6 @@ func init() { beego.Router("/api/"+api.APIVersion+"/chartrepo/:repo/charts/:name/:version/labels", chartLabelAPIType, "get:GetLabels;post:MarkLabel") beego.Router("/api/"+api.APIVersion+"/chartrepo/:repo/charts/:name/:version/labels/:id([0-9]+)", chartLabelAPIType, "delete:RemoveLabel") - beego.Router("/api/internal/switchquota", &InternalAPI{}, "put:SwitchQuota") beego.Router("/api/internal/syncquota", &InternalAPI{}, "post:SyncQuota") // Init user Info diff --git a/src/core/api/internal.go b/src/core/api/internal.go index 6d6cd6518..12ab4c19c 100644 --- a/src/core/api/internal.go +++ b/src/core/api/internal.go @@ -69,40 +69,6 @@ func (ia *InternalAPI) RenameAdmin() { ia.DestroySession() } -// QuotaSwitcher ... -type QuotaSwitcher struct { - Enabled bool -} - -// SwitchQuota ... -func (ia *InternalAPI) SwitchQuota() { - var req QuotaSwitcher - if err := ia.DecodeJSONReq(&req); err != nil { - ia.SendBadRequestError(err) - return - } - ctx := orm.NewContext(ia.Ctx.Request.Context(), o.NewOrm()) - cur := config.ReadOnly(ctx) - // quota per project from disable to enable, it needs to update the quota usage bases on the DB records. - if !config.QuotaPerProjectEnable(ctx) && req.Enabled { - if !cur { - config.GetCfgManager(ctx).Set(ctx, common.ReadOnly, true) - config.GetCfgManager(ctx).Save(ctx) - } - if err := quota.RefreshForProjects(ctx); err != nil { - ia.SendInternalServerError(err) - return - } - } - defer func() { - ctx := orm.Context() - config.GetCfgManager(ctx).Set(ctx, common.ReadOnly, cur) - config.GetCfgManager(ctx).Set(ctx, common.QuotaPerProjectEnable, req.Enabled) - config.GetCfgManager(ctx).Save(ctx) - }() - return -} - // SyncQuota ... func (ia *InternalAPI) SyncQuota() { if !config.QuotaPerProjectEnable(orm.Context()) { diff --git a/src/core/api/internal_test.go b/src/core/api/internal_test.go index 02903a98b..2ca101d21 100644 --- a/src/core/api/internal_test.go +++ b/src/core/api/internal_test.go @@ -19,42 +19,6 @@ import ( "testing" ) -// cannot verify the real scenario here -func TestSwitchQuota(t *testing.T) { - cases := []*codeCheckingCase{ - // 401 - { - request: &testingRequest{ - method: http.MethodPut, - url: "/api/internal/switchquota", - }, - code: http.StatusUnauthorized, - }, - // 200 - { - request: &testingRequest{ - method: http.MethodPut, - url: "/api/internal/switchquota", - credential: sysAdmin, - bodyJSON: &QuotaSwitcher{ - Enabled: true, - }, - }, - code: http.StatusOK, - }, - // 403 - { - request: &testingRequest{ - url: "/api/internal/switchquota", - method: http.MethodPut, - credential: nonSysAdmin, - }, - code: http.StatusForbidden, - }, - } - runCodeCheckingCases(t, cases...) -} - // cannot verify the real scenario here func TestSyncQuota(t *testing.T) { cases := []*codeCheckingCase{ diff --git a/src/server/route.go b/src/server/route.go index 5e73943d4..7ee8c6817 100644 --- a/src/server/route.go +++ b/src/server/route.go @@ -46,7 +46,6 @@ func registerRoutes() { beego.Router(common.AuthProxyRediretPath, &controllers.AuthProxyController{}, "get:HandleRedirect") beego.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin") - beego.Router("/api/internal/switchquota", &api.InternalAPI{}, "put:SwitchQuota") beego.Router("/api/internal/syncquota", &api.InternalAPI{}, "post:SyncQuota") beego.Router("/service/notifications/jobs/webhook/:id([0-9]+)", &jobs.Handler{}, "post:HandleNotificationJob")