Commit c086411ce4
Verified · cmc
Layout: unified · split
internal/httpd/settings.go +16 −7
| @@ -82,6 +82,10 @@ func (s *Server) settingsRedirect(w http.ResponseWriter, r *http.Request, msg st | |||
| 82 | // settingsSubmit routes one form to its command. Keeping the mapping in | 82 | // settingsSubmit routes one form to its command. Keeping the mapping in |
| 83 | // one place makes what the page can reach obvious. | 83 | // one place makes what the page can reach obvious. |
| 84 | func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store.User) { | 84 | func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store.User) { |
| 85 | row, ok := s.repoForUser(w, r, u, policyCanAdmin) | ||
| 86 | if !ok { | ||
| 87 | return | ||
| 88 | } | ||
| 85 | repo := r.PathValue("owner") + "/" + r.PathValue("repo") | 89 | repo := r.PathValue("owner") + "/" + r.PathValue("repo") |
| 86 | v := func(k string) string { return strings.TrimSpace(r.FormValue(k)) } | 90 | v := func(k string) string { return strings.TrimSpace(r.FormValue(k)) } |
| 87 | field := r.FormValue("field") | 91 | field := r.FormValue("field") |
| @@ -131,11 +135,6 @@ func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store. | |||
| 131 | } | 135 | } |
| 132 | argv = []string{"repo", verb, repo} | 136 | argv = []string{"repo", verb, repo} |
| 133 | case "topics": | 137 | case "topics": |
| 134 | row, err := s.st.RepoByPath(repo) | ||
| 135 | if err != nil { | ||
| 136 | http.NotFound(w, r) | ||
| 137 | return | ||
| 138 | } | ||
| 139 | want := map[string]bool{} | 138 | want := map[string]bool{} |
| 140 | var order []string | 139 | var order []string |
| 141 | for _, t := range strings.Split(v("topics"), ",") { | 140 | for _, t := range strings.Split(v("topics"), ",") { |
| @@ -160,11 +159,13 @@ func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store. | |||
| 160 | remove = append(remove, t) | 159 | remove = append(remove, t) |
| 161 | } | 160 | } |
| 162 | } | 161 | } |
| 162 | removed := false | ||
| 163 | if len(remove) > 0 { | 163 | if len(remove) > 0 { |
| 164 | if _, msg, ok := s.runControl(u, append([]string{"repo", "topics", "remove", repo}, remove...)); !ok { | 164 | if _, msg, ok := s.runControl(u, append([]string{"repo", "topics", "remove", repo}, remove...)); !ok { |
| 165 | s.settingsFormWith(w, r, u, msg, r.Form) | 165 | s.settingsFormWith(w, r, u, msg, r.Form) |
| 166 | return | 166 | return |
| 167 | } | 167 | } |
| 168 | removed = true | ||
| 168 | } | 169 | } |
| 169 | if len(add) > 0 { | 170 | if len(add) > 0 { |
| 170 | argv = append([]string{"repo", "topics", "add", repo}, add...) | 171 | argv = append([]string{"repo", "topics", "add", repo}, add...) |
| @@ -172,6 +173,14 @@ func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store. | |||
| 172 | s.settingsRedirect(w, r, "Saved the topics.") | 173 | s.settingsRedirect(w, r, "Saved the topics.") |
| 173 | return | 174 | return |
| 174 | } | 175 | } |
| 176 | if removed { | ||
| 177 | if _, msg, ok := s.runControl(u, argv); !ok { | ||
| 178 | s.settingsFormWith(w, r, u, "Removed "+strings.Join(remove, ", ")+"; "+msg, r.Form) | ||
| 179 | return | ||
| 180 | } | ||
| 181 | s.settingsRedirect(w, r, "Saved the "+fieldLabel(field)+".") | ||
| 182 | return | ||
| 183 | } | ||
| 175 | case "runner-add": | 184 | case "runner-add": |
| 176 | body := v("key") | 185 | body := v("key") |
| 177 | if body == "" { | 186 | if body == "" { |
| @@ -223,7 +232,7 @@ func fieldLabel(field string) string { | |||
| 223 | case "require-codeowners": | 232 | case "require-codeowners": |
| 224 | return "CODEOWNERS" | 233 | return "CODEOWNERS" |
| 225 | case "require-mr": | 234 | case "require-mr": |
| 226 | return "require-MR" | 235 | return "merge request requirement" |
| 227 | case "require-signed": | 236 | case "require-signed": |
| 228 | return "signed commits" | 237 | return "signed commits" |
| 229 | case "protect", "unprotect": | 238 | case "protect", "unprotect": |
| @@ -233,7 +242,7 @@ func fieldLabel(field string) string { | |||
| 233 | case "deps": | 242 | case "deps": |
| 234 | return "dependency scanning" | 243 | return "dependency scanning" |
| 235 | case "archive": | 244 | case "archive": |
| 236 | return "archive" | 245 | return "archived state" |
| 237 | case "topics": | 246 | case "topics": |
| 238 | return "topics" | 247 | return "topics" |
| 239 | case "runner-add", "runner-remove": | 248 | case "runner-add", "runner-remove": |
internal/httpd/web.go +1 −10
| @@ -193,14 +193,6 @@ var landingPicture = func() bool { | |||
| 193 | }() | 193 | }() |
| 194 | 194 | ||
| 195 | func (s *Server) dashboard(w http.ResponseWriter, r *http.Request, viewer store.User) { | 195 | func (s *Server) dashboard(w http.ResponseWriter, r *http.Request, viewer store.User) { |
| 196 | pinned, _ := s.st.PinnedRepos(viewer.ID) | ||
| 197 | var visible []store.Repo | ||
| 198 | for _, rp := range pinned { | ||
| 199 | grant, _ := s.st.AccessRole(rp.ID, viewer.ID) | ||
| 200 | if policy.CanRead(viewer, rp, grant) { | ||
| 201 | visible = append(visible, rp) | ||
| 202 | } | ||
| 203 | } | ||
| 204 | mrs, _ := s.st.DashboardMRs(viewer.ID) | 196 | mrs, _ := s.st.DashboardMRs(viewer.ID) |
| 205 | issues, _ := s.st.DashboardIssues(viewer.ID) | 197 | issues, _ := s.st.DashboardIssues(viewer.ID) |
| 206 | reviews, _ := s.st.ReviewQueue(viewer.ID) | 198 | reviews, _ := s.st.ReviewQueue(viewer.ID) |
| @@ -208,13 +200,12 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request, viewer store. | |||
| 208 | events, _ := s.st.RecentEvents(viewer.ID, 20, 0) | 200 | events, _ := s.st.RecentEvents(viewer.ID, 20, 0) |
| 209 | s.render(w, "dashboard.html", struct { | 201 | s.render(w, "dashboard.html", struct { |
| 210 | basePage | 202 | basePage |
| 211 | Pinned []store.Repo | ||
| 212 | Reviews []store.DashboardItem | 203 | Reviews []store.DashboardItem |
| 213 | Assigned []store.DashboardItem | 204 | Assigned []store.DashboardItem |
| 214 | MRs []store.DashboardItem | 205 | MRs []store.DashboardItem |
| 215 | Issues []store.DashboardItem | 206 | Issues []store.DashboardItem |
| 216 | Feed []feedLine | 207 | Feed []feedLine |
| 217 | }{s.baseFor(viewer), visible, reviews, assigned, mrs, issues, feedLines(events)}) | 208 | }{s.baseFor(viewer), reviews, assigned, mrs, issues, feedLines(events)}) |
| 218 | } | 209 | } |
| 219 | 210 | ||
| 220 | func (s *Server) explore(w http.ResponseWriter, r *http.Request) { | 211 | func (s *Server) explore(w http.ResponseWriter, r *http.Request) { |