Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ci_dataspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ concurrency:
cancel-in-progress: true

jobs:
main:
lint:
name: Lint code
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: rokroskar/workflow-run-cleanup-action@v0.3.0
if: "github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: OpenSourcePolitics/lint-action@master
tests:
name: Tests
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim", "~> 0.29.1"
gem "decidim", "~> 0.29.3"
gem "decidim-dataspace", path: "."

gem "bootsnap", "~> 1.4"
Expand All @@ -14,7 +14,7 @@ gem "uri", ">= 1.0.4"
group :development, :test do
gem "byebug", "~> 11.0", platform: :mri

gem "decidim-dev", "~> 0.29.1"
gem "decidim-dev", "~> 0.29.3"
end

group :development do
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,9 @@ PLATFORMS
DEPENDENCIES
bootsnap (~> 1.4)
byebug (~> 11.0)
decidim (~> 0.29.1)
decidim (~> 0.29.3)
decidim-dataspace!
decidim-dev (~> 0.29.1)
decidim-dev (~> 0.29.3)
faker (~> 3.2)
letter_opener_web (~> 2.0)
listen (~> 3.1)
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/decidim/dataspace/api/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

module Decidim
module Dataspace
class Api::V1::BaseController < ActionController::API
class Api::V1::BaseController < Decidim::Api::ApplicationController
# skip_before_action :verify_authenticity_token
before_action :verify_dataspace_enabled

rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from ActiveRecord::RecordInvalid, with: :validation_error
Expand All @@ -21,6 +22,14 @@ def validation_error(exception)
def resource_not_found(resource)
render json: { error: "#{resource} not found" }, status: :not_found
end

def verify_dataspace_enabled
render json: { error: "Dataspace is not enabled for this organization" }, status: :forbidden unless dataspace_enabled?
end

def dataspace_enabled?
current_organization.enable_dataspace == true
end
end
end
end
3 changes: 3 additions & 0 deletions app/views/decidim/admin/components/_settings_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<% manifest.settings(settings_name).attributes.each do |field_name, settings_attribute| %>
<% dataspace_related = [:add_integration, :integration_url, :preferred_locale] %>
<% next if dataspace_related.include?(field_name) && current_organization.enable_dataspace == false %>

<div class="row column mb-2">
<%= settings_attribute_input(
form,
Expand Down
53 changes: 53 additions & 0 deletions app/views/decidim/system/organizations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<% add_decidim_page_title(t(".title")) %>

<% provide :title do %>
<h1 class="h1"><%= t ".title" %></h1>
<% end %>

<%= decidim_form_for(@form, url: organization_path(@organization)) do |f| %>
<div class="form__wrapper">
<div>
<%= f.translated :text_field, :name, autofocus: true %>
</div>

<%= f.text_field :host %>

<%= f.text_area :secondary_hosts, help_text: t(".secondary_hosts_hint") %>

<%= field_set_tag f.label(:force_authentication, nil, for: nil) do %>
<%= f.check_box :force_users_to_authenticate_before_access_organization, label_options: { class: "form__wrapper-checkbox-label" } %>
<% end %>

<%= field_set_tag f.label(:enable_dataspace, nil, for: nil) do %>
<%= f.check_box :enable_dataspace, label_options: { class: "form__wrapper-checkbox-label" } %>
<% end %>

<%= field_set_tag f.label(:users_registration_mode, nil, for: nil) do %>
<%= f.collection_radio_buttons :users_registration_mode,
Decidim::Organization.users_registration_modes,
:first,
->(mode) { t("decidim.system.organizations.users_registration_mode.#{mode.first}") } do |builder|
builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.radio_button(id: nil) + builder.text }
end %>
<% end %>

<%= field_set_tag f.label(:available_authorizations, nil, for: nil) do %>
<%= f.collection_check_boxes :available_authorizations, Decidim.authorization_workflows, :name, :description do |builder|
builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.check_box(id: nil) + builder.text }
end %>
<% end %>

<%= render partial: "advanced_settings", locals: { f: } %>
</div>

<div class="form__wrapper-block flex-col-reverse md:flex-row justify-between">
<% if @organization&.users&.first&.invitation_pending? %>
<%= link_to t(".resend_invitation"),
resend_invitation_organization_path(@organization),
method: :post,
class: "button button__sm md:button__lg button__transparent-secondary",
data: { confirm: t(".confirm_resend_invitation") } %>
<% end %>
<%= f.submit t("decidim.system.actions.save"), class: "button button__sm md:button__lg button__primary" %>
</div>
<% end %>
72 changes: 72 additions & 0 deletions app/views/decidim/system/organizations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<% add_decidim_page_title(t(".title")) %>

<% provide :title do %>
<h1 class="h1"><%= t ".title" %></h1>
<% end %>

<%= decidim_form_for(@form) do |f| %>
<div class="form__wrapper">
<%= f.text_field :name, autofocus: true %>

<%= f.text_field :reference_prefix, help_text: t(".reference_prefix_hint") %>

<%= f.text_field :host %>

<%= f.text_area :secondary_hosts, help_text: t(".secondary_hosts_hint") %>

<%= f.text_field :organization_admin_name %>

<%= f.email_field :organization_admin_email, help_text: t(".organization_admin_email_hint") %>

<%= f.fields_for :locales do |fields| %>
<%= f.label :organization_locales, "", class: @form.respond_to?(:errors) && @form.errors[:default_locale].present? ? "is-invalid-label" : "" %>
<table>
<thead>
<tr>
<th><%= t(".locale") %></th>
<th><%= t(".enabled") %> <%= f.error_for(:available_locales) %></th>
<th><%= t(".default") %><%= f.error_for(:default_locale) %></th>
</tr>
</thead>
<tbody>
<% localized_locales.each do |locale| %>
<tr>
<td><%= locale.name %></td>
<td><%= check_box_tag "organization[available_locales][#{locale.id}]", locale.id, @form.available_locales.include?(locale.id), class: "!m-0" %></td>
<td><%= radio_button_tag "organization[default_locale]", locale.id, @form.default_locale == locale.id, class: "!m-0" %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

<%= field_set_tag f.label(:force_authentication, nil, for: nil) do %>
<%= f.check_box :force_users_to_authenticate_before_access_organization, label_options: { class: "form__wrapper-checkbox-label" } %>
<% end %>

<%= field_set_tag f.label(:enable_dataspace, nil, for: nil) do %>
<%= f.check_box :enable_dataspace, label_options: { class: "form__wrapper-checkbox-label" } %>
<% end %>

<%= field_set_tag f.label(:users_registration_mode, nil, for: nil) do %>
<%= f.collection_radio_buttons :users_registration_mode,
Decidim::Organization.users_registration_modes,
:first,
->(mode) { t("decidim.system.organizations.users_registration_mode.#{mode.first}") } do |builder|
builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.radio_button(id: nil) + builder.text }
end %>
<% end %>

<%= field_set_tag f.label(:available_authorizations, nil, for: nil) do %>
<%= f.collection_check_boxes :available_authorizations, Decidim.authorization_workflows, :name, :description do |builder|
builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.check_box(id: nil) + builder.text }
end %>
<% end %>

<%= render partial: "advanced_settings", locals: { f: } %>
</div>

<div class="form__wrapper-block">
<%= f.submit t("decidim.system.models.organization.actions.save_and_invite"), class: "button button__sm md:button__lg button__primary" %>
</div>
<% end %>
11 changes: 11 additions & 0 deletions db/migrate/20260129143027_add_enable_dataspace_to_organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class AddEnableDataspaceToOrganizations < ActiveRecord::Migration[7.0]
def up
add_column :decidim_organizations, :enable_dataspace, :boolean, default: false, null: false
end

def down
remove_column :decidim_organizations, :enable_dataspace
end
end
3 changes: 3 additions & 0 deletions lib/decidim/dataspace/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Engine < ::Rails::Engine
require "extends/controllers/decidim/proposals/proposals_controller_extends"
require "extends/models/decidim/comments/comment_extends"
require "extends/lib/decidim/core_extends"
require "extends/commands/decidim/system/create_organization_extends"
require "extends/commands/decidim/system/update_organization_extends"
require "extends/forms/decidim/system/base_organization_form_extends"
end
end

Expand Down
33 changes: 33 additions & 0 deletions lib/extends/commands/decidim/system/create_organization_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module CreateOrganizationExtends
extend ActiveSupport::Concern

included do
def create_organization
Decidim::Organization.create!(
name: { form.default_locale => form.name },
host: form.host,
secondary_hosts: form.clean_secondary_hosts,
reference_prefix: form.reference_prefix,
available_locales: form.available_locales,
available_authorizations: form.clean_available_authorizations,
external_domain_allowlist: ["decidim.org", "github.com"],
users_registration_mode: form.users_registration_mode,
force_users_to_authenticate_before_access_organization: form.force_users_to_authenticate_before_access_organization,
badges_enabled: true,
user_groups_enabled: true,
default_locale: form.default_locale,
omniauth_settings: form.encrypted_omniauth_settings,
smtp_settings: form.encrypted_smtp_settings,
send_welcome_notification: true,
file_upload_settings: form.file_upload_settings.final,
colors: default_colors,
content_security_policy: form.content_security_policy,
enable_dataspace: form.enable_dataspace
)
end
end
end

Decidim::System::CreateOrganization.include(CreateOrganizationExtends)
25 changes: 25 additions & 0 deletions lib/extends/commands/decidim/system/update_organization_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module UpdateOrganizationExtends
extend ActiveSupport::Concern

included do
def save_organization
organization.name = form.name
organization.host = form.host
organization.secondary_hosts = form.clean_secondary_hosts
organization.force_users_to_authenticate_before_access_organization = form.force_users_to_authenticate_before_access_organization
organization.available_authorizations = form.clean_available_authorizations
organization.users_registration_mode = form.users_registration_mode
organization.omniauth_settings = form.encrypted_omniauth_settings
organization.smtp_settings = form.encrypted_smtp_settings
organization.file_upload_settings = form.file_upload_settings.final
organization.content_security_policy = form.content_security_policy
organization.enable_dataspace = form.enable_dataspace

organization.save!
end
end
end

Decidim::System::UpdateOrganization.include(UpdateOrganizationExtends)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module ProposalsControllerExtends
extend ActiveSupport::Concern

included do
before_action :dataspace_enabled, only: :external_proposal

def index
if component_settings.participatory_texts_enabled?
@proposals = Decidim::Proposals::Proposal.where(component: current_component)
Expand All @@ -17,8 +19,7 @@ def index
.order(position: :asc)
render "decidim/proposals/proposals/participatory_texts/participatory_text"
else
if component_settings.add_integration && component_settings.integration_url.present? && data.present?

if verify_dataspace? && data.present?
external_proposals = data["contributions"]
@authors = data["authors"]
proposals = search.result
Expand Down Expand Up @@ -58,6 +59,14 @@ def external_proposal

private

def verify_dataspace?
current_organization.enable_dataspace == true && component_settings.add_integration && component_settings.integration_url.present?
end

def dataspace_enabled
redirect_to(root_url) && return unless verify_dataspace?
end

def voted_proposals
if current_user
Decidim::Proposals::ProposalVote.where(
Expand Down
11 changes: 11 additions & 0 deletions lib/extends/forms/decidim/system/base_organization_form_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module BaseOrganizationFormExtends
extend ActiveSupport::Concern

included do
attribute :enable_dataspace, Decidim::AttributeObject::TypeMap::Boolean
end
end

Decidim::System::BaseOrganizationForm.include(BaseOrganizationFormExtends)
7 changes: 2 additions & 5 deletions lib/extends/lib/decidim/core_extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ module CoreExtends
lambda do |resource, component|
ref = ""

if resource.is_a?(Decidim::HasComponent) && component.present?
# It is a component resource
ref = component.participatory_space.organization.reference_prefix
elsif resource.is_a?(Decidim::Comments::Comment) && component.present?
# It is a comment resource
if (resource.is_a?(Decidim::HasComponent) || resource.is_a?(Decidim::Comments::Comment)) && component.present?
# It is a component resource or a comment resource
ref = component.participatory_space.organization.reference_prefix
elsif resource.is_a?(Decidim::Participable)
# It is a participatory space
Expand Down
Loading
Loading