@@ -621,7 +621,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
621
621
}
622
622
623
623
// validate data
624
- if err := validateUser (u ); err != nil {
624
+ if err := ValidateUser (u ); err != nil {
625
625
return err
626
626
}
627
627
@@ -767,19 +767,26 @@ func checkDupEmail(ctx context.Context, u *User) error {
767
767
return nil
768
768
}
769
769
770
- // validateUser check if user is valid to insert / update into database
771
- func validateUser (u * User ) error {
772
- if ! setting .Service .AllowedUserVisibilityModesSlice .IsAllowedVisibility (u .Visibility ) && ! u .IsOrganization () {
773
- return fmt .Errorf ("visibility Mode not allowed: %s" , u .Visibility .String ())
770
+ // ValidateUser check if user is valid to insert / update into database
771
+ func ValidateUser (u * User , cols ... string ) error {
772
+ if len (cols ) == 0 || util .SliceContainsString (cols , "visibility" , true ) {
773
+ if ! setting .Service .AllowedUserVisibilityModesSlice .IsAllowedVisibility (u .Visibility ) && ! u .IsOrganization () {
774
+ return fmt .Errorf ("visibility Mode not allowed: %s" , u .Visibility .String ())
775
+ }
774
776
}
775
777
776
- u .Email = strings .ToLower (u .Email )
777
- return ValidateEmail (u .Email )
778
+ if len (cols ) == 0 || util .SliceContainsString (cols , "email" , true ) {
779
+ u .Email = strings .ToLower (u .Email )
780
+ if err := ValidateEmail (u .Email ); err != nil {
781
+ return err
782
+ }
783
+ }
784
+ return nil
778
785
}
779
786
780
787
// UpdateUser updates user's information.
781
788
func UpdateUser (ctx context.Context , u * User , changePrimaryEmail bool , cols ... string ) error {
782
- err := validateUser ( u )
789
+ err := ValidateUser ( u , cols ... )
783
790
if err != nil {
784
791
return err
785
792
}
@@ -845,7 +852,7 @@ func UpdateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...s
845
852
846
853
// UpdateUserCols update user according special columns
847
854
func UpdateUserCols (ctx context.Context , u * User , cols ... string ) error {
848
- if err := validateUser ( u ); err != nil {
855
+ if err := ValidateUser ( u , cols ... ); err != nil {
849
856
return err
850
857
}
851
858
0 commit comments