Compare commits

..

1 Commits

Author SHA1 Message Date
Lauris BH
3083522620 Starting v1.11.0 development 2019-10-15 00:02:16 +03:00
51 changed files with 416 additions and 596 deletions

View File

@@ -4,32 +4,6 @@ This changelog goes through all the changes that have been made in each release
without substantial changes to our git log; to see the highlights of what has without substantial changes to our git log; to see the highlights of what has
been added to each release, please refer to the [blog](https://blog.gitea.io). been added to each release, please refer to the [blog](https://blog.gitea.io).
## [1.10.0-RC2](https://github.com/go-gitea/gitea/releases/tag/v1.10.0-rc2) - 2019-10-30
* BREAKING
* Fix deadline on update issue or PR via API (#8698)
* Hide some user information via API if user doesn't have enough permission (#8655) (#8657)
* BUGFIXES
* Expose db.SetMaxOpenConns and allow non MySQL dbs to set conn pool params (#8528) (#8618)
* Fix milestone close timestamp (#8728) (#8730)
* Fix 500 when getting user as unauthenticated user (#8653) (#8663)
* Fix 'New Issue Missing Milestone Comment' (#8678) (#8681)
* Use AppSubUrl for more redirections (#8647) (#8651)
* Add SubURL to redirect path (#8632) (#8634)
* Fix template error on account page (#8562) (#8622)
* Allow externalID to be UUID (#8551) (#8624)
* Prevent removal of non-empty emoji panel following selection of duplicate (#8609) (#8623)
* Update heatmap fixtures to restore tests (#8615) (#8616)
* Ensure that diff stats can scroll independently of the diff (#8581) (#8621)
* Webhook: set Content-Type for application/x-www-form-urlencoded (#8600)
* Fix #8582 by handling empty repos (#8587) (#8594)
* Fix bug on pull requests when transfer head repository (#8564) (#8569)
* Add missed close in ServeBlobLFS (#8527) (#8542)
* Ensure that GitRepo is set on Empty repositories (#8539) (#8541)
* Fix migrate mirror 500 bug (#8526) (#8530)
* Fix password complexity regex for special characters (#8524)
* Prevent .code-view from overriding font on icon fonts (#8614) (#8627)
* Allow more than 255 characters for tokens in external_login_user table (#8554)
## [1.10.0-RC1](https://github.com/go-gitea/gitea/releases/tag/v1.10.0-rc1) - 2019-10-14 ## [1.10.0-RC1](https://github.com/go-gitea/gitea/releases/tag/v1.10.0-rc1) - 2019-10-14
* BREAKING * BREAKING
* Remove legacy handling of drone token (#8191) * Remove legacy handling of drone token (#8191)

View File

@@ -277,12 +277,10 @@ LOG_SQL = true
DB_RETRIES = 10 DB_RETRIES = 10
; Backoff time per DB retry (time.Duration) ; Backoff time per DB retry (time.Duration)
DB_RETRY_BACKOFF = 3s DB_RETRY_BACKOFF = 3s
; Max idle database connections on connnection pool, default is 2 ; Max idle database connections on connnection pool, default is 0
MAX_IDLE_CONNS = 2 MAX_IDLE_CONNS = 0
; Database connection max life time, default is 0 or 3s mysql (See #6804 & #7071 for reasoning) ; Database connection max life time, default is 3s
CONN_MAX_LIFETIME = 3s CONN_MAX_LIFETIME = 3s
; Database maximum number of open connections, default is 0 meaning no maximum
MAX_OPEN_CONNS = 0
[indexer] [indexer]
; Issue indexer type, currently support: bleve or db, default is bleve ; Issue indexer type, currently support: bleve or db, default is bleve
@@ -335,8 +333,7 @@ IMPORT_LOCAL_PATHS = false
; Set to true to prevent all users (including admin) from creating custom git hooks ; Set to true to prevent all users (including admin) from creating custom git hooks
DISABLE_GIT_HOOKS = false DISABLE_GIT_HOOKS = false
;Comma separated list of character classes required to pass minimum complexity. ;Comma separated list of character classes required to pass minimum complexity.
;If left empty or no valid values are specified, the default values ("lower,upper,digit,spec") will be used. ;If left empty or no valid values are specified, the default values (`lower,upper,digit,spec`) will be used.
;Use "off" to disable checking.
PASSWORD_COMPLEXITY = lower,upper,digit,spec PASSWORD_COMPLEXITY = lower,upper,digit,spec
; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt" ; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
PASSWORD_HASH_ALGO = pbkdf2 PASSWORD_HASH_ALGO = pbkdf2
@@ -825,6 +822,6 @@ TOKEN =
QUEUE_TYPE = channel QUEUE_TYPE = channel
; Task queue length, available only when `QUEUE_TYPE` is `channel`. ; Task queue length, available only when `QUEUE_TYPE` is `channel`.
QUEUE_LENGTH = 1000 QUEUE_LENGTH = 1000
; Task queue connection string, available only when `QUEUE_TYPE` is `redis`. ; Task queue connction string, available only when `QUEUE_TYPE` is `redis`.
; If there is a password of redis, use `addrs=127.0.0.1:6379 password=123 db=0`. ; If there is a password of redis, use `addrs=127.0.0.1:6379 password=123 db=0`.
QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0" QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"

View File

@@ -167,12 +167,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `LOG_SQL`: **true**: Log the executed SQL. - `LOG_SQL`: **true**: Log the executed SQL.
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed. - `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.
- `DB_RETRY_BACKOFF`: **3s**: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured. - `DB_RETRY_BACKOFF`: **3s**: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured.
- `MAX_OPEN_CONNS` **0**: Database maximum open connections - default is 0, meaning there is no limit. - `MAX_IDLE_CONNS` **0**: Max idle database connections on connnection pool, default is 0
- `MAX_IDLE_CONNS` **2**: Max idle database connections on connnection pool, default is 2 - this will be capped to `MAX_OPEN_CONNS`. - `CONN_MAX_LIFETIME` **3s**: Database connection max lifetime
- `CONN_MAX_LIFETIME` **0 or 3s**: Sets the maximum amount of time a DB connection may be reused - default is 0, meaning there is no limit (except on MySQL where it is 3s - see #6804 & #7071).
Please see #8540 & #8273 for further discussion of the appropriate values for `MAX_OPEN_CONNS`, `MAX_IDLE_CONNS` & `CONN_MAX_LIFETIME` and their
relation to port exhaustion.
## Indexer (`indexer`) ## Indexer (`indexer`)
@@ -216,8 +212,7 @@ relation to port exhaustion.
- lower - use one or more lower latin characters - lower - use one or more lower latin characters
- upper - use one or more upper latin characters - upper - use one or more upper latin characters
- digit - use one or more digits - digit - use one or more digits
- spec - use one or more special characters as ``!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~`` - spec - use one or more special characters as ``][!"#$%&'()*+,./:;<=>?@\^_{|}~`-`` and space symbol.
- off - do not check password complexity
## OpenID (`openid`) ## OpenID (`openid`)

View File

@@ -29,6 +29,7 @@ func TestAPITeamUser(t *testing.T) {
var user2 *api.User var user2 *api.User
DecodeJSON(t, resp, &user2) DecodeJSON(t, resp, &user2)
user2.Created = user2.Created.In(time.Local) user2.Created = user2.Created.In(time.Local)
user2.LastLogin = user2.LastLogin.In(time.Local)
user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User) user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
assert.Equal(t, convert.ToUser(user, true, false), user2) assert.Equal(t, convert.ToUser(user, true, false), user2)

View File

@@ -26,7 +26,7 @@ func TestUserHeatmap(t *testing.T) {
var heatmap []*models.UserHeatmapData var heatmap []*models.UserHeatmapData
DecodeJSON(t, resp, &heatmap) DecodeJSON(t, resp, &heatmap)
var dummyheatmap []*models.UserHeatmapData var dummyheatmap []*models.UserHeatmapData
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1571616000, Contributions: 1}) dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1540080000, Contributions: 1})
assert.Equal(t, dummyheatmap, heatmap) assert.Equal(t, dummyheatmap, heatmap)
} }

View File

@@ -28,9 +28,9 @@ type ExternalLoginUser struct {
Description string Description string
AvatarURL string AvatarURL string
Location string Location string
AccessToken string `xorm:"TEXT"` AccessToken string
AccessTokenSecret string `xorm:"TEXT"` AccessTokenSecret string
RefreshToken string `xorm:"TEXT"` RefreshToken string
ExpiresAt time.Time ExpiresAt time.Time
} }
@@ -168,7 +168,7 @@ func FindExternalUsersByProvider(opts FindExternalUserOptions) ([]ExternalLoginU
} }
// UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID // UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID
func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID string, userID int64) error { func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID, userID int64) error {
if err := UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil { if err := UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil {
return err return err
} }

View File

@@ -5,7 +5,7 @@
act_user_id: 2 act_user_id: 2
repo_id: 2 repo_id: 2
is_private: true is_private: true
created_unix: 1571686356 created_unix: 1540139562
- -
id: 2 id: 2

View File

@@ -6,6 +6,7 @@
index: 2 index: 2
head_repo_id: 1 head_repo_id: 1
base_repo_id: 1 base_repo_id: 1
head_user_name: user1
head_branch: branch1 head_branch: branch1
base_branch: master base_branch: master
merge_base: 1234567890abcdef merge_base: 1234567890abcdef
@@ -20,6 +21,7 @@
index: 3 index: 3
head_repo_id: 1 head_repo_id: 1
base_repo_id: 1 base_repo_id: 1
head_user_name: user1
head_branch: branch2 head_branch: branch2
base_branch: master base_branch: master
merge_base: fedcba9876543210 merge_base: fedcba9876543210
@@ -33,6 +35,7 @@
index: 1 index: 1
head_repo_id: 11 head_repo_id: 11
base_repo_id: 10 base_repo_id: 10
head_user_name: user13
head_branch: branch2 head_branch: branch2
base_branch: master base_branch: master
merge_base: 0abcb056019adb83 merge_base: 0abcb056019adb83

View File

@@ -1072,10 +1072,6 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil { if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil {
return err return err
} }
if _, err = createMilestoneComment(e, doer, opts.Repo, opts.Issue, 0, opts.Issue.MilestoneID); err != nil {
return err
}
} }
// Insert the assignees // Insert the assignees
@@ -1954,7 +1950,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
} }
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID // UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error { func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
_, err := x.Table("issue"). _, err := x.Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType). Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID). And("original_author_id = ?", originalAuthorID).

View File

@@ -1025,7 +1025,7 @@ func FetchCodeComments(issue *Issue, currentUser *User) (CodeComments, error) {
} }
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id // UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error { func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID, posterID int64) error {
_, err := x.Table("comment"). _, err := x.Table("comment").
Where(builder.In("issue_id", Where(builder.In("issue_id",
builder.Select("issue.id"). builder.Select("issue.id").

View File

@@ -306,11 +306,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
} }
m.IsClosed = isClosed m.IsClosed = isClosed
if isClosed { if _, err := sess.ID(m.ID).Cols("is_closed").Update(m); err != nil {
m.ClosedDateUnix = timeutil.TimeStampNow()
}
if _, err := sess.ID(m.ID).Cols("is_closed", "closed_date_unix").Update(m); err != nil {
return err return err
} }

View File

@@ -256,10 +256,6 @@ var migrations = []Migration{
NewMigration("add task table and status column for repository table", addTaskTable), NewMigration("add task table and status column for repository table", addTaskTable),
// v100 -> v101 // v100 -> v101
NewMigration("update migration repositories' service type", updateMigrationServiceTypes), NewMigration("update migration repositories' service type", updateMigrationServiceTypes),
// v101 -> v102
NewMigration("change length of some external login users columns", changeSomeColumnsLengthOfExternalLoginUser),
// v102 -> v103
NewMigration("update migration repositories' service type", dropColumnHeadUserNameOnPullRequest),
} }
// Migrate database to current version // Migrate database to current version

View File

@@ -1,19 +0,0 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"github.com/go-xorm/xorm"
)
func changeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error {
type ExternalLoginUser struct {
AccessToken string `xorm:"TEXT"`
AccessTokenSecret string `xorm:"TEXT"`
RefreshToken string `xorm:"TEXT"`
}
return x.Sync2(new(ExternalLoginUser))
}

View File

@@ -1,15 +0,0 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"github.com/go-xorm/xorm"
)
func dropColumnHeadUserNameOnPullRequest(x *xorm.Engine) error {
sess := x.NewSession()
defer sess.Close()
return dropTableColumns(sess, "pull_request", "head_user_name")
}

View File

@@ -157,9 +157,11 @@ func SetEngine() (err error) {
// so use log file to instead print to stdout. // so use log file to instead print to stdout.
x.SetLogger(NewXORMLogger(setting.Database.LogSQL)) x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
x.ShowSQL(setting.Database.LogSQL) x.ShowSQL(setting.Database.LogSQL)
x.SetMaxOpenConns(setting.Database.MaxOpenConns) if setting.Database.UseMySQL {
x.SetMaxIdleConns(setting.Database.MaxIdleConns) x.SetMaxIdleConns(setting.Database.MaxIdleConns)
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime) x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
}
return nil return nil
} }

View File

@@ -66,6 +66,7 @@ type PullRequest struct {
HeadRepo *Repository `xorm:"-"` HeadRepo *Repository `xorm:"-"`
BaseRepoID int64 `xorm:"INDEX"` BaseRepoID int64 `xorm:"INDEX"`
BaseRepo *Repository `xorm:"-"` BaseRepo *Repository `xorm:"-"`
HeadUserName string
HeadBranch string HeadBranch string
BaseBranch string BaseBranch string
ProtectedBranch *ProtectedBranch `xorm:"-"` ProtectedBranch *ProtectedBranch `xorm:"-"`
@@ -78,15 +79,6 @@ type PullRequest struct {
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"` MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
} }
// MustHeadUserName returns the HeadRepo's username if failed return blank
func (pr *PullRequest) MustHeadUserName() string {
if err := pr.LoadHeadRepo(); err != nil {
log.Error("LoadHeadRepo: %v", err)
return ""
}
return pr.HeadRepo.MustOwnerName()
}
// Note: don't try to get Issue because will end up recursive querying. // Note: don't try to get Issue because will end up recursive querying.
func (pr *PullRequest) loadAttributes(e Engine) (err error) { func (pr *PullRequest) loadAttributes(e Engine) (err error) {
if pr.HasMerged && pr.Merger == nil { if pr.HasMerged && pr.Merger == nil {
@@ -110,10 +102,6 @@ func (pr *PullRequest) LoadAttributes() error {
// LoadBaseRepo loads pull request base repository from database // LoadBaseRepo loads pull request base repository from database
func (pr *PullRequest) LoadBaseRepo() error { func (pr *PullRequest) LoadBaseRepo() error {
if pr.BaseRepo == nil { if pr.BaseRepo == nil {
if pr.HeadRepoID == pr.BaseRepoID && pr.HeadRepo != nil {
pr.BaseRepo = pr.HeadRepo
return nil
}
var repo Repository var repo Repository
if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil { if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil {
return err return err
@@ -125,24 +113,6 @@ func (pr *PullRequest) LoadBaseRepo() error {
return nil return nil
} }
// LoadHeadRepo loads pull request head repository from database
func (pr *PullRequest) LoadHeadRepo() error {
if pr.HeadRepo == nil {
if pr.HeadRepoID == pr.BaseRepoID && pr.BaseRepo != nil {
pr.HeadRepo = pr.BaseRepo
return nil
}
var repo Repository
if has, err := x.ID(pr.HeadRepoID).Get(&repo); err != nil {
return err
} else if !has {
return ErrRepoNotExist{ID: pr.BaseRepoID}
}
pr.HeadRepo = &repo
}
return nil
}
// LoadIssue loads issue information from database // LoadIssue loads issue information from database
func (pr *PullRequest) LoadIssue() (err error) { func (pr *PullRequest) LoadIssue() (err error) {
return pr.loadIssue(x) return pr.loadIssue(x)
@@ -182,7 +152,7 @@ func (pr *PullRequest) GetDefaultMergeMessage() string {
return "" return ""
} }
} }
return fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.MustHeadUserName(), pr.HeadRepo.Name, pr.BaseBranch) return fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.HeadUserName, pr.HeadRepo.Name, pr.BaseBranch)
} }
// GetDefaultSquashMessage returns default message used when squash and merging pull request // GetDefaultSquashMessage returns default message used when squash and merging pull request
@@ -1189,6 +1159,18 @@ func checkForInvalidation(requests PullRequestList, repoID int64, doer *User, br
return nil return nil
} }
// ChangeUsernameInPullRequests changes the name of head_user_name
func ChangeUsernameInPullRequests(oldUserName, newUserName string) error {
pr := PullRequest{
HeadUserName: strings.ToLower(newUserName),
}
_, err := x.
Cols("head_user_name").
Where("head_user_name = ?", strings.ToLower(oldUserName)).
Update(pr)
return err
}
// checkAndUpdateStatus checks if pull request is possible to leaving checking status, // checkAndUpdateStatus checks if pull request is possible to leaving checking status,
// and set to be either conflict or mergeable. // and set to be either conflict or mergeable.
func (pr *PullRequest) checkAndUpdateStatus() { func (pr *PullRequest) checkAndUpdateStatus() {

View File

@@ -232,6 +232,20 @@ func TestPullRequestList_LoadAttributes(t *testing.T) {
// TODO TestAddTestPullRequestTask // TODO TestAddTestPullRequestTask
func TestChangeUsernameInPullRequests(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
const newUsername = "newusername"
assert.NoError(t, ChangeUsernameInPullRequests("user1", newUsername))
prs := make([]*PullRequest, 0, 10)
assert.NoError(t, x.Where("head_user_name = ?", newUsername).Find(&prs))
assert.Len(t, prs, 2)
for _, pr := range prs {
assert.Equal(t, newUsername, pr.HeadUserName)
}
CheckConsistencyFor(t, &PullRequest{})
}
func TestPullRequest_IsWorkInProgress(t *testing.T) { func TestPullRequest_IsWorkInProgress(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())

View File

@@ -369,7 +369,7 @@ func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error {
} }
// UpdateReleasesMigrationsByType updates all migrated repositories' releases from gitServiceType to replace originalAuthorID to posterID // UpdateReleasesMigrationsByType updates all migrated repositories' releases from gitServiceType to replace originalAuthorID to posterID
func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error { func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
_, err := x.Table("release"). _, err := x.Table("release").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType). Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID). And("original_author_id = ?", originalAuthorID).

View File

@@ -1430,7 +1430,6 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
IsFsckEnabled: !opts.IsMirror, IsFsckEnabled: !opts.IsMirror,
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
Status: opts.Status, Status: opts.Status,
IsEmpty: !opts.AutoInit,
} }
sess := x.NewSession() sess := x.NewSession()

View File

@@ -994,6 +994,10 @@ func ChangeUserName(u *User, newUserName string) (err error) {
return ErrUserAlreadyExist{newUserName} return ErrUserAlreadyExist{newUserName}
} }
if err = ChangeUsernameInPullRequests(u.Name, newUserName); err != nil {
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
}
// Do not fail if directory does not exist // Do not fail if directory does not exist
if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) { if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Rename user directory: %v", err) return fmt.Errorf("Rename user directory: %v", err)

View File

@@ -17,7 +17,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
CountResult int CountResult int
JSONResult string JSONResult string
}{ }{
{2, 1, `[{"timestamp":1571616000,"contributions":1}]`}, {2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
{3, 0, `[]`}, {3, 0, `[]`},
} }
// Prepare // Prepare
@@ -41,7 +41,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
// Get the heatmap and compare // Get the heatmap and compare
heatmap, err := GetUserHeatmapDataByUser(user) heatmap, err := GetUserHeatmapDataByUser(user)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, len(actions), len(heatmap), "invalid action count: did the test data became too old?") assert.Equal(t, len(actions), len(heatmap))
assert.Equal(t, tc.CountResult, len(heatmap)) assert.Equal(t, tc.CountResult, len(heatmap))
//Test JSON rendering //Test JSON rendering

View File

@@ -833,8 +833,6 @@ func (t *HookTask) deliver() error {
return err return err
} }
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
} }
case http.MethodGet: case http.MethodGet:
u, err := url.Parse(t.URL) u, err := url.Parse(t.URL)

View File

@@ -63,7 +63,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
// Force redirection when username is actually a user. // Force redirection when username is actually a user.
if !org.IsOrganization() { if !org.IsOrganization() {
ctx.Redirect(setting.AppSubURL + "/" + org.Name) ctx.Redirect("/" + org.Name)
return return
} }

View File

@@ -236,7 +236,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
if ctx.Req.URL.RawQuery != "" { if ctx.Req.URL.RawQuery != "" {
redirectPath += "?" + ctx.Req.URL.RawQuery redirectPath += "?" + ctx.Req.URL.RawQuery
} }
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath)) ctx.Redirect(redirectPath)
} }
func repoAssignment(ctx *Context, repo *models.Repository) { func repoAssignment(ctx *Context, repo *models.Repository) {
@@ -414,8 +414,8 @@ func RepoAssignment() macaron.Handler {
} }
} }
// Disable everything when the repo is being created // repo is empty and display enable
if ctx.Repo.Repository.IsBeingCreated() { if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
return return
} }
@@ -427,12 +427,6 @@ func RepoAssignment() macaron.Handler {
} }
ctx.Repo.GitRepo = gitRepo ctx.Repo.GitRepo = gitRepo
// Stop at this point when the repo is empty.
if ctx.Repo.Repository.IsEmpty {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
return
}
tags, err := ctx.Repo.GitRepo.GetTags() tags, err := ctx.Repo.GitRepo.GetTags()
if err != nil { if err != nil {
ctx.ServerError("GetTags", err) ctx.ServerError("GetTags", err)

View File

@@ -581,6 +581,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
var pullRequest = models.PullRequest{ var pullRequest = models.PullRequest{
HeadRepoID: g.repo.ID, HeadRepoID: g.repo.ID,
HeadBranch: head, HeadBranch: head,
HeadUserName: g.repoOwner,
BaseRepoID: g.repo.ID, BaseRepoID: g.repo.ID,
BaseBranch: pr.Base.Ref, BaseBranch: pr.Base.Ref,
MergeBase: pr.Base.SHA, MergeBase: pr.Base.SHA,

View File

@@ -5,6 +5,8 @@
package migrations package migrations
import ( import (
"strconv"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
@@ -38,7 +40,11 @@ func updateMigrationPosterIDByGitService(tp structs.GitServiceType) error {
} }
for _, user := range users { for _, user := range users {
externalUserID := user.ExternalID externalUserID, err := strconv.ParseInt(user.ExternalID, 10, 64)
if err != nil {
log.Warn("Parse externalUser %#v 's userID failed: %v", user, err)
continue
}
if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil { if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil {
log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err) log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err)
} }

View File

@@ -7,60 +7,45 @@ package password
import ( import (
"crypto/rand" "crypto/rand"
"math/big" "math/big"
"strings" "regexp"
"sync" "sync"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
) )
var ( var matchComplexities = map[string]regexp.Regexp{}
matchComplexityOnce sync.Once var matchComplexityOnce sync.Once
validChars string var validChars string
requiredChars []string var validComplexities = map[string]string{
"lower": "abcdefghijklmnopqrstuvwxyz",
charComplexities = map[string]string{ "upper": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"lower": `abcdefghijklmnopqrstuvwxyz`, "digit": "0123456789",
"upper": `ABCDEFGHIJKLMNOPQRSTUVWXYZ`, "spec": `][ !"#$%&'()*+,./:;<=>?@\^_{|}~` + "`-",
"digit": `0123456789`, }
"spec": ` !"#$%&'()*+,-./:;<=>?@[\]^_{|}~` + "`",
}
)
// NewComplexity for preparation // NewComplexity for preparation
func NewComplexity() { func NewComplexity() {
matchComplexityOnce.Do(func() { matchComplexityOnce.Do(func() {
setupComplexity(setting.PasswordComplexity) if len(setting.PasswordComplexity) > 0 {
for key, val := range setting.PasswordComplexity {
matchComplexity := regexp.MustCompile(val)
matchComplexities[key] = *matchComplexity
validChars += validComplexities[key]
}
} else {
for _, val := range validComplexities {
validChars += val
}
}
}) })
} }
func setupComplexity(values []string) { // IsComplexEnough return True if password is Complexity
if len(values) != 1 || values[0] != "off" {
for _, val := range values {
if chars, ok := charComplexities[val]; ok {
validChars += chars
requiredChars = append(requiredChars, chars)
}
}
if len(requiredChars) == 0 {
// No valid character classes found; use all classes as default
for _, chars := range charComplexities {
validChars += chars
requiredChars = append(requiredChars, chars)
}
}
}
if validChars == "" {
// No complexities to check; provide a sensible default for password generation
validChars = charComplexities["lower"] + charComplexities["upper"] + charComplexities["digit"]
}
}
// IsComplexEnough return True if password meets complexity settings
func IsComplexEnough(pwd string) bool { func IsComplexEnough(pwd string) bool {
if len(setting.PasswordComplexity) > 0 {
NewComplexity() NewComplexity()
if len(validChars) > 0 { for _, val := range matchComplexities {
for _, req := range requiredChars { if !val.MatchString(pwd) {
if !strings.ContainsAny(req, pwd) {
return false return false
} }
} }

View File

@@ -1,75 +0,0 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package password
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestComplexity_IsComplexEnough(t *testing.T) {
matchComplexityOnce.Do(func() {})
testlist := []struct {
complexity []string
truevalues []string
falsevalues []string
}{
{[]string{"lower"}, []string{"abc", "abc!"}, []string{"ABC", "123", "=!$", ""}},
{[]string{"upper"}, []string{"ABC"}, []string{"abc", "123", "=!$", "abc!", ""}},
{[]string{"digit"}, []string{"123"}, []string{"abc", "ABC", "=!$", "abc!", ""}},
{[]string{"spec"}, []string{"=!$", "abc!"}, []string{"abc", "ABC", "123", ""}},
{[]string{"off"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}, nil},
{[]string{"lower", "spec"}, []string{"abc!"}, []string{"abc", "ABC", "123", "=!$", "abcABC123", ""}},
{[]string{"lower", "upper", "digit"}, []string{"abcABC123"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}},
}
for _, test := range testlist {
testComplextity(test.complexity)
for _, val := range test.truevalues {
assert.True(t, IsComplexEnough(val))
}
for _, val := range test.falsevalues {
assert.False(t, IsComplexEnough(val))
}
}
// Remove settings for other tests
testComplextity([]string{"off"})
}
func TestComplexity_Generate(t *testing.T) {
matchComplexityOnce.Do(func() {})
const maxCount = 50
const pwdLen = 50
test := func(t *testing.T, modes []string) {
testComplextity(modes)
for i := 0; i < maxCount; i++ {
pwd, err := Generate(pwdLen)
assert.NoError(t, err)
assert.Equal(t, pwdLen, len(pwd))
assert.True(t, IsComplexEnough(pwd), "Failed complexities with modes %+v for generated: %s", modes, pwd)
}
}
test(t, []string{"lower"})
test(t, []string{"upper"})
test(t, []string{"lower", "upper", "spec"})
test(t, []string{"off"})
test(t, []string{""})
// Remove settings for other tests
testComplextity([]string{"off"})
}
func testComplextity(values []string) {
// Cleanup previous values
validChars = ""
requiredChars = make([]string, 0, len(values))
setupComplexity(values)
}

View File

@@ -38,9 +38,6 @@ func (ct *ContentType) String() string {
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree // GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag // directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
if repo.IsEmpty {
return make([]interface{}, 0), nil
}
if ref == "" { if ref == "" {
ref = repo.DefaultBranch ref = repo.DefaultBranch
} }

View File

@@ -190,19 +190,3 @@ func TestGetContentsOrListErrors(t *testing.T) {
assert.Nil(t, fileContentResponse) assert.Nil(t, fileContentResponse)
}) })
} }
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
models.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo15")
ctx.SetParams(":id", "15")
test.LoadRepo(t, ctx, 15)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
repo := ctx.Repo.Repository
t.Run("empty repo", func(t *testing.T) {
contents, err := GetContentsOrList(repo, "", "")
assert.NoError(t, err)
assert.Empty(t, contents)
})
}

View File

@@ -42,11 +42,12 @@ var (
DBConnectRetries int DBConnectRetries int
DBConnectBackoff time.Duration DBConnectBackoff time.Duration
MaxIdleConns int MaxIdleConns int
MaxOpenConns int
ConnMaxLifetime time.Duration ConnMaxLifetime time.Duration
IterateBufferSize int IterateBufferSize int
}{ }{
Timeout: 500, Timeout: 500,
MaxIdleConns: 0,
ConnMaxLifetime: 3 * time.Second,
} }
) )
@@ -79,13 +80,8 @@ func InitDBConfig() {
Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"}) Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db")) Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500) Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(0)
if Database.UseMySQL {
Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(3 * time.Second) Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(3 * time.Second)
} else {
Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFE_TIME").MustDuration(0)
}
Database.MaxOpenConns = sec.Key("MAX_OPEN_CONNS").MustInt(0)
Database.IterateBufferSize = sec.Key("ITERATE_BUFFER_SIZE").MustInt(50) Database.IterateBufferSize = sec.Key("ITERATE_BUFFER_SIZE").MustInt(50)
Database.LogSQL = sec.Key("LOG_SQL").MustBool(true) Database.LogSQL = sec.Key("LOG_SQL").MustBool(true)

