diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-03 12:30:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 10:30:41 +0000 |
commit | cc5df266808361c1dd3a1d17cbba712826a93d7e (patch) | |
tree | f77c59a61d3dc36f07b5b84596e4a1cde12b55cc /models | |
parent | 08507e2760638124d75774c29ef37e692a88c02d (diff) | |
download | gitea-cc5df266808361c1dd3a1d17cbba712826a93d7e.tar.gz gitea-cc5df266808361c1dd3a1d17cbba712826a93d7e.zip |
Even more `db.DefaultContext` refactor (#27352)
Part of #27065
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'models')
-rw-r--r-- | models/activities/action.go | 2 | ||||
-rw-r--r-- | models/activities/statistic.go | 2 | ||||
-rw-r--r-- | models/issues/assignees_test.go | 2 | ||||
-rw-r--r-- | models/issues/comment.go | 4 | ||||
-rw-r--r-- | models/issues/issue.go | 30 | ||||
-rw-r--r-- | models/issues/issue_test.go | 4 | ||||
-rw-r--r-- | models/issues/issue_watch.go | 2 | ||||
-rw-r--r-- | models/issues/pull.go | 2 | ||||
-rw-r--r-- | models/issues/tracked_time.go | 18 | ||||
-rw-r--r-- | models/issues/tracked_time_test.go | 8 | ||||
-rw-r--r-- | models/org_team.go | 2 | ||||
-rw-r--r-- | models/organization/org.go | 78 | ||||
-rw-r--r-- | models/organization/org_test.go | 36 | ||||
-rw-r--r-- | models/organization/org_user.go | 8 | ||||
-rw-r--r-- | models/organization/org_user_test.go | 6 | ||||
-rw-r--r-- | models/organization/team.go | 12 | ||||
-rw-r--r-- | models/organization/team_test.go | 14 | ||||
-rw-r--r-- | models/organization/team_unit.go | 4 | ||||
-rw-r--r-- | models/organization/team_user.go | 4 | ||||
-rw-r--r-- | models/perm/access/repo_permission.go | 14 | ||||
-rw-r--r-- | models/repo/pushmirror.go | 4 | ||||
-rw-r--r-- | models/repo/repo_unit.go | 8 | ||||
-rw-r--r-- | models/system/notice.go | 4 | ||||
-rw-r--r-- | models/system/notice_test.go | 2 |
24 files changed, 135 insertions, 135 deletions
diff --git a/models/activities/action.go b/models/activities/action.go index 67828f65a1..9b62a4631a 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -524,7 +524,7 @@ func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder. } if opts.RequestedTeam != nil { - env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(opts.RequestedTeam) + env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(ctx, opts.RequestedTeam) teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos) if err != nil { return nil, fmt.Errorf("GetTeamRepositories: %w", err) diff --git a/models/activities/statistic.go b/models/activities/statistic.go index 5479db20eb..ea13f3ed5c 100644 --- a/models/activities/statistic.go +++ b/models/activities/statistic.go @@ -52,7 +52,7 @@ type IssueByRepositoryCount struct { func GetStatistic(ctx context.Context) (stats Statistic) { e := db.GetEngine(ctx) stats.Counter.User = user_model.CountUsers(ctx, nil) - stats.Counter.Org, _ = organization.CountOrgs(organization.FindOrgOptions{IncludePrivate: true}) + stats.Counter.Org, _ = organization.CountOrgs(ctx, organization.FindOrgOptions{IncludePrivate: true}) stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey)) stats.Counter.Repo, _ = repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{}) stats.Counter.Watch, _ = e.Count(new(repo_model.Watch)) diff --git a/models/issues/assignees_test.go b/models/issues/assignees_test.go index 65a5ddba31..3898e814c3 100644 --- a/models/issues/assignees_test.go +++ b/models/issues/assignees_test.go @@ -18,7 +18,7 @@ func TestUpdateAssignee(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) // Fake issue with assignees - issue, err := issues_model.GetIssueWithAttrsByID(1) + issue, err := issues_model.GetIssueWithAttrsByID(db.DefaultContext, 1) assert.NoError(t, err) // Assign multiple users diff --git a/models/issues/comment.go b/models/issues/comment.go index 6f16a866ff..901958dc5d 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -655,12 +655,12 @@ func (c *Comment) LoadDepIssueDetails(ctx context.Context) (err error) { } // LoadTime loads the associated time for a CommentTypeAddTimeManual -func (c *Comment) LoadTime() error { +func (c *Comment) LoadTime(ctx context.Context) error { if c.Time != nil || c.TimeID == 0 { return nil } var err error - c.Time, err = GetTrackedTimeByID(c.TimeID) + c.Time, err = GetTrackedTimeByID(ctx, c.TimeID) return err } diff --git a/models/issues/issue.go b/models/issues/issue.go index 341ec8547a..6d9c8727b3 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -201,12 +201,12 @@ func (issue *Issue) IsTimetrackerEnabled(ctx context.Context) bool { } // GetPullRequest returns the issue pull request -func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) { +func (issue *Issue) GetPullRequest(ctx context.Context) (pr *PullRequest, err error) { if !issue.IsPull { return nil, fmt.Errorf("Issue is not a pull request") } - pr, err = GetPullRequestByIssueID(db.DefaultContext, issue.ID) + pr, err = GetPullRequestByIssueID(ctx, issue.ID) if err != nil { return nil, err } @@ -369,9 +369,9 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { } // GetIsRead load the `IsRead` field of the issue -func (issue *Issue) GetIsRead(userID int64) error { +func (issue *Issue) GetIsRead(ctx context.Context, userID int64) error { issueUser := &IssueUser{IssueID: issue.ID, UID: userID} - if has, err := db.GetEngine(db.DefaultContext).Get(issueUser); err != nil { + if has, err := db.GetEngine(ctx).Get(issueUser); err != nil { return err } else if !has { issue.IsRead = false @@ -382,9 +382,9 @@ func (issue *Issue) GetIsRead(userID int64) error { } // APIURL returns the absolute APIURL to this issue. -func (issue *Issue) APIURL() string { +func (issue *Issue) APIURL(ctx context.Context) string { if issue.Repo == nil { - err := issue.LoadRepo(db.DefaultContext) + err := issue.LoadRepo(ctx) if err != nil { log.Error("Issue[%d].APIURL(): %v", issue.ID, err) return "" @@ -479,9 +479,9 @@ func (issue *Issue) GetLastEventLabel() string { } // GetLastComment return last comment for the current issue. -func (issue *Issue) GetLastComment() (*Comment, error) { +func (issue *Issue) GetLastComment(ctx context.Context) (*Comment, error) { var c Comment - exist, err := db.GetEngine(db.DefaultContext).Where("type = ?", CommentTypeComment). + exist, err := db.GetEngine(ctx).Where("type = ?", CommentTypeComment). And("issue_id = ?", issue.ID).Desc("created_unix").Get(&c) if err != nil { return nil, err @@ -543,12 +543,12 @@ func GetIssueByID(ctx context.Context, id int64) (*Issue, error) { } // GetIssueWithAttrsByID returns an issue with attributes by given ID. -func GetIssueWithAttrsByID(id int64) (*Issue, error) { - issue, err := GetIssueByID(db.DefaultContext, id) +func GetIssueWithAttrsByID(ctx context.Context, id int64) (*Issue, error) { + issue, err := GetIssueByID(ctx, id) if err != nil { return nil, err } - return issue, issue.LoadAttributes(db.DefaultContext) + return issue, issue.LoadAttributes(ctx) } // GetIssuesByIDs return issues with the given IDs. @@ -600,8 +600,8 @@ func GetParticipantsIDsByIssueID(ctx context.Context, issueID int64) ([]int64, e } // IsUserParticipantsOfIssue return true if user is participants of an issue -func IsUserParticipantsOfIssue(user *user_model.User, issue *Issue) bool { - userIDs, err := issue.GetParticipantIDsByIssue(db.DefaultContext) +func IsUserParticipantsOfIssue(ctx context.Context, user *user_model.User, issue *Issue) bool { + userIDs, err := issue.GetParticipantIDsByIssue(ctx) if err != nil { log.Error(err.Error()) return false @@ -894,8 +894,8 @@ func IsErrIssueMaxPinReached(err error) bool { } // InsertIssues insert issues to database -func InsertIssues(issues ...*Issue) error { - ctx, committer, err := db.TxContext(db.DefaultContext) +func InsertIssues(ctx context.Context, issues ...*Issue) error { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index 5993e918e7..4e98442c11 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -65,7 +65,7 @@ func TestIssueAPIURL(t *testing.T) { err := issue.LoadAttributes(db.DefaultContext) assert.NoError(t, err) - assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL()) + assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL(db.DefaultContext)) } func TestGetIssuesByIDs(t *testing.T) { @@ -477,7 +477,7 @@ func assertCreateIssues(t *testing.T, isPull bool) { Labels: []*issues_model.Label{label}, Reactions: []*issues_model.Reaction{reaction}, } - err := issues_model.InsertIssues(is) + err := issues_model.InsertIssues(db.DefaultContext, is) assert.NoError(t, err) i := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: title}) diff --git a/models/issues/issue_watch.go b/models/issues/issue_watch.go index b7e9504c67..9e616a0eb1 100644 --- a/models/issues/issue_watch.go +++ b/models/issues/issue_watch.go @@ -81,7 +81,7 @@ func CheckIssueWatch(ctx context.Context, user *user_model.User, issue *Issue) ( if err != nil { return false, err } - return repo_model.IsWatchMode(w.Mode) || IsUserParticipantsOfIssue(user, issue), nil + return repo_model.IsWatchMode(w.Mode) || IsUserParticipantsOfIssue(ctx, user, issue), nil } // GetIssueWatchersIDs returns IDs of subscribers or explicit unsubscribers to a given issue id diff --git a/models/issues/pull.go b/models/issues/pull.go index 3ca0847652..9adcaee1a1 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -1040,7 +1040,7 @@ func ParseCodeOwnersLine(ctx context.Context, tokens []string) (*CodeOwnerRule, warnings = append(warnings, fmt.Sprintf("incorrect codeowner organization: %s", user)) continue } - teams, err := org.LoadTeams() + teams, err := org.LoadTeams(ctx) if err != nil { warnings = append(warnings, fmt.Sprintf("incorrect codeowner team: %s", user)) continue diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index c51df627ac..89c99c5cd1 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -199,8 +199,8 @@ func addTime(ctx context.Context, user *user_model.User, issue *Issue, amount in } // TotalTimesForEachUser returns the spent time in seconds for each user by an issue -func TotalTimesForEachUser(options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) { - trackedTimes, err := GetTrackedTimes(db.DefaultContext, options) +func TotalTimesForEachUser(ctx context.Context, options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) { + trackedTimes, err := GetTrackedTimes(ctx, options) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func TotalTimesForEachUser(options *FindTrackedTimesOptions) (map[*user_model.Us totalTimes := make(map[*user_model.User]int64) // Fetching User and making time human readable for userID, total := range totalTimesByUser { - user, err := user_model.GetUserByID(db.DefaultContext, userID) + user, err := user_model.GetUserByID(ctx, userID) if err != nil { if user_model.IsErrUserNotExist(err) { continue @@ -226,8 +226,8 @@ func TotalTimesForEachUser(options *FindTrackedTimesOptions) (map[*user_model.Us } // DeleteIssueUserTimes deletes times for issue -func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { - ctx, committer, err := db.TxContext(db.DefaultContext) +func DeleteIssueUserTimes(ctx context.Context, issue *Issue, user *user_model.User) error { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } @@ -265,8 +265,8 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { } // DeleteTime delete a specific Time -func DeleteTime(t *TrackedTime) error { - ctx, committer, err := db.TxContext(db.DefaultContext) +func DeleteTime(ctx context.Context, t *TrackedTime) error { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } @@ -315,9 +315,9 @@ func deleteTime(ctx context.Context, t *TrackedTime) error { } // GetTrackedTimeByID returns raw TrackedTime without loading attributes by id -func GetTrackedTimeByID(id int64) (*TrackedTime, error) { +func GetTrackedTimeByID(ctx context.Context, id int64) (*TrackedTime, error) { time := new(TrackedTime) - has, err := db.GetEngine(db.DefaultContext).ID(id).Get(time) + has, err := db.GetEngine(ctx).ID(id).Get(time) if err != nil { return nil, err } else if !has { diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go index 24081f1bfa..cc2cb918e0 100644 --- a/models/issues/tracked_time_test.go +++ b/models/issues/tracked_time_test.go @@ -82,7 +82,7 @@ func TestGetTrackedTimes(t *testing.T) { func TestTotalTimesForEachUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - total, err := issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 1}) + total, err := issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 1}) assert.NoError(t, err) assert.Len(t, total, 1) for user, time := range total { @@ -90,7 +90,7 @@ func TestTotalTimesForEachUser(t *testing.T) { assert.EqualValues(t, 400, time) } - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 2}) + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 2}) assert.NoError(t, err) assert.Len(t, total, 2) for user, time := range total { @@ -103,7 +103,7 @@ func TestTotalTimesForEachUser(t *testing.T) { } } - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 5}) + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 5}) assert.NoError(t, err) assert.Len(t, total, 1) for user, time := range total { @@ -111,7 +111,7 @@ func TestTotalTimesForEachUser(t *testing.T) { assert.EqualValues(t, 1, time) } - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 4}) + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 4}) assert.NoError(t, err) assert.Len(t, total, 2) } diff --git a/models/org_team.go b/models/org_team.go index ea73918435..acbab56089 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -362,7 +362,7 @@ func AddTeamMember(ctx context.Context, team *organization.Team, userID int64) e return err } - if err := organization.AddOrgUser(team.OrgID, userID); err != nil { + if err := organization.AddOrgUser(ctx, team.OrgID, userID); err != nil { return err } diff --git a/models/organization/org.go b/models/organization/org.go index 260571b4b2..07091194eb 100644 --- a/models/organization/org.go +++ b/models/organization/org.go @@ -96,23 +96,23 @@ func (Organization) TableName() string { } // IsOwnedBy returns true if given user is in the owner team. -func (org *Organization) IsOwnedBy(uid int64) (bool, error) { - return IsOrganizationOwner(db.DefaultContext, org.ID, uid) +func (org *Organization) IsOwnedBy(ctx context.Context, uid int64) (bool, error) { + return IsOrganizationOwner(ctx, org.ID, uid) } // IsOrgAdmin returns true if given user is in the owner team or an admin team. -func (org *Organization) IsOrgAdmin(uid int64) (bool, error) { - return IsOrganizationAdmin(db.DefaultContext, org.ID, uid) +func (org *Organization) IsOrgAdmin(ctx context.Context, uid int64) (bool, error) { + return IsOrganizationAdmin(ctx, org.ID, uid) } // IsOrgMember returns true if given user is member of organization. -func (org *Organization) IsOrgMember(uid int64) (bool, error) { - return IsOrganizationMember(db.DefaultContext, org.ID, uid) +func (org *Organization) IsOrgMember(ctx context.Context, uid int64) (bool, error) { + return IsOrganizationMember(ctx, org.ID, uid) } // CanCreateOrgRepo returns true if given user can create repo in organization -func (org *Organization) CanCreateOrgRepo(uid int64) (bool, error) { - return CanCreateOrgRepo(db.DefaultContext, org.ID, uid) +func (org *Organization) CanCreateOrgRepo(ctx context.Context, uid int64) (bool, error) { + return CanCreateOrgRepo(ctx, org.ID, uid) } // GetTeam returns named team of organization. @@ -135,8 +135,8 @@ func FindOrgTeams(ctx context.Context, orgID int64) ([]*Team, error) { } // LoadTeams load teams if not loaded. -func (org *Organization) LoadTeams() ([]*Team, error) { - return FindOrgTeams(db.DefaultContext, org.ID) +func (org *Organization) LoadTeams(ctx context.Context) ([]*Team, error) { + return FindOrgTeams(ctx, org.ID) } // GetMembers returns all members of organization. @@ -147,8 +147,8 @@ func (org *Organization) GetMembers(ctx context.Context) (user_model.UserList, m } // HasMemberWithUserID returns true if user with userID is part of the u organisation. -func (org *Organization) HasMemberWithUserID(userID int64) bool { - return org.hasMemberWithUserID(db.DefaultContext, userID) +func (org *Organization) HasMemberWithUserID(ctx context.Context, userID int64) bool { + return org.hasMemberWithUserID(ctx, userID) } func (org *Organization) hasMemberWithUserID(ctx context.Context, userID int64) bool { @@ -199,8 +199,8 @@ type FindOrgMembersOpts struct { } // CountOrgMembers counts the organization's members -func CountOrgMembers(opts *FindOrgMembersOpts) (int64, error) { - sess := db.GetEngine(db.DefaultContext).Where("org_id=?", opts.OrgID) +func CountOrgMembers(ctx context.Context, opts *FindOrgMembersOpts) (int64, error) { + sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID) if opts.PublicOnly { sess.And("is_public = ?", true) } @@ -271,7 +271,7 @@ func (org *Organization) UnitPermission(ctx context.Context, doer *user_model.Us } // CreateOrganization creates record of a new organization. -func CreateOrganization(org *Organization, owner *user_model.User) (err error) { +func CreateOrganization(ctx context.Context, org *Organization, owner *user_model.User) (err error) { if !owner.CanCreateOrganization() { return ErrUserNotAllowedCreateOrg{} } @@ -280,7 +280,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { return err } - isExist, err := user_model.IsUserExist(db.DefaultContext, 0, org.Name) + isExist, err := user_model.IsUserExist(ctx, 0, org.Name) if err != nil { return err } else if isExist { @@ -300,7 +300,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { org.NumMembers = 1 org.Type = user_model.UserTypeOrganization - ctx, committer, err := db.TxContext(db.DefaultContext) + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } @@ -412,9 +412,9 @@ func DeleteOrganization(ctx context.Context, org *Organization) error { } // GetOrgUserMaxAuthorizeLevel returns highest authorize level of user in an organization -func (org *Organization) GetOrgUserMaxAuthorizeLevel(uid int64) (perm.AccessMode, error) { +func (org *Organization) GetOrgUserMaxAuthorizeLevel(ctx context.Context, uid int64) (perm.AccessMode, error) { var authorize perm.AccessMode - _, err := db.GetEngine(db.DefaultContext). + _, err := db.GetEngine(ctx). Select("max(team.authorize)"). Table("team"). Join("INNER", "team_user", "team_user.team_id = team.id"). @@ -468,9 +468,9 @@ func (opts FindOrgOptions) toConds() builder.Cond { } // FindOrgs returns a list of organizations according given conditions -func FindOrgs(opts FindOrgOptions) ([]*Organization, error) { +func FindOrgs(ctx context.Context, opts FindOrgOptions) ([]*Organization, error) { orgs := make([]*Organization, 0, 10) - sess := db.GetEngine(db.DefaultContext). + sess := db.GetEngine(ctx). Where(opts.toConds()). Asc("`user`.name") if opts.Page > 0 && opts.PageSize > 0 { @@ -480,8 +480,8 @@ func FindOrgs(opts FindOrgOptions) ([]*Organization, error) { } // CountOrgs returns total count organizations according options -func CountOrgs(opts FindOrgOptions) (int64, error) { - return db.GetEngine(db.DefaultContext). +func CountOrgs(ctx context.Context, opts FindOrgOptions) (int64, error) { + return db.GetEngine(ctx). Where(opts.toConds()). Count(new(Organization)) } @@ -505,13 +505,13 @@ func HasOrgOrUserVisible(ctx context.Context, orgOrUser, user *user_model.User) } // HasOrgsVisible tells if the given user can see at least one of the orgs provided -func HasOrgsVisible(orgs []*Organization, user *user_model.User) bool { +func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.User) bool { if len(orgs) == 0 { return false } for _, org := range orgs { - if HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), user) { + if HasOrgOrUserVisible(ctx, org.AsUser(), user) { return true } } @@ -550,9 +550,9 @@ func GetOrgUsersByOrgID(ctx context.Context, opts *FindOrgMembersOpts) ([]*OrgUs } // ChangeOrgUserStatus changes public or private membership status. -func ChangeOrgUserStatus(orgID, uid int64, public bool) error { +func ChangeOrgUserStatus(ctx context.Context, orgID, uid int64, public bool) error { ou := new(OrgUser) - has, err := db.GetEngine(db.DefaultContext). + has, err := db.GetEngine(ctx). Where("uid=?", uid). And("org_id=?", orgID). Get(ou) @@ -563,18 +563,18 @@ func ChangeOrgUserStatus(orgID, uid int64, public bool) error { } ou.IsPublic = public - _, err = db.GetEngine(db.DefaultContext).ID(ou.ID).Cols("is_public").Update(ou) + _, err = db.GetEngine(ctx).ID(ou.ID).Cols("is_public").Update(ou) return err } // AddOrgUser adds new user to given organization. -func AddOrgUser(orgID, uid int64) error { - isAlreadyMember, err := IsOrganizationMember(db.DefaultContext, orgID, uid) +func AddOrgUser(ctx context.Context, orgID, uid int64) error { + isAlreadyMember, err := IsOrganizationMember(ctx, orgID, uid) if err != nil || isAlreadyMember { return err } - ctx, committer, err := db.TxContext(db.DefaultContext) + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } @@ -669,19 +669,19 @@ func (org *Organization) getUserTeamIDs(ctx context.Context, userID int64) ([]in } // TeamsWithAccessToRepo returns all teams that have given access level to the repository. -func (org *Organization) TeamsWithAccessToRepo(repoID int64, mode perm.AccessMode) ([]*Team, error) { - return GetTeamsWithAccessToRepo(db.DefaultContext, org.ID, repoID, mode) +func (org *Organization) TeamsWithAccessToRepo(ctx context.Context, repoID int64, mode perm.AccessMode) ([]*Team, error) { + return GetTeamsWithAccessToRepo(ctx, org.ID, repoID, mode) } // GetUserTeamIDs returns of all team IDs of the organization that user is member of. -func (org *Organization) GetUserTeamIDs(userID int64) ([]int64, error) { - return org.getUserTeamIDs(db.DefaultContext, userID) +func (org *Organization) GetUserTeamIDs(ctx context.Context, userID int64) ([]int64, error) { + return org.getUserTeamIDs(ctx, userID) } // GetUserTeams returns all teams that belong to user, // and that the user has joined. -func (org *Organization) GetUserTeams(userID int64) ([]*Team, error) { - return org.getUserTeams(db.DefaultContext, userID) +func (org *Organization) GetUserTeams(ctx context.Context, userID int64) ([]*Team, error) { + return org.getUserTeams(ctx, userID) } // AccessibleReposEnvironment operations involving the repositories that are @@ -733,11 +733,11 @@ func AccessibleReposEnv(ctx context.Context, org *Organization, userID int64) (A // AccessibleTeamReposEnv an AccessibleReposEnvironment for the repositories in `org` // that are accessible to the specified team. -func (org *Organization) AccessibleTeamReposEnv(team *Team) AccessibleReposEnvironment { +func (org *Organization) AccessibleTeamReposEnv(ctx context.Context, team *Team) AccessibleReposEnvironment { return &accessibleReposEnv{ org: org, team: team, - ctx: db.DefaultContext, + ctx: ctx, orderBy: db.SearchOrderByRecentUpdated, } } diff --git a/models/organization/org_test.go b/models/organization/org_test.go index b5dff9ec01..aa72fc467e 100644 --- a/models/organization/org_test.go +++ b/models/organization/org_test.go @@ -31,7 +31,7 @@ func TestUser_IsOwnedBy(t *testing.T) { {2, 3, false}, } { org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID}) - isOwner, err := org.IsOwnedBy(testCase.UserID) + isOwner, err := org.IsOwnedBy(db.DefaultContext, testCase.UserID) assert.NoError(t, err) assert.Equal(t, testCase.ExpectedOwner, isOwner) } @@ -52,7 +52,7 @@ func TestUser_IsOrgMember(t *testing.T) { {2, 3, false}, } { org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID}) - isMember, err := org.IsOrgMember(testCase.UserID) + isMember, err := org.IsOrgMember(db.DefaultContext, testCase.UserID) assert.NoError(t, err) assert.Equal(t, testCase.ExpectedMember, isMember) } @@ -89,7 +89,7 @@ func TestUser_GetOwnerTeam(t *testing.T) { func TestUser_GetTeams(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) - teams, err := org.LoadTeams() + teams, err := org.LoadTeams(db.DefaultContext) assert.NoError(t, err) if assert.Len(t, teams, 5) { assert.Equal(t, int64(1), teams[0].ID) @@ -131,7 +131,7 @@ func TestCountOrganizations(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) expected, err := db.GetEngine(db.DefaultContext).Where("type=?", user_model.UserTypeOrganization).Count(&organization.Organization{}) assert.NoError(t, err) - cnt, err := organization.CountOrgs(organization.FindOrgOptions{IncludePrivate: true}) + cnt, err := organization.CountOrgs(db.DefaultContext, organization.FindOrgOptions{IncludePrivate: true}) assert.NoError(t, err) assert.Equal(t, expected, cnt) } @@ -168,7 +168,7 @@ func TestIsOrganizationMember(t *testing.T) { func TestIsPublicMembership(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) test := func(orgID, userID int64, expected bool) { - isMember, err := organization.IsPublicMembership(orgID, userID) + isMember, err := organization.IsPublicMembership(db.DefaultContext, orgID, userID) assert.NoError(t, err) assert.EqualValues(t, expected, isMember) } @@ -183,7 +183,7 @@ func TestIsPublicMembership(t *testing.T) { func TestFindOrgs(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - orgs, err := organization.FindOrgs(organization.FindOrgOptions{ + orgs, err := organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ UserID: 4, IncludePrivate: true, }) @@ -192,14 +192,14 @@ func TestFindOrgs(t *testing.T) { assert.EqualValues(t, 3, orgs[0].ID) } - orgs, err = organization.FindOrgs(organization.FindOrgOptions{ + orgs, err = organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ UserID: 4, IncludePrivate: false, }) assert.NoError(t, err) assert.Len(t, orgs, 0) - total, err := organization.CountOrgs(organization.FindOrgOptions{ + total, err := organization.CountOrgs(db.DefaultContext, organization.FindOrgOptions{ UserID: 4, IncludePrivate: true, }) @@ -250,7 +250,7 @@ func TestChangeOrgUserStatus(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) testSuccess := func(orgID, userID int64, public bool) { - assert.NoError(t, organization.ChangeOrgUserStatus(orgID, userID, public)) + assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, orgID, userID, public)) orgUser := unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{OrgID: orgID, UID: userID}) assert.Equal(t, public, orgUser.IsPublic) } @@ -258,14 +258,14 @@ func TestChangeOrgUserStatus(t *testing.T) { testSuccess(3, 2, false) testSuccess(3, 2, false) testSuccess(3, 4, true) - assert.NoError(t, organization.ChangeOrgUserStatus(unittest.NonexistentID, unittest.NonexistentID, true)) + assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID, true)) } func TestUser_GetUserTeamIDs(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) testSuccess := func(userID int64, expected []int64) { - teamIDs, err := org.GetUserTeamIDs(userID) + teamIDs, err := org.GetUserTeamIDs(db.DefaultContext, userID) assert.NoError(t, err) assert.Equal(t, expected, teamIDs) } @@ -352,7 +352,7 @@ func TestHasOrgVisibleTypePublic(t *testing.T) { } unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) - assert.NoError(t, organization.CreateOrganization(org, owner)) + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) @@ -375,7 +375,7 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) { } unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) - assert.NoError(t, organization.CreateOrganization(org, owner)) + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) @@ -398,7 +398,7 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) { } unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) - assert.NoError(t, organization.CreateOrganization(org, owner)) + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) @@ -461,7 +461,7 @@ func TestCreateOrganization(t *testing.T) { } unittest.AssertNotExistsBean(t, &user_model.User{Name: newOrgName, Type: user_model.UserTypeOrganization}) - assert.NoError(t, organization.CreateOrganization(org, owner)) + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) ownerTeam := unittest.AssertExistsAndLoadBean(t, @@ -481,7 +481,7 @@ func TestCreateOrganization2(t *testing.T) { } unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) - err := organization.CreateOrganization(org, owner) + err := organization.CreateOrganization(db.DefaultContext, org, owner) assert.Error(t, err) assert.True(t, organization.IsErrUserNotAllowedCreateOrg(err)) unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) @@ -495,7 +495,7 @@ func TestCreateOrganization3(t *testing.T) { owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) org := &organization.Organization{Name: "org3"} // should already exist unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: org.Name}) // sanity check - err := organization.CreateOrganization(org, owner) + err := organization.CreateOrganization(db.DefaultContext, org, owner) assert.Error(t, err) assert.True(t, user_model.IsErrUserAlreadyExist(err)) unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) @@ -506,7 +506,7 @@ func TestCreateOrganization4(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - err := organization.CreateOrganization(&organization.Organization{Name: "assets"}, owner) + err := organization.CreateOrganization(db.DefaultContext, &organization.Organization{Name: "assets"}, owner) assert.Error(t, err) assert.True(t, db.IsErrNameReserved(err)) unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{}) diff --git a/models/organization/org_user.go b/models/organization/org_user.go index d0598ab5d1..5fe3a178d2 100644 --- a/models/organization/org_user.go +++ b/models/organization/org_user.go @@ -78,8 +78,8 @@ func IsOrganizationMember(ctx context.Context, orgID, uid int64) (bool, error) { } // IsPublicMembership returns true if the given user's membership of given org is public. -func IsPublicMembership(orgID, uid int64) (bool, error) { - return db.GetEngine(db.DefaultContext). +func IsPublicMembership(ctx context.Context, orgID, uid int64) (bool, error) { + return db.GetEngine(ctx). Where("uid=?", uid). And("org_id=?", orgID). And("is_public=?", true). @@ -98,12 +98,12 @@ func CanCreateOrgRepo(ctx context.Context, orgID, uid int64) (bool, error) { } // IsUserOrgOwner returns true if user is in the owner team of given organization. -func IsUserOrgOwner(users user_model.UserList, orgID int64) map[int64]bool { +func IsUserOrgOwner(ctx context.Context, users user_model.UserList, orgID int64) map[int64]bool { results := make(map[int64]bool, len(users)) for _, user := range users { results[user.ID] = false // Set default to false } - ownerMaps, err := loadOrganizationOwners(db.DefaultContext, users, orgID) + ownerMaps, err := loadOrganizationOwners(ctx, users, orgID) if err == nil { for _, owner := range ownerMaps { results[owner.UID] = true diff --git a/models/organization/org_user_test.go b/models/organization/org_user_test.go index 1c3cf2798d..7924517f31 100644 --- a/models/organization/org_user_test.go +++ b/models/organization/org_user_test.go @@ -39,7 +39,7 @@ func TestUserIsPublicMember(t *testing.T) { func testUserIsPublicMember(t *testing.T, uid, orgID int64, expected bool) { user, err := user_model.GetUserByID(db.DefaultContext, uid) assert.NoError(t, err) - is, err := organization.IsPublicMembership(orgID, user.ID) + is, err := organization.IsPublicMembership(db.DefaultContext, orgID, user.ID) assert.NoError(t, err) assert.Equal(t, expected, is) } @@ -123,7 +123,7 @@ func testUserListIsUserOrgOwner(t *testing.T, orgID int64, expected map[int64]bo assert.NoError(t, err) members, _, err := org.GetMembers(db.DefaultContext) assert.NoError(t, err) - assert.Equal(t, expected, organization.IsUserOrgOwner(members, orgID)) + assert.Equal(t, expected, organization.IsUserOrgOwner(db.DefaultContext, members, orgID)) } func TestAddOrgUser(t *testing.T) { @@ -134,7 +134,7 @@ func TestAddOrgUser(t *testing.T) { if !unittest.BeanExists(t, &organization.OrgUser{OrgID: orgID, UID: userID}) { expectedNumMembers++ } - assert.NoError(t, organization.AddOrgUser(orgID, userID)) + assert.NoError(t, organization.AddOrgUser(db.DefaultContext, orgID, userID)) ou := &organization.OrgUser{OrgID: orgID, UID: userID} unittest.AssertExistsAndLoadBean(t, ou) assert.Equal(t, isPublic, ou.IsPublic) diff --git a/models/organization/team.go b/models/organization/team.go index 3624fdc466..72afc67369 100644 --- a/models/organization/team.go +++ b/models/organization/team.go @@ -144,8 +144,8 @@ func (t *Team) IsOwnerTeam() bool { } // IsMember returns true if given user is a member of team. -func (t *Team) IsMember(userID int64) bool { - isMember, err := IsTeamMember(db.DefaultContext, t.OrgID, t.ID, userID) +func (t *Team) IsMember(ctx context.Context, userID int64) bool { + isMember, err := IsTeamMember(ctx, t.OrgID, t.ID, userID) if err != nil { log.Error("IsMember: %v", err) return false @@ -217,10 +217,10 @@ func GetTeam(ctx context.Context, orgID int64, name string) (*Team, error) { } // GetTeamIDsByNames returns a slice of team ids corresponds to names. -func GetTeamIDsByNames(orgID int64, names []string, ignoreNonExistent bool) ([]int64, error) { +func GetTeamIDsByNames(ctx context.Context, orgID int64, names []string, ignoreNonExistent bool) ([]int64, error) { ids := make([]int64, 0, len(names)) for _, name := range names { - u, err := GetTeam(db.DefaultContext, orgID, name) + u, err := GetTeam(ctx, orgID, name) if err != nil { if ignoreNonExistent { continue @@ -251,13 +251,13 @@ func GetTeamByID(ctx context.Context, teamID int64) (*Team, error) { } // GetTeamNamesByID returns team's lower name from a list of team ids. -func GetTeamNamesByID(teamIDs []int64) ([]string, error) { +func GetTeamNamesByID(ctx context.Context, teamIDs []int64) ([]string, error) { if len(teamIDs) == 0 { return []string{}, nil } var teamNames []string - err := db.GetEngine(db.DefaultContext).Table("team"). + err := db.GetEngine(ctx).Table("team"). Select("lower_name"). In("id", teamIDs). Asc("name"). diff --git a/models/organization/team_test.go b/models/organization/team_test.go index af69715ca9..23a6affe24 100644 --- a/models/organization/team_test.go +++ b/models/organization/team_test.go @@ -27,14 +27,14 @@ func TestTeam_IsMember(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1}) - assert.True(t, team.IsMember(2)) - assert.False(t, team.IsMember(4)) - assert.False(t, team.IsMember(unittest.NonexistentID)) + assert.True(t, team.IsMember(db.DefaultContext, 2)) + assert.False(t, team.IsMember(db.DefaultContext, 4)) + assert.False(t, team.IsMember(db.DefaultContext, unittest.NonexistentID)) team = unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) - assert.True(t, team.IsMember(2)) - assert.True(t, team.IsMember(4)) - assert.False(t, team.IsMember(unittest.NonexistentID)) + assert.True(t, team.IsMember(db.DefaultContext, 2)) + assert.True(t, team.IsMember(db.DefaultContext, 4)) + assert.False(t, team.IsMember(db.DefaultContext, unittest.NonexistentID)) } func TestTeam_GetRepositories(t *testing.T) { @@ -188,7 +188,7 @@ func TestUsersInTeamsCount(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) test := func(teamIDs, userIDs []int64, expected int64) { - count, err := organization.UsersInTeamsCount(teamIDs, userIDs) + count, err := organization.UsersInTeamsCount(db.DefaultContext, teamIDs, userIDs) assert.NoError(t, err) assert.Equal(t, expected, count) } diff --git a/models/organization/team_unit.go b/models/organization/team_unit.go index 7668ca7483..3087b70770 100644 --- a/models/organization/team_unit.go +++ b/models/organization/team_unit.go @@ -30,8 +30,8 @@ func getUnitsByTeamID(ctx context.Context, teamID int64) (units []*TeamUnit, err } // UpdateTeamUnits updates a teams's units -func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) { - ctx, committer, err := db.TxContext(db.DefaultContext) +func UpdateTeamUnits(ctx context.Context, team *Team, units []TeamUnit) (err error) { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } diff --git a/models/organization/team_user.go b/models/organization/team_user.go index 768dc24c50..ab767db200 100644 --- a/models/organization/team_user.go +++ b/models/organization/team_user.go @@ -78,9 +78,9 @@ func IsUserInTeams(ctx context.Context, userID int64, teamIDs []int64) (bool, er } // UsersInTeamsCount counts the number of users which are in userIDs and teamIDs -func UsersInTeamsCount(userIDs, teamIDs []int64) (int64, error) { +func UsersInTeamsCount(ctx context.Context, userIDs, teamIDs []int64) (int64, error) { var ids []int64 - if err := db.GetEngine(db.DefaultContext).In("uid", userIDs).In("team_id", teamIDs). + if err := db.GetEngine(ctx).In("uid", userIDs).In("team_id", teamIDs). Table("team_user"). Cols("uid").GroupBy("uid").Find(&ids); err != nil { return 0, err diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 2027b87ecb..395ecdf1a5 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -261,16 +261,16 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use } // IsUserRealRepoAdmin check if this user is real repo admin -func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bool, error) { +func IsUserRealRepoAdmin(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (bool, error) { if repo.OwnerID == user.ID { return true, nil } - if err := repo.LoadOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return false, err } - accessMode, err := accessLevel(db.DefaultContext, user, repo) + accessMode, err := accessLevel(ctx, user, repo) if err != nil { return false, err } @@ -394,13 +394,13 @@ func getUsersWithAccessMode(ctx context.Context, repo *repo_model.Repository, mo } // GetRepoReaders returns all users that have explicit read access or higher to the repository. -func GetRepoReaders(repo *repo_model.Repository) (_ []*user_model.User, err error) { - return getUsersWithAccessMode(db.DefaultContext, repo, perm_model.AccessModeRead) +func GetRepoReaders(ctx context.Context, repo *repo_model.Repository) (_ []*user_model.User, err error) { + return getUsersWithAccessMode(ctx, repo, perm_model.AccessModeRead) } // GetRepoWriters returns all users that have write access to the repository. -func GetRepoWriters(repo *repo_model.Repository) (_ []*user_model.User, err error) { - return getUsersWithAccessMode(db.DefaultContext, repo, perm_model.AccessModeWrite) +func GetRepoWriters(ctx context.Context, repo *repo_model.Repository) (_ []*user_model.User, err error) { + return getUsersWithAccessMode(ctx, repo, perm_model.AccessModeWrite) } // IsRepoReader returns true if user has explicit read access or higher to the repository. diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index 73c1384444..61cf1849b0 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -58,12 +58,12 @@ func init() { } // GetRepository returns the path of the repository. -func (m *PushMirror) GetRepository() *Repository { +func (m *PushMirror) GetRepository(ctx context.Context) *Repository { if m.Repo != nil { return m.Repo } var err error - m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID) + m.Repo, err = GetRepositoryByID(ctx, m.RepoID) if err != nil { log.Error("getRepositoryByID[%d]: %v", m.ID, err) } diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go index b8804c6df1..89f28b8fca 100644 --- a/models/repo/repo_unit.go +++ b/models/repo/repo_unit.go @@ -279,14 +279,14 @@ func getUnitsByRepoID(ctx context.Context, repoID int64) (units []*RepoUnit, err } // UpdateRepoUnit updates the provided repo unit -func UpdateRepoUnit(unit *RepoUnit) error { - _, err := db.GetEngine(db.DefaultContext).ID(unit.ID).Update(unit) +func UpdateRepoUnit(ctx context.Context, unit *RepoUnit) error { + _, err := db.GetEngine(ctx).ID(unit.ID).Update(unit) return err } // UpdateRepositoryUnits updates a repository's units -func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { - ctx, committer, err := db.TxContext(db.DefaultContext) +func UpdateRepositoryUnits(ctx context.Context, repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } diff --git a/models/system/notice.go b/models/system/notice.go index b0c0bfb95d..058b78e677 100644 --- a/models/system/notice.go +++ b/models/system/notice.go @@ -88,8 +88,8 @@ func RemoveStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, } // CountNotices returns number of notices. -func CountNotices() int64 { - count, _ := db.GetEngine(db.DefaultContext).Count(new(Notice)) +func CountNotices(ctx context.Context) int64 { + count, _ := db.GetEngine(ctx).Count(new(Notice)) return count } diff --git a/models/system/notice_test.go b/models/system/notice_test.go index 871ffa54ce..e8ce05d332 100644 --- a/models/system/notice_test.go +++ b/models/system/notice_test.go @@ -49,7 +49,7 @@ func TestCreateRepositoryNotice(t *testing.T) { func TestCountNotices(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - assert.Equal(t, int64(3), system.CountNotices()) + assert.Equal(t, int64(3), system.CountNotices(db.DefaultContext)) } func TestNotices(t *testing.T) { |