parameter create fix && itsm add quick complete method

This commit is contained in:
TangBin
2019-06-03 19:00:10 +08:00
parent 1b54c012ed
commit f2ceea4fe8
4 changed files with 42 additions and 3 deletions
+8
View File
@@ -28,8 +28,16 @@ func SendHTTPErrorHeader(w http.ResponseWriter, statusCode int) {
w.Header().Set("Content-Type", "application/json")
}
func SetHTTPRedirectLocationHeader(w http.ResponseWriter, location string) {
w.Header().Set("Location", location)
}
func HTTPError(w http.ResponseWriter, msg string, statusCode int, class string, error httputils.Error) {
SendHTTPErrorHeader(w, statusCode)
if statusCode >= 300 && statusCode <= 400 {
SetHTTPRedirectLocationHeader(w, msg)
}
body := jsonutils.NewDict()
body.Add(jsonutils.NewInt(int64(statusCode)), "code")
body.Add(jsonutils.NewString(msg), "details")
+3
View File
@@ -72,6 +72,9 @@ func NewClient(authUrl string, timeout int, debug bool, insecure bool, certFile,
debug: debug,
httpconn: &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}, // 不自动处理重定向请求
},
}
return &client
+27 -3
View File
@@ -14,14 +14,38 @@
package modules
import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SProcessTasksManager struct {
ResourceManager
}
var (
ProcessTasks ResourceManager
ProcessTasks SProcessTasksManager
)
func init() {
ProcessTasks = NewITSMManager("process-task", "process-tasks",
ProcessTasks = SProcessTasksManager{NewITSMManager("process-task", "process-tasks",
[]string{"id", "name", "description", "owner", "priority", "tenant_id"},
[]string{},
)
)}
register(&ProcessTasks)
}
func (this *SProcessTasksManager) QuickComplete(s *mcclient.ClientSession, params jsonutils.JSONObject) error {
path := fmt.Sprintf("/%s/quick-complete", this.KeywordPlural)
if params != nil {
qs := params.QueryString()
if len(qs) > 0 {
path = fmt.Sprintf("%s?%s", path, qs)
}
}
_, err := this._get(s, path, "")
return err
}
+4
View File
@@ -165,6 +165,10 @@ func (manager *SParameterManager) AllowListItems(ctx context.Context, userCred m
return db.IsAdminAllowList(userCred, manager)
}
func (manager *SParameterManager) NamespaceScope() rbacutils.TRbacScope {
return rbacutils.ScopeUser
}
func (manager *SParameterManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
if !isAdminQuery(query) {
return true