Skip to content

Commit 1f05c6f

Browse files
committed
Add coauthorship notification
1 parent dbf616f commit 1f05c6f

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

app/controllers/registers_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,24 @@ def coauthors_commit
275275
@coauthor = User.find_by_email_or_username(@register.coauthor)
276276
if @coauthor.present?
277277
rc_par = { register: @register, user: @coauthor }
278+
notify = true
278279
rc =
279280
case params['register']['action']
280281
when 'unlink'
281282
RegisterCoauthor.find_by(rc_par).destroy
282283
when 'up'
284+
notify = false
283285
RegisterCoauthor.find_by(rc_par).tap(&:move_up)
284286
else
285287
rc_par.merge!(order: @register.register_coauthors.size + 1)
286288
RegisterCoauthor.new(rc_par).tap(&:save)
287289
end
288290

289291
if rc && !rc.errors.present?
292+
Notification.create(
293+
user: @coauthor, notifiable: @register,
294+
action: :coauthor_register, title: 'Authorship status changed'
295+
) if notify
290296
flash[:notice] = 'Successfully updated coauthors'
291297
redirect_back(fallback_location: @register)
292298
else

app/mailers/admin_mailer.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def templated_email
1616
when :status
1717
# For observers
1818
observer_status_email
19+
when :coauthor_register
20+
# For added/removed authors in a register list
21+
coauthor_register_email
1922
else
2023
if @object.is_a? Name
2124
# All other name status changes
@@ -93,6 +96,19 @@ def correspondence_email
9396
)
9497
end
9598

99+
##
100+
# Email coauthors when added to or removed from a register list
101+
def coauthor_register_email
102+
return unless @user.opt_message_email? || @user.opt_regular_email?
103+
104+
@object = params[:object]
105+
106+
mail(
107+
subject: 'Your authorship status changed in SeqCode Registry list',
108+
template_name: 'coauthor_register_email'
109+
)
110+
end
111+
96112
##
97113
# Email notifying observers of a new status change
98114
def observer_status_email
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<p>Your authorship status for the following list has changed
2+
<%= link_to(@object.display, @object) %>.</p>
3+
<br/>
4+
5+
<h2>What does this mean?</h2>
6+
<p>
7+
The submitting author of the list or a curator has added you or
8+
removed you as a coauthor
9+
</p>
10+
<br/>
11+
12+
<h2>What to do next?</h2>
13+
<p>
14+
If you were expecting this change, you don't need to take any action.
15+
Otherwise, please <%= link_to('contact us', page_connect_url) %>.
16+
</p>
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Your authorship status for the following list has changed
2+
<%= @object.display %>
3+
4+
What does this mean?
5+
====================
6+
7+
The submitting author of the list or a curator has added you or
8+
removed you as a coauthor
9+
10+
To view the entry in the Registry, visit:
11+
<%= polymorphic_url(@object) %>
12+
13+
What to do next?
14+
================
15+
16+
If you were expecting this change, you don't need to take any action.
17+
18+
Otherwise, please contact us: <%= page_connect_url %>
19+

0 commit comments

Comments
 (0)