diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index 8cc5c73..6e79f0e 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -67,30 +67,19 @@ @current = Template.current(@template.dmptemplate_id) if @template == @current - # 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 - # @current = Template.current(@template.dmptemplate_id) + # Redirects to the newly template created + redirect_to(action: 'edit', id: new_version.id) + return end else 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 @template_hash = @template.to_hash render('container', @@ -380,7 +369,7 @@ end - # PUT /org_admin/templates/:id/publish (AJAX) + # GET /org_admin/templates/:id/publish (AJAX) TODO convert to PUT verb # ----------------------------------------------------- def publish template = Template.find(params[:id]) @@ -409,7 +398,7 @@ end end - # PUT /org_admin/templates/:id/unpublish (AJAX) + # GET /org_admin/templates/:id/unpublish (AJAX) TODO convert to PUT verb # ----------------------------------------------------- def unpublish template = Template.find(params[:id]) diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 20b105e..a1c8125 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -69,7 +69,6 @@ if @section.destroy @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id), notice: success_message(_('section'), _('deleted')) else @edit = (@phase.template.org == current_user.org) @@ -84,7 +83,7 @@ else @original_org = @phase.template.org end - render template: 'phases/admin_show' + redirect_to(admin_show_phase_path(id: @phase.id)) end end diff --git a/test/functional/org_admin/templates_controller_test.rb b/test/functional/org_admin/templates_controller_test.rb index 26aceff..1110437 100644 --- a/test/functional/org_admin/templates_controller_test.rb +++ b/test/functional/org_admin/templates_controller_test.rb @@ -99,15 +99,30 @@ assert_authorized_redirect_to_plans_page end - test "get the template edit page" do + test 'get templates#edit returns redirect (found) when template is current and is published' do + @template.dirty = false + @template.published = true + @template.save sign_in @user + get(edit_org_admin_template_path(@template.id)) + assert_response(:redirect) + end - get edit_org_admin_template_path(@template) - assert_response :success + test 'get templates#edit returns ok when template is current and is NOT published' do + sign_in @user + get(edit_org_admin_template_path(@template.id)) + assert_response(:ok) + assert_nil(flash[:notice]) + end - assert assigns(:template) - assert assigns(:template_hash) - assert assigns(:current) + test 'get templates#edit returns ok with flash notice when template is not current' do + new_version = Template.deep_copy(@template) + new_version.version = (@template.version + 1) + new_version.save + sign_in @user + get(edit_org_admin_template_path(@template.id)) + assert_response(:ok) + assert_equal(_('You are viewing a historical version of this template. You will not be able to make changes.'), flash[:notice]) end test "unauthorized user cannot access the new template page" do