receiver.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. "yunion.io/x/onecloud/cmd/climc/shell"
  17. identity_api "yunion.io/x/onecloud/pkg/apis/identity"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. identity_modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
  21. options "yunion.io/x/onecloud/pkg/mcclient/options/notify"
  22. )
  23. func init() {
  24. cmd := shell.NewResourceCmd(&modules.NotifyReceiver).WithKeyword("notify-receiver")
  25. cmd.List(new(options.ReceiverListOptions))
  26. cmd.Create(new(options.ReceiverCreateOptions))
  27. cmd.Update(new(options.ReceiverUpdateOptions))
  28. cmd.Show(new(options.ReceiverOptions))
  29. cmd.Delete(new(options.ReceiverOptions))
  30. cmd.Perform("enable", new(options.ReceiverOptions))
  31. cmd.Perform("disable", new(options.ReceiverOptions))
  32. cmd.Perform("trigger-verify", new(options.ReceiverTriggerVerifyOptions))
  33. cmd.Perform("verify", new(options.ReceiverVerifyOptions))
  34. cmd.Perform("enable-contact-type", new(options.ReceiverEnableContactTypeInput))
  35. cmd.PerformClass("intellij-get", new(options.ReceiverIntellijGetOptions))
  36. cmd.PerformClass("get-types", new(options.ReceiverGetTypeOptions))
  37. cmd.Perform("get-subscription", new(options.ReceiverGetSubscriptionOptions))
  38. cmd.GetProperty(new(options.SReceiverRoleContactType))
  39. type SyncUserContactOptions struct {
  40. USERID string `json:"user_id"`
  41. Mobile string `json:"mobile"`
  42. Email string `json:"email"`
  43. }
  44. R(&SyncUserContactOptions{}, "sync-user-contacts", "Sync user contact", func(s *mcclient.ClientSession, args *SyncUserContactOptions) error {
  45. userObj, err := identity_modules.UsersV3.Get(s, args.USERID, nil)
  46. if err != nil {
  47. return err
  48. }
  49. user := identity_api.UserDetails{}
  50. err = userObj.Unmarshal(&user)
  51. if err != nil {
  52. return err
  53. }
  54. if len(args.Mobile) == 0 {
  55. args.Mobile = user.Mobile
  56. }
  57. if len(args.Email) == 0 {
  58. args.Email = user.Email
  59. }
  60. err = modules.NotifyReceiver.SyncUserContact(s, user.Id, args.Mobile, args.Email)
  61. if err != nil {
  62. return err
  63. }
  64. return nil
  65. })
  66. }