Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Introduce the display_name option
Browse files Browse the repository at this point in the history
From now on, users will be able to introduce a "display name". This display
name will be the one shown on the website. The main goal of this feature is to
allow users to see names on the website that are more familiar to them (e.g.
users coming from LDAP but that have an "ugly" username there).

Notice that this "display name" is only used on the web site, not in the
`docker login` procedure. Because of this, and because it might confuse people,
this configuration option is disabled by default.

Fixes #699

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jun 1, 2016
1 parent 3b0365e commit 5d8c7e4
Show file tree
Hide file tree
Showing 43 changed files with 124 additions and 49 deletions.
15 changes: 14 additions & 1 deletion app/assets/javascripts/profile.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@

jQuery ->
email = $('#user_email').val()
display = $('#user_display_name').val()

$('#user_email').keyup ->
val = $('#user_email').val()
if val == email || val == ''
dname = $('#user_display_name').val()

if dname == display && (val == email || val == '')
$('#edit_user.profile .btn').attr('disabled', 'disabled')
else
$('#edit_user.profile .btn').removeAttr('disabled')

$('#user_display_name').keyup ->
val = $('#user_display_name').val()
em = $('#user_email').val()

if val == display && (em == email || em == '')
$('#edit_user.profile .btn').attr('disabled', 'disabled')
else
$('#edit_user.profile .btn').removeAttr('disabled')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def edit
def update
return if @user.nil?

attr = params.require(:user).permit([:email])
attr = params.require(:user).permit([:email, :display_name])

if @user.update_attributes(attr)
redirect_to admin_users_path, notice: "User updated successfully"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def update
sign_in(current_user, bypass: true) if succ
succ
else
current_user.update_without_password(params.require(:user).permit(:email))
current_user.update_without_password(params.require(:user).permit(:email, :display_name))
end

if success
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
# ldap_name :string(255)
# failed_attempts :integer default("0")
# locked_at :datetime
# display_name :string(255)
#
# Indexes
#
# index_users_on_display_name (display_name) UNIQUE
# index_users_on_email (email) UNIQUE
# index_users_on_ldap_name (ldap_name) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
Expand Down Expand Up @@ -77,6 +79,12 @@ def portus?
username == "portus"
end

# Returns the username to be displayed.
def display_username
return username unless APP_CONFIG.enabled?("display_name")
display_name.blank? ? username : display_name
end

# This method will be called automatically once a user is created. It will
# also be created for each user of the system when a registry is saved in the
# system.
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/users/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
.col-md-7
= f.email_field(:email, class: 'form-control', required: true, autofocus: true)

- if APP_CONFIG.enabled?("display_name")
.form-group
= f.label :display_name, {class: 'control-label col-md-2'}
.col-md-7
= f.text_field(:display_name, class: 'form-control')

.form-group
.col-md-offset-2.col-md-7
= f.submit('Update', class: 'btn btn-primary')
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/users/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
- @users.each do |user|
tr[id="user_#{user.id}"]
- if user == current_user
td= user.username
td= user.display_username
- else
td
= link_to user.username, edit_admin_user_path(user), { title: "Edit user '#{user.username}'" }
= link_to user.display_username, edit_admin_user_path(user), { title: "Edit user '#{user.display_username}'" }
td= user.email
td.admin-btn
- if current_user.id == user.id
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/_comment.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.panel-heading
h5
strong
= comment.author.username
= comment.author.display_username
' commented
= activity_time_tag comment.updated_at
' ago
Expand Down
9 changes: 8 additions & 1 deletion app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
= f.label :email
- else
= f.label :email, "Email", class: "control-label", title: "This profile is not complete. You need to provide an email first"
= f.text_field(:email, class: 'form-control', required: true, autofocus: true)
= f.email_field(:email, class: 'form-control', required: true, autofocus: true)

- if APP_CONFIG.enabled?("display_name")
.form-group
.field
= f.label :display_name
= f.text_field(:display_name, class: 'form-control')

