Skip to content

Commit

Permalink
Fix editor image upload for private user / Add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Jun 18, 2024
1 parent 803fdd4 commit c0d56db
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/concerns/decidim/privacy/editor_image_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Decidim
module Privacy
module EditorImageExtensions
extend ActiveSupport::Concern

included do
belongs_to :author, -> { entire_collection }, foreign_key: :decidim_author_id, class_name: "Decidim::User"
end
end
end
end
1 change: 1 addition & 0 deletions lib/decidim/privacy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Engine < ::Rails::Engine
Decidim::UserGroup.include(Decidim::Privacy::UserGroupExtensions)
Decidim::UserBaseEntity.include(Decidim::Privacy::UserBaseEntityExtensions)
Decidim::Organization.include(Decidim::Privacy::OrganizationExtensions)
Decidim::EditorImage.include(Decidim::Privacy::EditorImageExtensions)

# forms
Decidim::AccountForm.include(Decidim::Privacy::AccountFormExtensions)
Expand Down
54 changes: 54 additions & 0 deletions spec/commands/decidim/create_editor_image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
describe CreateEditorImage do
subject { described_class.new(form) }

let(:form) do
EditorImageForm.from_params(attributes).with_context(context)
end
let(:attributes) do
{
"editor_image" => {
organization:,
author_id: user.id,
file:
}
}
end
let(:context) do
{
current_organization: organization,
current_user: user
}
end
let(:user) { create(:user, :admin, :confirmed) }
let(:organization) { user.organization }
let(:file) { Decidim::Dev.test_file("city.jpeg", "image/jpeg") }

context "when the user is private" do
it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
expect(user.public?).to be(false)
end

it "creates an editor image" do
expect { subject.call }.to change(Decidim::EditorImage, :count).by(1)
end
end

context "when the user is public" do
let(:user) { create(:user, :admin, :published, :confirmed) }
it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
expect(user.public?).to be(true)
end

it "creates an editor image" do
expect { subject.call }.to change(Decidim::EditorImage, :count).by(1)
end
end
end
end

0 comments on commit c0d56db

Please sign in to comment.