mod_contacts.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package notify
  15. import (
  16. "fmt"
  17. "net/url"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/onecloud/pkg/mcclient"
  20. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  21. "yunion.io/x/onecloud/pkg/mcclient/modules"
  22. )
  23. type ContactsManager struct {
  24. modulebase.ResourceManager
  25. }
  26. func (this *ContactsManager) PerformActionWithArrayParams(s *mcclient.ClientSession, id string, action string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  27. path := fmt.Sprintf("/%s/%s/%s", this.KeywordPlural, id, action)
  28. body := jsonutils.NewDict()
  29. if params != nil {
  30. body.Add(params, this.KeywordPlural)
  31. }
  32. return modulebase.Post(this.ResourceManager, s, path, body, this.Keyword)
  33. }
  34. func (this *ContactsManager) DoBatchDeleteContacts(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  35. path := "/contacts/delete-contact?uname=true"
  36. return modulebase.Post(this.ResourceManager, s, path, params, this.Keyword)
  37. }
  38. func (this *ContactsManager) CustomizedPerformAction(session *mcclient.ClientSession, id, action string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  39. body := jsonutils.NewDict()
  40. if params != nil {
  41. body.Add(params, this.Keyword)
  42. }
  43. path := fmt.Sprintf("/%s/%s/%s?uname=true", this.ContextPath(nil), url.PathEscape(id), url.PathEscape(action))
  44. return modulebase.Post(this.ResourceManager, session, path, body, this.KeywordPlural)
  45. }
  46. func (this *ContactsManager) CustomizedGet(session *mcclient.ClientSession, id string,
  47. params jsonutils.JSONObject) (jsonutils.JSONObject,
  48. error) {
  49. q := params.(*jsonutils.JSONDict)
  50. q.Add(jsonutils.JSONTrue, "uname")
  51. return this.ResourceManager.Get(session, id, params)
  52. }
  53. var (
  54. Contacts ContactsManager
  55. )
  56. func init() {
  57. Contacts = ContactsManager{modules.NewNotifyManager("contact", "contacts",
  58. []string{"id", "name", "display_name", "details", "status", "create_by", "update_by", "delete_by", "gmt_create", "gmt_modified", "gmt_delete", "project_id", "remark"},
  59. []string{})}
  60. modules.Register(&Contacts)
  61. }