Skip to content

Commit

Permalink
Merge pull request #308 from DigitalCurationCentre/vyruss/bugfixes
Browse files Browse the repository at this point in the history
vyruss/bugfixes
  • Loading branch information
briri committed May 12, 2017
2 parents b87fcd2 + 0157456 commit 0280a26
Show file tree
Hide file tree
Showing 31 changed files with 240 additions and 109 deletions.
11 changes: 6 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ def set_locale_session

def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" && \
request.fullpath != "/users/sign_up" && \
request.fullpath != "/users/password" && \
request.fullpath != "/users/sign_up?nosplash=true" && \
!request.xhr?) # don't store ajax calls
unless ["/users/sign_in",
"/users/sign_up",
"/users/password",
"/users/invitation/accept",
].any? { |ur| request.fullpath.include?(ur) } \
or request.xhr? # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def create

@all_guidance_groups = @plan.get_guidance_group_options
@selected_guidance_groups = @plan.guidance_groups.pluck(:id)


respond_to do |format|
if @plan.save
Expand All @@ -130,7 +131,24 @@ def show
@plan = Plan.eager_load(params[:id])
authorize @plan
@editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id))

# Get all Guidance Groups applicable for the plan and group them by org
@all_guidance_groups = @plan.get_guidance_group_options
@all_ggs_grouped_by_org = @all_guidance_groups.sort.group_by(&:org)

# Important ones come first on the page - we grab the user's org's GGs and "Organisation" org type GGs
@important_ggs = []
@important_ggs << [current_user.org, @all_ggs_grouped_by_org.delete(current_user.org)]
@all_ggs_grouped_by_org.each do |org, ggs|
if org.organisation?
@important_ggs << [org,ggs]
@all_ggs_grouped_by_org.delete(org)
end
end

# Sort the rest by org name for the accordion
@all_ggs_grouped_by_org = @all_ggs_grouped_by_org.sort_by {|org,gg| org.name}

@selected_guidance_groups = @plan.guidance_groups.pluck(:id)
@based_on = @plan.base_template

Expand Down
14 changes: 8 additions & 6 deletions app/controllers/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class RolesController < ApplicationController
after_action :verify_authorized

def create
registered = true
@role = Role.new(role_params)
authorize @role
access_level = params[:role][:access_level].to_i
Expand All @@ -14,16 +15,17 @@ def create
message = _('User added to project')
user = User.find_by(email: params[:user])
if user.nil?
registered = false
User.invite!(email: params[:user])
message = _('Invitation issued successfully.')
user = User.find_by(email: params[:user])
end
@role.user = user
if @role.save
UserMailer.sharing_notification(@role, current_user).deliver
if registered then UserMailer.sharing_notification(@role, current_user).deliver_now end
flash[:notice] = message
else
flash[:notice] = generate_error_notice(@role, _('role'))
flash[:notice] = failed_create_error(@role, _('role'))
end
end
else
Expand All @@ -40,10 +42,10 @@ def update
set_access_level(access_level)
if @role.update_attributes(role_params)
flash[:notice] = _('Sharing details successfully updated.')
UserMailer.permissions_change_notification(@role).deliver_now
UserMailer.permissions_change_notification(@role, current_user).deliver_now
redirect_to controller: 'plans', action: 'share', id: @role.plan.id
else
flash[:notice] = generate_error_notice(@role, _('role'))
flash[:notice] = failed_create_error(@role, _('role'))
render action: "edit"
end
end
Expand All @@ -55,7 +57,7 @@ def destroy
plan = @role.plan
@role.destroy
flash[:notice] = _('Access removed')
UserMailer.project_access_removed_notification(user, plan).deliver_now
UserMailer.project_access_removed_notification(user, plan, current_user).deliver_now
redirect_to controller: 'plans', action: 'share', id: @role.plan.id
end

Expand Down Expand Up @@ -83,4 +85,4 @@ def set_access_level(access_level)
end
end

end
end
8 changes: 5 additions & 3 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ def sharing_notification(role, user)
end
end

def permissions_change_notification(role)
def permissions_change_notification(role, current_user)
@role = role
@current_user = current_user
FastGettext.with_locale FastGettext.default_locale do
mail(to: @role.user.email,
subject: "#{_('Changed permissions on a DMP in')} #{Rails.configuration.branding[:application][:name]}")
end
end

