Skip to content

Commit dab9ca3

Browse files
Merge branch 'master' into certmagic
2 parents 5b1bbec + 9659808 commit dab9ca3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+778
-255
lines changed

.drone.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ steps:
3333
GOSUMDB: sum.golang.org
3434
TAGS: bindata sqlite sqlite_unlock_notify
3535

36+
- name: lint-backend-windows
37+
pull: always
38+
image: golang:1.15
39+
commands:
40+
- make golangci-lint vet
41+
environment:
42+
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
43+
GOSUMDB: sum.golang.org
44+
TAGS: bindata sqlite sqlite_unlock_notify
45+
GOOS: windows
46+
GOARCH: amd64
47+
3648
- name: lint-backend-gogit
3749
pull: always
3850
image: golang:1.15
@@ -85,6 +97,18 @@ steps:
8597
- rm ./gitea # clean
8698
depends_on: [checks-backend]
8799

100+
- name: build-backend-windows
101+
image: golang:1.15
102+
environment:
103+
GO111MODULE: on
104+
GOPROXY: off
105+
GOOS: windows
106+
GOARCH: amd64
107+
TAGS: bindata gogit
108+
commands:
109+
- go build -mod=vendor -o gitea_windows
110+
depends_on: [checks-backend]
111+
88112
- name: build-backend-386
89113
image: golang:1.15
90114
environment:

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Mura Li <[email protected]> (@typeless)
3636
6543 <[email protected]> (@6543)
3737
jaqra <[email protected]> (@jaqra)
3838
David Svantesson <[email protected]> (@davidsvantesson)
39-
CirnoT <[email protected]> (@CirnoT)
4039
a1012112796 <[email protected]> (@a1012112796)
4140
Karl Heinz Marbaise <[email protected]> (@khmarbaise)
4241
Norwin Roosen <[email protected]> (@noerw)

