Skip to content

Commit

Permalink
CSV & JSON export function fix (#11186)
Browse files Browse the repository at this point in the history
* CSV/JSON export function fix

* Added change to permissions.rb/initiatives to allow export

* export_controller_spec.rb added for elections/voting and Initiatives

Co-authored-by: Tom <101816158+greenwoodt@users.noreply.github.com>
  • Loading branch information
alecslupu and greenwoodt committed Jul 14, 2023
1 parent 99f4839 commit ace88bd
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 1 deletion.
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module Votings
module Admin
# This controller allows exporting things.
# It is targeted for customizations for exporting things that lives under
# a participatory process.
class ExportsController < Decidim::Admin::ExportsController
include VotingAdmin
end
end
end
end
Expand Up @@ -132,7 +132,7 @@ def allowed_voting_action?
when :ballot_styles
toggle_allow(user.admin?) if permission_action.action == :read
when :component_data
toggle_allow(user.admin?) if permission_action.action == :import
toggle_allow(user.admin?) if [:import, :export].member? permission_action.action
end
end

Expand Down
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Votings
module Admin
describe ExportsController, type: :controller do
routes { Decidim::Votings::AdminEngine.routes }

let!(:organization) { create(:organization) }
let!(:voting) { create(:voting, organization: organization) }
let!(:user) { create(:user, :admin, :confirmed, organization: organization) }
let!(:component) { create(:component, participatory_space: voting, manifest_name: "dummy") }

let(:params) do
{
id: "dummies",
component_id: component.id,
voting_slug: voting.slug
}
end

before do
request.env["decidim.current_organization"] = organization
sign_in user, scope: :user
end

describe "POST create" do
context "when a format is provided" do
it "enqueues a job with the provided format" do
params[:format] = "csv"

expect(ExportJob).to receive(:perform_later)
.with(user, component, "dummies", "csv", nil)

post(:create, params: params)
end
end

context "when a format is not provided" do
it "enqueues a job with the default format" do
expect(ExportJob).to receive(:perform_later)
.with(user, component, "dummies", "json", nil)

post(:create, params: params)
end
end
end
end
end
end
end
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module Initiatives
module Admin
# This controller allows exporting things.
# It is targeted for customizations for exporting things that lives under
# a participatory process.
class ExportsController < Decidim::Admin::ExportsController
include InitiativeAdmin
end
end
end
end
Expand Up @@ -163,6 +163,7 @@ def initiative_admin_user_action?

def initiative_export_action?
allow! if permission_action.subject == :initiatives && permission_action.action == :export
allow! if permission_action.action == :export && permission_action.subject == :component_data
end

def moderator_action?
Expand Down
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Initiatives
module Admin
describe ExportsController, type: :controller do
routes { Decidim::Initiatives::AdminEngine.routes }

let!(:organization) { create(:organization) }
let!(:initiative) { create(:initiative, organization: organization) }
let!(:user) { create(:user, :admin, :confirmed, organization: organization) }
let!(:component) { create(:component, participatory_space: initiative, manifest_name: "dummy") }

let(:params) do
{
id: "dummies",
component_id: component.id,
initiative_slug: initiative.slug
}
end

before do
request.env["decidim.current_organization"] = organization
sign_in user, scope: :user
end

describe "POST create" do
context "when a format is provided" do
it "enqueues a job with the provided format" do
params[:format] = "csv"

expect(ExportJob).to receive(:perform_later)
.with(user, component, "dummies", "csv", nil)

post(:create, params: params)
end
end

context "when a format is not provided" do
it "enqueues a job with the default format" do
expect(ExportJob).to receive(:perform_later)
.with(user, component, "dummies", "json", nil)

post(:create, params: params)
end
end
end
end
end
end
end

0 comments on commit ace88bd

Please sign in to comment.