@@ -52,6 +52,7 @@ const (
52
52
53
53
type NotificationRestHandler interface {
54
54
SaveNotificationSettings (w http.ResponseWriter , r * http.Request )
55
+ SaveNotificationSettingsV2 (w http.ResponseWriter , r * http.Request )
55
56
UpdateNotificationSettings (w http.ResponseWriter , r * http.Request )
56
57
SaveNotificationChannelConfig (w http.ResponseWriter , r * http.Request )
57
58
FindSESConfig (w http.ResponseWriter , r * http.Request )
@@ -146,6 +147,65 @@ func (impl NotificationRestHandlerImpl) SaveNotificationSettings(w http.Response
146
147
}
147
148
//RBAC
148
149
150
+ providers := notificationSetting .Providers
151
+
152
+ if len (providers ) != 0 {
153
+ for _ , provider := range providers {
154
+ if provider .Destination == "smtp" || provider .Destination == "ses" {
155
+ if provider .Recipient == "" {
156
+ userEmail , err := impl .userAuthService .GetEmailById (int32 (provider .ConfigId ))
157
+ if err != nil {
158
+ impl .logger .Errorw ("service err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
159
+ common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
160
+ return
161
+ }
162
+ provider .Recipient = userEmail
163
+ }
164
+ // get default configID for SES and SMTP
165
+ provider .ConfigId = notificationSetting .SesConfigId
166
+ }
167
+ }
168
+ }
169
+
170
+ res , err := impl .notificationService .CreateOrUpdateNotificationSettings (& notificationSetting , userId )
171
+ if err != nil {
172
+ impl .logger .Errorw ("service err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
173
+ common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
174
+ return
175
+ }
176
+ w .Header ().Set ("Content-Type" , "application/json" )
177
+ common .WriteJsonResp (w , nil , res , http .StatusOK )
178
+ }
179
+
180
+ func (impl NotificationRestHandlerImpl ) SaveNotificationSettingsV2 (w http.ResponseWriter , r * http.Request ) {
181
+ userId , err := impl .userAuthService .GetLoggedInUser (r )
182
+ if userId == 0 || err != nil {
183
+ common .WriteJsonResp (w , err , "Unauthorized User" , http .StatusUnauthorized )
184
+ return
185
+ }
186
+ var notificationSetting beans.NotificationRequest
187
+ err = json .NewDecoder (r .Body ).Decode (& notificationSetting )
188
+ if err != nil {
189
+ impl .logger .Errorw ("request err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
190
+ common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
191
+ return
192
+ }
193
+ impl .logger .Infow ("request payload, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
194
+ err = impl .validator .Struct (notificationSetting )
195
+ if err != nil {
196
+ impl .logger .Errorw ("validation err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
197
+ common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
198
+ return
199
+ }
200
+
201
+ //RBAC
202
+ token := r .Header .Get ("token" )
203
+ if isSuperAdmin := impl .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionGet , "*" ); ! isSuperAdmin {
204
+ common .WriteJsonResp (w , err , nil , http .StatusForbidden )
205
+ return
206
+ }
207
+ //RBAC
208
+
149
209
res , err := impl .notificationService .CreateOrUpdateNotificationSettings (& notificationSetting , userId )
150
210
if err != nil {
151
211
impl .logger .Errorw ("service err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
0 commit comments