Skip to content

Commit 2bee512

Browse files
committed
Fix migration, and remove fields completely
1 parent 1014138 commit 2bee512

File tree

8 files changed

+167
-158
lines changed

8 files changed

+167
-158
lines changed

integrations/mysql.ini

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DB_TYPE = mysql
66
HOST = 127.0.0.1:3306
77
NAME = testgitea
88
USER = root
9-
PASSWD =
9+
PASSWD =
1010
SSL_MODE = disable
1111
PATH = data/gitea.db
1212

@@ -26,14 +26,14 @@ OFFLINE_MODE = false
2626
ENABLED = false
2727

2828
[service]
29-
REGISTER_EMAIL_CONFIRM = false
30-
ENABLE_NOTIFY_MAIL = false
31-
DISABLE_REGISTRATION = false
32-
ENABLE_CAPTCHA = false
33-
REQUIRE_SIGNIN_VIEW = false
34-
DEFAULT_KEEP_EMAIL_PRIVATE = false
29+
REGISTER_EMAIL_CONFIRM = false
30+
ENABLE_NOTIFY_MAIL = false
31+
DISABLE_REGISTRATION = false
32+
ENABLE_CAPTCHA = false
33+
REQUIRE_SIGNIN_VIEW = false
34+
DEFAULT_KEEP_EMAIL_PRIVATE = false
3535
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
36-
NO_REPLY_ADDRESS = noreply.example.org
36+
NO_REPLY_ADDRESS = noreply.example.org
3737

3838
[picture]
3939
DISABLE_GRAVATAR = false
@@ -53,5 +53,7 @@ LEVEL = Warn
5353
LEVEL = Info
5454

5555
[security]
56-
INSTALL_LOCK = true
57-
SECRET_KEY = 9pCviYTWSb
56+
INSTALL_LOCK = true
57+
SECRET_KEY = 9pCviYTWSb
58+
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
59+

models/action.go

