Show only published draft versions to users (and also drafts to admins)
This commit is contained in:
@@ -6,14 +6,15 @@ class Legislation::DraftVersionsController < Legislation::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
load_version(params[:id])
|
||||
end
|
||||
|
||||
def changes
|
||||
@draft_version = @process.draft_versions.find(params[:draft_version_id])
|
||||
load_version(params[:draft_version_id])
|
||||
end
|
||||
|
||||
def go_to_version
|
||||
version = @process.draft_versions.find(params[:draft_version_id])
|
||||
version = @process.draft_versions.published.find(params[:draft_version_id])
|
||||
|
||||
if params[:redirect_action] == 'changes'
|
||||
redirect_to legislation_process_draft_version_changes_path(@process, version)
|
||||
@@ -21,4 +22,14 @@ class Legislation::DraftVersionsController < Legislation::BaseController
|
||||
redirect_to legislation_process_draft_version_path(@process, version)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_version(id_param)
|
||||
if current_user && current_user.administrator?
|
||||
@draft_version = @process.draft_versions.find(id_param)
|
||||
else
|
||||
@draft_version = @process.draft_versions.published.find(id_param)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,6 +10,8 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
||||
validates :body, presence: true
|
||||
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||
|
||||
scope :published, -> { where(status: 'published').order('id DESC') }
|
||||
|
||||
before_save :render_html
|
||||
|
||||
def render_html
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<h3><%= t('.seeing_changelog_version') %></h3>
|
||||
<div class="select-box">
|
||||
<%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %>
|
||||
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %>
|
||||
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %>
|
||||
<%= hidden_field_tag "redirect_action", "changes" %>
|
||||
<%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %>
|
||||
<% end %>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<h3><%= t('.seeing_version') %></h3>
|
||||
<div class="select-box">
|
||||
<%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %>
|
||||
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %>
|
||||
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %>
|
||||
<%= submit_tag t('.select_version_submit'), class: "button" %>
|
||||
<% end %>
|
||||
<span><%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %></span>
|
||||
|
||||
@@ -1,18 +1,44 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Legislation Draft Versions' do
|
||||
let(:user) { create(:user) }
|
||||
let(:administrator) do
|
||||
create(:administrator, user: user)
|
||||
user
|
||||
end
|
||||
|
||||
context "See draft text page" do
|
||||
before(:each) do
|
||||
@process = create(:legislation_process)
|
||||
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version")
|
||||
@draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version")
|
||||
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", status: "published")
|
||||
@draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", status: "published")
|
||||
@draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", status: "draft")
|
||||
end
|
||||
|
||||
it "shows the text body for this version" do
|
||||
visit legislation_process_draft_version_path(@process, @draft_version_1)
|
||||
|
||||
expect(page).to have_content("Body of the first version")
|
||||
|
||||
within('select#draft_version_id') do
|
||||
expect(page).to have_content("Version 1")
|
||||
expect(page).to have_content("Version 2")
|
||||
expect(page).to_not have_content("Version 3")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows an unpublished version to admins" do
|
||||
login_as(administrator)
|
||||
|
||||
visit legislation_process_draft_version_path(@process, @draft_version_3)
|
||||
|
||||
expect(page).to have_content("Body of the third version")
|
||||
|
||||
within('select#draft_version_id') do
|
||||
expect(page).to have_content("Version 1")
|
||||
expect(page).to have_content("Version 2")
|
||||
expect(page).to_not have_content("Version 3")
|
||||
end
|
||||
end
|
||||
|
||||
it "switches to another version without js" do
|
||||
@@ -40,14 +66,35 @@ feature 'Legislation Draft Versions' do
|
||||
context "See changes page" do
|
||||
before(:each) do
|
||||
@process = create(:legislation_process)
|
||||
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version")
|
||||
@draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version")
|
||||
@draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version", status: "published")
|
||||
@draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version", status: "published")
|
||||
@draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", changelog: "Changes for third version", status: "draft")
|
||||
end
|
||||
|
||||
it "shows the text body for this version" do
|
||||
it "shows the changes for this version" do
|
||||
visit legislation_process_draft_version_changes_path(@process, @draft_version_1)
|
||||
|
||||
expect(page).to have_content("Changes for first version")
|
||||
|
||||
within('select#draft_version_id') do
|
||||
expect(page).to have_content("Version 1")
|
||||
expect(page).to have_content("Version 2")
|
||||
expect(page).to_not have_content("Version 3")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows an unpublished version to admins" do
|
||||
login_as(administrator)
|
||||
|
||||
visit legislation_process_draft_version_changes_path(@process, @draft_version_3)
|
||||
|
||||
expect(page).to have_content("Changes for third version")
|
||||
|
||||
within('select#draft_version_id') do
|
||||
expect(page).to have_content("Version 1")
|
||||
expect(page).to have_content("Version 2")
|
||||
expect(page).to_not have_content("Version 3")
|
||||
end
|
||||
end
|
||||
|
||||
it "switches to another version without js" do
|
||||
|
||||
Reference in New Issue
Block a user