cmd/admin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,11 @@ func runChangePassword(c *cli.Context) error {
349349
if err != nil {
350350
return err
351351
}
352-
if user.Salt, err = models.GetUserSalt(); err != nil {
352+
if err = user.SetPassword(c.String("password")); err != nil {
353353
return err
354354
}
355-
user.HashPassword(c.String("password"))
356355

357-
if err := models.UpdateUserCols(user, "passwd", "passwd_hash_algo", "salt"); err != nil {
356+
if err = models.UpdateUserCols(user, "passwd", "passwd_hash_algo", "salt"); err != nil {
358357
return err
359358
}
360359

docs/content/page/index.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
268268
## Components
269269

270270
* Web framework: [Macaron](http://go-macaron.com/)
271-
* ORM: [XORM](https://github.com/go-xorm/xorm)
271+
* ORM: [XORM](https://xorm.io)
272272
* UI components:
273273
* [Semantic UI](http://semantic-ui.com/)
274274
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.fr-fr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide
255255
## Composants
256256

257257
* Framework web : [Macaron](http://go-macaron.com/)
258-
* ORM : [XORM](https://github.com/go-xorm/xorm)
258+
* ORM: [XORM](https://xorm.io)
259259
* Interface graphique :
260260
* [Semantic UI](http://semantic-ui.com/)
261261
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和
4848
## 组件
4949

5050
* Web框架: [Macaron](http://go-macaron.com/)
51-
* ORM [XORM](https://github.com/go-xorm/xorm)
51+
* ORM: [XORM](https://xorm.io)
5252
* UI组件:
5353
* [Semantic UI](http://semantic-ui.com/)
5454
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.zh-tw.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Gitea 的首要目標是建立一個容易安裝,運行快速,安装和使
4848
## 元件
4949

5050
* Web 框架: [Macaron](http://go-macaron.com/)
51-
* ORM: [XORM](https://github.com/go-xorm/xorm)
51+
* ORM: [XORM](https://xorm.io)
5252
* UI 元件:
5353
* [Semantic UI](http://semantic-ui.com/)
5454
* [GitHub Octicons](https://octicons.github.com/)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.14
55
require (
66
code.gitea.io/gitea-vet v0.2.1
77
code.gitea.io/sdk/gitea v0.13.1
8-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27
8+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
99
gitea.com/lunny/levelqueue v0.3.0
1010
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
1111
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFj
4040
code.gitea.io/sdk/gitea v0.13.1 h1:Y7bpH2iO6Q0KhhMJfjP/LZ0AmiYITeRQlCD8b0oYqhk=
4141
code.gitea.io/sdk/gitea v0.13.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
4242
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
43-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27 h1:cdb1OTNXGLwQ55gg+9tIPWufdsnrHWcIq8Qs+j/E8JU=
44-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
43+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee h1:9U6HuKUBt/cGK6T/64dEuz0r7Yp97WAAEJvXHDlY3ws=
44+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
4545
gitea.com/lunny/levelqueue v0.3.0 h1:MHn1GuSZkxvVEDMyAPqlc7A3cOW+q8RcGhRgH/xtm6I=
4646
gitea.com/lunny/levelqueue v0.3.0/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
4747
gitea.com/lunny/log v0.0.0-20190322053110-01b5df579c4e h1:r1en/D7xJmcY24VkHkjkcJFa+7ZWubVWPBrvsHkmHxk=

integrations/admin_user_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"strconv"
10+
"testing"
11+
12+
"code.gitea.io/gitea/models"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestAdminViewUsers(t *testing.T) {
18+
prepareTestEnv(t)
19+
20+
session := loginUser(t, "user1")
21+
req := NewRequest(t, "GET", "/admin/users")
22+
session.MakeRequest(t, req, http.StatusOK)
23+
24+
session = loginUser(t, "user2")
25+
req = NewRequest(t, "GET", "/admin/users")
26+
session.MakeRequest(t, req, http.StatusForbidden)
27+
}
28+
29+
func TestAdminViewUser(t *testing.T) {
30+
prepareTestEnv(t)
31+
32+
session := loginUser(t, "user1")
33+
req := NewRequest(t, "GET", "/admin/users/1")
34+
session.MakeRequest(t, req, http.StatusOK)
35+
36+
session = loginUser(t, "user2")
37+
req = NewRequest(t, "GET", "/admin/users/1")
38+
session.MakeRequest(t, req, http.StatusForbidden)
39+
}
40+
41+
func TestAdminEditUser(t *testing.T) {
42+
prepareTestEnv(t)
43+
44+
testSuccessfullEdit(t, models.User{ID: 2, Name: "newusername", LoginName: "otherlogin", Email: "[email protected]"})
45+
}
46+
47+
func testSuccessfullEdit(t *testing.T, formData models.User) {
48+
makeRequest(t, formData, http.StatusFound)
49+
}
50+
51+
func makeRequest(t *testing.T, formData models.User, headerCode int) {
52+
session := loginUser(t, "user1")
53+
csrf := GetCSRF(t, session, "/admin/users/"+strconv.Itoa(int(formData.ID)))
54+
req := NewRequestWithValues(t, "POST", "/admin/users/"+strconv.Itoa(int(formData.ID)), map[string]string{
55+
"_csrf": csrf,
56+
"user_name": formData.Name,
57+
"login_name": formData.LoginName,
58+
"login_type": "0-0",
59+
"email": formData.Email,
60+
})
61+
62+
session.MakeRequest(t, req, headerCode)
63+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: formData.ID}).(*models.User)
64+
assert.Equal(t, formData.Name, user.Name)
65+
assert.Equal(t, formData.LoginName, user.LoginName)
66+
assert.Equal(t, formData.Email, user.Email)
67+
}
68+
69+
func TestAdminDeleteUser(t *testing.T) {
70+
defer prepareTestEnv(t)()
71+
72+
session := loginUser(t, "user1")
73+
74+
csrf := GetCSRF(t, session, "/admin/users/8")
75+
req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
76+
"_csrf": csrf,
77+
})
78+
session.MakeRequest(t, req, http.StatusOK)
79+
80+
assertUserDeleted(t, 8)
81+
models.CheckConsistencyFor(t, &models.User{})
82+
}

integrations/delete_user_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ func assertUserDeleted(t *testing.T, userID int64) {
2424
models.AssertNotExistsBean(t, &models.Star{UID: userID})
2525
}
2626

27-
func TestAdminDeleteUser(t *testing.T) {
28-
defer prepareTestEnv(t)()
29-
30-
session := loginUser(t, "user1")
31-
32-
csrf := GetCSRF(t, session, "/admin/users/8")
33-
req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
34-
"_csrf": csrf,
35-
})
36-
session.MakeRequest(t, req, http.StatusOK)
37-
38-
assertUserDeleted(t, 8)
39-
models.CheckConsistencyFor(t, &models.User{})
40-
}
41-
4227
func TestUserDeleteAccount(t *testing.T) {
4328
defer prepareTestEnv(t)()
4429

integrations/pull_merge_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func TestCantMergeConflict(t *testing.T) {
246246
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleRebase, "CONFLICT")
247247
assert.Error(t, err, "Merge should return an error due to conflict")
248248
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
249+
gitRepo.Close()
249250
})
250251
}
251252

@@ -329,5 +330,6 @@ func TestCantMergeUnrelated(t *testing.T) {
329330
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleMerge, "UNRELATED")
330331
assert.Error(t, err, "Merge should return an error due to unrelated")
331332
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
333+
gitRepo.Close()
332334
})
333335
}

models/issue_comment.go

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
979979
if opts.Type != CommentTypeUnknown {
980980
cond = cond.And(builder.Eq{"comment.type": opts.Type})
981981
}
982-
if opts.Line > 0 {
982+
if opts.Line != 0 {
983983
cond = cond.And(builder.Eq{"comment.line": opts.Line})
984984
}
985985
if len(opts.TreePath) > 0 {
@@ -1078,18 +1078,35 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
10781078
if review == nil {
10791079
review = &Review{ID: 0}
10801080
}
1081-
//Find comments
10821081
opts := FindCommentsOptions{
10831082
Type: CommentTypeCode,
10841083
IssueID: issue.ID,
10851084
ReviewID: review.ID,
10861085
}
1086+
1087+
comments, err := findCodeComments(e, opts, issue, currentUser, review)
1088+
if err != nil {
1089+
return nil, err
1090+
}
1091+
1092+
for _, comment := range comments {
1093+
if pathToLineToComment[comment.TreePath] == nil {
1094+
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
1095+
}
1096+
pathToLineToComment[comment.TreePath][comment.Line] = append(pathToLineToComment[comment.TreePath][comment.Line], comment)
1097+
}
1098+
return pathToLineToComment, nil
1099+
}
1100+
1101+
func findCodeComments(e Engine, opts FindCommentsOptions, issue *Issue, currentUser *User, review *Review) ([]*Comment, error) {
1102+
var comments []*Comment
1103+
if review == nil {
1104+
review = &Review{ID: 0}
1105+
}
10871106
conds := opts.toConds()
10881107
if review.ID == 0 {
10891108
conds = conds.And(builder.Eq{"invalidated": false})
10901109
}
1091-
1092-
var comments []*Comment
10931110
if err := e.Where(conds).
10941111
Asc("comment.created_unix").
10951112
Asc("comment.id").
@@ -1117,7 +1134,19 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
11171134
return nil, err
11181135
}
11191136

1137+
n := 0
11201138
for _, comment := range comments {
1139+
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
1140+
// If the review is pending only the author can see the comments (except if the review is set)
1141+
if review.ID == 0 && re.Type == ReviewTypePending &&
1142+
(currentUser == nil || currentUser.ID != re.ReviewerID) {
1143+
continue
1144+
}
1145+
comment.Review = re
1146+
}
1147+
comments[n] = comment
1148+
n++
1149+
11211150
if err := comment.LoadResolveDoer(); err != nil {
11221151
return nil, err
11231152
}
@@ -1126,25 +1155,21 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
11261155
return nil, err
11271156
}
11281157

1129-
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
1130-
// If the review is pending only the author can see the comments (except the review is set)
1131-
if review.ID == 0 {
1132-
if re.Type == ReviewTypePending &&
1133-
(currentUser == nil || currentUser.ID != re.ReviewerID) {
1134-
continue
1135-
}
1136-
}
1137-
comment.Review = re
1138-
}
1139-
11401158
comment.RenderedContent = string(markdown.Render([]byte(comment.Content), issue.Repo.Link(),
11411159
issue.Repo.ComposeMetas()))
1142-
if pathToLineToComment[comment.TreePath] == nil {
1143-
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
1144-
}
1145-
pathToLineToComment[comment.TreePath][comment.Line] = append(pathToLineToComment[comment.TreePath][comment.Line], comment)
11461160
}
1147-
return pathToLineToComment, nil
1161+
return comments[:n], nil
1162+
}
1163+
1164+
// FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
1165+
func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, line int64) ([]*Comment, error) {
1166+
opts := FindCommentsOptions{
1167+
Type: CommentTypeCode,
1168+
IssueID: issue.ID,
1169+
TreePath: treePath,
1170+
Line: line,
1171+
}
1172+
return findCodeComments(x, opts, issue, currentUser, nil)
11481173
}
11491174

11501175
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line

models/login_source.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,10 @@ func UserSignIn(username, password string) (*User, error) {
771771

772772
// Update password hash if server password hash algorithm have changed
773773
if user.PasswdHashAlgo != setting.PasswordHashAlgo {
774-
user.HashPassword(password)
775-
if err := UpdateUserCols(user, "passwd", "passwd_hash_algo"); err != nil {
774+
if err = user.SetPassword(password); err != nil {
775+
return nil, err
776+
}
777+
if err = UpdateUserCols(user, "passwd", "passwd_hash_algo", "salt"); err != nil {
776778
return nil, err
777779
}
778780
}

0 commit comments

Comments
 (0)