.form-group
.actions
= f.submit('Update', class: 'btn btn-primary', disabled: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(["application token", "#{activity.parameters[:application]}", "create", "-", activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(["application token", "#{activity.parameters[:application]}", "create", "-", activity.owner.display_username, activity.created_at, "-"])
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= activity.owner.username
= activity.owner.display_username
| created a token for the "
em= activity.parameters[:application]
| " application
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(["application token", "#{activity.parameters[:application]}", "destroy", "-", activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(["application token", "#{activity.parameters[:application]}", "destroy", "-", activity.owner.display_username, activity.created_at, "-"])
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= activity.owner.username
= activity.owner.display_username
| removed the token of "
em= activity.parameters[:application]
| " application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
activity.trackable.name,
'change the description of the namespace',
activity.recipient.name,
activity.owner.username,
activity.owner.display_username,
activity.created_at,
"from #{activity.parameters[:old_description]} to \
#{activity.parameters[:new_description]}"])
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ li
h6
- if activity.parameters[:new].blank?
strong
= "#{activity.owner.username} deleted the description of the namespace "
= "#{activity.owner.display_username} deleted the description of the namespace "
- else
strong
= "#{activity.owner.username} edited the description of the namespace "
= "#{activity.owner.display_username} edited the description of the namespace "
= link_to activity.trackable.name, activity.trackable
small
i.fa.fa-clock-o
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_create.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['namespace', activity.trackable.name, 'create', '-', activity.owner.username, activity.created_at, "owned by team #{activity.trackable.team.name}"])
= CSV.generate_line(['namespace', activity.trackable.name, 'create', '-', activity.owner.display_username, activity.created_at, "owned by team #{activity.trackable.team.name}"])
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_create.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} created the "
= "#{activity.owner.display_username} created the "
= link_to activity.trackable.name , activity.trackable
= " namespace under the "
= link_to activity.trackable.team.name, activity.trackable.team
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_delete.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= " #{activity.owner.username} deleted "
= " #{activity.owner.display_username} deleted "
- if activity.parameters[:repository_name]
= link_to activity.trackable.clean_name, activity.trackable
= " / #{activity.parameters[:repository_name]}"
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_private.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['namespace', activity.trackable.name, 'make private', '-', activity.owner.username, activity.created_at, '-'])
= CSV.generate_line(['namespace', activity.trackable.name, 'make private', '-', activity.owner.display_username, activity.created_at, '-'])
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_private.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} set the "
= "#{activity.owner.display_username} set the "
= link_to activity.trackable.name, activity.trackable
= " namespace as private"
small
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_public.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['namespace', activity.trackable.name, 'make public', '-', activity.owner.username, activity.created_at, '-'])
= CSV.generate_line(['namespace', activity.trackable.name, 'make public', '-', activity.owner.display_username, activity.created_at, '-'])
2 changes: 1 addition & 1 deletion app/views/public_activity/namespace/_public.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} set the "
= "#{activity.owner.display_username} set the "
= link_to activity.trackable.name, activity.trackable
= " namespace as public"
small
Expand Down
6 changes: 3 additions & 3 deletions app/views/public_activity/repository/_delete.csv.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- unless activity.trackable.nil?
- if activity.recipient.nil?
- if activity.parameters[:tag_name].nil?
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}", 'delete tag', '-', activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}", 'delete tag', '-', activity.owner.display_username, activity.created_at, "-"])
- else
= CSV.generate_line(['repository',
"#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.parameters[:tag_name]}", 'delete tag', '-', activity.owner.username, activity.created_at, "-"])
"#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.parameters[:tag_name]}", 'delete tag', '-', activity.owner.display_username, activity.created_at, "-"])
- else
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.recipient.name}", 'delete tag', '-', activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.recipient.name}", 'delete tag', '-', activity.owner.display_username, activity.created_at, "-"])
6 changes: 3 additions & 3 deletions app/views/public_activity/repository/_push.csv.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- unless activity.trackable.nil?
- if activity.recipient.nil?
- if activity.parameters[:tag_name].nil?
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}", 'push tag', '-', activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}", 'push tag', '-', activity.owner.display_username, activity.created_at, "-"])
- else
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.parameters[:tag_name]}", 'push tag', '-', activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.parameters[:tag_name]}", 'push tag', '-', activity.owner.display_username, activity.created_at, "-"])
- else
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.recipient.name}", 'push tag', '-', activity.owner.username, activity.created_at, "-"])
= CSV.generate_line(['repository', "#{activity.trackable.namespace.global? ? activity.trackable.namespace.registry.hostname : activity.trackable.namespace.name}/#{activity.trackable.name}:#{activity.recipient.name}", 'push tag', '-', activity.owner.display_username, activity.created_at, "-"])
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_add_member.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['team', activity.trackable.name, 'add member', activity.recipient.username, activity.owner.username, activity.created_at, "role #{activity.parameters[:role]}"])
= CSV.generate_line(['team', activity.trackable.name, 'add member', activity.recipient.display_username, activity.owner.display_username, activity.created_at, "role #{activity.parameters[:role]}"])
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_add_member.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} added user #{activity.recipient.username} "
= "#{activity.owner.display_username} added user #{activity.recipient.display_username} "
= "with role #{activity.parameters[:role]} to the "
= link_to activity.trackable.name, activity.trackable
| team
Expand Down
4 changes: 2 additions & 2 deletions app/views/public_activity/team/_change_member_role.csv.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
= CSV.generate_line(['team',
activity.trackable.name,
'change member role',
activity.recipient.username,
activity.owner.username,
activity.recipient.display_username,
activity.owner.display_username,
activity.created_at,
"from #{activity.parameters[:old_role]} to \
#{activity.parameters[:new_role]}"])
4 changes: 2 additions & 2 deletions app/views/public_activity/team/_change_member_role.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ li
h6
strong
- if activity.owner == activity.recipient
= "#{activity.owner.username} changed its role "
= "#{activity.owner.display_username} changed its role "
- else
= "#{activity.owner.username} changed role of user #{activity.recipient.username} "
= "#{activity.owner.display_username} changed role of user #{activity.recipient.display_username} "
= "from #{activity.parameters[:old_role]} to #{activity.parameters[:new_role]} "
= "within the team "
= link_to activity.trackable.name, activity.trackable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
activity.trackable.name,
'change the description of the team',
activity.recipient.name,
activity.owner.username,
activity.owner.display_username,
activity.created_at,
"from #{activity.parameters[:old_description]} to \
#{activity.parameters[:new_description]}"])
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ li
h6
- if activity.parameters[:new].blank?
strong
="#{activity.owner.username} deleted the description of the team "
="#{activity.owner.display_username} deleted the description of the team "
- else
strong
= "#{activity.owner.username} edited the description of the team "
= "#{activity.owner.display_username} edited the description of the team "
= link_to activity.trackable.name, activity.trackable
small
i.fa.fa-clock-o
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_change_team_name.csv.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
activity.trackable.name,
'change the name of the team',
activity.recipient.name,
activity.owner.username,
activity.owner.display_username,
activity.created_at,
"from #{activity.parameters[:old_name]} to \
#{activity.parameters[:new_name]}"])
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_change_team_name.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} renamed the team #{activity.parameters[:old]} to "
= "#{activity.owner.display_username} renamed the team #{activity.parameters[:old]} to "
= link_to activity.parameters[:new], activity.trackable
small
i.fa.fa-clock-o
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_create.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['team', activity.trackable.name, 'create', '-', activity.owner.username, activity.created_at, '-'])
= CSV.generate_line(['team', activity.trackable.name, 'create', '-', activity.owner.display_username, activity.created_at, '-'])
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_create.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ li
.description
h6
strong
= "#{activity.owner.username} created team "
= "#{activity.owner.display_username} created team "
= link_to activity.trackable.name, activity.trackable
small
i.fa.fa-clock-o
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/team/_remove_member.csv.slim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= CSV.generate_line(['team', activity.trackable.name, 'remove member', activity.recipient.username, activity.owner.username, activity.created_at, "role #{activity.parameters[:role]}"])
= CSV.generate_line(['team', activity.trackable.name, 'remove member', activity.recipient.display_username, activity.owner.display_username, activity.created_at, "role #{activity.parameters[:role]}"])
4 changes: 2 additions & 2 deletions app/views/public_activity/team/_remove_member.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ li
h6
strong
- if activity.owner == activity.recipient
= "#{activity.owner.username} removed itself "
= "#{activity.owner.display_username} removed itself "
- else
= "#{activity.owner.username} removed user #{activity.recipient.username} "
= "#{activity.owner.display_username} removed user #{activity.recipient.display_username} "
= "from the "
= link_to activity.trackable.name, activity.trackable
| team
Expand Down
4 changes: 2 additions & 2 deletions app/views/repositories/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
td
.label.label-success
= t.name
td= tag.first.author.username
td= tag.first.author.display_username
td
- if tag.first.image_id.blank?
= "-"
Expand All @@ -68,7 +68,7 @@
- tag.each do |t|
.label.label-success
= t.name
td= tag.first.author.username
td= tag.first.author.display_username
td
- if tag.first.image_id.blank?
= "-"
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_header.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
= user_image_tag(current_user.email)

= link_to edit_user_registration_path, class: 'nav-a' do
span.username = current_user.username
span.username = current_user.display_username
= link_to destroy_user_session_path, method: :delete, class: 'topbar btn btn-default', id: 'logout' do
i.fa.fa-sign-out
2 changes: 1 addition & 1 deletion app/views/team_users/_team_user.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tr id="team_user_#{team_user.id}"
td.table-icon= team_user_role_icon(team_user)
td= team_user.user.username
td= team_user.user.display_username
td
.role= team_user.role.titleize
.collapse id="change_role_team_user_#{team_user.id}"
Expand Down
6 changes: 6 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ jwt_expiration_time:
# The FQDN of the machine where Portus is being deployed.
machine_fqdn:
value: "portus.test.lan"

# Allow users to have different display names on the web site. This will
# **not** be the username used by `docker login`. It defaults to false because
# it might confuse users that are not fully aware of it.
display_name:
enabled: false
6 changes: 6 additions & 0 deletions db/migrate/20160531151718_add_display_name_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddDisplayNameToUsers < ActiveRecord::Migration
def change
add_column :users, :display_name, :string, default: nil
add_index :users, :display_name, unique: true
end
end
Loading

0 comments on commit 5d8c7e4

Please sign in to comment.