aboutsummaryrefslogtreecommitdiff
path: root/internal/route
diff options
context:
space:
mode:
Diffstat (limited to 'internal/route')
3 files changed, 139 insertions, 2 deletions
diff --git a/internal/route/lfs/mocks_test.go b/internal/route/lfs/mocks_test.go
index 960f7108..9a51b395 100644
--- a/internal/route/lfs/mocks_test.go
+++ b/internal/route/lfs/mocks_test.go
@@ -2319,6 +2319,10 @@ type MockUsersStore struct {
// GetByUsernameFunc is an instance of a mock function object
// controlling the behavior of the method GetByUsername.
GetByUsernameFunc *UsersStoreGetByUsernameFunc
+ // GetMailableEmailsByUsernamesFunc is an instance of a mock function
+ // object controlling the behavior of the method
+ // GetMailableEmailsByUsernames.
+ GetMailableEmailsByUsernamesFunc *UsersStoreGetMailableEmailsByUsernamesFunc
// HasForkedRepositoryFunc is an instance of a mock function object
// controlling the behavior of the method HasForkedRepository.
HasForkedRepositoryFunc *UsersStoreHasForkedRepositoryFunc
@@ -2394,6 +2398,11 @@ func NewMockUsersStore() *MockUsersStore {
return
},
},
+ GetMailableEmailsByUsernamesFunc: &UsersStoreGetMailableEmailsByUsernamesFunc{
+ defaultHook: func(context.Context, []string) (r0 []string, r1 error) {
+ return
+ },
+ },
HasForkedRepositoryFunc: &UsersStoreHasForkedRepositoryFunc{
defaultHook: func(context.Context, int64, int64) (r0 bool) {
return
@@ -2486,6 +2495,11 @@ func NewStrictMockUsersStore() *MockUsersStore {
panic("unexpected invocation of MockUsersStore.GetByUsername")
},
},
+ GetMailableEmailsByUsernamesFunc: &UsersStoreGetMailableEmailsByUsernamesFunc{
+ defaultHook: func(context.Context, []string) ([]string, error) {
+ panic("unexpected invocation of MockUsersStore.GetMailableEmailsByUsernames")
+ },
+ },
HasForkedRepositoryFunc: &UsersStoreHasForkedRepositoryFunc{
defaultHook: func(context.Context, int64, int64) bool {
panic("unexpected invocation of MockUsersStore.HasForkedRepository")
@@ -2560,6 +2574,9 @@ func NewMockUsersStoreFrom(i db.UsersStore) *MockUsersStore {
GetByUsernameFunc: &UsersStoreGetByUsernameFunc{
defaultHook: i.GetByUsername,
},
+ GetMailableEmailsByUsernamesFunc: &UsersStoreGetMailableEmailsByUsernamesFunc{
+ defaultHook: i.GetMailableEmailsByUsernames,
+ },
HasForkedRepositoryFunc: &UsersStoreHasForkedRepositoryFunc{
defaultHook: i.HasForkedRepository,
},
@@ -3561,6 +3578,118 @@ func (c UsersStoreGetByUsernameFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
+// UsersStoreGetMailableEmailsByUsernamesFunc describes the behavior when
+// the GetMailableEmailsByUsernames method of the parent MockUsersStore
+// instance is invoked.
+type UsersStoreGetMailableEmailsByUsernamesFunc struct {
+ defaultHook func(context.Context, []string) ([]string, error)
+ hooks []func(context.Context, []string) ([]string, error)
+ history []UsersStoreGetMailableEmailsByUsernamesFuncCall
+ mutex sync.Mutex
+}
+
+// GetMailableEmailsByUsernames delegates to the next hook function in the
+// queue and stores the parameter and result values of this invocation.
+func (m *MockUsersStore) GetMailableEmailsByUsernames(v0 context.Context, v1 []string) ([]string, error) {
+ r0, r1 := m.GetMailableEmailsByUsernamesFunc.nextHook()(v0, v1)
+ m.GetMailableEmailsByUsernamesFunc.appendCall(UsersStoreGetMailableEmailsByUsernamesFuncCall{v0, v1, r0, r1})
+ return r0, r1
+}
+
+// SetDefaultHook sets function that is called when the
+// GetMailableEmailsByUsernames method of the parent MockUsersStore instance
+// is invoked and the hook queue is empty.
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) SetDefaultHook(hook func(context.Context, []string) ([]string, error)) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// GetMailableEmailsByUsernames method of the parent MockUsersStore instance
+// invokes the hook at the front of the queue and discards it. After the
+// queue is empty, the default hook function is invoked for any future
+// action.
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) PushHook(hook func(context.Context, []string) ([]string, error)) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
+}
+
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) SetDefaultReturn(r0 []string, r1 error) {
+ f.SetDefaultHook(func(context.Context, []string) ([]string, error) {
+ return r0, r1
+ })
+}
+
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) PushReturn(r0 []string, r1 error) {
+ f.PushHook(func(context.Context, []string) ([]string, error) {
+ return r0, r1
+ })
+}
+
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) nextHook() func(context.Context, []string) ([]string, error) {
+ f.mutex.Lock()
+ defer f.mutex.Unlock()
+
+ if len(f.hooks) == 0 {
+ return f.defaultHook
+ }
+
+ hook := f.hooks[0]
+ f.hooks = f.hooks[1:]
+ return hook
+}
+
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) appendCall(r0 UsersStoreGetMailableEmailsByUsernamesFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
+}
+
+// History returns a sequence of
+// UsersStoreGetMailableEmailsByUsernamesFuncCall objects describing the
+// invocations of this function.
+func (f *UsersStoreGetMailableEmailsByUsernamesFunc) History() []UsersStoreGetMailableEmailsByUsernamesFuncCall {
+ f.mutex.Lock()
+ history := make([]UsersStoreGetMailableEmailsByUsernamesFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
+}
+
+// UsersStoreGetMailableEmailsByUsernamesFuncCall is an object that
+// describes an invocation of method GetMailableEmailsByUsernames on an
+// instance of MockUsersStore.
+type UsersStoreGetMailableEmailsByUsernamesFuncCall struct {
+ // Arg0 is the value of the 1st argument passed to this method
+ // invocation.
+ Arg0 context.Context
+ // Arg1 is the value of the 2nd argument passed to this method
+ // invocation.
+ Arg1 []string
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 []string
+ // Result1 is the value of the 2nd result returned from this method
+ // invocation.
+ Result1 error
+}
+
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c UsersStoreGetMailableEmailsByUsernamesFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
+}
+
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c UsersStoreGetMailableEmailsByUsernamesFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0, c.Result1}
+}
+
// UsersStoreHasForkedRepositoryFunc describes the behavior when the
// HasForkedRepository method of the parent MockUsersStore instance is
// invoked.
diff --git a/internal/route/repo/commit.go b/internal/route/repo/commit.go
index 3e09bd06..da8c5e48 100644
--- a/internal/route/repo/commit.go
+++ b/internal/route/repo/commit.go
@@ -5,6 +5,7 @@
package repo
import (
+ gocontext "context"
"path"
"time"
@@ -110,6 +111,13 @@ func FileHistory(c *context.Context) {
renderCommits(c, c.Repo.TreePath)
}
+// tryGetUserByEmail returns a non-nil value if the email is corresponding to an
+// existing user.
+func tryGetUserByEmail(ctx gocontext.Context, email string) *db.User {
+ user, _ := db.Users.GetByEmail(ctx, email)
+ return user
+}
+
func Diff(c *context.Context) {
c.PageIs("Diff")
c.RequireHighlightJS()
@@ -156,7 +164,7 @@ func Diff(c *context.Context) {
c.Data["IsImageFile"] = commit.IsImageFile
c.Data["IsImageFileByIndex"] = commit.IsImageFileByIndex
c.Data["Commit"] = commit
- c.Data["Author"] = db.ValidateCommitWithEmail(commit)
+ c.Data["Author"] = tryGetUserByEmail(c.Req.Context(), commit.Author.Email)
c.Data["Diff"] = diff
c.Data["Parents"] = parents
c.Data["DiffNotAvailable"] = diff.NumFiles() == 0
diff --git a/internal/route/repo/view.go b/internal/route/repo/view.go
index f4b6a162..ac5ed333 100644
--- a/internal/route/repo/view.go
+++ b/internal/route/repo/view.go
@@ -111,7 +111,7 @@ func renderDirectory(c *context.Context, treeLink string) {
}
}
c.Data["LatestCommit"] = latestCommit
- c.Data["LatestCommitUser"] = db.ValidateCommitWithEmail(latestCommit)
+ c.Data["LatestCommitUser"] = tryGetUserByEmail(c.Req.Context(), latestCommit.Author.Email)
if c.Repo.CanEnableEditor() {
c.Data["CanAddFile"] = true