From 134e55510eda8c3c6d61da18ee97e3243c6e3bc2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 23 Feb 2019 00:14:45 +0800 Subject: [PATCH] fix bug when update owner team then visit team's repo return 404 (#6119) --- models/repo_permission.go | 9 +++++++++ models/repo_permission_test.go | 11 +++++++++++ routers/org/teams.go | 2 -- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/models/repo_permission.go b/models/repo_permission.go index 9dd7cc559d2..418cd77f2dc 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -151,6 +151,15 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss return } + // if user in an owner team + for _, team := range teams { + if team.Authorize >= AccessModeOwner { + perm.AccessMode = AccessModeOwner + perm.UnitsMode = nil + return + } + } + for _, u := range repo.Units { var found bool for _, team := range teams { diff --git a/models/repo_permission_test.go b/models/repo_permission_test.go index fd55ae5e524..0f350e62aad 100644 --- a/models/repo_permission_test.go +++ b/models/repo_permission_test.go @@ -219,6 +219,17 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { assert.True(t, perm.CanWrite(unit.Type)) } + // update team information and then check permission + team := AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team) + err = UpdateTeamUnits(team, nil) + assert.NoError(t, err) + perm, err = GetUserRepoPermission(repo, owner) + assert.NoError(t, err) + for _, unit := range repo.Units { + assert.True(t, perm.CanRead(unit.Type)) + assert.True(t, perm.CanWrite(unit.Type)) + } + // org member team tester tester := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) perm, err = GetUserRepoPermission(repo, tester) diff --git a/routers/org/teams.go b/routers/org/teams.go index 80309dff449..1c097379971 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -288,8 +288,6 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) { }) } models.UpdateTeamUnits(t, units) - } else { - models.UpdateTeamUnits(t, nil) } if ctx.HasError() {