@@ -613,7 +613,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
613
613
}
614
614
615
615
// validate data
616
- if err := validateUser (u ); err != nil {
616
+ if err := ValidateUser (u ); err != nil {
617
617
return err
618
618
}
619
619
@@ -803,19 +803,26 @@ func checkDupEmail(ctx context.Context, u *User) error {
803
803
return nil
804
804
}
805
805
806
- // validateUser check if user is valid to insert / update into database
807
- func validateUser (u * User ) error {
808
- if ! setting .Service .AllowedUserVisibilityModesSlice .IsAllowedVisibility (u .Visibility ) && ! u .IsOrganization () {
809
- return fmt .Errorf ("visibility Mode not allowed: %s" , u .Visibility .String ())
806
+ // ValidateUser check if user is valid to insert / update into database
807
+ func ValidateUser (u * User , cols ... string ) error {
808
+ if len (cols ) == 0 || util .SliceContainsString (cols , "visibility" , true ) {
809
+ if ! setting .Service .AllowedUserVisibilityModesSlice .IsAllowedVisibility (u .Visibility ) && ! u .IsOrganization () {
810
+ return fmt .Errorf ("visibility Mode not allowed: %s" , u .Visibility .String ())
811
+ }
810
812
}
811
813
812
- u .Email = strings .ToLower (u .Email )
813
- return ValidateEmail (u .Email )
814
+ if len (cols ) == 0 || util .SliceContainsString (cols , "email" , true ) {
815
+ u .Email = strings .ToLower (u .Email )
816
+ if err := ValidateEmail (u .Email ); err != nil {
817
+ return err
818
+ }
819
+ }
820
+ return nil
814
821
}
815
822
816
823
// UpdateUser updates user's information.
817
824
func UpdateUser (ctx context.Context , u * User , changePrimaryEmail bool , cols ... string ) error {
818
- err := validateUser ( u )
825
+ err := ValidateUser ( u , cols ... )
819
826
if err != nil {
820
827
return err
821
828
}
@@ -881,7 +888,7 @@ func UpdateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...s
881
888
882
889
// UpdateUserCols update user according special columns
883
890
func UpdateUserCols (ctx context.Context , u * User , cols ... string ) error {
884
- if err := validateUser ( u ); err != nil {
891
+ if err := ValidateUser ( u , cols ... ); err != nil {
885
892
return err
886
893
}
887
894
0 commit comments