/
user_setting.go
64 lines (57 loc) · 1.29 KB
/
user_setting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package model
import (
"encoding/json"
"github.com/KubeOperator/KubeOperator/pkg/constant"
"github.com/KubeOperator/KubeOperator/pkg/model/common"
uuid "github.com/satori/go.uuid"
)
type UserSetting struct {
common.BaseModel
ID string `json:"id"`
Msg string `json:"-"`
UserID string `json:"userId"`
}
func (u *UserSetting) BeforeCreate() error {
u.ID = uuid.NewV4().String()
return nil
}
func (u *UserSetting) GetMsgSetting() MsgSetting {
var msg MsgSetting
json.Unmarshal([]byte(u.Msg), &msg)
return msg
}
func NewUserSetting(userId string) UserSetting {
msgConfig := &MsgSetting{
DingTalk: ReceiveSetting{
Account: "",
Receive: constant.Disable,
},
Email: ReceiveSetting{
Account: "",
Receive: constant.Disable,
},
WorkWeiXin: ReceiveSetting{
Account: "",
Receive: constant.Disable,
},
Local: ReceiveSetting{
Account: "",
Receive: constant.Enable,
},
}
msg, _ := json.Marshal(msgConfig)
return UserSetting{
UserID: userId,
Msg: string(msg),
}
}
type MsgSetting struct {
DingTalk ReceiveSetting `json:"dingTalk"`
Email ReceiveSetting `json:"email"`
WorkWeiXin ReceiveSetting `json:"workWeiXin"`
Local ReceiveSetting `json:"local"`
}
type ReceiveSetting struct {
Account string `json:"account"`
Receive string `json:"receive"`
}