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

Method putAppearance

enterprise/coderd/appearance.go:145–210  ·  view source on GitHub ↗

@Summary Update appearance @ID update-appearance @Security CoderSessionToken @Accept json @Produce json @Tags Enterprise @Param request body codersdk.UpdateAppearanceConfig true "Update appearance request" @Success 200 {object} codersdk.UpdateAppearanceConfig @Router /api/v2/appearance [put]

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

Source from the content-addressed store, hash-verified

143// @Success 200 {object} codersdk.UpdateAppearanceConfig
144// @Router /api/v2/appearance [put]
145func (api *API) putAppearance(rw http.ResponseWriter, r *http.Request) {
146 ctx := r.Context()
147
148 if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) {
149 httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
150 Message: "Insufficient permissions to update appearance",
151 })
152 return
153 }
154
155 var appearance codersdk.UpdateAppearanceConfig
156 if !httpapi.Read(ctx, rw, r, &appearance) {
157 return
158 }
159
160 for _, banner := range appearance.AnnouncementBanners {
161 if err := validateHexColor(banner.BackgroundColor); err != nil {
162 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
163 Message: fmt.Sprintf("Invalid color format: %q", banner.BackgroundColor),
164 Detail: err.Error(),
165 })
166 return
167 }
168 }
169
170 if appearance.AnnouncementBanners == nil {
171 appearance.AnnouncementBanners = []codersdk.BannerConfig{}
172 }
173 announcementBannersJSON, err := json.Marshal(appearance.AnnouncementBanners)
174 if err != nil {
175 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
176 Message: "Unable to marshal announcement banners",
177 Detail: err.Error(),
178 })
179 return
180 }
181
182 err = api.Database.UpsertAnnouncementBanners(ctx, string(announcementBannersJSON))
183 if err != nil {
184 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
185 Message: "Unable to set announcement banners",
186 Detail: err.Error(),
187 })
188 return
189 }
190
191 err = api.Database.UpsertApplicationName(ctx, appearance.ApplicationName)
192 if err != nil {
193 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
194 Message: "Unable to set application name",
195 Detail: err.Error(),
196 })
197 return
198 }
199
200 err = api.Database.UpsertLogoURL(ctx, appearance.LogoURL)
201 if err != nil {
202 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{

Callers

nothing calls this directly

Calls 10

AuthorizeMethod · 0.95
WriteFunction · 0.92
ReadFunction · 0.92
validateHexColorFunction · 0.85
ContextMethod · 0.65
UpsertApplicationNameMethod · 0.65
UpsertLogoURLMethod · 0.65
ErrorMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected