BlueGit

timfa bluegit

Merge branch 'cursor/release-only-logo' into 'stage'

timfa

Authored 2026-10-25 · 3 weeks ago

Hash
79095b872e091bda2d2df8c5e9688fa09b75f8bf
Pipeline
Passed
4 files changed +40 −4
internal/server/media.go +14 −1
@@ -14,6 +14,7 @@ import (
14 14 "gitlab.com/Timfa/bluegit/internal/access"
15 15 "gitlab.com/Timfa/bluegit/internal/i18n"
16 16 "gitlab.com/Timfa/bluegit/internal/logo"
17 "gitlab.com/Timfa/bluegit/internal/store"
17 18 )
18 19
19 20 func wantsModal(r *http.Request) bool {
@@ -109,7 +110,9 @@ func (s *Server) toggleStar(w http.ResponseWriter, r *http.Request) {
109 110 }
110 111
111 112 func (s *Server) repoLogo(w http.ResponseWriter, r *http.Request) {
112 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
113 // Repo-logo volgt de Releases-regel: wie de releases mag zien, ziet ook
114 // het logo (privé repo met publieke releases); verder zoals guard.
115 repo, ok := s.logoRepo(w, r)
113 116 if !ok {
114 117 return
115 118 }
@@ -212,3 +215,13 @@ func (s *Server) logoPath(kind string, id int64) (string, error) {
212 215 }
213 216 return filepath.Join(s.StateDir, "logos", kind+"-"+strconv.FormatInt(id, 10)), nil
214 217 }
218
219 func (s *Server) logoRepo(w http.ResponseWriter, r *http.Request) (store.Repo, bool) {
220 if repo, err := s.Store.RepoByPath(r.Context(), r.PathValue("owner"), r.PathValue("repo")); err == nil && repo.Visibility != "public" && !isCrawler(r) {
221 if _, role, err := s.webRole(r, repo); err == nil && releaseOnly(repo, role) {
222 return repo, true
223 }
224 }
225 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
226 return repo, ok
227 }
@@ -14,6 +14,7 @@ import (
14 "gitlab.com/Timfa/bluegit/internal/access"
14 "gitlab.com/Timfa/bluegit/internal/access"
15 "gitlab.com/Timfa/bluegit/internal/i18n"
15 "gitlab.com/Timfa/bluegit/internal/i18n"
16 "gitlab.com/Timfa/bluegit/internal/logo"
16 "gitlab.com/Timfa/bluegit/internal/logo"
17 "gitlab.com/Timfa/bluegit/internal/store"
17)
18)
18
19
19func wantsModal(r *http.Request) bool {
20func wantsModal(r *http.Request) bool {
@@ -109,7 +110,9 @@ func (s *Server) toggleStar(w http.ResponseWriter, r *http.Request) {
109}
110}
110
111
111func (s *Server) repoLogo(w http.ResponseWriter, r *http.Request) {
112func (s *Server) repoLogo(w http.ResponseWriter, r *http.Request) {
112 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
113 // Repo-logo volgt de Releases-regel: wie de releases mag zien, ziet ook
114 // het logo (privé repo met publieke releases); verder zoals guard.
115 repo, ok := s.logoRepo(w, r)
113 if !ok {
116 if !ok {
114 return
117 return
115 }
118 }
@@ -212,3 +215,13 @@ func (s *Server) logoPath(kind string, id int64) (string, error) {
212 }
215 }
213 return filepath.Join(s.StateDir, "logos", kind+"-"+strconv.FormatInt(id, 10)), nil
216 return filepath.Join(s.StateDir, "logos", kind+"-"+strconv.FormatInt(id, 10)), nil
214}
217}
218
219func (s *Server) logoRepo(w http.ResponseWriter, r *http.Request) (store.Repo, bool) {
220 if repo, err := s.Store.RepoByPath(r.Context(), r.PathValue("owner"), r.PathValue("repo")); err == nil && repo.Visibility != "public" && !isCrawler(r) {
221 if _, role, err := s.webRole(r, repo); err == nil && releaseOnly(repo, role) {
222 return repo, true
223 }
224 }
225 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
226 return repo, ok
227}
internal/server/release_access.go +1 −1
@@ -44,7 +44,7 @@ func shortDesc(s string) string {
44 44 // releases in overzichten ziet: naam, korte beschrijving, verder niets.
45 45 func releaseOnlyCard(r store.Repo) store.Repo {
46 46 return store.Repo{ID: r.ID, OwnerKind: r.OwnerKind, OwnerPath: r.OwnerPath, Name: r.Name,
47 Description: shortDesc(r.Description), Visibility: r.Visibility, ReleaseVisibility: r.ReleaseVisibility}
47 Description: shortDesc(r.Description), Visibility: r.Visibility, ReleaseVisibility: r.ReleaseVisibility, LogoMIME: r.LogoMIME}
48 48 }
49 49
50 50 func (s *Server) releaseOnlyRepos(r *http.Request, viewer int64) []store.Repo {
@@ -44,7 +44,7 @@ func shortDesc(s string) string {
44// releases in overzichten ziet: naam, korte beschrijving, verder niets.
44// releases in overzichten ziet: naam, korte beschrijving, verder niets.
45func releaseOnlyCard(r store.Repo) store.Repo {
45func releaseOnlyCard(r store.Repo) store.Repo {
46 return store.Repo{ID: r.ID, OwnerKind: r.OwnerKind, OwnerPath: r.OwnerPath, Name: r.Name,
46 return store.Repo{ID: r.ID, OwnerKind: r.OwnerKind, OwnerPath: r.OwnerPath, Name: r.Name,
47 Description: shortDesc(r.Description), Visibility: r.Visibility, ReleaseVisibility: r.ReleaseVisibility}
47 Description: shortDesc(r.Description), Visibility: r.Visibility, ReleaseVisibility: r.ReleaseVisibility, LogoMIME: r.LogoMIME}
48}
48}
49
49
50func (s *Server) releaseOnlyRepos(r *http.Request, viewer int64) []store.Repo {
50func (s *Server) releaseOnlyRepos(r *http.Request, viewer int64) []store.Repo {
internal/server/release_visibility_test.go +24 −1
@@ -71,6 +71,14 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
71 71 if _, err := st.CreateRelease(ctx, repo.ID, "v1", e.sha, "Eerste", "Release-notes hier", tim.ID, 0, []store.ReleaseAsset{{Name: "app.bin", StoragePath: asset, Size: 14}}); err != nil {
72 72 t.Fatal(err)
73 73 }
74 e.srv.StateDir = t.TempDir()
75 if lp, err := e.srv.logoPath("repo", repo.ID); err == nil {
76 _ = os.MkdirAll(filepath.Dir(lp), 0o755)
77 _ = os.WriteFile(lp, []byte("\x89PNG\r\n\x1a\nlogo"), 0o644)
78 _ = st.SetLogoMIME(ctx, "repo", repo.ID, "image/png")
79 } else {
80 t.Fatal(err)
81 }
74 82 pid, _ := st.CreatePipeline(ctx, repo.ID, e.sha, "refs/heads/master", "push", "tim", "init", []store.NewJob{{Name: "build", Stage: "build", Script: "true"}})
75 83
76 84 out, _ := st.UpsertUser(ctx, 10, "outsider", "", false)
@@ -99,7 +107,7 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
99 107
100 108 code := []string{"/-/tree", "/-/blob/README.md", "/-/commits", "/-/branches", "/-/tags", "/-/issues", "/-/merge-requests",
101 109 "/-/pipelines", "/-/pipelines/" + itoa(pid), "/-/archive/master/lib-master.zip", "/-/archive/master/lib-master.tar.gz",
102 "/-/tags/archive?tag=v1&format=zip", "/-/branches/archive?branch=master&format=tar.gz", "/-/commit/" + e.sha, "/-/logo", "/-/settings"}
110 "/-/tags/archive?tag=v1&format=zip", "/-/branches/archive?branch=master&format=tar.gz", "/-/commit/" + e.sha, "/-/settings"}
103 111 apiCode := []string{"", "/repository/tree", "/repository/commits", "/repository/files/README.md/raw?ref=master", "/pipelines", "/issues",
104 112 "/repository/tags/v1/archive"}
105 113
@@ -200,6 +208,21 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
200 208 if canRel && (c != http.StatusSeeOther || h.Get("Location") != "/team/lib/-/releases") || !canRel && c < 400 {
201 209 t.Errorf("%s %s releases/: %d %s", label, a.name, c, h.Get("Location"))
202 210 }
211 // HEAD (curl -I) gedraagt zich als GET op de projectroot.
212 for _, suf := range []string{"", "/", "/-"} {
213 req, _ := http.NewRequest(http.MethodHead, base+"/team/lib"+suf, nil)
214 if res, err := a.client.Do(req); err == nil {
215 res.Body.Close()
216 if !canCode && relPublic && (res.StatusCode != http.StatusSeeOther || res.Header.Get("Location") != "/team/lib/-/releases") {
217 t.Errorf("%s %s HEAD %s: %d", label, a.name, suf, res.StatusCode)
218 }
219 }
220 }
221 // Repo-logo volgt de Releases-regel (t701u).
222 c, _, _ = rvGet(t, a.client, base+"/team/lib/-/logo", "")
223 if seeLogo := canRel || canCode; seeLogo && c != 200 || !seeLogo && c < 400 {
224 t.Errorf("%s %s logo: %d", label, a.name, c)
225 }
203 226 // Niet-bestaand blijft 404; open redirect via dubbele slash kan niet.
204 227 for _, p := range []string{"/team/nope", "/team/nope/", "/team/nope/-", "//evil.example/x/-"} {
205 228 if c, _, h := rvGet(t, a.client, base+p, ""); c != 404 && !strings.HasPrefix(h.Get("Location"), "/") || strings.HasPrefix(h.Get("Location"), "//") {
@@ -71,6 +71,14 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
71 if _, err := st.CreateRelease(ctx, repo.ID, "v1", e.sha, "Eerste", "Release-notes hier", tim.ID, 0, []store.ReleaseAsset{{Name: "app.bin", StoragePath: asset, Size: 14}}); err != nil {
71 if _, err := st.CreateRelease(ctx, repo.ID, "v1", e.sha, "Eerste", "Release-notes hier", tim.ID, 0, []store.ReleaseAsset{{Name: "app.bin", StoragePath: asset, Size: 14}}); err != nil {
72 t.Fatal(err)
72 t.Fatal(err)
73 }
73 }
74 e.srv.StateDir = t.TempDir()
75 if lp, err := e.srv.logoPath("repo", repo.ID); err == nil {
76 _ = os.MkdirAll(filepath.Dir(lp), 0o755)
77 _ = os.WriteFile(lp, []byte("\x89PNG\r\n\x1a\nlogo"), 0o644)
78 _ = st.SetLogoMIME(ctx, "repo", repo.ID, "image/png")
79 } else {
80 t.Fatal(err)
81 }
74 pid, _ := st.CreatePipeline(ctx, repo.ID, e.sha, "refs/heads/master", "push", "tim", "init", []store.NewJob{{Name: "build", Stage: "build", Script: "true"}})
82 pid, _ := st.CreatePipeline(ctx, repo.ID, e.sha, "refs/heads/master", "push", "tim", "init", []store.NewJob{{Name: "build", Stage: "build", Script: "true"}})
75
83
76 out, _ := st.UpsertUser(ctx, 10, "outsider", "", false)
84 out, _ := st.UpsertUser(ctx, 10, "outsider", "", false)
@@ -99,7 +107,7 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
99
107
100 code := []string{"/-/tree", "/-/blob/README.md", "/-/commits", "/-/branches", "/-/tags", "/-/issues", "/-/merge-requests",
108 code := []string{"/-/tree", "/-/blob/README.md", "/-/commits", "/-/branches", "/-/tags", "/-/issues", "/-/merge-requests",
101 "/-/pipelines", "/-/pipelines/" + itoa(pid), "/-/archive/master/lib-master.zip", "/-/archive/master/lib-master.tar.gz",
109 "/-/pipelines", "/-/pipelines/" + itoa(pid), "/-/archive/master/lib-master.zip", "/-/archive/master/lib-master.tar.gz",
102 "/-/tags/archive?tag=v1&format=zip", "/-/branches/archive?branch=master&format=tar.gz", "/-/commit/" + e.sha, "/-/logo", "/-/settings"}
110 "/-/tags/archive?tag=v1&format=zip", "/-/branches/archive?branch=master&format=tar.gz", "/-/commit/" + e.sha, "/-/settings"}
103 apiCode := []string{"", "/repository/tree", "/repository/commits", "/repository/files/README.md/raw?ref=master", "/pipelines", "/issues",
111 apiCode := []string{"", "/repository/tree", "/repository/commits", "/repository/files/README.md/raw?ref=master", "/pipelines", "/issues",
104 "/repository/tags/v1/archive"}
112 "/repository/tags/v1/archive"}
105
113
@@ -200,6 +208,21 @@ func TestReleaseVisibilityMatrix(t *testing.T) {
200 if canRel && (c != http.StatusSeeOther || h.Get("Location") != "/team/lib/-/releases") || !canRel && c < 400 {
208 if canRel && (c != http.StatusSeeOther || h.Get("Location") != "/team/lib/-/releases") || !canRel && c < 400 {
201 t.Errorf("%s %s releases/: %d %s", label, a.name, c, h.Get("Location"))
209 t.Errorf("%s %s releases/: %d %s", label, a.name, c, h.Get("Location"))
202 }
210 }
211 // HEAD (curl -I) gedraagt zich als GET op de projectroot.
212 for _, suf := range []string{"", "/", "/-"} {
213 req, _ := http.NewRequest(http.MethodHead, base+"/team/lib"+suf, nil)
214 if res, err := a.client.Do(req); err == nil {
215 res.Body.Close()
216 if !canCode && relPublic && (res.StatusCode != http.StatusSeeOther || res.Header.Get("Location") != "/team/lib/-/releases") {
217 t.Errorf("%s %s HEAD %s: %d", label, a.name, suf, res.StatusCode)
218 }
219 }
220 }
221 // Repo-logo volgt de Releases-regel (t701u).
222 c, _, _ = rvGet(t, a.client, base+"/team/lib/-/logo", "")
223 if seeLogo := canRel || canCode; seeLogo && c != 200 || !seeLogo && c < 400 {
224 t.Errorf("%s %s logo: %d", label, a.name, c)
225 }
203 // Niet-bestaand blijft 404; open redirect via dubbele slash kan niet.
226 // Niet-bestaand blijft 404; open redirect via dubbele slash kan niet.
204 for _, p := range []string{"/team/nope", "/team/nope/", "/team/nope/-", "//evil.example/x/-"} {
227 for _, p := range []string{"/team/nope", "/team/nope/", "/team/nope/-", "//evil.example/x/-"} {
205 if c, _, h := rvGet(t, a.client, base+p, ""); c != 404 && !strings.HasPrefix(h.Get("Location"), "/") || strings.HasPrefix(h.Get("Location"), "//") {
228 if c, _, h := rvGet(t, a.client, base+p, ""); c != 404 && !strings.HasPrefix(h.Get("Location"), "/") || strings.HasPrefix(h.Get("Location"), "//") {
internal/server/repo_handlers.go +1 −1
@@ -34,7 +34,7 @@ func (s *Server) guard(w http.ResponseWriter, r *http.Request, min access.Role)
34 34 role = access.RoleNone
35 35 }
36 36 readable := role.CanRead() || repo.Visibility == "public"
37 if !readable && releaseOnly(repo, role) && r.Method == http.MethodGet && isRepoRootPath(r.URL.Path, repo) {
37 if !readable && releaseOnly(repo, role) && (r.Method == http.MethodGet || r.Method == http.MethodHead) && isRepoRootPath(r.URL.Path, repo) {
38 38 // Privé repo met publieke releases: alleen de Releases-pagina.
39 39 http.Redirect(w, r, "/"+repo.FullPath()+"/-/releases", http.StatusSeeOther)
40 40 return store.User{}, store.Repo{}, "", false
@@ -34,7 +34,7 @@ func (s *Server) guard(w http.ResponseWriter, r *http.Request, min access.Role)
34 role = access.RoleNone
34 role = access.RoleNone
35 }
35 }
36 readable := role.CanRead() || repo.Visibility == "public"
36 readable := role.CanRead() || repo.Visibility == "public"
37 if !readable && releaseOnly(repo, role) && r.Method == http.MethodGet && isRepoRootPath(r.URL.Path, repo) {
37 if !readable && releaseOnly(repo, role) && (r.Method == http.MethodGet || r.Method == http.MethodHead) && isRepoRootPath(r.URL.Path, repo) {
38 // Privé repo met publieke releases: alleen de Releases-pagina.
38 // Privé repo met publieke releases: alleen de Releases-pagina.
39 http.Redirect(w, r, "/"+repo.FullPath()+"/-/releases", http.StatusSeeOther)
39 http.Redirect(w, r, "/"+repo.FullPath()+"/-/releases", http.StatusSeeOther)
40 return store.User{}, store.Repo{}, "", false
40 return store.User{}, store.Repo{}, "", false