def project_access_removed_notification(user, plan)
def project_access_removed_notification(user, plan, current_user)
@user = user
@plan = plan
@current_user = current_user
FastGettext.with_locale FastGettext.default_locale do
mail(to: @user.email,
subject: "#{_('Permissions removed on a DMP in')} #{Rails.configuration.branding[:application][:name]}")
Expand All @@ -42,4 +44,4 @@ def api_token_granted_notification(user)
subject: "#{_('API rights in')} #{Rails.configuration.branding[:application][:name]}")
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/guidance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This class keeps the information organisations enter to support users when answering questions.
# It always belongs to a guidance group class and it can be linked directly to a question or through one or more themes
# [+Created:+] 07/07/2014
# [+Copyright:+] Digital Curation Centre and University of California Curation Center
# [+Copyright:+] Digital Curation Centre and California Digital Library



Expand Down
16 changes: 6 additions & 10 deletions app/views/devise/mailer/invitation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<% FastGettext.with_locale FastGettext.default_locale do %>
<p><%= _("Hello") %> <%= @resource.email %>!</p>
<p><%= _("Hello") %> <%= @resource.email %>,</p>
<p><%= _("A colleague has invited you to contribute to their Data Management Plan at ") %> <%= link_to Rails.configuration.branding[:application][:name], root_url %>.</p>
<p><%= link_to _("Click here to accept the invitation"), accept_invitation_url(@resource, :invitation_token => @token) %> (<%= _("or copy") %> <%= accept_invitation_url(@resource, :invitation_token => @token) %> <%= _("into your browser") %>).</p>
<p><%= _("If you don't want to accept the invitation, please ignore this email.") %><br /><%= _("Your account won't be created until you access the link above and set your password.") %></p>
<p><%=_('All the best,')%><br /><%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.</p>

<p><%= _("A colleague has invited you to contribute to their Data Management Plan at ") %> <%= link_to Rails.configuration.branding[:application][:name], root_url %></p>

<p><%= link_to _("Click here to accept the invitation"), accept_invitation_url(@resource, :invitation_token => @token) %> (<%= _("or copy") %> <%= accept_invitation_url(@resource, :invitation_token => @token) %> <%= _("into your browser") %>).</p>

<p>
<%= _("If you don't want to accept the invitation, please ignore this email.") %><br />
<%= _("Your account won't be created until you access the link above and set your password.") %>
</p>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</div>
</div>
<div class="right_side_footer">
<p><%= link_to( image_tag("dcc_logo.png"), "http://www.dcc.ac.uk/")%>
<%= link_to( image_tag("uc3_logo.jpg", class: "footer_logo"), "http://www.cdlib.org/uc3/", id: "footer_right_uc3") %></p>
<p><%= link_to( image_tag("dcc_logo.png"), "http://www.dcc.ac.uk/", title: "Digital Curation Centre", ) %>
<%= link_to( image_tag("uc3_logo.jpg", class: "footer_logo"), "http://www.cdlib.org/uc3/", title: "California Digital Library", id: "footer_right_uc3", ) %></p>
</div>

</footer>
Expand All @@ -40,4 +40,4 @@
</div>
</div>

<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/phases/_answer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: this partial renders an answer when there is a conflict.
**Arguments transferred: question, answer
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<% qformat = question.question_format %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/phases/_answer_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block sets up the type of question, its guidance.
**Arguments transferred: an instance of "question"
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<div class="question-div">
Expand Down
2 changes: 1 addition & 1 deletion app/views/phases/_answer_form_ro.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block sets up the type of question, its guidance.
**Arguments transferred: an instance of "question"
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->
<% answer = @plan.answer(question.id) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/plans/_answer_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block sets up the type of question, its guidance.
**Arguments transferred: an instance of "question"
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->
<% answer = @plan.answer(question.id) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/plans/_answer_form_ro.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block sets up the type of question, its guidance.
**Arguments transferred: an instance of "question"
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->
<% answer = @plan.answer(question.id) %>

Expand Down
73 changes: 54 additions & 19 deletions app/views/plans/_plan_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,69 @@


