@@ -51,7 +51,6 @@ const (
5151)
5252
5353type NotificationRestHandler interface {
54- SaveNotificationSettings (w http.ResponseWriter , r * http.Request )
5554 SaveNotificationSettingsV2 (w http.ResponseWriter , r * http.Request )
5655 UpdateNotificationSettings (w http.ResponseWriter , r * http.Request )
5756 SaveNotificationChannelConfig (w http.ResponseWriter , r * http.Request )
@@ -118,66 +117,6 @@ func NewNotificationRestHandlerImpl(dockerRegistryConfig pipeline.DockerRegistry
118117 }
119118}
120119
121- // SaveNotificationSettings will be deprecated in future
122- func (impl NotificationRestHandlerImpl ) SaveNotificationSettings (w http.ResponseWriter , r * http.Request ) {
123- userId , err := impl .userAuthService .GetLoggedInUser (r )
124- if userId == 0 || err != nil {
125- common .WriteJsonResp (w , err , "Unauthorized User" , http .StatusUnauthorized )
126- return
127- }
128- var notificationSetting beans.NotificationRequest
129- err = json .NewDecoder (r .Body ).Decode (& notificationSetting )
130- if err != nil {
131- impl .logger .Errorw ("request err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
132- common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
133- return
134- }
135- impl .logger .Infow ("request payload, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
136- err = impl .validator .Struct (notificationSetting )
137- if err != nil {
138- impl .logger .Errorw ("validation err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
139- common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
140- return
141- }
142-
143- //RBAC
144- token := r .Header .Get ("token" )
145- if isSuperAdmin := impl .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionGet , "*" ); ! isSuperAdmin {
146- common .WriteJsonResp (w , err , nil , http .StatusForbidden )
147- return
148- }
149- //RBAC
150-
151- providers := notificationSetting .Providers
152-
153- if len (providers ) != 0 {
154- for _ , provider := range providers {
155- if provider .Destination == util .SMTP || provider .Destination == util .SES {
156- if provider .Recipient == "" {
157- userEmail , err := impl .userAuthService .GetEmailById (int32 (provider .ConfigId ))
158- if err != nil {
159- impl .logger .Errorw ("service err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
160- common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
161- return
162- }
163- provider .Recipient = userEmail
164- }
165- // get default configID for SES and SMTP
166- provider .ConfigId = notificationSetting .SesConfigId
167- }
168- }
169- }
170-
171- res , err := impl .notificationService .CreateOrUpdateNotificationSettings (& notificationSetting , userId )
172- if err != nil {
173- impl .logger .Errorw ("service err, SaveNotificationSettings" , "err" , err , "payload" , notificationSetting )
174- common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
175- return
176- }
177- w .Header ().Set ("Content-Type" , "application/json" )
178- common .WriteJsonResp (w , nil , res , http .StatusOK )
179- }
180-
181120func (impl NotificationRestHandlerImpl ) SaveNotificationSettingsV2 (w http.ResponseWriter , r * http.Request ) {
182121 userId , err := impl .userAuthService .GetLoggedInUser (r )
183122 if userId == 0 || err != nil {
0 commit comments