Skip to content

Commit e50192b

Browse files
committed
Allow admin to change user's type
1 parent 698ae7a commit e50192b

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

models/user/user.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,19 @@ func (u *User) IsOrganization() bool {
395395
return u.Type == UserTypeOrganization
396396
}
397397

398+
func (u *User) IsReservedOrganization() bool {
399+
return u.Type == UserTypeOrganizationReserved
400+
}
401+
398402
// IsIndividual returns true if user is actually a individual user.
399403
func (u *User) IsIndividual() bool {
400404
return u.Type == UserTypeIndividual
401405
}
402406

407+
func (u *User) IsReservedIndividual() bool {
408+
return u.Type == UserTypeUserReserved
409+
}
410+
403411
// IsTypeBot returns whether the user is of type bot
404412
func (u *User) IsTypeBot() bool {
405413
return u.Type == UserTypeBot

options/locale/locale_en-US.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,21 @@ email_notifications.disable = Disable Email Notifications
10101010
email_notifications.submit = Set Email Preference
10111011
email_notifications.andyourown = And Your Own Notifications
10121012

1013-
visibility = User visibility
1013+
visibility = User Visibility
10141014
visibility.public = Public
10151015
visibility.public_tooltip = Visible to everyone
10161016
visibility.limited = Limited
10171017
visibility.limited_tooltip = Visible only to authenticated users
10181018
visibility.private = Private
10191019
visibility.private_tooltip = Visible only to members of organizations you have joined
10201020

1021+
user_type = User Type
1022+
user_type.individual = Individual
1023+
user_type.organization = Organization
1024+
user_type.reservedindividual = Reserved Individual
1025+
user_type.reservedorganization = Reserved Organization
1026+
user_type.bot = Bot
1027+
10211028
[repo]
10221029
new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
10231030
owner = Owner

routers/web/admin/users.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ func EditUserPost(ctx *context.Context) {
440440
IsRestricted: optional.Some(form.Restricted),
441441
Visibility: optional.Some(form.Visibility),
442442
Language: optional.Some(form.Language),
443+
UserType: optional.Some(form.UserType),
443444
}
444445

445446
if err := user_service.UpdateUser(ctx, u, opts); err != nil {

services/forms/admin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type AdminEditUserForm struct {
5252
ProhibitLogin bool
5353
Reset2FA bool `form:"reset_2fa"`
5454
Visibility structs.VisibleType
55+
UserType int
5556
}
5657

5758
// Validate validates form fields

services/user/update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type UpdateOptions struct {
3636
EmailNotificationsPreference optional.Option[string]
3737
SetLastLogin bool
3838
RepoAdminChangeTeamAccess optional.Option[bool]
39+
UserType optional.Option[int]
3940
}
4041

4142
func UpdateUser(ctx context.Context, u *user_model.User, opts *UpdateOptions) error {
@@ -133,6 +134,10 @@ func UpdateUser(ctx context.Context, u *user_model.User, opts *UpdateOptions) er
133134

134135
cols = append(cols, "keep_activity_private")
135136
}
137+
if opts.UserType.Has() {
138+
u.Type = user_model.UserType(opts.UserType.Value())
139+
cols = append(cols, "type")
140+
}
136141

137142
if opts.AllowCreateOrganization.Has() {
138143
u.AllowCreateOrganization = opts.AllowCreateOrganization.Value()

templates/admin/user/edit.tmpl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@
5353
</div>
5454
</div>
5555

56+
<div class="inline field {{if .Err_Type}}error{{end}}">
57+
<span class="inline required field"><label for="type">{{ctx.Locale.Tr "settings.user_type"}}</label></span>
58+
<div class="ui selection type dropdown">
59+
<input type="hidden" id="user_type" name="user_type" value="{{.User.Type}}">
60+
<div class="text">
61+
{{if .User.IsIndividual}}{{ctx.Locale.Tr "settings.user_type.individual"}}{{end}}
62+
{{if .User.IsOrganization}}{{ctx.Locale.Tr "settings.user_type.organization"}}{{end}}
63+
{{if .User.IsReservedIndividual}}{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}{{end}}
64+
{{if .User.IsReservedOrganization}}{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}{{end}}
65+
{{if .User.IsTypeBot}}{{ctx.Locale.Tr "settings.user_type.bot"}}{{end}}
66+
</div>
67+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
68+
<div class="menu">
69+
<div class="item" data-value="0">{{ctx.Locale.Tr "settings.user_type.individual"}}</div>
70+
<div class="item" data-value="1">{{ctx.Locale.Tr "settings.user_type.organization"}}</div>
71+
<div class="item" data-value="2">{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}</div>
72+
<div class="item" data-value="3">{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}</div>
73+
<div class="item" data-value="4">{{ctx.Locale.Tr "settings.user_type.bot"}}</div>
74+
</div>
75+
</div>
76+
</div>
77+
5678
<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .User.LoginSource 0}}tw-hidden{{end}}">
5779
<label for="login_name">{{ctx.Locale.Tr "admin.users.auth_login_name"}}</label>
5880
<input id="login_name" name="login_name" value="{{.User.LoginName}}" autofocus>

templates/admin/user/view_details.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<b>{{ctx.Locale.Tr "admin.users.restricted"}}:</b>
3030
{{svg (Iif .User.IsRestricted "octicon-check" "octicon-x")}}
3131
</div>
32+
<div class="flex-item-body">
33+
<b>{{ctx.Locale.Tr "settings.user_type"}}:</b>
34+
{{if .User.IsIndividual}}{{ctx.Locale.Tr "settings.user_type.individual"}}{{end}}
35+
{{if .User.IsOrganization}}{{ctx.Locale.Tr "settings.user_type.organization"}}{{end}}
36+
{{if .User.IsReservedIndividual}}{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}{{end}}
37+
{{if .User.IsReservedOrganization}}{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}{{end}}
38+
{{if .User.IsTypeBot}}{{ctx.Locale.Tr "settings.user_type.bot"}}{{end}}
39+
</div>
3240
<div class="flex-item-body">
3341
<b>{{ctx.Locale.Tr "settings.visibility"}}:</b>
3442
{{if .User.Visibility.IsPublic}}{{ctx.Locale.Tr "settings.visibility.public"}}{{end}}

0 commit comments

Comments
 (0)