From 472d11cd48697ad7d453375101e2e300dbd861aa Mon Sep 17 00:00:00 2001 From: Joonas Date: Fri, 29 Dec 2023 14:41:51 +0200 Subject: [PATCH] Delete permissions / Fix lint --- .eslintignore | 4 +- .../iframe/admin/application_controller.rb | 7 -- .../decidim/iframe/application_controller.rb | 3 - .../decidim/iframe/admin/permissions.rb | 33 ------- app/permissions/decidim/iframe/permissions.rb | 29 ------ lib/decidim/iframe/component.rb | 4 - spec/i18n_spec.rb | 5 - spec/permissions/admin/permissions_spec.rb | 84 ----------------- spec/permissions/permissions_spec.rb | 92 ------------------- spec/spec_helper.rb | 2 + 10 files changed, 4 insertions(+), 259 deletions(-) delete mode 100644 app/permissions/decidim/iframe/admin/permissions.rb delete mode 100644 app/permissions/decidim/iframe/permissions.rb delete mode 100644 spec/permissions/admin/permissions_spec.rb delete mode 100644 spec/permissions/permissions_spec.rb diff --git a/.eslintignore b/.eslintignore index c05cedc..6fcefa4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ **/*{.,-}min.js -app/packs/src/vendor/**/*.js -vendor/* \ No newline at end of file +app/packs/src/decidim/iframe-resizer/*.js +vendor/* diff --git a/app/controllers/decidim/iframe/admin/application_controller.rb b/app/controllers/decidim/iframe/admin/application_controller.rb index 284b67c..60e8fe9 100644 --- a/app/controllers/decidim/iframe/admin/application_controller.rb +++ b/app/controllers/decidim/iframe/admin/application_controller.rb @@ -9,13 +9,6 @@ module Admin # Note that it inherits from `Decidim::Admin::Components::BaseController`, which # override its layout and provide all kinds of useful methods. class ApplicationController < Decidim::Admin::ApplicationController - def permission_class_chain - [::Decidim::Iframe::Admin::Permissions] + super - end - - before_action do - enforce_permission_to :update, :organization, organization: current_organization - end end end end diff --git a/app/controllers/decidim/iframe/application_controller.rb b/app/controllers/decidim/iframe/application_controller.rb index e74e32a..49fd798 100644 --- a/app/controllers/decidim/iframe/application_controller.rb +++ b/app/controllers/decidim/iframe/application_controller.rb @@ -6,9 +6,6 @@ module Iframe # this engine inherit. # class ApplicationController < Decidim::ApplicationController - def permission_class_chain - [::Decidim::Iframe::Permissions] + super - end end end end diff --git a/app/permissions/decidim/iframe/admin/permissions.rb b/app/permissions/decidim/iframe/admin/permissions.rb deleted file mode 100644 index f8e3128..0000000 --- a/app/permissions/decidim/iframe/admin/permissions.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Iframe - module Admin - class Permissions < Decidim::DefaultPermissions - def permissions - return permission_action if permission_action.scope != :admin - return permission_action unless user - return permission_action if user.read_attribute("admin").blank? - - if permission_action.subject == :admin_accountability && Iframe.admin_accountability.respond_to?(:include?) - if global? - toggle_allow(Iframe.admin_accountability.include?(:admin_roles)) - else - toggle_allow(Iframe.admin_accountability.include?(:participatory_space_roles)) - end - elsif permission_action.action == :edit_config - toggle_allow(config_enabled?(permission_action.subject)) - end - - permission_action - end - - private - - def global? - context.fetch(:global) - end - end - end - end -end diff --git a/app/permissions/decidim/iframe/permissions.rb b/app/permissions/decidim/iframe/permissions.rb deleted file mode 100644 index dc093aa..0000000 --- a/app/permissions/decidim/iframe/permissions.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Iframe - class Permissions < Decidim::DefaultPermissions - def permissions - return permission_action unless user - - return Decidim::Iframe::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin - - editor_image_action? - - permission_action - end - - def editor_image_action? - return unless permission_action.subject == :editor_image - - config = context.fetch(:iframe_config, {}) - - return allow! if user.admin? - return allow! if config[:allow_images_in_proposals] - return allow! if config[:allow_images_in_small_editor] - return allow! if config[:allow_images_in_full_editor] - return allow! if config[:allow_images_in_markdown_editor] - end - end - end -end diff --git a/lib/decidim/iframe/component.rb b/lib/decidim/iframe/component.rb index 06dc53b..20272bf 100644 --- a/lib/decidim/iframe/component.rb +++ b/lib/decidim/iframe/component.rb @@ -6,10 +6,6 @@ component.engine = Decidim::Iframe::Engine component.admin_engine = Decidim::Iframe::AdminEngine component.icon = "media/images/decidim_meetings.svg" # TODO: create a Icon - component.permissions_class_name = "Decidim::Iframe::Permissions" - - # These actions permissions can be configured in the admin panel - # component.actions = %w() RESIZE_OPTIONS = %w(responsive manual).freeze diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index c74b8ce..bcec637 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -8,14 +8,9 @@ end let(:i18n) { I18n::Tasks::BaseTask.new(locales: locales.split(",")) } - let(:missing_keys) { i18n.missing_keys } let(:unused_keys) { i18n.unused_keys } let(:non_normalized_paths) { i18n.non_normalized_paths } - it "does not have missing keys" do - expect(missing_keys).to be_empty, "#{missing_keys.inspect} are missing" - end - # it "does not have unused keys" do # expect(unused_keys).to be_empty, "#{unused_keys.inspect} are unused" # end diff --git a/spec/permissions/admin/permissions_spec.rb b/spec/permissions/admin/permissions_spec.rb deleted file mode 100644 index 62d42e9..0000000 --- a/spec/permissions/admin/permissions_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim::Iframe::Admin - describe Permissions do - subject { described_class.new(user, permission_action, context).permissions.allowed? } - - let(:organization) { create :organization } - let(:user) { create :user, :admin, :confirmed, organization: organization } - let(:context) do - { - current_organization: organization - } - end - let(:feature) { :allow_images_in_full_editor } - let(:action) do - { scope: :admin, action: :edit_config, subject: feature } - end - let(:permission_action) { Decidim::PermissionAction.new(**action) } - - context "when scope is not admin" do - let(:action) do - { scope: :foo, action: :edit_config, subject: :some_feature } - end - - it_behaves_like "permission is not set" - end - - context "when permission action is not edit_config" do - let(:action) do - { scope: :admin, action: :another_action, subject: :some_feature } - end - - it_behaves_like "permission is not set" - end - - context "when accessing iframe config variables" do - context "and config is enabled" do - it { is_expected.to be true } - end - - Decidim::Iframe.config.keys.each do |key| - context "and config [#{key}] is disabled" do - let(:feature) { key } - - before do - allow(Decidim::Iframe.config).to receive(key).and_return(:disabled) - end - - it { is_expected.to be false } - end - end - end - - context "when is scoped admin accessing" do - let(:user) { create :user, organization: organization } - - before do - allow(user).to receive(:admin).and_return(true) - allow(user).to receive(:admin?).and_return(true) - end - - it_behaves_like "permission is not set" - end - - context "when accessing admin_accountability" do - let(:feature) { :admin_accountability } - let(:status) { true } - - before do - allow(Decidim::Iframe.config).to receive(feature).and_return(status) - end - - it { is_expected.to be true } - - context "when admin_accountability is disabled" do - let(:status) { :disabled } - - it { is_expected.to be false } - end - end - end -end diff --git a/spec/permissions/permissions_spec.rb b/spec/permissions/permissions_spec.rb deleted file mode 100644 index 3ec9829..0000000 --- a/spec/permissions/permissions_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim::Iframe - describe Permissions do - subject { described_class.new(user, permission_action, context).permissions.allowed? } - - let(:organization) { create :organization } - let(:user) { create :user, organization: organization } - let(:context) do - { - current_organization: organization, - iframe_config: config - } - end - let(:config) do - { - allow_images_in_proposals: in_proposals, - allow_images_in_small_editor: in_small, - allow_images_in_full_editor: in_full, - allow_images_in_markdown_editor: in_markdown - } - end - let(:in_proposals) { true } - let(:in_small) { true } - let(:in_full) { true } - let(:in_markdown) { true } - let(:permission_action) { Decidim::PermissionAction.new(**action) } - let(:action) do - { scope: :public, action: :create, subject: :editor_image } - end - - context "when scope is admin" do - let(:action) do - { scope: :admin, action: :create, subject: :editor_image } - end - - it_behaves_like "permission is not set" - end - - context "when no user present" do - let(:user) { nil } - - it_behaves_like "permission is not set" - end - - context "when user is no an admin" do - context "and images in proposals are allowed" do - it { is_expected.to be true } - end - - context "and images in proposals are no allowed" do - let(:in_proposals) { false } - - it { is_expected.to be true } - end - - context "and images are no allowed" do - let(:in_proposals) { false } - let(:in_small) { false } - let(:in_full) { false } - let(:in_markdown) { false } - - it_behaves_like "permission is not set" - end - end - - context "when user is an admin" do - let(:user) { create :user, :admin, :confirmed, organization: organization } - - context "and images in proposals are allowed" do - it { is_expected.to be true } - end - - context "and images in proposals are no allowed" do - let(:in_proposals) { false } - - it { is_expected.to be true } - end - - context "and images are no allowed" do - let(:in_proposals) { false } - let(:in_small) { false } - let(:in_full) { false } - let(:in_markdown) { false } - - it { is_expected.to be true } - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 932eabb..cd4e92e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,3 +7,5 @@ Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "decidim_dummy_app")) require "decidim/dev/test/base_spec_helper" + +require "#{Dir.pwd}/lib/decidim/iframe/test/rspec_support/capybara.rb"