diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 261c1dd..4f83340 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,5 +1,5 @@ # [+Project:+] DMPRoadmap -# [+Description:+] This controller is responsible for all the actions in the admin interface under templates (e.g. phases, versions, sections, questions, annotations) (index; show; create; edit; delete) +# [+Description:+] This controller is responsible for all the actions in the admin interface under templates (e.g. phases, versions, sections, questions, suggested answer) (index; show; create; edit; delete) # [+Copyright:+] Digital Curation Centre and University of California Curation Center class TemplatesController < ApplicationController @@ -106,12 +106,6 @@ @template.published = true @template.save - # Create a new version - new_version = Template.deep_copy(@template) - new_version.version = (@template.version + 1) - new_version.published = false - new_version.save - flash[:notice] = _('Your template has been published and is now available to users.') redirect_to admin_index_template_path(current_user.org) @@ -150,6 +144,16 @@ flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.') end + # If the template is published + if @template.published? + # We need to create a new, editable version + new_version = Template.deep_copy(@template) + new_version.version = (@template.version + 1) + new_version.published = false + new_version.save + @template = new_version + end + # once the correct template has been generated, we convert it to hash @hash = @template.to_hash end @@ -245,4 +249,4 @@ @current = Template.current(@template.dmptemplate_id) end -end \ No newline at end of file +end diff --git a/app/views/user_mailer/permissions_change_notification.html.erb b/app/views/user_mailer/permissions_change_notification.html.erb index 92eed7f..c2c0740 100644 --- a/app/views/user_mailer/permissions_change_notification.html.erb +++ b/app/views/user_mailer/permissions_change_notification.html.erb @@ -12,7 +12,7 @@ end %>

<%= _('Hello ') %><%= @role.user.name %>,

-

<%= _('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 %>

+

<%= _('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.name(false)}. " %><%= _('You now have ') %><%= access_level %><%= _(' access. ') %><%= permissions %>

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

<% end %> diff --git a/app/views/user_mailer/project_access_removed_notification.html.erb b/app/views/user_mailer/project_access_removed_notification.html.erb index 63ec8d9..53a5e40 100644 --- a/app/views/user_mailer/project_access_removed_notification.html.erb +++ b/app/views/user_mailer/project_access_removed_notification.html.erb @@ -1,6 +1,6 @@ <% FastGettext.with_locale FastGettext.default_locale do %>

<%= _('Hello ') %><%= @user.email %>,

-

<%= _('Your access to ') %>"<%= @plan.title %>"<%= _(' has been removed by ') %><%= "#{@current_user.firstname} #{@current_user.surname}"%>.

+

<%= _('Your access to ') %>"<%= @plan.title %>"<%= _(' has been removed by ') %><%= "#{@current_user.name(false)}"%>.

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

<% end %> diff --git a/app/views/user_mailer/sharing_notification.html.erb b/app/views/user_mailer/sharing_notification.html.erb index 95ee5b1..dc2fed4 100644 --- a/app/views/user_mailer/sharing_notification.html.erb +++ b/app/views/user_mailer/sharing_notification.html.erb @@ -13,7 +13,7 @@ %>

<%= _('Hello ') %><%= @role.user.name %>,

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

-

<%= _('You have been given ') %><%= access_level %><%= _(' access to') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%=_(' by ')%><%= "#{@user.firstname} #{@user.surname}"%>.

+

<%= _('You have been given ') %><%= access_level %><%= _(' access to') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%=_('by ')%><%= "#{@user.name(false)}" %>.

<%= link_to _('Click here'), url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' to accept the invitation, (or copy ') %><%= url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' into your browser)')%>

<%= _('If you don\'t want to accept the invitation, please ignore this email.') %>

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

diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 45ca826..30c57f9 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -279,6 +279,9 @@ assert_response :redirect assert_redirected_to admin_index_template_path(@user.org) + # Update the description so that the template gets versioned + put admin_update_template_path(current), {template: {description: "this is an update"}} + # Make sure it versioned properly current = Template.includes(:phases, :sections, :questions).find(current.id) new_version = Template.current(family) @@ -287,7 +290,7 @@ assert current.published?, "expected the old version to be published" assert_not new_version.published?, "expected the new version to NOT be published" assert_not current.dirty?, "expected the old dirty flag to be false" - assert_not new_version.dirty?, "expected the new dirty flag to be false" + assert new_version.dirty?, "expected the new dirty flag to be true" assert_equal current.dmptemplate_id, new_version.dmptemplate_id, "expected the old and new versions to share the same dmptemplate_id" end diff --git a/test/integration/template_versioning_test.rb b/test/integration/template_versioning_test.rb index aea0d73..97e1cec 100644 --- a/test/integration/template_versioning_test.rb +++ b/test/integration/template_versioning_test.rb @@ -25,12 +25,6 @@ put admin_publish_template_path(@template) @template = Template.current(@dmptemplate_id) - assert_equal (@initial_version + 1), @template.version, "expected the version to have incremented" - assert_not_equal @initial_id, @template.id, "expected the id to have changed" - assert_equal @dmptemplate_id, @template.dmptemplate_id, "expected the dmptemplate_id to match" - assert_equal false, @template.published?, "expected the new version to be unpublished" - assert_equal @initial_title, @template.title, "expected the title to have been updated" - # Change the title after its been published put admin_update_template_path(@template), {template: {title: "Blah blah blah"}} @template = Template.current(@dmptemplate_id) diff --git a/test/test_helper.rb b/test/test_helper.rb index def6783..f95c34d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -89,6 +89,7 @@ # ---------------------------------------------------------------------- def version_the_template put admin_publish_template_path(@template) + put admin_update_template_path(@template), {template: {title: "#{@template.title} - VERSIONED"}} end # Scaffold a new Plan based on the scaffolded Template