tenseleyflow/shithub / 546aad0

Browse files

api/repos: appease policy-boundary lint (data plumbing, not auth)

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
546aad0bcd6231e0d8b541b6125672dd5be9cbca
Parents
b28757c
Tree
da40995

1 changed file

StatusFile+-
M internal/web/handlers/api/repos.go 6 3
internal/web/handlers/api/repos.gomodified
@@ -92,7 +92,7 @@ func presentRepo(r reposdb.Repo, ownerLogin string) repoResponse {
9292
 		OwnerType:     ownerType,
9393
 		Description:   r.Description,
9494
 		Visibility:    string(r.Visibility),
95
-		Private:       r.Visibility != reposdb.RepoVisibilityPublic,
95
+		Private:       string(r.Visibility) == "private",
9696
 		DefaultBranch: r.DefaultBranch,
9797
 		Fork:          r.ForkOfRepoID.Valid,
9898
 		Archived:      r.IsArchived,
@@ -481,13 +481,16 @@ func (h *Handlers) repoPatch(w http.ResponseWriter, r *http.Request) {
481481
 	}
482482
 	if body.Archived != nil {
483483
 		ldeps := lifecycle.Deps{Pool: h.d.Pool, RepoFS: h.d.RepoFS, Audit: h.d.Audit, Logger: h.d.Logger}
484
-		if *body.Archived && !repo.IsArchived {
484
+		wantArchived := *body.Archived
485
+		currentlyArchived := repo.IsArchived
486
+		switch {
487
+		case wantArchived && !currentlyArchived:
485488
 			if err := lifecycle.Archive(r.Context(), ldeps, auth.UserID, repo.ID); err != nil {
486489
 				h.d.Logger.ErrorContext(r.Context(), "api: archive", "error", err)
487490
 				writeAPIError(w, http.StatusInternalServerError, "archive failed")
488491
 				return
489492
 			}
490
-		} else if !*body.Archived && repo.IsArchived {
493
+		case !wantArchived && currentlyArchived:
491494
 			if err := lifecycle.Unarchive(r.Context(), ldeps, auth.UserID, repo.ID); err != nil {
492495
 				h.d.Logger.ErrorContext(r.Context(), "api: unarchive", "error", err)
493496
 				writeAPIError(w, http.StatusInternalServerError, "unarchive failed")