mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge remote-tracking branch 'upstream/master' into team-grant-all-repos
This commit is contained in:
@@ -6,9 +6,12 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/password"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
@@ -73,7 +76,11 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if !password.IsComplexEnough(form.Password) {
|
||||
err := errors.New("PasswordComplexity")
|
||||
ctx.Error(400, "PasswordComplexity", err)
|
||||
return
|
||||
}
|
||||
if err := models.CreateUser(u); err != nil {
|
||||
if models.IsErrUserAlreadyExist(err) ||
|
||||
models.IsErrEmailAlreadyUsed(err) ||
|
||||
@@ -131,6 +138,11 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
|
||||
}
|
||||
|
||||
if len(form.Password) > 0 {
|
||||
if !password.IsComplexEnough(form.Password) {
|
||||
err := errors.New("PasswordComplexity")
|
||||
ctx.Error(400, "PasswordComplexity", err)
|
||||
return
|
||||
}
|
||||
var err error
|
||||
if u.Salt, err = models.GetUserSalt(); err != nil {
|
||||
ctx.Error(500, "UpdateUser", err)
|
||||
|
||||
@@ -507,6 +507,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||
m.Get("/swagger", misc.Swagger)
|
||||
}
|
||||
m.Get("/version", misc.Version)
|
||||
m.Get("/signing-key.gpg", misc.SigningKey)
|
||||
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
|
||||
m.Post("/markdown/raw", misc.MarkdownRaw)
|
||||
|
||||
@@ -771,6 +772,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||
m.Delete("", bind(api.DeleteFileOptions{}), repo.DeleteFile)
|
||||
}, reqRepoWriter(models.UnitTypeCode), reqToken())
|
||||
}, reqRepoReader(models.UnitTypeCode))
|
||||
m.Get("/signing-key.gpg", misc.SigningKey)
|
||||
m.Group("/topics", func() {
|
||||
m.Combo("").Get(repo.ListTopics).
|
||||
Put(reqToken(), reqAdmin(), bind(api.RepoTopicOptions{}), repo.UpdateTopics)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
@@ -84,17 +85,21 @@ func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
||||
// ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification
|
||||
func ToVerification(c *git.Commit) *api.PayloadCommitVerification {
|
||||
verif := models.ParseCommitWithSignature(c)
|
||||
var signature, payload string
|
||||
commitVerification := &api.PayloadCommitVerification{
|
||||
Verified: verif.Verified,
|
||||
Reason: verif.Reason,
|
||||
}
|
||||
if c.Signature != nil {
|
||||
signature = c.Signature.Signature
|
||||
payload = c.Signature.Payload
|
||||
commitVerification.Signature = c.Signature.Signature
|
||||
commitVerification.Payload = c.Signature.Payload
|
||||
}
|
||||
return &api.PayloadCommitVerification{
|
||||
Verified: verif.Verified,
|
||||
Reason: verif.Reason,
|
||||
Signature: signature,
|
||||
Payload: payload,
|
||||
if verif.SigningUser != nil {
|
||||
commitVerification.Signer = &structs.PayloadUser{
|
||||
Name: verif.SigningUser.Name,
|
||||
Email: verif.SigningUser.Email,
|
||||
}
|
||||
}
|
||||
return commitVerification
|
||||
}
|
||||
|
||||
// ToPublicKey convert models.PublicKey to api.PublicKey
|
||||
@@ -233,12 +238,9 @@ func ToTeam(team *models.Team) *api.Team {
|
||||
// ToUser convert models.User to api.User
|
||||
func ToUser(user *models.User, signed, authed bool) *api.User {
|
||||
result := &api.User{
|
||||
ID: user.ID,
|
||||
UserName: user.Name,
|
||||
AvatarURL: user.AvatarLink(),
|
||||
FullName: markup.Sanitize(user.FullName),
|
||||
IsAdmin: user.IsAdmin,
|
||||
LastLogin: user.LastLoginUnix.AsTime(),
|
||||
Created: user.CreatedUnix.AsTime(),
|
||||
}
|
||||
// hide primary email if API caller isn't user itself or an admin
|
||||
@@ -246,8 +248,11 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
|
||||
result.Email = ""
|
||||
} else if user.KeepEmailPrivate && !authed {
|
||||
result.Email = user.GetEmail()
|
||||
} else {
|
||||
} else { // only user himself and admin could visit these information
|
||||
result.ID = user.ID
|
||||
result.Email = user.Email
|
||||
result.IsAdmin = user.IsAdmin
|
||||
result.LastLogin = user.LastLoginUnix.AsTime()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
// SigningKey returns the public key of the default signing key if it exists
|
||||
func SigningKey(ctx *context.Context) {
|
||||
// swagger:operation GET /signing-key.gpg miscellaneous getSigningKey
|
||||
// ---
|
||||
// summary: Get default signing-key.gpg
|
||||
// produces:
|
||||
// - text/plain
|
||||
// responses:
|
||||
// "200":
|
||||
// description: "GPG armored public key"
|
||||
// schema:
|
||||
// type: string
|
||||
|
||||
// swagger:operation GET /repos/{owner}/{repo}/signing-key.gpg repository repoSigningKey
|
||||
// ---
|
||||
// summary: Get signing-key.gpg for given repository
|
||||
// produces:
|
||||
// - text/plain
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// description: "GPG armored public key"
|
||||
// schema:
|
||||
// type: string
|
||||
|
||||
path := ""
|
||||
if ctx.Repo != nil && ctx.Repo.Repository != nil {
|
||||
path = ctx.Repo.Repository.RepoPath()
|
||||
}
|
||||
|
||||
content, err := models.PublicSigningKey(path)
|
||||
if err != nil {
|
||||
ctx.ServerError("gpg export", err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write([]byte(content))
|
||||
if err != nil {
|
||||
log.Error("Error writing key content %v", err)
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("%v", err))
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func GetEditorconfig(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
fileName := ctx.Params("filename")
|
||||
def := ec.GetDefinitionForFilename(fileName)
|
||||
def, err := ec.GetDefinitionForFilename(fileName)
|
||||
if def == nil {
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
|
||||
@@ -213,12 +213,31 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the passed assignees is assignable
|
||||
for _, aID := range assigneeIDs {
|
||||
assignee, err := models.GetUserByID(aID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetUserByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
valid, err := models.CanBeAssigned(assignee, ctx.Repo.Repository, false)
|
||||
if err != nil {
|
||||
ctx.Error(500, "canBeAssigned", err)
|
||||
return
|
||||
}
|
||||
if !valid {
|
||||
ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// setting labels is not allowed if user is not a writer
|
||||
form.Labels = make([]int64, 0)
|
||||
}
|
||||
|
||||
if err := issue_service.NewIssue(ctx.Repo.Repository, issue, form.Labels, assigneeIDs, nil); err != nil {
|
||||
if err := issue_service.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil); err != nil {
|
||||
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err)
|
||||
return
|
||||
@@ -227,6 +246,11 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue_service.AddAssignees(issue, ctx.User, assigneeIDs); err != nil {
|
||||
ctx.ServerError("AddAssignees", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyNewIssue(issue)
|
||||
|
||||
if form.Closed {
|
||||
@@ -336,9 +360,9 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
oneAssignee = *form.Assignee
|
||||
}
|
||||
|
||||
err = models.UpdateAPIAssignee(issue, oneAssignee, form.Assignees, ctx.User)
|
||||
err = issue_service.UpdateAssignees(issue, oneAssignee, form.Assignees, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(500, "UpdateAPIAssignee", err)
|
||||
ctx.Error(500, "UpdateAssignees", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
)
|
||||
|
||||
// ListIssueLabels list all the labels of an issue
|
||||
@@ -116,7 +117,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = issue.AddLabels(ctx.User, labels); err != nil {
|
||||
if err = issue_service.AddLabels(issue, ctx.User, labels); err != nil {
|
||||
ctx.Error(500, "AddLabels", err)
|
||||
return
|
||||
}
|
||||
@@ -314,7 +315,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue.ClearLabels(ctx.User); err != nil {
|
||||
if err := issue_service.ClearLabels(issue, ctx.User); err != nil {
|
||||
ctx.Error(500, "ClearLabels", err)
|
||||
return
|
||||
}
|
||||
|
||||
+36
-13
@@ -17,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
milestone_service "code.gitea.io/gitea/services/milestone"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
@@ -190,7 +191,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
)
|
||||
|
||||
// Get repo/branch information
|
||||
headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form)
|
||||
_, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
@@ -265,15 +266,14 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
DeadlineUnix: deadlineUnix,
|
||||
}
|
||||
pr := &models.PullRequest{
|
||||
HeadRepoID: headRepo.ID,
|
||||
BaseRepoID: repo.ID,
|
||||
HeadUserName: headUser.Name,
|
||||
HeadBranch: headBranch,
|
||||
BaseBranch: baseBranch,
|
||||
HeadRepo: headRepo,
|
||||
BaseRepo: repo,
|
||||
MergeBase: compareInfo.MergeBase,
|
||||
Type: models.PullRequestGitea,
|
||||
HeadRepoID: headRepo.ID,
|
||||
BaseRepoID: repo.ID,
|
||||
HeadBranch: headBranch,
|
||||
BaseBranch: baseBranch,
|
||||
HeadRepo: headRepo,
|
||||
BaseRepo: repo,
|
||||
MergeBase: compareInfo.MergeBase,
|
||||
Type: models.PullRequestGitea,
|
||||
}
|
||||
|
||||
// Get all assignee IDs
|
||||
@@ -286,8 +286,26 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
}
|
||||
return
|
||||
}
|
||||
// Check if the passed assignees is assignable
|
||||
for _, aID := range assigneeIDs {
|
||||
assignee, err := models.GetUserByID(aID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetUserByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch, assigneeIDs); err != nil {
|
||||
valid, err := models.CanBeAssigned(assignee, repo, true)
|
||||
if err != nil {
|
||||
ctx.Error(500, "canBeAssigned", err)
|
||||
return
|
||||
}
|
||||
if !valid {
|
||||
ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch); err != nil {
|
||||
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err)
|
||||
return
|
||||
@@ -299,6 +317,11 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue_service.AddAssignees(prIssue, ctx.User, assigneeIDs); err != nil {
|
||||
ctx.ServerError("AddAssignees", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyNewPullRequest(pr)
|
||||
|
||||
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
|
||||
@@ -388,12 +411,12 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||
// Send an empty array ([]) to clear all assignees from the Issue.
|
||||
|
||||
if ctx.Repo.CanWrite(models.UnitTypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
|
||||
err = models.UpdateAPIAssignee(issue, form.Assignee, form.Assignees, ctx.User)
|
||||
err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.User)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||
} else {
|
||||
ctx.Error(500, "UpdateAPIAssignee", err)
|
||||
ctx.Error(500, "UpdateAssignees", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+23
-14
@@ -8,6 +8,7 @@ package repo
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/migrations"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
@@ -397,21 +399,28 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||
return
|
||||
}
|
||||
|
||||
var gitServiceType = structs.PlainGitService
|
||||
u, err := url.Parse(remoteAddr)
|
||||
if err == nil && strings.EqualFold(u.Host, "github.com") {
|
||||
gitServiceType = structs.GithubService
|
||||
}
|
||||
|
||||
var opts = migrations.MigrateOptions{
|
||||
RemoteURL: remoteAddr,
|
||||
Name: form.RepoName,
|
||||
Description: form.Description,
|
||||
Private: form.Private || setting.Repository.ForcePrivate,
|
||||
Mirror: form.Mirror,
|
||||
AuthUsername: form.AuthUsername,
|
||||
AuthPassword: form.AuthPassword,
|
||||
Wiki: form.Wiki,
|
||||
Issues: form.Issues,
|
||||
Milestones: form.Milestones,
|
||||
Labels: form.Labels,
|
||||
Comments: true,
|
||||
PullRequests: form.PullRequests,
|
||||
Releases: form.Releases,
|
||||
CloneAddr: remoteAddr,
|
||||
RepoName: form.RepoName,
|
||||
Description: form.Description,
|
||||
Private: form.Private || setting.Repository.ForcePrivate,
|
||||
Mirror: form.Mirror,
|
||||
AuthUsername: form.AuthUsername,
|
||||
AuthPassword: form.AuthPassword,
|
||||
Wiki: form.Wiki,
|
||||
Issues: form.Issues,
|
||||
Milestones: form.Milestones,
|
||||
Labels: form.Labels,
|
||||
Comments: true,
|
||||
PullRequests: form.PullRequests,
|
||||
Releases: form.Releases,
|
||||
GitServiceType: gitServiceType,
|
||||
}
|
||||
if opts.Mirror {
|
||||
opts.Issues = false
|
||||
|
||||
@@ -52,7 +52,7 @@ func ListUserRepos(ctx *context.APIContext) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
private := ctx.IsSigned && (ctx.User.ID == user.ID || ctx.User.IsAdmin)
|
||||
private := ctx.IsSigned
|
||||
listUserRepos(ctx, user, private)
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ func GetInfo(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin))
|
||||
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin)))
|
||||
}
|
||||
|
||||
// GetAuthenticatedUser get current user's information
|
||||
|
||||
Reference in New Issue
Block a user