mirror of
https://github.com/go-gitea/gitea
synced 2024-11-17 23:41:49 +01:00
parent
f144521aea
commit
265f485295
3 changed files with 62 additions and 3 deletions
|
@ -789,6 +789,24 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.APIC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func individualPermsChecker(ctx *context.APIContext) {
|
||||||
|
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
|
||||||
|
if ctx.ContextUser.IsIndividual() {
|
||||||
|
switch {
|
||||||
|
case ctx.ContextUser.Visibility == api.VisibleTypePrivate:
|
||||||
|
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
||||||
|
ctx.NotFound("Visit Project", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
|
||||||
|
if ctx.Doer == nil {
|
||||||
|
ctx.NotFound("Visit Project", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check for and warn against deprecated authentication options
|
// check for and warn against deprecated authentication options
|
||||||
func checkDeprecatedAuthMethods(ctx *context.APIContext) {
|
func checkDeprecatedAuthMethods(ctx *context.APIContext) {
|
||||||
if ctx.FormString("token") != "" || ctx.FormString("access_token") != "" {
|
if ctx.FormString("token") != "" || ctx.FormString("access_token") != "" {
|
||||||
|
@ -898,7 +916,7 @@ func Routes() *web.Route {
|
||||||
}, reqSelfOrAdmin(), reqBasicOrRevProxyAuth())
|
}, reqSelfOrAdmin(), reqBasicOrRevProxyAuth())
|
||||||
|
|
||||||
m.Get("/activities/feeds", user.ListUserActivityFeeds)
|
m.Get("/activities/feeds", user.ListUserActivityFeeds)
|
||||||
}, context_service.UserAssignmentAPI())
|
}, context_service.UserAssignmentAPI(), individualPermsChecker)
|
||||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser))
|
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser))
|
||||||
|
|
||||||
// Users (requires user scope)
|
// Users (requires user scope)
|
||||||
|
|
|
@ -795,6 +795,24 @@ func registerRoutes(m *web.Route) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
individualPermsChecker := func(ctx *context.Context) {
|
||||||
|
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
|
||||||
|
if ctx.ContextUser.IsIndividual() {
|
||||||
|
switch {
|
||||||
|
case ctx.ContextUser.Visibility == structs.VisibleTypePrivate:
|
||||||
|
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
||||||
|
ctx.NotFound("Visit Project", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case ctx.ContextUser.Visibility == structs.VisibleTypeLimited:
|
||||||
|
if ctx.Doer == nil {
|
||||||
|
ctx.NotFound("Visit Project", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ***** START: Organization *****
|
// ***** START: Organization *****
|
||||||
m.Group("/org", func() {
|
m.Group("/org", func() {
|
||||||
m.Group("/{org}", func() {
|
m.Group("/{org}", func() {
|
||||||
|
@ -975,11 +993,11 @@ func registerRoutes(m *web.Route) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}, reqUnitAccess(unit.TypeProjects, perm.AccessModeRead, true), individualPermsChecker)
|
||||||
|
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/code", user.CodeSearch)
|
m.Get("/code", user.CodeSearch)
|
||||||
}, reqUnitAccess(unit.TypeCode, perm.AccessModeRead, false))
|
}, reqUnitAccess(unit.TypeCode, perm.AccessModeRead, false), individualPermsChecker)
|
||||||
}, ignSignIn, context_service.UserAssignmentWeb(), context.OrgAssignment()) // for "/{username}/-" (packages, projects, code)
|
}, ignSignIn, context_service.UserAssignmentWeb(), context.OrgAssignment()) // for "/{username}/-" (packages, projects, code)
|
||||||
|
|
||||||
m.Group("/{username}/{reponame}", func() {
|
m.Group("/{username}/{reponame}", func() {
|
||||||
|
|
23
tests/integration/project_test.go
Normal file
23
tests/integration/project_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/tests"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrivateRepoProject(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
// not logged in user
|
||||||
|
req := NewRequest(t, "GET", "/user31/-/projects")
|
||||||
|
MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
|
||||||
|
sess := loginUser(t, "user1")
|
||||||
|
req = NewRequest(t, "GET", "/user31/-/projects")
|
||||||
|
sess.MakeRequest(t, req, http.StatusOK)
|
||||||
|
}
|
Loading…
Reference in a new issue