Skip to content

Commit 0b31272

Browse files
GiteaBotlunnywxiaoguang
authored
Fix updating user visibility (#35036) (#35044)
Backport #35036 by @lunny Fix #35030 --------- Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent ec0c418 commit 0b31272

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ been added to each release, please refer to the [blog](https://blog.gitea.com).
77
## [1.24.3](https://github.com/go-gitea/gitea/releases/tag/1.24.3) - 2025-07-11
88

99
* BUGFIXES
10+
* Fix updating user visibility (#35036) (#35044)
1011
* Support base64-encoded agit push options (#35037) (#35041)
1112
* Make submodule link work with relative path (#35034) (#35038)
1213
* Fix bug when displaying git user avatar in commits list (#35006)

modules/optional/option.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ func FromPtr[T any](v *T) Option[T] {
2222
return Some(*v)
2323
}
2424

25+
func FromMapLookup[K comparable, V any](m map[K]V, k K) Option[V] {
26+
if v, ok := m[k]; ok {
27+
return Some(v)
28+
}
29+
return None[V]()
30+
}
31+
2532
func FromNonDefault[T comparable](v T) Option[T] {
2633
var zero T
2734
if v == zero {

modules/optional/option_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ func TestOption(t *testing.T) {
5656
opt3 := optional.FromNonDefault(1)
5757
assert.True(t, opt3.Has())
5858
assert.Equal(t, int(1), opt3.Value())
59+
60+
opt4 := optional.FromMapLookup(map[string]int{"a": 1}, "a")
61+
assert.True(t, opt4.Has())
62+
assert.Equal(t, 1, opt4.Value())
63+
opt4 = optional.FromMapLookup(map[string]int{"a": 1}, "b")
64+
assert.False(t, opt4.Has())
5965
}
6066

6167
func Test_ParseBool(t *testing.T) {

routers/api/v1/admin/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func EditUser(ctx *context.APIContext) {
240240
Description: optional.FromPtr(form.Description),
241241
IsActive: optional.FromPtr(form.Active),
242242
IsAdmin: user_service.UpdateOptionFieldFromPtr(form.Admin),
243-
Visibility: optional.FromNonDefault(api.VisibilityModes[form.Visibility]),
243+
Visibility: optional.FromMapLookup(api.VisibilityModes, form.Visibility),
244244
AllowGitHook: optional.FromPtr(form.AllowGitHook),
245245
AllowImportLocal: optional.FromPtr(form.AllowImportLocal),
246246
MaxRepoCreation: optional.FromPtr(form.MaxRepoCreation),

routers/api/v1/org/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func Edit(ctx *context.APIContext) {
393393
Description: optional.Some(form.Description),
394394
Website: optional.Some(form.Website),
395395
Location: optional.Some(form.Location),
396-
Visibility: optional.FromNonDefault(api.VisibilityModes[form.Visibility]),
396+
Visibility: optional.FromMapLookup(api.VisibilityModes, form.Visibility),
397397
RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess),
398398
}
399399
if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil {

0 commit comments

Comments
 (0)