@@ -25,6 +25,7 @@ import (
2525 repo_module "code.gitea.io/gitea/modules/repository"
2626 "code.gitea.io/gitea/modules/setting"
2727 "code.gitea.io/gitea/modules/storage"
28+ "code.gitea.io/gitea/modules/util"
2829 auth_service "code.gitea.io/gitea/services/auth"
2930 "code.gitea.io/gitea/services/auth/source/oauth2"
3031 "code.gitea.io/gitea/services/auth/source/smtp"
@@ -114,6 +115,10 @@ var (
114115 Name : "access-token" ,
115116 Usage : "Generate access token for the user" ,
116117 },
118+ cli.BoolFlag {
119+ Name : "restricted" ,
120+ Usage : "Make a restricted user account" ,
121+ },
117122 },
118123 }
119124
@@ -551,25 +556,34 @@ func runCreateUser(c *cli.Context) error {
551556
552557 // If this is the first user being created.
553558 // Take it as the admin and don't force a password update.
554- if n := user_model .CountUsers (); n == 0 {
559+ if n := user_model .CountUsers (nil ); n == 0 {
555560 changePassword = false
556561 }
557562
558563 if c .IsSet ("must-change-password" ) {
559564 changePassword = c .Bool ("must-change-password" )
560565 }
561566
567+ restricted := util .OptionalBoolNone
568+
569+ if c .IsSet ("restricted" ) {
570+ restricted = util .OptionalBoolOf (c .Bool ("restricted" ))
571+ }
572+
562573 u := & user_model.User {
563574 Name : username ,
564575 Email : c .String ("email" ),
565576 Passwd : password ,
566- IsActive : true ,
567577 IsAdmin : c .Bool ("admin" ),
568578 MustChangePassword : changePassword ,
569- Theme : setting .UI .DefaultTheme ,
570579 }
571580
572- if err := user_model .CreateUser (u ); err != nil {
581+ overwriteDefault := & user_model.CreateUserOverwriteOptions {
582+ IsActive : util .OptionalBoolTrue ,
583+ IsRestricted : restricted ,
584+ }
585+
586+ if err := user_model .CreateUser (u , overwriteDefault ); err != nil {
573587 return fmt .Errorf ("CreateUser: %v" , err )
574588 }
575589
0 commit comments