View File

@@ -146,7 +146,7 @@ var (
MinPasswordLength int MinPasswordLength int
ImportLocalPaths bool ImportLocalPaths bool
DisableGitHooks bool DisableGitHooks bool
PasswordComplexity []string PasswordComplexity map[string]string
PasswordHashAlgo string PasswordHashAlgo string
// UI settings // UI settings
@@ -775,13 +775,25 @@ func NewContext() {
InternalToken = loadInternalToken(sec) InternalToken = loadInternalToken(sec)
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",") var dictPC = map[string]string{
PasswordComplexity = make([]string, 0, len(cfgdata)) "lower": "[a-z]+",
for _, name := range cfgdata { "upper": "[A-Z]+",
name := strings.ToLower(strings.Trim(name, `"`)) "digit": "[0-9]+",
if name != "" { "spec": `][ !"#$%&'()*+,./:;<=>?@\\^_{|}~` + "`-",
PasswordComplexity = append(PasswordComplexity, name)
} }
PasswordComplexity = make(map[string]string)
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
for _, y := range cfgdata {
ts := strings.TrimSpace(y)
for a := range dictPC {
if strings.ToLower(ts) == a {
PasswordComplexity[ts] = dictPC[ts]
break
}
}
}
if len(PasswordComplexity) == 0 {
PasswordComplexity = dictPC
} }
sec = Cfg.Section("attachment") sec = Cfg.Section("attachment")

View File

@@ -239,7 +239,7 @@ footer .ui.left,footer .ui.right{line-height:40px}
.lines-commit .ui.avatar.image{height:18px;width:18px} .lines-commit .ui.avatar.image{height:18px;width:18px}
.lines-code .bottom-line,.lines-commit .bottom-line,.lines-num .bottom-line{border-bottom:1px solid #eaecef} .lines-code .bottom-line,.lines-commit .bottom-line,.lines-num .bottom-line{border-bottom:1px solid #eaecef}
.code-view{overflow:auto;overflow-x:auto;overflow-y:hidden} .code-view{overflow:auto;overflow-x:auto;overflow-y:hidden}
.code-view :not(.fa):not(.octicon):not(.icon){font-size:12px;font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace;line-height:20px} .code-view *{font-size:12px;font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace;line-height:20px}
.code-view table{width:100%} .code-view table{width:100%}
.code-view .active{background:#fff866} .code-view .active{background:#fff866}
.markdown:not(code){overflow:hidden;font-size:16px;line-height:1.6!important;word-wrap:break-word} .markdown:not(code){overflow:hidden;font-size:16px;line-height:1.6!important;word-wrap:break-word}
@@ -659,6 +659,8 @@ footer .ui.left,footer .ui.right{line-height:40px}
.repository #commits-table td.sha .sha.label.isSigned.isVerified:hover,.repository #repo-files-table .sha.label.isSigned.isVerified:hover{background:rgba(33,186,69,.3)!important} .repository #commits-table td.sha .sha.label.isSigned.isVerified:hover,.repository #repo-files-table .sha.label.isSigned.isVerified:hover{background:rgba(33,186,69,.3)!important}
.repository .diff-detail-box{padding:7px 0;background:#fff;line-height:30px} .repository .diff-detail-box{padding:7px 0;background:#fff;line-height:30px}
.repository .diff-detail-box>div:after{clear:both;content:"";display:block} .repository .diff-detail-box>div:after{clear:both;content:"";display:block}
.repository .diff-detail-box ol{clear:both;padding-left:0;margin-top:5px;margin-bottom:28px}
.repository .diff-detail-box ol li{list-style:none;padding-bottom:4px;margin-bottom:4px;border-bottom:1px dashed #ddd;padding-left:6px}
.repository .diff-detail-box span.status{display:inline-block;width:12px;height:12px;margin-right:8px;vertical-align:middle} .repository .diff-detail-box span.status{display:inline-block;width:12px;height:12px;margin-right:8px;vertical-align:middle}
.repository .diff-detail-box span.status.modify{background-color:#f0db88} .repository .diff-detail-box span.status.modify{background-color:#f0db88}
.repository .diff-detail-box span.status.add{background-color:#b4e2b4} .repository .diff-detail-box span.status.add{background-color:#b4e2b4}
@@ -695,11 +697,6 @@ footer .ui.left,footer .ui.right{line-height:40px}
.repository .diff-file-box.file-content{clear:right} .repository .diff-file-box.file-content{clear:right}
.repository .diff-file-box.file-content img{max-width:100%;padding:5px 5px 0 5px} .repository .diff-file-box.file-content img{max-width:100%;padding:5px 5px 0 5px}
.repository .diff-file-box.file-content img.emoji{padding:0} .repository .diff-file-box.file-content img.emoji{padding:0}
.repository .diff-stats{clear:both;margin-bottom:5px;max-height:400px;overflow:auto;padding-left:0}
.repository .diff-stats li{list-style:none;padding-bottom:4px;margin-bottom:4px;border-bottom:1px dashed #ddd;padding-left:6px}
.repository .diff-stats .diff-counter{margin-right:15px}
.repository .diff-stats .diff-counter .del{color:red}
.repository .diff-stats .diff-counter .add{color:green}
.repository .repo-search-result{padding-top:10px;padding-bottom:10px} .repository .repo-search-result{padding-top:10px;padding-bottom:10px}
.repository .repo-search-result .lines-num a{color:inherit} .repository .repo-search-result .lines-num a{color:inherit}
.repository.quickstart .guide .item{padding:1em} .repository.quickstart .guide .item{padding:1em}

View File

@@ -306,7 +306,7 @@ function initReactionSelector(parent) {
if (resp && (resp.html || resp.empty)) { if (resp && (resp.html || resp.empty)) {
const content = $(vm).closest('.content'); const content = $(vm).closest('.content');
let react = content.find('.segment.reactions'); let react = content.find('.segment.reactions');
if (!resp.empty && react.length > 0) { if (react.length > 0) {
react.remove(); react.remove();
} }
if (!resp.empty) { if (!resp.empty) {

View File

@@ -1047,7 +1047,7 @@ footer {
overflow-x: auto; overflow-x: auto;
overflow-y: hidden; overflow-y: hidden;
*:not(.fa):not(.octicon):not(.icon) { * {
font-size: 12px; font-size: 12px;
font-family: @monospaced-fonts, monospace; font-family: @monospaced-fonts, monospace;
line-height: 20px; line-height: 20px;

View File

@@ -1237,6 +1237,21 @@
display: block; display: block;
} }
ol {
clear: both;
padding-left: 0;
margin-top: 5px;
margin-bottom: 28px;
li {
list-style: none;
padding-bottom: 4px;
margin-bottom: 4px;
border-bottom: 1px dashed #dddddd;
padding-left: 6px;
}
}
span.status { span.status {
display: inline-block; display: inline-block;
width: 12px; width: 12px;
@@ -1451,34 +1466,6 @@
} }
} }
.diff-stats {
clear: both;
margin-bottom: 5px;
max-height: 400px;
overflow: auto;
padding-left: 0;
li {
list-style: none;
padding-bottom: 4px;
margin-bottom: 4px;
border-bottom: 1px dashed #dddddd;
padding-left: 6px;
}
.diff-counter {
margin-right: 15px;
.del {
color: red;
}
.add {
color: green;
}
}
}
.repo-search-result { .repo-search-result {
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px; padding-bottom: 10px;

View File

@@ -34,7 +34,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
LoginName: "local", LoginName: "local",
UserName: username, UserName: username,
Email: email, Email: email,
Password: "abc123ABC!=$", Password: "xxxxxxxx",
SendNotify: false, SendNotify: false,
MustChangePassword: true, MustChangePassword: true,
} }
@@ -71,7 +71,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
LoginName: "local", LoginName: "local",
UserName: username, UserName: username,
Email: email, Email: email,
Password: "abc123ABC!=$", Password: "xxxxxxxx",
SendNotify: false, SendNotify: false,
MustChangePassword: false, MustChangePassword: false,
} }

View File

@@ -232,9 +232,12 @@ func ToTeam(team *models.Team) *api.Team {
// ToUser convert models.User to api.User // ToUser convert models.User to api.User
func ToUser(user *models.User, signed, authed bool) *api.User { func ToUser(user *models.User, signed, authed bool) *api.User {
result := &api.User{ result := &api.User{
ID: user.ID,
UserName: user.Name, UserName: user.Name,
AvatarURL: user.AvatarLink(), AvatarURL: user.AvatarLink(),
FullName: markup.Sanitize(user.FullName), FullName: markup.Sanitize(user.FullName),
IsAdmin: user.IsAdmin,
LastLogin: user.LastLoginUnix.AsTime(),
Created: user.CreatedUnix.AsTime(), Created: user.CreatedUnix.AsTime(),
} }
// hide primary email if API caller isn't user itself or an admin // hide primary email if API caller isn't user itself or an admin
@@ -242,11 +245,8 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
result.Email = "" result.Email = ""
} else if user.KeepEmailPrivate && !authed { } else if user.KeepEmailPrivate && !authed {
result.Email = user.GetEmail() result.Email = user.GetEmail()
} else { // only user himself and admin could visit these information } else {
result.ID = user.ID
result.Email = user.Email result.Email = user.Email
result.IsAdmin = user.IsAdmin
result.LastLogin = user.LastLoginUnix.AsTime()
} }
return result return result
} }

View File

@@ -312,14 +312,15 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
} }
// Update the deadline // Update the deadline
if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { var deadlineUnix timeutil.TimeStamp
deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) if form.Deadline != nil && !form.Deadline.IsZero() && ctx.Repo.CanWrite(models.UnitTypeIssues) {
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
}
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
ctx.Error(500, "UpdateIssueDeadline", err) ctx.Error(500, "UpdateIssueDeadline", err)
return return
} }
issue.DeadlineUnix = deadlineUnix
}
// Add/delete assignees // Add/delete assignees

View File

@@ -190,7 +190,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
) )
// Get repo/branch information // Get repo/branch information
_, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form) headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form)
if ctx.Written() { if ctx.Written() {
return return
} }
@@ -267,6 +267,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
pr := &models.PullRequest{ pr := &models.PullRequest{
HeadRepoID: headRepo.ID, HeadRepoID: headRepo.ID,
BaseRepoID: repo.ID, BaseRepoID: repo.ID,
HeadUserName: headUser.Name,
HeadBranch: headBranch, HeadBranch: headBranch,
BaseBranch: baseBranch, BaseBranch: baseBranch,
HeadRepo: headRepo, HeadRepo: headRepo,
@@ -368,14 +369,15 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
} }
// Update Deadline // Update Deadline
if form.Deadline != nil { var deadlineUnix timeutil.TimeStamp
deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) if form.Deadline != nil && !form.Deadline.IsZero() {
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
}
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
ctx.Error(500, "UpdateIssueDeadline", err) ctx.Error(500, "UpdateIssueDeadline", err)
return return
} }
issue.DeadlineUnix = deadlineUnix
}
// Add/delete assignees // Add/delete assignees

