Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,19 @@ func (u *User) IsOrganization() bool {
return u.Type == UserTypeOrganization
}

func (u *User) IsReservedOrganization() bool {
return u.Type == UserTypeOrganizationReserved
}

// IsIndividual returns true if user is actually a individual user.
func (u *User) IsIndividual() bool {
return u.Type == UserTypeIndividual
}

func (u *User) IsReservedIndividual() bool {
return u.Type == UserTypeUserReserved
}

// IsTypeBot returns whether the user is of type bot
func (u *User) IsTypeBot() bool {
return u.Type == UserTypeBot
Expand Down
9 changes: 8 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1010,14 +1010,21 @@ email_notifications.disable = Disable Email Notifications
email_notifications.submit = Set Email Preference
email_notifications.andyourown = And Your Own Notifications

visibility = User visibility
visibility = User Visibility
visibility.public = Public
visibility.public_tooltip = Visible to everyone
visibility.limited = Limited
visibility.limited_tooltip = Visible only to authenticated users
visibility.private = Private
visibility.private_tooltip = Visible only to members of organizations you have joined

user_type = User Type
user_type.individual = Individual
user_type.organization = Organization
user_type.reservedindividual = Reserved Individual
user_type.reservedorganization = Reserved Organization
user_type.bot = Bot

[repo]
new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
owner = Owner
Expand Down
1 change: 1 addition & 0 deletions routers/web/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func EditUserPost(ctx *context.Context) {
IsRestricted: optional.Some(form.Restricted),
Visibility: optional.Some(form.Visibility),
Language: optional.Some(form.Language),
UserType: optional.Some(form.UserType),
}

if err := user_service.UpdateUser(ctx, u, opts); err != nil {
Expand Down
1 change: 1 addition & 0 deletions services/forms/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type AdminEditUserForm struct {
ProhibitLogin bool
Reset2FA bool `form:"reset_2fa"`
Visibility structs.VisibleType
UserType int
}

// Validate validates form fields
Expand Down
5 changes: 5 additions & 0 deletions services/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type UpdateOptions struct {
EmailNotificationsPreference optional.Option[string]
SetLastLogin bool
RepoAdminChangeTeamAccess optional.Option[bool]
UserType optional.Option[int]
}

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

cols = append(cols, "keep_activity_private")
}
if opts.UserType.Has() {
u.Type = user_model.UserType(opts.UserType.Value())
cols = append(cols, "type")
}

if opts.AllowCreateOrganization.Has() {
u.AllowCreateOrganization = opts.AllowCreateOrganization.Value()
Expand Down
22 changes: 22 additions & 0 deletions templates/admin/user/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@
</div>
</div>

<div class="inline field {{if .Err_Type}}error{{end}}">
<span class="inline required field"><label for="type">{{ctx.Locale.Tr "settings.user_type"}}</label></span>
<div class="ui selection type dropdown">
<input type="hidden" id="user_type" name="user_type" value="{{.User.Type}}">
<div class="text">
{{if .User.IsIndividual}}{{ctx.Locale.Tr "settings.user_type.individual"}}{{end}}
{{if .User.IsOrganization}}{{ctx.Locale.Tr "settings.user_type.organization"}}{{end}}
{{if .User.IsReservedIndividual}}{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}{{end}}
{{if .User.IsReservedOrganization}}{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}{{end}}
{{if .User.IsTypeBot}}{{ctx.Locale.Tr "settings.user_type.bot"}}{{end}}
</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<div class="item" data-value="0">{{ctx.Locale.Tr "settings.user_type.individual"}}</div>
<div class="item" data-value="1">{{ctx.Locale.Tr "settings.user_type.organization"}}</div>
<div class="item" data-value="2">{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}</div>
<div class="item" data-value="3">{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}</div>
<div class="item" data-value="4">{{ctx.Locale.Tr "settings.user_type.bot"}}</div>
</div>
</div>
</div>

<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .User.LoginSource 0}}tw-hidden{{end}}">
<label for="login_name">{{ctx.Locale.Tr "admin.users.auth_login_name"}}</label>
<input id="login_name" name="login_name" value="{{.User.LoginName}}" autofocus>
Expand Down
8 changes: 8 additions & 0 deletions templates/admin/user/view_details.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
<b>{{ctx.Locale.Tr "admin.users.restricted"}}:</b>
{{svg (Iif .User.IsRestricted "octicon-check" "octicon-x")}}
</div>
<div class="flex-item-body">
<b>{{ctx.Locale.Tr "settings.user_type"}}:</b>
{{if .User.IsIndividual}}{{ctx.Locale.Tr "settings.user_type.individual"}}{{end}}
{{if .User.IsOrganization}}{{ctx.Locale.Tr "settings.user_type.organization"}}{{end}}
{{if .User.IsReservedIndividual}}{{ctx.Locale.Tr "settings.user_type.reservedindividual"}}{{end}}
{{if .User.IsReservedOrganization}}{{ctx.Locale.Tr "settings.user_type.reservedorganization"}}{{end}}
{{if .User.IsTypeBot}}{{ctx.Locale.Tr "settings.user_type.bot"}}{{end}}
</div>
<div class="flex-item-body">
<b>{{ctx.Locale.Tr "settings.visibility"}}:</b>
{{if .User.Visibility.IsPublic}}{{ctx.Locale.Tr "settings.visibility.public"}}{{end}}
Expand Down
Loading