fix: preserved 'Custom access' even after no permissions (#8943)

fixes #5382

Co-authored-by: Otto <otto@codeberg.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8943
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: zokki <zokki.softwareschmiede@gmail.com>
Co-committed-by: zokki <zokki.softwareschmiede@gmail.com>
This commit is contained in:
zokki 2025-09-01 15:19:17 +02:00 committed by Otto
commit 9162c82150
2 changed files with 37 additions and 1 deletions

View file

@ -52,7 +52,7 @@
<span class="help">{{ctx.Locale.Tr "org.teams.admin_access_helper"}}</span>
</label>
<label>
<input type="radio" name="permission" value="read" {{if or .PageIsOrgTeamsNew (eq .Team.AccessMode 1) (eq .Team.AccessMode 2)}}checked{{end}}>
<input type="radio" name="permission" value="read" {{if or .PageIsOrgTeamsNew (le .Team.AccessMode 2)}}checked{{end}}>
{{ctx.Locale.Tr "org.teams.general_access"}}
<span class="help">{{ctx.Locale.Tr "org.teams.general_access_helper"}}</span>
</label>

View file

@ -297,3 +297,39 @@ func TestOrgNewMigrationButton(t *testing.T) {
htmlDoc.AssertElement(t, migrateSelector, true)
})
}
func TestTeamWithoutPermissionToShowTable(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3, Type: user_model.UserTypeOrganization})
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2})
session := loginUser(t, user.Name)
// set all units to "No access"
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/org/%s/teams/%s/edit", org.Name, team.Name), map[string]string{
"_csrf": GetCSRF(t, session, fmt.Sprintf("/org/%s/teams/%s/edit", org.Name, team.Name)),
"team_name": team.Name,
"description": "",
"repo_access": "all",
"permission": "read",
"unit_1": "0",
"unit_2": "0",
"unit_3": "0",
"unit_4": "0",
"unit_5": "0",
"unit_8": "0",
"unit_9": "0",
"unit_10": "0",
})
session.MakeRequest(t, req, http.StatusSeeOther)
req = NewRequestWithValues(t, "GET", fmt.Sprintf("/org/%s/teams/%s/edit", org.Name, team.Name), map[string]string{
"_csrf": GetCSRF(t, session, fmt.Sprintf("/org/%s/teams/%s/edit", org.Name, team.Name)),
})
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
_, checked := htmlDoc.Find(`input[name="permission"][value="read"]`).Attr("checked")
assert.True(t, checked)
}