View File

@@ -104,7 +104,7 @@ func GetInfo(ctx *context.APIContext) {
return return
} }
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin))) ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin))
} }
// GetAuthenticatedUser get current user's information // GetAuthenticatedUser get current user's information

View File

@@ -273,7 +273,7 @@ func ExploreOrganizations(ctx *context.Context) {
// ExploreCode render explore code page // ExploreCode render explore code page
func ExploreCode(ctx *context.Context) { func ExploreCode(ctx *context.Context) {
if !setting.Indexer.RepoIndexerEnabled { if !setting.Indexer.RepoIndexerEnabled {
ctx.Redirect(setting.AppSubURL+"/explore", 302) ctx.Redirect("/explore", 302)
return return
} }

View File

@@ -84,11 +84,6 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error {
if err != nil { if err != nil {
return err return err
} }
defer func() {
if err = lfsDataRc.Close(); err != nil {
log.Error("ServeBlobOrLFS: Close: %v", err)
}
}()
return ServeData(ctx, ctx.Repo.TreePath, lfsDataRc) return ServeData(ctx, ctx.Repo.TreePath, lfsDataRc)
} }

View File

@@ -272,12 +272,12 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
} }
func setMergeTarget(ctx *context.Context, pull *models.PullRequest) { func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
if ctx.Repo.Owner.Name == pull.MustHeadUserName() { if ctx.Repo.Owner.Name == pull.HeadUserName {
ctx.Data["HeadTarget"] = pull.HeadBranch ctx.Data["HeadTarget"] = pull.HeadBranch
} else if pull.HeadRepo == nil { } else if pull.HeadRepo == nil {
ctx.Data["HeadTarget"] = pull.MustHeadUserName() + ":" + pull.HeadBranch ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch
} else { } else {
ctx.Data["HeadTarget"] = pull.MustHeadUserName() + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
} }
ctx.Data["BaseTarget"] = pull.BaseBranch ctx.Data["BaseTarget"] = pull.BaseBranch
} }
@@ -440,7 +440,7 @@ func ViewPullCommits(ctx *context.Context) {
ctx.NotFound("ViewPullCommits", nil) ctx.NotFound("ViewPullCommits", nil)
return return
} }
ctx.Data["Username"] = pull.MustHeadUserName() ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name ctx.Data["Reponame"] = pull.HeadRepo.Name
commits = prInfo.Commits commits = prInfo.Commits
} }
@@ -512,7 +512,7 @@ func ViewPullFiles(ctx *context.Context) {
return return
} }
headRepoPath := pull.HeadRepo.RepoPath() headRepoPath := models.RepoPath(pull.HeadUserName, pull.HeadRepo.Name)
headGitRepo, err := git.OpenRepository(headRepoPath) headGitRepo, err := git.OpenRepository(headRepoPath)
if err != nil { if err != nil {
@@ -531,8 +531,8 @@ func ViewPullFiles(ctx *context.Context) {
endCommitID = headCommitID endCommitID = headCommitID
gitRepo = headGitRepo gitRepo = headGitRepo
headTarget = path.Join(pull.MustHeadUserName(), pull.HeadRepo.Name) headTarget = path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["Username"] = pull.MustHeadUserName() ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name ctx.Data["Reponame"] = pull.HeadRepo.Name
} }
@@ -756,6 +756,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
pullRequest := &models.PullRequest{ pullRequest := &models.PullRequest{
HeadRepoID: headRepo.ID, HeadRepoID: headRepo.ID,
BaseRepoID: repo.ID, BaseRepoID: repo.ID,
HeadUserName: headUser.Name,
HeadBranch: headBranch, HeadBranch: headBranch,
BaseBranch: baseBranch, BaseBranch: baseBranch,
HeadRepo: headRepo, HeadRepo: headRepo,

View File

@@ -28,6 +28,7 @@ func Account(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true ctx.Data["PageIsSettingsAccount"] = true
ctx.Data["Email"] = ctx.User.Email ctx.Data["Email"] = ctx.User.Email
ctx.Data["EmailNotificationsPreference"] = ctx.User.EmailNotifications()
loadAccountData(ctx) loadAccountData(ctx)
@@ -53,7 +54,7 @@ func AccountPost(ctx *context.Context, form auth.ChangePasswordForm) {
} else if form.Password != form.Retype { } else if form.Password != form.Retype {
ctx.Flash.Error(ctx.Tr("form.password_not_match")) ctx.Flash.Error(ctx.Tr("form.password_not_match"))
} else if !password.IsComplexEnough(form.Password) { } else if !password.IsComplexEnough(form.Password) {
ctx.Flash.Error(ctx.Tr("form.password_complexity")) ctx.Flash.Error(ctx.Tr("settings.password_complexity"))
} else { } else {
var err error var err error
if ctx.User.Salt, err = models.GetUserSalt(); err != nil { if ctx.User.Salt, err = models.GetUserSalt(); err != nil {
@@ -229,5 +230,4 @@ func loadAccountData(ctx *context.Context) {
return return
} }
ctx.Data["Emails"] = emails ctx.Data["Emails"] = emails
ctx.Data["EmailNotificationsPreference"] = ctx.User.EmailNotifications()
} }

View File

@@ -19,64 +19,76 @@ import (
func TestChangePassword(t *testing.T) { func TestChangePassword(t *testing.T) {
oldPassword := "password" oldPassword := "password"
setting.MinPasswordLength = 6 setting.MinPasswordLength = 6
var pcALL = []string{"lower", "upper", "digit", "spec"} setting.PasswordComplexity = map[string]string{
var pcLUN = []string{"lower", "upper", "digit"} "lower": "[a-z]+",
var pcLU = []string{"lower", "upper"} "upper": "[A-Z]+",
"digit": "[0-9]+",
"spec": "[-_]+",
}
var pcLUN = map[string]string{
"lower": "[a-z]+",
"upper": "[A-Z]+",
"digit": "[0-9]+",
}
var pcLU = map[string]string{
"lower": "[a-z]+",
"upper": "[A-Z]+",
}
for _, req := range []struct { for _, req := range []struct {
OldPassword string OldPassword string
NewPassword string NewPassword string
Retype string Retype string
Message string Message string
PasswordComplexity []string PasswordComplexity map[string]string
}{ }{
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "Qwerty123456-", NewPassword: "Qwerty123456-",
Retype: "Qwerty123456-", Retype: "Qwerty123456-",
Message: "", Message: "",
PasswordComplexity: pcALL, PasswordComplexity: setting.PasswordComplexity,
}, },
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "12345", NewPassword: "12345",
Retype: "12345", Retype: "12345",
Message: "auth.password_too_short", Message: "auth.password_too_short",
PasswordComplexity: pcALL, PasswordComplexity: setting.PasswordComplexity,
}, },
{ {
OldPassword: "12334", OldPassword: "12334",
NewPassword: "123456", NewPassword: "123456",
Retype: "123456", Retype: "123456",
Message: "settings.password_incorrect", Message: "settings.password_incorrect",
PasswordComplexity: pcALL, PasswordComplexity: setting.PasswordComplexity,
}, },
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "123456", NewPassword: "123456",
Retype: "12345", Retype: "12345",
Message: "form.password_not_match", Message: "form.password_not_match",
PasswordComplexity: pcALL, PasswordComplexity: setting.PasswordComplexity,
}, },
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "Qwerty", NewPassword: "Qwerty",
Retype: "Qwerty", Retype: "Qwerty",
Message: "form.password_complexity", Message: "settings.password_complexity",
PasswordComplexity: pcALL, PasswordComplexity: setting.PasswordComplexity,
}, },
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "Qwerty", NewPassword: "Qwerty",
Retype: "Qwerty", Retype: "Qwerty",
Message: "form.password_complexity", Message: "settings.password_complexity",
PasswordComplexity: pcLUN, PasswordComplexity: pcLUN,
}, },
{ {
OldPassword: oldPassword, OldPassword: oldPassword,
NewPassword: "QWERTY", NewPassword: "QWERTY",
Retype: "QWERTY", Retype: "QWERTY",
Message: "form.password_complexity", Message: "settings.password_complexity",
PasswordComplexity: pcLU, PasswordComplexity: pcLU,
}, },
} { } {

View File

@@ -5,6 +5,7 @@
package externalaccount package externalaccount
import ( import (
"strconv"
"strings" "strings"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@@ -44,7 +45,10 @@ func LinkAccountToUser(user *models.User, gothUser goth.User) error {
return err return err
} }
externalID := externalLoginUser.ExternalID externalID, err := strconv.ParseInt(externalLoginUser.ExternalID, 10, 64)
if err != nil {
return err
}
var tp structs.GitServiceType var tp structs.GitServiceType
for _, s := range structs.SupportedFullGitService { for _, s := range structs.SupportedFullGitService {

View File

@@ -65,7 +65,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
} }
}() }()
headRepoPath := pr.HeadRepo.RepoPath() headRepoPath := models.RepoPath(pr.HeadUserName, pr.HeadRepo.Name)
if err := git.InitRepository(tmpBasePath, false); err != nil { if err := git.InitRepository(tmpBasePath, false); err != nil {
return fmt.Errorf("git init: %v", err) return fmt.Errorf("git init: %v", err)
@@ -260,17 +260,14 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
} }
} }
var headUser *models.User headUser, err := models.GetUserByName(pr.HeadUserName)
err = pr.HeadRepo.GetOwner()
if err != nil { if err != nil {
if !models.IsErrUserNotExist(err) { if !models.IsErrUserNotExist(err) {
log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err) log.Error("Can't find user: %s for head repository - %v", pr.HeadUserName, err)
return err return err
} }
log.Error("Can't find user: %d for head repository - defaulting to doer: %s - %v", pr.HeadRepo.OwnerID, doer.Name, err) log.Error("Can't find user: %s for head repository - defaulting to doer: %s - %v", pr.HeadUserName, doer.Name, err)
headUser = doer headUser = doer
} else {
headUser = pr.HeadRepo.Owner
} }
env := models.FullPushingEnvironment( env := models.FullPushingEnvironment(

View File

@@ -16,8 +16,8 @@
</div> </div>
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4> <h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}} {{else}}
<div>
<div class="diff-detail-box diff-box ui sticky"> <div class="diff-detail-box diff-box ui sticky">
<div>
<i class="fa fa-retweet"></i> <i class="fa fa-retweet"></i>
{{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}} {{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
<div class="ui right"> <div class="ui right">
@@ -32,17 +32,17 @@
{{end}} {{end}}
</div> </div>
</div> </div>
<ol class="diff-detail-box diff-stats detail-files hide" id="diff-files"> <ol class="detail-files hide" id="diff-files">
{{range .Diff.Files}} {{range .Diff.Files}}
<li> <li>
<div class="diff-counter count pull-right"> <div class="diff-counter count pull-right">
{{if not .IsBin}} {{if not .IsBin}}
<span class="add" data-line="{{.Addition}}">+{{.Addition}}</span> <span class="add" data-line="{{.Addition}}">{{.Addition}}</span>
<span class="bar"> <span class="bar">
<div class="pull-left add"></div> <div class="pull-left add"></div>
<div class="pull-left del"></div> <div class="pull-left del"></div>
</span> </span>
<span class="del" data-line="{{.Deletion}}">-{{.Deletion}}</span> <span class="del" data-line="{{.Deletion}}">{{.Deletion}}</span>
{{else}} {{else}}
<span>{{$.i18n.Tr "repo.diff.bin"}}</span> <span>{{$.i18n.Tr "repo.diff.bin"}}</span>
{{end}} {{end}}
@@ -53,6 +53,8 @@
</li> </li>
{{end}} {{end}}
</ol> </ol>
</div>
{{range $i, $file := .Diff.Files}} {{range $i, $file := .Diff.Files}}
{{if $file.IsIncomplete}} {{if $file.IsIncomplete}}
<div class="diff-file-box diff-box file-content"> <div class="diff-file-box diff-box file-content">
@@ -235,5 +237,4 @@
}); });
</script> </script>
{{end}} {{end}}
</div>
{{end}} {{end}}

View File

@@ -16,7 +16,7 @@
<p>{{.i18n.Tr "auth.authroize_redirect_notice" .ApplicationRedirectDomainHTML | Str2html}}</p> <p>{{.i18n.Tr "auth.authroize_redirect_notice" .ApplicationRedirectDomainHTML | Str2html}}</p>
</div> </div>
<div class="ui attached segment"> <div class="ui attached segment">
<form method="post" action="{{AppSubUrl}}/login/oauth/grant"> <form method="post" action="{{.AppSubUrl}}/login/oauth/grant">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<input type="hidden" name="client_id" value="{{.Application.ClientID}}"> <input type="hidden" name="client_id" value="{{.Application.ClientID}}">
<input type="hidden" name="state" value="{{.State}}"> <input type="hidden" name="state" value="{{.State}}">