Lines changed: 83 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,18 @@ func init() {
7070
// repository. It implemented interface base.Actioner so that can be
7171
// used in template render.
7272
type Action struct {
73-
ID int64 `xorm:"pk autoincr"`
74-
UserID int64 `xorm:"INDEX"` // Receiver user id.
75-
OpType ActionType
76-
ActUserID int64 `xorm:"INDEX"` // Action user id.
77-
ActUserName string `xorm:"-"`
78-
ActAvatar string `xorm:"-"`
79-
RepoID int64 `xorm:"INDEX"`
80-
RepoUserName string `xorm:"-"`
81-
RepoName string `xorm:"-"`
82-
RefName string
83-
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
84-
Content string `xorm:"TEXT"`
85-
Created time.Time `xorm:"-"`
86-
CreatedUnix int64 `xorm:"INDEX"`
73+
ID int64 `xorm:"pk autoincr"`
74+
UserID int64 `xorm:"INDEX"` // Receiver user id.
75+
OpType ActionType
76+
ActUserID int64 `xorm:"INDEX"` // Action user id.
77+
ActUser *User `xorm:"-"`
78+
RepoID int64 `xorm:"INDEX"`
79+
Repo *Repository `xorm:"-"`
80+
RefName string
81+
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
82+
Content string `xorm:"TEXT"`
83+
Created time.Time `xorm:"-"`
84+
CreatedUnix int64 `xorm:"INDEX"`
8785
}
8886

8987
// BeforeInsert will be invoked by XORM before inserting a record
@@ -106,42 +104,71 @@ func (a *Action) GetOpType() int {
106104
return int(a.OpType)
107105
}
108106

107+
func (a *Action) loadActUser() {
108+
if a.ActUser != nil {
109+
return
110+
}
111+
var err error
112+
a.ActUser, err = GetUserByID(a.ActUserID)
113+
if err == nil {
114+
return
115+
} else if IsErrUserNotExist(err) {
116+
a.ActUser = NewGhostUser()
117+
} else {
118+
log.Error(4, "GetUserByID(%d): %v", a.ActUserID, err)
119+
}
120+
}
121+
122+
func (a *Action) loadRepo() {
123+
if a.ActUser != nil {
124+
return
125+
}
126+
var err error
127+
a.Repo, err = GetRepositoryByID(a.RepoID)
128+
if err != nil {
129+
log.Error(4, "GetRepositoryByID(%d): %v", a.RepoID, err)
130+
}
131+
}
132+
109133
// GetActUserName gets the action's user name.
110134
func (a *Action) GetActUserName() string {
111-
return a.ActUserName
135+
a.loadActUser()
136+
return a.ActUser.Name
112137
}
113138

114139
// ShortActUserName gets the action's user name trimmed to max 20
115140
// chars.
116141
func (a *Action) ShortActUserName() string {
117-
return base.EllipsisString(a.ActUserName, 20)
142+
return base.EllipsisString(a.GetActUserName(), 20)
118143
}
119144

120145
// GetRepoUserName returns the name of the action repository owner.
121146
func (a *Action) GetRepoUserName() string {
122-
return a.RepoUserName
147+
a.loadRepo()
148+
return a.Repo.MustOwner().Name
123149
}
124150

125151
// ShortRepoUserName returns the name of the action repository owner
126152
// trimmed to max 20 chars.
127153
func (a *Action) ShortRepoUserName() string {
128-
return base.EllipsisString(a.RepoUserName, 20)
154+
return base.EllipsisString(a.GetRepoUserName(), 20)
129155
}
130156

131157
// GetRepoName returns the name of the action repository.
132158
func (a *Action) GetRepoName() string {
133-
return a.RepoName
159+
a.loadRepo()
160+
return a.Repo.Name
134161
}
135162

136163
// ShortRepoName returns the name of the action repository
137164
// trimmed to max 33 chars.
138165
func (a *Action) ShortRepoName() string {
139-
return base.EllipsisString(a.RepoName, 33)
166+
return base.EllipsisString(a.GetRepoName(), 33)
140167
}
141168

142169
// GetRepoPath returns the virtual path to the action repository.
143170
func (a *Action) GetRepoPath() string {
144-
return path.Join(a.RepoUserName, a.RepoName)
171+
return path.Join(a.GetRepoUserName(), a.GetRepoName())
145172
}
146173

147174
// ShortRepoPath returns the virtual path to the action repository
@@ -205,13 +232,12 @@ func (a *Action) GetIssueContent() string {
205232

206233
func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
207234
if err = notifyWatchers(e, &Action{
208-
ActUserID: u.ID,
209-
ActUserName: u.Name,
210-
OpType: ActionCreateRepo,
211-
RepoID: repo.ID,
212-
RepoUserName: repo.Owner.Name,
213-
RepoName: repo.Name,
214-
IsPrivate: repo.IsPrivate,
235+
ActUserID: u.ID,
236+
ActUser: u,
237+
OpType: ActionCreateRepo,
238+
RepoID: repo.ID,
239+
Repo: repo,
240+
IsPrivate: repo.IsPrivate,
215241
}); err != nil {
216242
return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err)
217243
}
@@ -227,14 +253,13 @@ func NewRepoAction(u *User, repo *Repository) (err error) {
227253

228254
func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) {
229255
if err = notifyWatchers(e, &Action{
230-
ActUserID: actUser.ID,
231-
ActUserName: actUser.Name,
232-
OpType: ActionRenameRepo,
233-
RepoID: repo.ID,
234-
RepoUserName: repo.Owner.Name,
235-
RepoName: repo.Name,
236-
IsPrivate: repo.IsPrivate,
237-
Content: oldRepoName,
256+
ActUserID: actUser.ID,
257+
ActUser: actUser,
258+
OpType: ActionRenameRepo,
259+
RepoID: repo.ID,
260+
Repo: repo,
261+
IsPrivate: repo.IsPrivate,
262+
Content: oldRepoName,
238263
}); err != nil {
239264
return fmt.Errorf("notify watchers: %v", err)
240265
}
@@ -521,15 +546,14 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
521546

522547
refName := git.RefEndName(opts.RefFullName)
523548
if err = NotifyWatchers(&Action{
524-
ActUserID: pusher.ID,
525-
ActUserName: pusher.Name,
526-
OpType: opType,
527-
Content: string(data),
528-
RepoID: repo.ID,
529-
RepoUserName: repo.MustOwner().Name,
530-
RepoName: repo.Name,
531-
RefName: refName,
532-
IsPrivate: repo.IsPrivate,
549+
ActUserID: pusher.ID,
550+
ActUser: pusher,
551+
OpType: opType,
552+
Content: string(data),
553+
RepoID: repo.ID,
554+
Repo: repo,
555+
RefName: refName,
556+
IsPrivate: repo.IsPrivate,
533557
}); err != nil {
534558
return fmt.Errorf("NotifyWatchers: %v", err)
535559
}
@@ -598,14 +622,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
598622

599623
func transferRepoAction(e Engine, doer, oldOwner *User, repo *Repository) (err error) {
600624
if err = notifyWatchers(e, &Action{
601-
ActUserID: doer.ID,
602-
ActUserName: doer.Name,
603-
OpType: ActionTransferRepo,
604-
RepoID: repo.ID,
605-
RepoUserName: repo.Owner.Name,
606-
RepoName: repo.Name,
607-
IsPrivate: repo.IsPrivate,
608-
Content: path.Join(oldOwner.Name, repo.Name),
625+
ActUserID: doer.ID,
626+
ActUser: doer,
627+
OpType: ActionTransferRepo,
628+
RepoID: repo.ID,
629+
Repo: repo,
630+
IsPrivate: repo.IsPrivate,
631+
Content: path.Join(oldOwner.Name, repo.Name),
609632
}); err != nil {
610633
return fmt.Errorf("notifyWatchers: %v", err)
611634
}
@@ -628,14 +651,13 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
628651

629652
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error {
630653
return notifyWatchers(e, &Action{
631-
ActUserID: doer.ID,
632-
ActUserName: doer.Name,
633-
OpType: ActionMergePullRequest,
634-
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
635-
RepoID: repo.ID,
636-
RepoUserName: repo.Owner.Name,
637-
RepoName: repo.Name,
638-
IsPrivate: repo.IsPrivate,
654+
ActUserID: doer.ID,
655+
ActUser: doer,
656+
OpType: ActionMergePullRequest,
657+
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
658+
RepoID: repo.ID,
659+
Repo: repo,
660+
IsPrivate: repo.IsPrivate,
639661
})
640662
}
641663

models/action_test.go

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,9 @@ import (
44
"strings"
55
"testing"
66

7-
"code.gitea.io/gitea/modules/setting"
8-
97
"github.com/stretchr/testify/assert"
108
)
119

12-
func TestAction_GetRepoPath(t *testing.T) {
13-
action := &Action{
14-
RepoUserName: "username",
15-
RepoName: "reponame",
16-
}
17-
assert.Equal(t, "username/reponame", action.GetRepoPath())
18-
}
19-
20-
func TestAction_GetRepoLink(t *testing.T) {
21-
action := &Action{
22-
RepoUserName: "username",
23-
RepoName: "reponame",
24-
}
25-
setting.AppSubURL = "/suburl/"
26-
assert.Equal(t, "/suburl/username/reponame", action.GetRepoLink())
27-
setting.AppSubURL = ""
28-
assert.Equal(t, "/username/reponame", action.GetRepoLink())
29-
}
30-
3110
func TestNewRepoAction(t *testing.T) {
3211
assert.NoError(t, PrepareTestDatabase())
3312

@@ -36,13 +15,12 @@ func TestNewRepoAction(t *testing.T) {
3615
repo.Owner = user
3716

3817
actionBean := &Action{
39-
OpType: ActionCreateRepo,
40-
ActUserID: user.ID,
41-
RepoID: repo.ID,
42-
ActUserName: user.Name,
43-
RepoName: repo.Name,
44-
RepoUserName: repo.Owner.Name,
45-
IsPrivate: repo.IsPrivate,
18+
OpType: ActionCreateRepo,
19+
ActUserID: user.ID,
20+
RepoID: repo.ID,
21+
ActUser: user,
22+
Repo: repo,
23+
IsPrivate: repo.IsPrivate,
4624
}
4725

4826
AssertNotExistsBean(t, actionBean)
@@ -64,14 +42,13 @@ func TestRenameRepoAction(t *testing.T) {
6442
repo.LowerName = strings.ToLower(newRepoName)
6543

6644
actionBean := &Action{
67-
OpType: ActionRenameRepo,
68-
ActUserID: user.ID,
69-
ActUserName: user.Name,
70-
RepoID: repo.ID,
71-
RepoName: repo.Name,
72-
RepoUserName: repo.Owner.Name,
73-
IsPrivate: repo.IsPrivate,
74-
Content: oldRepoName,
45+
OpType: ActionRenameRepo,
46+
ActUserID: user.ID,
47+
ActUser: user,
48+
RepoID: repo.ID,
49+
Repo: repo,
50+
IsPrivate: repo.IsPrivate,
51+
Content: oldRepoName,
7552
}
7653
AssertNotExistsBean(t, actionBean)
7754
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
@@ -232,13 +209,13 @@ func TestCommitRepoAction(t *testing.T) {
232209
pushCommits.Len = len(pushCommits.Commits)
233210

234211
actionBean := &Action{
235-
OpType: ActionCommitRepo,
236-
ActUserID: user.ID,
237-
ActUserName: user.Name,
238-
RepoID: repo.ID,
239-
RepoName: repo.Name,
240-
RefName: "refName",
241-
IsPrivate: repo.IsPrivate,
212+
OpType: ActionCommitRepo,
213+
ActUserID: user.ID,
214+
ActUser: user,
215+
RepoID: repo.ID,
216+
Repo: repo,
217+
RefName: "refName",
218+
IsPrivate: repo.IsPrivate,
242219
}
243220
AssertNotExistsBean(t, actionBean)
244221
assert.NoError(t, CommitRepoAction(CommitRepoActionOptions{
@@ -265,13 +242,12 @@ func TestTransferRepoAction(t *testing.T) {
265242
repo.Owner = user4
266243

267244
actionBean := &Action{
268-
OpType: ActionTransferRepo,
269-
ActUserID: user2.ID,
270-
ActUserName: user2.Name,
271-
RepoID: repo.ID,
272-
RepoName: repo.Name,
273-
RepoUserName: repo.Owner.Name,
274-
IsPrivate: repo.IsPrivate,
245+
OpType: ActionTransferRepo,
246+
ActUserID: user2.ID,
247+
ActUser: user2,
248+
RepoID: repo.ID,
249+
Repo: repo,
250+
IsPrivate: repo.IsPrivate,
275251
}
276252
AssertNotExistsBean(t, actionBean)
277253
assert.NoError(t, TransferRepoAction(user2, user2, repo))
@@ -290,13 +266,12 @@ func TestMergePullRequestAction(t *testing.T) {
290266
issue := AssertExistsAndLoadBean(t, &Issue{ID: 3, RepoID: repo.ID}).(*Issue)
291267

292268
actionBean := &Action{
293-
OpType: ActionMergePullRequest,
294-
ActUserID: user.ID,
295-
ActUserName: user.Name,
296-
RepoID: repo.ID,
297-
RepoName: repo.Name,
298-
RepoUserName: repo.Owner.Name,
299-
IsPrivate: repo.IsPrivate,
269+
OpType: ActionMergePullRequest,
270+
ActUserID: user.ID,
271+
ActUser: user,
272+
RepoID: repo.ID,
273+
Repo: repo,
274+
IsPrivate: repo.IsPrivate,
300275
}
301276
AssertNotExistsBean(t, actionBean)
302277
assert.NoError(t, MergePullRequestAction(user, repo, issue))

0 commit comments

Comments
 (0)