mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-03 16:52:10 +02:00
update serv command to recognize group ids in urls
This commit is contained in:
parent
29a68da062
commit
27cdd77a59
17
cmd/serv.go
17
cmd/serv.go
@ -201,8 +201,17 @@ func runServ(ctx context.Context, c *cli.Command) error {
|
||||
|
||||
repoPath := strings.TrimPrefix(sshCmdArgs[1], "/")
|
||||
repoPathFields := strings.SplitN(repoPath, "/", 2)
|
||||
rawGroup, _, _ := strings.Cut(repoPathFields[1], "/")
|
||||
var groupID int64
|
||||
if len(repoPathFields) != 2 {
|
||||
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
|
||||
if len(repoPathFields) == 3 {
|
||||
groupID, err = strconv.ParseInt(rawGroup, 10, 64)
|
||||
if err != nil {
|
||||
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
|
||||
}
|
||||
} else {
|
||||
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
|
||||
}
|
||||
}
|
||||
|
||||
username := repoPathFields[0]
|
||||
@ -249,16 +258,16 @@ func runServ(ctx context.Context, c *cli.Command) error {
|
||||
|
||||
requestedMode := getAccessMode(verb, lfsVerb)
|
||||
|
||||
results, extra := private.ServCommand(ctx, keyID, username, reponame, requestedMode, verb, lfsVerb)
|
||||
results, extra := private.ServCommand(ctx, keyID, username, reponame, groupID, requestedMode, verb, lfsVerb)
|
||||
if extra.HasError() {
|
||||
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
|
||||
}
|
||||
|
||||
// because the original repoPath maybe redirected, we need to use the returned actual repository information
|
||||
if results.IsWiki {
|
||||
repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName)
|
||||
repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName, groupID)
|
||||
} else {
|
||||
repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName)
|
||||
repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName, groupID)
|
||||
}
|
||||
|
||||
// LFS SSH protocol
|
||||
|
||||
@ -46,10 +46,15 @@ type ServCommandResults struct {
|
||||
}
|
||||
|
||||
// ServCommand preps for a serv call
|
||||
func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) {
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s?mode=%d",
|
||||
func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, groupID int64, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) {
|
||||
var groupSegment string
|
||||
if groupID > 0 {
|
||||
groupSegment = fmt.Sprintf("%d/", groupID)
|
||||
}
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s%s?mode=%d",
|
||||
keyID,
|
||||
url.PathEscape(ownerName),
|
||||
groupSegment,
|
||||
url.PathEscape(repoName),
|
||||
mode,
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user