<!-- Selection of guidance groups -->
<%= form_tag( update_guidance_choices_plan_path(@plan), method: :put) do %>
<div id="plan-guidance-important">
<h3>Guidance Choices</h3>
<table id="dmp_table" class="dmp_table tablesorter">
<tbody>
<% @important_ggs.each do |org, groups| %>
<tr>
<td class="dmp_td_medium">
<% if groups && groups.size == 1 %>
<%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %>
<%= org.name %>
<% elsif groups %>
<input type="checkbox" disabled> <%= org.name %>
<% groups.each do |group| %>
<tr><td class="dmp_td_small">
└─ <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %>
<%= group.name %>
</td></tr>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="accordion" id="plan-guidance-accordion">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#plan-guidance-accordion" href="#guidance-choices">
<h3>Guidance Choices<span class="plus-laranja"> </span></h3>
<h3><%=_('Other institutions')%><span class="plus-laranja"> </span></h3>
</a>
</div>
<div id="guidance-choices" class="accordion-project collapse">
<div class="accordion-inner">
<%= form_tag( update_guidance_choices_plan_path(@plan), method: :put) do %>
<table id="dmp_table" class="dmp_table tablesorter">
<tbody>
<% all_guidance_groups.each do |group| %>
<tr>
<td class="dmp_td_medium">
<%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %>
<%= group.name %>
</td>
</tr>
<% end %>
</tr>
</tbody>
</table>
<%= submit_tag _('Save'), class: "btn btn-primary"%>
<% end %>
<div class="accordion-inner">
<table id="other_ggs_table" class="dmp_table tablesorter">
<tbody>
<% @all_ggs_grouped_by_org.each do |org, groups| %>
<tr>
<td class="dmp_td_medium">
<% if groups && groups.size == 1 %>
<%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %>
<%= org.name %>
<% elsif groups %>
<input type="checkbox" disabled> <%= org.name %>
<% groups.each do |group| %>
<tr><td class="dmp_td_small">
└─ <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %>
<%= group.name %>
</td></tr>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<%= submit_tag _('Save'), class: "btn btn-primary"%>
<% end %>

<div class="div_clear"></div>

Expand Down Expand Up @@ -319,3 +353,4 @@
<%end%><!-- end of phases.each
<%end%> <!-- end of if phases.count == 1 -->
</div>

2 changes: 1 addition & 1 deletion app/views/questions/_add_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Description: This block displays adding a new question, its guidance, and options when multiple choice is selected
in the admin interface.
**Arguments transferred: an instance of 'section'
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<% @new_question = Question.new %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/_edit_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Description: This block displays editing a question, its guidance, and options when multiple choice is selected
in the admin interface.
**Arguments transferred: an instance of 'question'
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<%= form_for(question, url: admin_update_question_path(question), html: { method: :put}) do |f| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/_show_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block shows a question, its guidance, and options when multiple choice is selected.
**Arguments transferred: 'question'
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<div class="question-div">
Expand Down
2 changes: 1 addition & 1 deletion app/views/sections/_edit_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Project: DMPRoadmap
**Description: This block edits a section and its questions.
**Arguments transferred: 'section'
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->


Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/_edit_annotations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Description: This block displays editing a question, its guidance, and options when multiple choice is selected
in the admin interface.
**Arguments transferred: an instance of 'question'
**Copyright: Digital Curation Centre and University of California Curation Center
**Copyright: Digital Curation Centre and California Digital Library
-->

<%= form_for(question, url: admin_update_question_path(question), html: { method: :put}) do |f| %>
Expand Down
18 changes: 6 additions & 12 deletions app/views/user_mailer/permissions_change_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<% FastGettext.with_locale FastGettext.default_locale do %>
<p><%= _('Hello ') %><%= @role.user.name %></p>

<%
<%
access_level = "read-only"
permissions = "This means you can read the plan and leave comments."
if @role.editor?
Expand All @@ -12,13 +10,9 @@
access_level = "co-owner"
permissions = "This means you can write and edit the plan in a collaborative manner. You can also grant rights to other collaborators."
end
%>
%>
<p><%= _('Hello ') %><%= @role.user.name %>,</p>
<p><%= _('Your permissions relating to ') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%= _(' have been changed by') %><%="#{@current_user.firstname} #{@current_user.surname}. " %><%= _('You now have ') %><%= access_level %><%= _(' access. ') %><%= permissions %></p>
<p><%=_('All the best,')%><br /><%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.</p>

<p><%= _('Your permissions relating to ') %>"<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: I18n.default_locale) %>"<%= _(' have changed. You now have ') %><%= access_level %><%= _(' access. ')%><%= permissions %></p>

<p>
<%=_('All the best,')%>
<br />
<%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
</p>
<% end %>
<% end %>
Loading

0 comments on commit 0280a26

Please sign in to comment.