MCPcopy Index your code
hub / github.com/coder/coder / updateNotificationTemplateMethod

Method updateNotificationTemplateMethod

enterprise/coderd/notifications.go:26–98  ·  view source on GitHub ↗

@Summary Update notification template dispatch method @ID update-notification-template-dispatch-method @Security CoderSessionToken @Produce json @Param notification_template path string true "Notification template UUID" @Tags Enterprise @Success 200 "Success" @Success 304 "Not modified" @Router /api

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

24// @Success 304 "Not modified"
25// @Router /api/v2/notifications/templates/{notification_template}/method [put]
26func (api *API) updateNotificationTemplateMethod(rw http.ResponseWriter, r *http.Request) {
27 var (
28 ctx = r.Context()
29 template = httpmw.NotificationTemplateParam(r)
30 auditor = api.AGPL.Auditor.Load()
31 aReq, commitAudit = audit.InitRequest[database.NotificationTemplate](rw, &audit.RequestParams{
32 Audit: *auditor,
33 Log: api.Logger,
34 Request: r,
35 Action: database.AuditActionWrite,
36 })
37 )
38
39 var req codersdk.UpdateNotificationTemplateMethod
40 if !httpapi.Read(ctx, rw, r, &req) {
41 return
42 }
43
44 var nm database.NullNotificationMethod
45 if err := nm.Scan(req.Method); err != nil || !nm.Valid || !nm.NotificationMethod.Valid() {
46 vals := database.AllNotificationMethodValues()
47 acceptable := make([]string, len(vals))
48 for i, v := range vals {
49 acceptable[i] = string(v)
50 }
51
52 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
53 Message: "Invalid request to update notification template method",
54 Validations: []codersdk.ValidationError{
55 {
56 Field: "method",
57 Detail: fmt.Sprintf("%q is not a valid method; %s are the available options",
58 req.Method, strings.Join(acceptable, ", "),
59 ),
60 },
61 },
62 })
63 return
64 }
65
66 if template.Method == nm {
67 httpapi.Write(ctx, rw, http.StatusNotModified, codersdk.Response{
68 Message: "Notification template method unchanged.",
69 })
70 return
71 }
72
73 defer commitAudit()
74 aReq.Old = template
75
76 err := api.Database.InTx(func(tx database.Store) error {
77 var err error
78 template, err = tx.UpdateNotificationTemplateMethodByID(r.Context(), database.UpdateNotificationTemplateMethodByIDParams{
79 ID: template.ID,
80 Method: nm,
81 })
82 if err != nil {
83 return xerrors.Errorf("failed to update notification template ID: %w", err)

Callers 1

Calls 13

ScanMethod · 0.95
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
InternalServerErrorFunction · 0.92
ContextMethod · 0.65
ValidMethod · 0.65
InTxMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected