Skip to content

Commit

Permalink
add space specs
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Jul 26, 2024
1 parent b2daddd commit 8e6a317
Show file tree
Hide file tree
Showing 30 changed files with 211 additions and 31 deletions.
1 change: 1 addition & 0 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ en:
scopes: Scopes
see_site: See site
settings: Settings
share_tokens: Share tokens
static_page_topics: Topics
static_pages: Pages
user_groups: Groups
Expand Down
1 change: 0 additions & 1 deletion decidim-assemblies/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ en:
moderations: Moderations
private_users: Private participants
see_assembly: See assembly
share_tokens: Share tokens
assemblies_types: Assemblies types
models:
assemblies_types:
Expand Down
2 changes: 1 addition & 1 deletion decidim-assemblies/lib/decidim/assemblies/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AdminEngine < ::Rails::Engine
end
end

resources :participatory_process_share_tokens, except: [:show], path: "share_tokens"
resources :assembly_share_tokens, except: [:show], path: "share_tokens"
end

scope "/assemblies/:assembly_slug/components/:component_id/manage" do
Expand Down
2 changes: 1 addition & 1 deletion decidim-assemblies/lib/decidim/assemblies/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def self.register_admin_assembly_menu!
if: allowed_to?(:read, :moderation, assembly: current_participatory_space)

menu.add_item :assembly_share_tokens,
I18n.t("share_tokens", scope: "decidim.admin.menu.assemblies_submenu"),
I18n.t("menu.share_tokens", scope: "decidim.admin"),
decidim_admin_assemblies.assembly_share_tokens_path(current_participatory_space),
active: is_active_link?(decidim_admin_assemblies.assembly_share_tokens_path(current_participatory_space)),
icon_name: "share-line",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@
}
))
end

it_behaves_like "manage component share tokens"
end

context "when the component is published" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages assembly component share tokens" do
include_context "when admin administrating an assembly"

it_behaves_like "manage component share tokens" do
let(:participatory_space) { assembly }
let(:participatory_space_engine) { decidim_admin_assemblies }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages assembly share tokens" do
let!(:user) { create(:user, :admin, :confirmed, organization:) }
let(:organization) { create(:organization) }
let!(:assembly) { create(:assembly, organization:, private_space: true) }

it_behaves_like "manage participatory space share tokens" do
let(:participatory_space) { assembly }
let(:participatory_space_path) { decidim_admin_assemblies.edit_assembly_path(assembly) }
end
end
1 change: 0 additions & 1 deletion decidim-conferences/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ en:
registration_types: Registration Types
registrations: Registrations
see_conference: See conference
share_tokens: Share tokens
user_registrations: User Registrations
models:
conference:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class AdminEngine < ::Rails::Engine
resources :reports, controller: "moderations/reports", only: [:index, :show]
end

resources :participatory_process_share_tokens, except: [:show], path: "share_tokens"
resources :conference_share_tokens, except: [:show], path: "share_tokens"
end

scope "/conferences/:conference_slug/components/:component_id/manage" do
Expand Down
2 changes: 1 addition & 1 deletion decidim-conferences/lib/decidim/conferences/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def self.register_conferences_admin_menu!
if: allowed_to?(:read, :moderation, conference: current_participatory_space)

menu.add_item :conference_share_tokens,
I18n.t("share_tokens", scope: "decidim.admin.menu.conferences_submenu"),
I18n.t("menu.share_tokens", scope: "decidim.admin"),
decidim_admin_conferences.conference_share_tokens_path(current_participatory_space),
active: is_active_link?(decidim_admin_conferences.conference_share_tokens_path(current_participatory_space)),
icon_name: "share-line",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@
}
))
end

it_behaves_like "manage component share tokens"
end

context "when the component is published" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages conference component share tokens" do
include_context "when admin administrating a conference"

it_behaves_like "manage conference components" do
let(:participatory_space) { conference }
let(:participatory_space_engine) { decidim_admin_conferences }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages conference share tokens" do
include_context "when admin administrating a conference"

it_behaves_like "manage participatory space share tokens" do
let(:participatory_space) { conference }
let(:participatory_space_path) { decidim_admin_conferences.edit_conference_path(conference) }
end
end
3 changes: 2 additions & 1 deletion decidim-core/lib/decidim/core/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
require "decidim/core/test/shared_examples/admin_resource_gallery_examples"
require "decidim/core/test/shared_examples/map_examples"
require "decidim/core/test/shared_examples/preview_component_with_share_token_examples"
require "decidim/core/test/shared_examples/manage_component_share_tokens"
require "decidim/core/test/shared_examples/manage_component_share_tokens_examples"
require "decidim/core/test/shared_examples/manage_participatory_space_share_tokens_examples"
require "decidim/core/test/shared_examples/metric_manage_shared_context"
require "decidim/core/test/shared_examples/resource_search_examples"
require "decidim/core/test/shared_examples/static_pages_examples"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# frozen_string_literal: true

RSpec.shared_examples "manage component share tokens" do
let!(:components_path) { participatory_space_components_path(participatory_space) }
let!(:component) { create(:component, participatory_space:) }
let!(:components_path) { participatory_space_engine.components_path(participatory_space) }
let!(:component) { create(:component, participatory_space:, published_at: nil) }

before do
switch_to_host(organization.host)
login_as user, scope: :user
end

def visit_share_component
visit components_path
click_on "Components"
click_on "Share"
end

context "when visiting the components page for the participatory space" do
context "when visiting the share_tokens page for the component" do
let!(:share_token) { create(:share_token, token_for: component, organization:, user:, registered_only: true) }

before do
visit_share_component
visit components_path
end

it "has a share button that opens the share url for the component" do
share_window = window_opened_by { click_on "Preview", wait: 2 }

within_window share_window do
expect(current_url).to include(component.share_tokens.reload.last.url)
end
it "has a share button that opens the share tokens admin" do
click_on "Share"
expect(page).to have_content("Sharing tokens for: #{translated(component.name)}")
expect(page).to have_css("tbody tr", count: 1)
expect(page).to have_content(share_token.token)
end
end

context "when visiting the component configuration page" do
context "when visiting the share tokens index page" do
context "when there are no tokens" do
let(:last_token) { Decidim::ShareToken.last }
before do
Expand Down Expand Up @@ -88,6 +92,7 @@ def visit_share_component
before do
visit_share_component
end

it "displays all tokens" do
within ".share_tokens" do
expect(page).to have_css("tbody tr", count: 3)
Expand Down Expand Up @@ -151,6 +156,16 @@ def visit_share_component
end
end

it "has a share button that opens the share url for the component" do
within ".share_tokens tbody tr:first-child" do
share_window = window_opened_by { click_on "Preview", wait: 2 }

within_window share_window do
expect(current_url).to include(component.share_tokens.first.url)
end
end
end

it "can delete tokens" do
within ".share_tokens tbody tr:first-child" do
accept_confirm { click_on "Delete" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

RSpec.shared_examples "manage participatory space share tokens" do
before do
switch_to_host(organization.host)
login_as user, scope: :user
end

def visit_share_tokens_path
visit participatory_space_path
click_on "Share tokens"
end

context "when visiting the share_tokens page for the participatory space" do
let!(:share_token) { create(:share_token, token_for: participatory_space, organization:, user:, registered_only: true) }

before do
visit participatory_space_path
end

it "has a share button that opens the share tokens admin" do
click_on "Share"
expect(page).to have_content("Sharing tokens for: #{translated(participatory_space.title)}")
expect(page).to have_css("tbody tr", count: 1)
expect(page).to have_content(share_token.token)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Decidim
module Initiatives
module Admin
# This controller allows sharing unpublished things.
# It is targeted for customizations for sharing unpublished things that lives under
# an initiative.
class ComponentShareTokensController < Decidim::Admin::ShareTokensController
include InitiativeAdmin

def resource
@resource ||= current_participatory_space.components.find(params[:component_id])
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ module Admin
# This controller allows sharing unpublished things.
# It is targeted for customizations for sharing unpublished things that lives under
# an initiative.
class ShareTokensController < Decidim::Admin::ShareTokensController
class InitiativeShareTokensController < Decidim::Admin::ShareTokensController
include InitiativeAdmin

def resource
current_initiative
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions decidim-initiatives/app/models/decidim/initiative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ def user_allowed_to_comment?(user)
ActionAuthorizer.new(user, "comment", self, nil).authorize.ok?
end

def shareable_url(share_token)
EngineRouter.main_proxy(self).initiative_url(self, share_token: share_token.token)
end

def self.ransack(params = {}, options = {})
Initiatives::InitiativeSearch.new(self, params, options)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def permissions
initiative_export_action?
initiatives_settings_action?
moderator_action?
share_tokens_action?
allow! if permission_action.subject == :attachment

permission_action
Expand Down Expand Up @@ -179,6 +180,12 @@ def moderator_action?
allow!
end

def share_tokens_action?
return unless permission_action.subject == :share_tokens

allow!
end

def read_initiative_list_action?
return unless permission_action.subject == :initiative &&
permission_action.action == :list
Expand Down
4 changes: 3 additions & 1 deletion decidim-initiatives/lib/decidim/initiatives/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AdminEngine < ::Rails::Engine
put :unpublish
get :share
end
resources :share_tokens, except: [:show]
resources :component_share_tokens, except: [:show], path: "share_tokens", as: "share_tokens"
resources :exports, only: :create
end

Expand All @@ -72,6 +72,8 @@ class AdminEngine < ::Rails::Engine
end
resources :reports, controller: "moderations/reports", only: [:index, :show]
end

resources :initiative_share_tokens, except: [:show], path: "share_tokens"
end

scope "/initiatives/:initiative_slug/components/:component_id/manage" do
Expand Down
9 changes: 8 additions & 1 deletion decidim-initiatives/lib/decidim/initiatives/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.register_admin_initiatives_components_menu!
active: is_active_link?(manage_component_path(component)) ||
is_active_link?(decidim_admin_initiatives.edit_component_path(current_participatory_space, component)) ||
is_active_link?(decidim_admin_initiatives.edit_component_permissions_path(current_participatory_space, component)) ||
is_active_link?(share_tokens_path(component)) ||
is_active_link?(decidim_admin_initiatives.component_share_tokens_path(current_participatory_space, component)) ||
participatory_space_active_link?(component),
if: component.manifest.admin_engine # && user_role_config.component_is_accessible?(component.manifest_name)
end
Expand Down Expand Up @@ -107,6 +107,13 @@ def self.register_admin_initiative_menu!
decidim_admin_initiatives.moderations_path(current_participatory_space),
icon_name: "flag-line",
if: allowed_to?(:read, :moderation)

menu.add_item :initiatives_share_tokens,
I18n.t("menu.share_tokens", scope: "decidim.admin"),
decidim_admin_initiatives.initiative_share_tokens_path(current_participatory_space),
active: is_active_link?(decidim_admin_initiatives.initiative_share_tokens_path(current_participatory_space)),
icon_name: "share-line",
if: allowed_to?(:read, :share_tokens, current_participatory_space:)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages initiative component share tokens" do
let(:organization) { create(:organization) }
let(:user) { create(:user, :admin, :confirmed, organization:) }
let!(:participatory_space) do
create(:initiative, organization:)
end

it_behaves_like "manage component share tokens" do
let(:participatory_space_engine) { decidim_admin_initiatives }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@
expect(page).to have_css(".action-icon--unpublish")
end
end

it_behaves_like "manage component share tokens"
end

context "when the component is published" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin manages initiative share tokens" do
let(:organization) { create(:organization) }
let(:user) { create(:user, :admin, :confirmed, organization:) }
let!(:participatory_space) do
create(:initiative, organization:)
end

it_behaves_like "manage participatory space share tokens" do
let(:participatory_space_path) { decidim_admin_initiatives.edit_initiative_path(participatory_space) }
end
end
1 change: 0 additions & 1 deletion decidim-participatory_processes/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ en:
moderations: Moderations
private_users: Private participants
process_admins: Process admins
share_tokens: Share tokens
steps: Phases
models:
participatory_process:
Expand Down
Loading

0 comments on commit 8e6a317

Please sign in to comment.