aboutsummaryrefslogtreecommitdiffstats
path: root/models/organization
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-03 10:48:26 +0800
committerGitHub <noreply@github.com>2022-12-03 10:48:26 +0800
commit0a7d3ff786508284224ada17956a65bb759d9265 (patch)
tree4860fca95c1432ab59c6723ee2b053b1c7d6779d /models/organization
parent8698458f48eafeab21014db544aa7160368856e1 (diff)
downloadgitea-0a7d3ff786508284224ada17956a65bb759d9265.tar.gz
gitea-0a7d3ff786508284224ada17956a65bb759d9265.zip
refactor some functions to support ctx as first parameter (#21878)
Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/organization')
-rw-r--r--models/organization/org.go2
-rw-r--r--models/organization/org_user_test.go4
-rw-r--r--models/organization/team.go10
-rw-r--r--models/organization/team_test.go4
4 files changed, 10 insertions, 10 deletions
diff --git a/models/organization/org.go b/models/organization/org.go
index ef7b834ad3..a5b07d5aae 100644
--- a/models/organization/org.go
+++ b/models/organization/org.go
@@ -701,7 +701,7 @@ func AccessibleReposEnv(ctx context.Context, org *Organization, userID int64) (A
var user *user_model.User
if userID > 0 {
- u, err := user_model.GetUserByIDCtx(ctx, userID)
+ u, err := user_model.GetUserByID(ctx, userID)
if err != nil {
return nil, err
}
diff --git a/models/organization/org_user_test.go b/models/organization/org_user_test.go
index 1da17631e3..edd0aa3ea0 100644
--- a/models/organization/org_user_test.go
+++ b/models/organization/org_user_test.go
@@ -37,7 +37,7 @@ func TestUserIsPublicMember(t *testing.T) {
}
func testUserIsPublicMember(t *testing.T, uid, orgID int64, expected bool) {
- user, err := user_model.GetUserByID(uid)
+ user, err := user_model.GetUserByID(db.DefaultContext, uid)
assert.NoError(t, err)
is, err := organization.IsPublicMembership(orgID, user.ID)
assert.NoError(t, err)
@@ -65,7 +65,7 @@ func TestIsUserOrgOwner(t *testing.T) {
}
func testIsUserOrgOwner(t *testing.T, uid, orgID int64, expected bool) {
- user, err := user_model.GetUserByID(uid)
+ user, err := user_model.GetUserByID(db.DefaultContext, uid)
assert.NoError(t, err)
is, err := organization.IsOrganizationOwner(db.DefaultContext, orgID, user.ID)
assert.NoError(t, err)
diff --git a/models/organization/team.go b/models/organization/team.go
index f6d71845df..86ea30c801 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -222,8 +222,8 @@ func (t *Team) IsMember(userID int64) bool {
return isMember
}
-// GetRepositoriesCtx returns paginated repositories in team of organization.
-func (t *Team) GetRepositoriesCtx(ctx context.Context) (err error) {
+// LoadRepositories returns paginated repositories in team of organization.
+func (t *Team) LoadRepositories(ctx context.Context) (err error) {
if t.Repos != nil {
return nil
}
@@ -233,8 +233,8 @@ func (t *Team) GetRepositoriesCtx(ctx context.Context) (err error) {
return err
}
-// GetMembersCtx returns paginated members in team of organization.
-func (t *Team) GetMembersCtx(ctx context.Context) (err error) {
+// LoadMembers returns paginated members in team of organization.
+func (t *Team) LoadMembers(ctx context.Context) (err error) {
t.Members, err = GetTeamMembers(ctx, &SearchMembersOptions{
TeamID: t.ID,
})
@@ -248,7 +248,7 @@ func (t *Team) UnitEnabled(tp unit.Type) bool {
// UnitAccessMode returns if the team has the given unit type enabled
// it is called in templates, should not be replaced by `UnitAccessModeCtx(ctx ...)`
-func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode {
+func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode { // Notice: It will be used in template, don't remove it directly
return t.UnitAccessModeCtx(db.DefaultContext, tp)
}
diff --git a/models/organization/team_test.go b/models/organization/team_test.go
index d324c6d0da..c63b83aab7 100644
--- a/models/organization/team_test.go
+++ b/models/organization/team_test.go
@@ -42,7 +42,7 @@ func TestTeam_GetRepositories(t *testing.T) {
test := func(teamID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, team.GetRepositoriesCtx(db.DefaultContext))
+ assert.NoError(t, team.LoadRepositories(db.DefaultContext))
assert.Len(t, team.Repos, team.NumRepos)
for _, repo := range team.Repos {
unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repo.ID})
@@ -57,7 +57,7 @@ func TestTeam_GetMembers(t *testing.T) {
test := func(teamID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, team.GetMembersCtx(db.DefaultContext))
+ assert.NoError(t, team.LoadMembers(db.DefaultContext))
assert.Len(t, team.Members, team.NumMembers)
for _, member := range team.Members {
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: member.ID, TeamID: teamID})