Skip to content

Commit ebbf8d9

Browse files
committed
Add user transfer for individual names
1 parent 9820777 commit ebbf8d9

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

app/controllers/names_controller.rb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class NamesController < ApplicationController
99
edit_description edit_rank edit_notes edit_etymology edit_links edit_type
1010
edit_redirect autofill_etymology edit_parent
1111
return validate endorse claim unclaim demote temporary_editable
12+
transfer_user transfer_user_commit
1213
new_correspondence observe unobserve
1314
]
1415
)
@@ -24,7 +25,8 @@ class NamesController < ApplicationController
2425
)
2526
before_action(:authenticate_can_edit_type!, only: [:edit_type])
2627
before_action(
27-
:authenticate_owner_or_curator!, only: %i[unclaim new_correspondence]
28+
:authenticate_owner_or_curator!,
29+
only: %i[unclaim new_correspondence transfer_user transfer_user_commit]
2830
)
2931
before_action(:authenticate_contributor!, only: %i[new create claim])
3032
before_action(:authenticate_admin!, only: %i[demote temporary_editable])
@@ -474,6 +476,36 @@ def unclaim
474476
change_status(:unclaim, 'Name successfully claimed', current_user)
475477
end
476478

479+
# GET /names/1/transfer_user
480+
def transfer_user
481+
end
482+
483+
# POST /names/1/transfer_user
484+
def transfer_user_commit
485+
old_user = @name.user
486+
username = params.require(:name)[:user]
487+
user = User.find_by_email_or_username(username)
488+
489+
if !user.present?
490+
flash[:alert] = 'The user could not be found'
491+
render :transfer_user
492+
elsif @name.transfer(current_user, user)
493+
add_automatic_correspondence(
494+
'SeqCode Register transferred from %s to %s' % [
495+
old_user&.username, user&.username
496+
]
497+
)
498+
flash[:notice] =
499+
'Name successfully transferred to the new user'
500+
redirect_to(@name)
501+
else
502+
flash[:alert] =
503+
'The list has not been transferred due to a failed check: ' +
504+
@name.status_alert
505+
render :transfer_user
506+
end
507+
end
508+
477509
# POST /names/1/demote
478510
def demote
479511
change_status(:demote, 'Name successfully demoted', current_user)
@@ -626,4 +658,12 @@ def change_status(fun, success_msg, *extra_opts)
626658
inv.record.errors.map { |e| "#{e.attribute} #{e.message}" }.to_sentence
627659
redirect_to(inv.record)
628660
end
661+
662+
def add_automatic_correspondence(message)
663+
NameCorrespondence.new(
664+
message: message, notify: '0', automatic: true,
665+
user: current_user, name: @name
666+
).save
667+
end
668+
629669
end

app/views/names/_curator.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
&raquo; Remove ownership of this name and make it public
2323
<hr/>
2424
<% end %>
25+
26+
<%= link_to(
27+
transfer_user_name_url(@name),
28+
class: 'btn btn-primary btn-sm'
29+
) do %>
30+
<%= fa_icon('people-arrows') %> Transfer to another user
31+
<% end %>
32+
&raquo; Transfer the name ownership to a different contributor and
33+
notify the current owner
34+
<hr/>
35+
2536
<% unless @name.after_endorsement? || !@name.register %>
2637
<% id = modal('Are you sure?') do %>
2738
<h5>Endorse individual name</h5>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<% provide(:title, @name.abbr_name_raw) %>
2+
<%= render(partial: 'title') %>
3+
4+
<h2>Transfer user</h2>
5+
<p class="lead">
6+
Use this option with reserve. Consider contacting the current submitter
7+
before you proceed, and make sure you give them at least one month to
8+
respond before transfering the list.
9+
</p>
10+
<%= simple_form_for(
11+
@name, url: transfer_user_name_url(@name),
12+
method: :post) do |f| %>
13+
<div>
14+
The current submitter is: <%= display_link(@name.user) %>
15+
</div>
16+
<%= f.input(
17+
:user, label: 'Username or email',
18+
input_html: { value: f.object.user&.username }) %>
19+
<br/>
20+
<%= f.button(:submit, 'Transfer register list') %>
21+
<%= link_to('Cancel', @name, class: 'btn btn-secondary') %>
22+
<br/><br/>
23+
<% end %>
24+

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
post :claim
9494
post :unclaim
9595
post :demote
96+
get :transfer_user
97+
post :transfer_user, action: :transfer_user_commit
9698
# --> Edit name relationships
9799
get :edit_parent
98100
post :new_correspondence

0 commit comments

Comments
 (0)