File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,13 @@ func FromPtr[T any](v *T) Option[T] {
2828	return  Some (* v )
2929}
3030
31+ func  FromMapLookup [K  comparable , V  any ](m  map [K ]V , k  K ) Option [V ] {
32+ 	if  v , ok  :=  m [k ]; ok  {
33+ 		return  Some (v )
34+ 	}
35+ 	return  None [V ]()
36+ }
37+ 
3138func  FromNonDefault [T  comparable ](v  T ) Option [T ] {
3239	var  zero  T 
3340	if  v  ==  zero  {
Original file line number Diff line number Diff 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
6167func  Test_ParseBool (t  * testing.T ) {
Original file line number Diff line number Diff 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 ),
Original file line number Diff line number Diff line change @@ -391,7 +391,7 @@ func Edit(ctx *context.APIContext) {
391391		Description :               optional .Some (form .Description ),
392392		Website :                   optional .Some (form .Website ),
393393		Location :                  optional .Some (form .Location ),
394- 		Visibility :                optional .FromNonDefault (api .VisibilityModes [ form .Visibility ] ),
394+ 		Visibility :                optional .FromMapLookup (api .VisibilityModes ,  form .Visibility ),
395395		RepoAdminChangeTeamAccess : optional .FromPtr (form .RepoAdminChangeTeamAccess ),
396396	}
397397	if  err  :=  user_service .UpdateUser (ctx , ctx .Org .Organization .AsUser (), opts ); err  !=  nil  {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments