forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
* upstream/main: Always go full width in PR view (go-gitea#22844) Increase Content field size of gpg_key_import to MEDIUMTEXT (go-gitea#22897) Fix context bug (go-gitea#22940) Allow custom "created" timestamps in user creation API (go-gitea#22549) Use "Title Case" for text "Reference in new issue" (go-gitea#22936) First step to refactor the `.hide` to `.gt-hidden` (go-gitea#22916) Add continue option to backport.go (go-gitea#22930) Add `title` to PR file tree items (go-gitea#22918) # Conflicts: # templates/repo/issue/view_content/comments.tmpl
- Loading branch information
Showing
19 changed files
with
188 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_19 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
// AlterPublicGPGKeyImportContentFieldToMediumText: set GPGKeyImport Content field to MEDIUMTEXT | ||
func AlterPublicGPGKeyImportContentFieldToMediumText(x *xorm.Engine) error { | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
if setting.Database.UseMySQL { | ||
if _, err := sess.Exec("ALTER TABLE `gpg_key_import` CHANGE `content` `content` MEDIUMTEXT"); err != nil { | ||
return err | ||
} | ||
} | ||
return sess.Commit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,19 @@ | |
package user_test | ||
|
||
import ( | ||
"context" | ||
"math/rand" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models/auth" | ||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/models/unittest" | ||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
"code.gitea.io/gitea/modules/util" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -252,6 +255,58 @@ func TestCreateUserEmailAlreadyUsed(t *testing.T) { | |
assert.True(t, user_model.IsErrEmailAlreadyUsed(err)) | ||
} | ||
|
||
func TestCreateUserCustomTimestamps(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) | ||
|
||
// Add new user with a custom creation timestamp. | ||
var creationTimestamp timeutil.TimeStamp = 12345 | ||
user.Name = "testuser" | ||
user.LowerName = strings.ToLower(user.Name) | ||
user.ID = 0 | ||
user.Email = "[email protected]" | ||
user.CreatedUnix = creationTimestamp | ||
err := user_model.CreateUser(user) | ||
assert.NoError(t, err) | ||
|
||
fetched, err := user_model.GetUserByID(context.Background(), user.ID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, creationTimestamp, fetched.CreatedUnix) | ||
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix) | ||
} | ||
|
||
func TestCreateUserWithoutCustomTimestamps(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) | ||
|
||
// There is no way to use a mocked time for the XORM auto-time functionality, | ||
// so use the real clock to approximate the expected timestamp. | ||
timestampStart := time.Now().Unix() | ||
|
||
// Add new user without a custom creation timestamp. | ||
user.Name = "Testuser" | ||
user.LowerName = strings.ToLower(user.Name) | ||
user.ID = 0 | ||
user.Email = "[email protected]" | ||
user.CreatedUnix = 0 | ||
user.UpdatedUnix = 0 | ||
err := user_model.CreateUser(user) | ||
assert.NoError(t, err) | ||
|
||
timestampEnd := time.Now().Unix() | ||
|
||
fetched, err := user_model.GetUserByID(context.Background(), user.ID) | ||
assert.NoError(t, err) | ||
|
||
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix) | ||
assert.LessOrEqual(t, fetched.CreatedUnix, timestampEnd) | ||
|
||
assert.LessOrEqual(t, timestampStart, fetched.UpdatedUnix) | ||
assert.LessOrEqual(t, fetched.UpdatedUnix, timestampEnd) | ||
} | ||
|
||
func TestGetUserIDsByNames(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.