From d87aa947baa247bae145dd64c436b23a3a39352a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 10 Jul 2025 09:16:27 -0700 Subject: [PATCH] Add test and also fix org api --- modules/optional/option_test.go | 5 +++++ routers/api/v1/org/org.go | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/optional/option_test.go b/modules/optional/option_test.go index f600ff5a2c..36bcf0c745 100644 --- a/modules/optional/option_test.go +++ b/modules/optional/option_test.go @@ -56,6 +56,11 @@ func TestOption(t *testing.T) { opt3 := optional.FromNonDefault(1) assert.True(t, opt3.Has()) assert.Equal(t, int(1), opt3.Value()) + + opt4 := optional.FromNonDefaultFunc(1, func(t int) bool { + return t == 1 + }) + assert.False(t, opt4.Has()) } func Test_ParseBool(t *testing.T) { diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 05744ba155..d7656d4a92 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -387,11 +387,13 @@ func Edit(ctx *context.APIContext) { } opts := &user_service.UpdateOptions{ - FullName: optional.Some(form.FullName), - Description: optional.Some(form.Description), - Website: optional.Some(form.Website), - Location: optional.Some(form.Location), - Visibility: optional.FromNonDefault(api.VisibilityModes[form.Visibility]), + FullName: optional.Some(form.FullName), + Description: optional.Some(form.Description), + Website: optional.Some(form.Website), + Location: optional.Some(form.Location), + Visibility: optional.FromNonDefaultFunc(api.VisibilityModes[form.Visibility], func(v api.VisibleType) bool { + return v < api.VisibleTypePublic || v > api.VisibleTypePrivate + }), RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess), } if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil {