Skip to content

Commit

Permalink
fix(yunionconf): allow disable bug report (#18653)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Nov 13, 2023
1 parent f0b9b73 commit 7ddcafd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/climc/shell/yunionconf/bugreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ func init() {
return nil
})

R(&BugReportEnableOptions{}, "bug-report-disable", "Disable bug report", func(s *mcclient.ClientSession, args *BugReportEnableOptions) error {
ret, err := yunionconf.BugReport.DoBugReportDisable(s, nil)
if err != nil {
return err
}
printObject(ret)
return nil
})

}
4 changes: 4 additions & 0 deletions pkg/mcclient/modules/yunionconf/mod_bugreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (m BugReportManager) DoBugReportEnable(s *mcclient.ClientSession, _ jsonuti
return modulebase.Post(m.ResourceManager, s, "enable-bug-report", nil, "")
}

func (m BugReportManager) DoBugReportDisable(s *mcclient.ClientSession, _ jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return modulebase.Post(m.ResourceManager, s, "disable-bug-report", nil, "")
}

func (m BugReportManager) GetBugReportEnabled(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return modulebase.Get(m.ResourceManager, s, "bug-report-status", "")
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/yunionconf/models/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,17 @@ func (manager *SParameterManager) EnableBugReport(ctx context.Context) bool {
bugReportEnable = &enabled
return true
}

func (manager *SParameterManager) DisableBugReport(ctx context.Context) error {
if !manager.GetBugReportEnabled() {
return nil
}
_, err := sqlchemy.GetDB().Exec(
fmt.Sprintf(
"delete from %s where namespace = ?",
manager.TableSpec().Name(),
), NAMESPACE_BUG_REPORT,
)
bugReportEnable = nil
return err
}
6 changes: 6 additions & 0 deletions pkg/yunionconf/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func InitHandlers(app *appsrv.Application) {
func addBugReportHandler(prefix string, app *appsrv.Application) {
app.AddHandler("GET", fmt.Sprintf("%s/bug-report-status", prefix), bugReportStatusHandler)
app.AddHandler("POST", fmt.Sprintf("%s/enable-bug-report", prefix), enableBugReportHandler)
app.AddHandler("POST", fmt.Sprintf("%s/disable-bug-report", prefix), disableBugReportHandler)
app.AddHandler("POST", fmt.Sprintf("%s/send-bug-report", prefix), sendBugReportHandler)
}

Expand All @@ -79,6 +80,11 @@ func enableBugReportHandler(ctx context.Context, w http.ResponseWriter, r *http.
appsrv.SendJSON(w, jsonutils.Marshal(map[string]bool{"enabled": enabled}))
}

func disableBugReportHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
models.ParameterManager.DisableBugReport(ctx)
appsrv.SendJSON(w, jsonutils.Marshal(map[string]bool{"enabled": false}))
}

func sendBugReportHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
if !models.ParameterManager.GetBugReportEnabled() {
appsrv.SendJSON(w, jsonutils.Marshal(map[string]bool{"status": false}))
Expand Down

0 comments on commit 7ddcafd

Please sign in to comment.