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