diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b1f9db1..8425430 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,7 @@ on: pull_request: env: - RUBY_VERSION: 3.0.2 + RUBY_VERSION: 3.0.6 NODE_VERSION: 16.9.1 jobs: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aff836e..49e7dd3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: pull_request: env: - RUBY_VERSION: 3.0.2 + RUBY_VERSION: 3.0.6 NODE_VERSION: 16.9.1 jobs: @@ -35,6 +35,10 @@ jobs: ruby-version: ${{ env.RUBY_VERSION }} bundler-cache: true + - uses: nanasess/setup-chromedriver@v2 + with: + chromedriver-version: 119.0.6045.105 + - name: Bundle Install run: bundle install diff --git a/.ruby-version b/.ruby-version index b502146..818bd47 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.2 +3.0.6 diff --git a/Gemfile b/Gemfile index 541a06b..73e4854 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,10 @@ gem "decidim", DECIDIM_VERSION # gem "decidim-initiatives", DECIDIM_VERSION # gem "decidim-templates", DECIDIM_VERSION +gem "decidim-centers", "~> 0.1.0" +gem "decidim-extra_user_fields", git: "https://github.com/Platoniq/decidim-module-extra_user_fields" +gem "decidim-term_customizer", git: "https://github.com/mainio/decidim-module-term_customizer" + gem "bootsnap", "~> 1.3" gem "puma", ">= 5.0.0" @@ -56,4 +60,5 @@ end group :test do gem "codecov", require: false + gem "database_cleaner" end diff --git a/Gemfile.lock b/Gemfile.lock index 7ead10a..63400e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,20 @@ +GIT + remote: https://github.com/Platoniq/decidim-module-extra_user_fields + revision: e6122fd80135a7f84eb416ff2cf589e2951bb633 + specs: + decidim-extra_user_fields (0.27.2) + country_select (~> 4.0) + decidim-core (>= 0.27.0, < 0.28) + deface (~> 1.5) + +GIT + remote: https://github.com/mainio/decidim-module-term_customizer + revision: abbf0c69e1bcaafebc5aa4f8da22fdb64ce62149 + specs: + decidim-term_customizer (0.27.0) + decidim-admin (~> 0.27.0) + decidim-core (~> 0.27.0) + GEM remote: https://rubygems.org/ specs: @@ -167,11 +184,24 @@ GEM commonmarker (0.23.9) concurrent-ruby (1.1.10) connection_pool (2.4.1) + countries (3.1.0) + i18n_data (~> 0.11.0) + sixarm_ruby_unaccent (~> 1.1) + unicode_utils (~> 1.4) + country_select (4.0.0) + countries (~> 3.0) + sort_alphabetical (~> 1.0) crack (0.4.5) rexml crass (1.0.6) css_parser (1.14.0) addressable + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) date_validator (0.12.0) activemodel (>= 3) activesupport (>= 3) @@ -221,6 +251,9 @@ GEM decidim-budgets (0.27.4) decidim-comments (= 0.27.4) decidim-core (= 0.27.4) + decidim-centers (0.1.1) + decidim-core (>= 0.27.0, < 0.28) + deface (~> 1.9) decidim-comments (0.27.4) decidim-core (= 0.27.4) redcarpet (~> 3.5, >= 3.5.1) @@ -348,6 +381,12 @@ GEM declarative-builder (0.1.0) declarative-option (< 0.2.0) declarative-option (0.1.0) + deface (1.9.0) + actionview (>= 5.2) + nokogiri (>= 1.6) + polyglot + railties (>= 5.2) + rainbow (>= 2.1.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) devise (4.9.2) @@ -470,6 +509,7 @@ GEM rails-i18n rainbow (>= 2.2.2, < 4.0) terminal-table (>= 1.5.1) + i18n_data (0.11.0) icalendar (2.8.0) ice_cube (~> 0.16) ice_cube (0.16.4) @@ -600,6 +640,7 @@ GEM pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) + polyglot (0.3.5) premailer (1.21.0) addressable css_parser (>= 1.12.0) @@ -757,12 +798,15 @@ GEM simplecov (~> 0.19) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + sixarm_ruby_unaccent (1.2.2) smart_properties (1.17.0) snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) social-share-button (1.2.4) coffee-rails + sort_alphabetical (1.1.0) + unicode_utils (>= 1.2.2) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -792,6 +836,7 @@ GEM concurrent-ruby (~> 1.0) uber (0.1.0) unicode-display_width (2.4.2) + unicode_utils (1.4.0) valid_email2 (2.3.1) activemodel (>= 3.2) mail (~> 2.5) @@ -843,6 +888,8 @@ GEM PLATFORMS arm64-darwin-21 + arm64-darwin-22 + arm64-darwin-23 x86_64-linux DEPENDENCIES @@ -857,8 +904,12 @@ DEPENDENCIES capistrano-rbenv capistrano-sidekiq codecov + database_cleaner decidim (= 0.27.4) + decidim-centers (~> 0.1.0) decidim-dev (= 0.27.4) + decidim-extra_user_fields! + decidim-term_customizer! faker (~> 2.14) figaro (~> 1.2) letter_opener_web (~> 2.0) @@ -876,7 +927,7 @@ DEPENDENCIES wicked_pdf (~> 2.1) RUBY VERSION - ruby 3.0.2p107 + ruby 3.0.6p216 BUNDLED WITH 2.3.20 diff --git a/app/forms/concerns/decidim/account_form_override.rb b/app/forms/concerns/decidim/account_form_override.rb new file mode 100644 index 0000000..08d3c3e --- /dev/null +++ b/app/forms/concerns/decidim/account_form_override.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "active_support/concern" + +module Decidim + module AccountFormOverride + extend ActiveSupport::Concern + + included do + def map_model(model) + map_model_centers(model) + map_model_extra_user_fields(model) + end + + private + + def map_model_centers(model) + self.center_id = model.center.try(:id) + self.scope_id = model.scope.try(:id) + end + + def map_model_extra_user_fields(model) + extended_data = model.extended_data.with_indifferent_access + + self.country = extended_data[:country] + self.postal_code = extended_data[:postal_code] + self.date_of_birth = Date.parse(extended_data[:date_of_birth]) if extended_data[:date_of_birth].present? + self.gender = extended_data[:gender] + self.phone_number = extended_data[:phone_number] + self.location = extended_data[:location] + self.profession = extended_data[:profession] + self.document_id = extended_data[:document_id] + end + end + end +end diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb new file mode 100644 index 0000000..2e757fd --- /dev/null +++ b/config/initializers/decidim_overrides.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +Rails.application.config.to_prepare do + Decidim::RegistrationForm.include(Decidim::AccountFormOverride) + Decidim::OmniauthRegistrationForm.include(Decidim::AccountFormOverride) + Decidim::AccountForm.include(Decidim::AccountFormOverride) +end diff --git a/db/migrate/20231213130434_add_extra_user_fields_to_decidim_organization.decidim_extra_user_fields.rb b/db/migrate/20231213130434_add_extra_user_fields_to_decidim_organization.decidim_extra_user_fields.rb new file mode 100644 index 0000000..3a4ff40 --- /dev/null +++ b/db/migrate/20231213130434_add_extra_user_fields_to_decidim_organization.decidim_extra_user_fields.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +# This migration comes from decidim_extra_user_fields (originally 20221024121407) + +class AddExtraUserFieldsToDecidimOrganization < ActiveRecord::Migration[6.0] + def up + add_column :decidim_organizations, :extra_user_fields, :jsonb, default: { "enabled" => false } + end + + def down + remove_column :decidim_organizations, :extra_user_fields, :jsonb + end +end diff --git a/db/migrate/20231213130435_create_decidim_term_customizer_translation_sets.decidim_term_customizer.rb b/db/migrate/20231213130435_create_decidim_term_customizer_translation_sets.decidim_term_customizer.rb new file mode 100644 index 0000000..c0fc109 --- /dev/null +++ b/db/migrate/20231213130435_create_decidim_term_customizer_translation_sets.decidim_term_customizer.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true +# This migration comes from decidim_term_customizer (originally 20190217132503) + +class CreateDecidimTermCustomizerTranslationSets < ActiveRecord::Migration[5.2] + def change + create_table :decidim_term_customizer_translation_sets do |t| + t.jsonb :name + end + end +end diff --git a/db/migrate/20231213130436_create_decidim_term_customizer_translations.decidim_term_customizer.rb b/db/migrate/20231213130436_create_decidim_term_customizer_translations.decidim_term_customizer.rb new file mode 100644 index 0000000..90bced4 --- /dev/null +++ b/db/migrate/20231213130436_create_decidim_term_customizer_translations.decidim_term_customizer.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +# This migration comes from decidim_term_customizer (originally 20190217132654) + +class CreateDecidimTermCustomizerTranslations < ActiveRecord::Migration[5.2] + def change + create_table :decidim_term_customizer_translations do |t| + t.string :locale + t.string :key + t.text :value + + t.references( + :translation_set, + null: false, + foreign_key: { to_table: :decidim_term_customizer_translation_sets }, + index: { name: "decidim_term_customizer_translation_translation_set" } + ) + end + end +end diff --git a/db/migrate/20231213130437_create_decidim_term_customizer_constraints.decidim_term_customizer.rb b/db/migrate/20231213130437_create_decidim_term_customizer_constraints.decidim_term_customizer.rb new file mode 100644 index 0000000..c027259 --- /dev/null +++ b/db/migrate/20231213130437_create_decidim_term_customizer_constraints.decidim_term_customizer.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +# This migration comes from decidim_term_customizer (originally 20190217132726) + +class CreateDecidimTermCustomizerConstraints < ActiveRecord::Migration[5.2] + def change + create_table :decidim_term_customizer_constraints do |t| + t.references :decidim_organization, null: false, foreign_key: true, index: { name: "decidim_term_customizer_constraint_organization" } + t.references :subject, polymorphic: true, index: { name: "decidim_term_customizer_constraint_subject" } + + t.references( + :translation_set, + null: false, + foreign_key: { to_table: :decidim_term_customizer_translation_sets }, + index: { name: "decidim_term_customizer_constraint_translation_set" } + ) + end + end +end diff --git a/db/migrate/20231213131628_create_decidim_centers_centers.decidim_centers.rb b/db/migrate/20231213131628_create_decidim_centers_centers.decidim_centers.rb new file mode 100644 index 0000000..f5d2218 --- /dev/null +++ b/db/migrate/20231213131628_create_decidim_centers_centers.decidim_centers.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +# This migration comes from decidim_centers (originally 20231129114029) + +class CreateDecidimCentersCenters < ActiveRecord::Migration[6.1] + def change + create_table :decidim_centers_centers do |t| + t.references :decidim_organization, foreign_key: true, index: true + t.jsonb :title, null: false + t.datetime :deleted_at + + t.timestamps + end + end +end diff --git a/db/migrate/20231213131629_create_decidim_centers_center_users.decidim_centers.rb b/db/migrate/20231213131629_create_decidim_centers_center_users.decidim_centers.rb new file mode 100644 index 0000000..37fc045 --- /dev/null +++ b/db/migrate/20231213131629_create_decidim_centers_center_users.decidim_centers.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +# This migration comes from decidim_centers (originally 20231130125631) + +class CreateDecidimCentersCenterUsers < ActiveRecord::Migration[6.1] + def change + create_table :decidim_centers_center_users do |t| + t.references :decidim_centers_center, foreign_key: true, index: { name: "index_decidim_center_users_on_decidim_center_id" } + t.references :decidim_user, foreign_key: true, index: { name: "index_decidim_center_users_on_decidim_user_id" } + + t.timestamps + end + end +end diff --git a/db/migrate/20231213131630_create_decidim_centers_scope_users.decidim_centers.rb b/db/migrate/20231213131630_create_decidim_centers_scope_users.decidim_centers.rb new file mode 100644 index 0000000..ad55b1d --- /dev/null +++ b/db/migrate/20231213131630_create_decidim_centers_scope_users.decidim_centers.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +# This migration comes from decidim_centers (originally 20231205153627) + +class CreateDecidimCentersScopeUsers < ActiveRecord::Migration[6.1] + def change + create_table :decidim_centers_scope_users do |t| + t.references :decidim_scope, foreign_key: true, index: { name: "index_decidim_scope_users_on_decidim_scope_id" } + t.references :decidim_user, foreign_key: true, index: { name: "index_decidim_scope_users_on_decidim_user_id" } + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0ff2c81..d72a86b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_11_28_122856) do +ActiveRecord::Schema.define(version: 2023_12_13_131630) do # These are extensions that must be enabled in order to support this database enable_extension "ltree" @@ -381,6 +381,33 @@ t.index ["decidim_category_id"], name: "index_decidim_categorizations_on_decidim_category_id" end + create_table "decidim_centers_center_users", force: :cascade do |t| + t.bigint "decidim_centers_center_id" + t.bigint "decidim_user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["decidim_centers_center_id"], name: "index_decidim_center_users_on_decidim_center_id" + t.index ["decidim_user_id"], name: "index_decidim_center_users_on_decidim_user_id" + end + + create_table "decidim_centers_centers", force: :cascade do |t| + t.bigint "decidim_organization_id" + t.jsonb "title", null: false + t.datetime "deleted_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["decidim_organization_id"], name: "index_decidim_centers_centers_on_decidim_organization_id" + end + + create_table "decidim_centers_scope_users", force: :cascade do |t| + t.bigint "decidim_scope_id" + t.bigint "decidim_user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["decidim_scope_id"], name: "index_decidim_scope_users_on_decidim_scope_id" + t.index ["decidim_user_id"], name: "index_decidim_scope_users_on_decidim_user_id" + end + create_table "decidim_coauthorships", force: :cascade do |t| t.bigint "decidim_author_id", null: false t.bigint "decidim_user_group_id" @@ -993,6 +1020,7 @@ t.string "machine_translation_display_priority", default: "original", null: false t.string "external_domain_whitelist", default: [], array: true t.boolean "enable_participatory_space_filters", default: true + t.jsonb "extra_user_fields", default: {"enabled"=>false} t.index ["host"], name: "index_decidim_organizations_on_host", unique: true t.index ["name"], name: "index_decidim_organizations_on_name", unique: true end @@ -1463,6 +1491,28 @@ t.index ["templatable_type", "templatable_id"], name: "index_decidim_templates_templatable" end + create_table "decidim_term_customizer_constraints", force: :cascade do |t| + t.bigint "decidim_organization_id", null: false + t.string "subject_type" + t.bigint "subject_id" + t.bigint "translation_set_id", null: false + t.index ["decidim_organization_id"], name: "decidim_term_customizer_constraint_organization" + t.index ["subject_type", "subject_id"], name: "decidim_term_customizer_constraint_subject" + t.index ["translation_set_id"], name: "decidim_term_customizer_constraint_translation_set" + end + + create_table "decidim_term_customizer_translation_sets", force: :cascade do |t| + t.jsonb "name" + end + + create_table "decidim_term_customizer_translations", force: :cascade do |t| + t.string "locale" + t.string "key" + t.text "value" + t.bigint "translation_set_id", null: false + t.index ["translation_set_id"], name: "decidim_term_customizer_translation_translation_set" + end + create_table "decidim_user_blocks", force: :cascade do |t| t.bigint "decidim_user_id" t.integer "blocking_user_id" @@ -1673,6 +1723,11 @@ add_foreign_key "decidim_budgets_orders", "decidim_budgets_budgets" add_foreign_key "decidim_budgets_projects", "decidim_budgets_budgets" add_foreign_key "decidim_categorizations", "decidim_categories" + add_foreign_key "decidim_centers_center_users", "decidim_centers_centers" + add_foreign_key "decidim_centers_center_users", "decidim_users" + add_foreign_key "decidim_centers_centers", "decidim_organizations" + add_foreign_key "decidim_centers_scope_users", "decidim_scopes" + add_foreign_key "decidim_centers_scope_users", "decidim_users" add_foreign_key "decidim_debates_debates", "decidim_scopes" add_foreign_key "decidim_editor_images", "decidim_organizations" add_foreign_key "decidim_editor_images", "decidim_users", column: "decidim_author_id" @@ -1692,6 +1747,9 @@ add_foreign_key "decidim_scopes", "decidim_scope_types", column: "scope_type_id" add_foreign_key "decidim_scopes", "decidim_scopes", column: "parent_id" add_foreign_key "decidim_static_pages", "decidim_organizations" + add_foreign_key "decidim_term_customizer_constraints", "decidim_organizations" + add_foreign_key "decidim_term_customizer_constraints", "decidim_term_customizer_translation_sets", column: "translation_set_id" + add_foreign_key "decidim_term_customizer_translations", "decidim_term_customizer_translation_sets", column: "translation_set_id" add_foreign_key "decidim_user_blocks", "decidim_users" add_foreign_key "decidim_user_blocks", "decidim_users", column: "blocking_user_id" add_foreign_key "decidim_user_moderations", "decidim_users" diff --git a/db/seeds.rb b/db/seeds.rb index 9ff1c87..ef9289d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,3 +9,125 @@ # Character.create(name: 'Luke', movie: movies.first) # You can remove the 'faker' gem if you don't want Decidim seeds. Decidim.seed! + +[ + "Agencia de Evaluación de la Calidad y Acreditación del Sistema Universitario Vasco (Unibasq)", + "Centro de Enseñanza Superior Cardenal Cisneros", + "Centro de Estudios de Física del Cosmos de Aragón (CEFCA)", + "Centro de Investigación y Tecnología Agroalimentaria de Aragón (CITA)", + "Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas (CIEMAT)", + "Centro de Magisterio La Inmaculada", + "Centro Nacional de Investigaciones Cardiovasculares (CNIC)", + "Centro Universitario Cardenal Spínola", + "Centro Universitario de Enfermería Cruz Roja (Adscrito a la U. de Sevilla)", + "Centro Universitario de la Defensa de Marín", + "Centro Universitario de la Defensa de San Javier", + "Centro Universitario de Osuna", + "Centro Universitario de Tecnología y Arte Digital (U-Tad)", + "Centro Universitario Sagrada Familia", + "Centro Universitario San Isidoro de Sevilla", + "Consejo Superior de Investigaciones Científicas", + "Cunef Universidad", + "Escuela Universitaria de Artes Tai", + "Escuela Universitaria de Diseño, Innovación y Tecnología", + "Escuela Universitaria de Magisterio Fray Luis de León", + "Esic Universidad", + "Facultad Padre Ossó", + "Fundación Agencia Aragonesa para la Investigación y el Desarrollo (Araid)", + "Fundación San Juan de Dios (Centro Universitario de Ciencias de La Salud \"San Rafael\")", + "IE Universidad de Segovia", + "Instituto de Astrofísica de Canarias (IAC)", + "Instituto de Salud Carlos III (ISCIII)", + "Instituto Español de Oceanografía (IEO)", + "Instituto Geológico y Minero de España (IGME)", + "Instituto Nacional de Investigación y Tecnología Agraria y Alimentaria (INIA)", + "Instituto Nacional de Técnica Aeroespacial (INTA)", + "Itainnova (Instituto Tecnológico de Aragón)", + "UNIE Universidad", + "Universidad A Distancia de Madrid (Udima)", + "Universidad Alfonso X El Sabio", + "Universidad Antonio de Nebrija", + "Universidad Autónoma de Barcelona", + "Universidad Autónoma de Madrid", + "Universidad Camilo José Cela", + "Universidad Cardenal Herrera-Ceu", + "Universidad Carlos III de Madrid", + "Universidad Católica de Valencia San Vicente Mártir", + "Universidad Católica San Antonio de Murcia", + "Universidad Católica Santa Teresa de Jesús de Ávila", + "Universidad Complutense de Madrid", + "Universidad de A Coruña", + "Universidad de Alcalá de Henares", + "Universidad de Alicante", + "Universidad de Almería", + "Universidad de Barcelona", + "Universidad de Burgos", + "Universidad de Cádiz", + "Universidad de Cantabria", + "Universidad de Castilla-La Mancha", + "Universidad de Córdoba", + "Universidad de Deusto", + "Universidad de Extremadura", + "Universidad de Girona", + "Universidad de Granada", + "Universidad de Huelva", + "Universidad de Jaén", + "Universidad de La Laguna", + "Universidad de La Rioja", + "Universidad de Las Illes Balears", + "Universidad de Las Palmas de Gran Canaria", + "Universidad de León", + "Universidad de Lleida", + "Universidad de Málaga", + "Universidad de Murcia", + "Universidad de Navarra", + "Universidad de Oviedo", + "Universidad de Salamanca", + "Universidad de Santiago de Compostela", + "Universidad de Sevilla", + "Universidad de Valladolid", + "Universidad de Vic", + "Universidad de Vigo", + "Universidad de Zaragoza", + "Universidad del Atlántico Medio", + "Universidad del País Vasco/Euskal Herriko Unibertsitatea", + "Universidad Europea de Canarias", + "Universidad Europea de Madrid", + "Universidad Europea de Miguel de Cervantes", + "Universidad Europea de Valencia", + "Universidad Europea Del Atlántico", + "Universidad Francisco de Vitoria", + "Universidad Internacional de Cataluña", + "Universidad Internacional de La Rioja", + "Universidad Internacional de Valencia", + "Universidad Internacional Villanueva", + "Universidad Isabel I de Castilla", + "Universidad Jaume I de Castellón", + "Universidad Loyola Andalucia", + "Universidad Miguel Hernández de Elche", + "Universidad Nacional de Educación A Distancia (UNED)", + "Universidad Oberta de Catalunya", + "Universidad Pablo de Olavide", + "Universidad Politécnica de Cartagena", + "Universidad Politécnica de Catalunya", + "Universidad Politécnica de Madrid", + "Universidad Politécnica de Valencia", + "Universidad Pompeu Fabra", + "Universidad Pontificia Comillas", + "Universidad Pontificia de Salamanca", + "Universidad Pública de Navarra", + "Universidad Ramon Llull", + "Universidad Rey Juan Carlos", + "Universidad Rovira I Virgili", + "Universidad San Jorge", + "Universidad San Pablo-Ceu", + "Universidade de Santiago de Compostela", + "Universitat Abat Oliba Ceu", + "Universitat de Valencia (Estudi General)", + "Universitat Jaume I", + "UPF Barcelona School Of Management" +].each do |center_name| + # rubocop:disable Rails/IndexWith + Decidim::Centers::Center.create(title: Decidim.available_locales.to_h { |locale| [locale, center_name] }, organization: Decidim::Organization.first) + # rubocop:enable Rails/IndexWith +end diff --git a/spec/factories.rb b/spec/factories.rb index 0e6d87b..6b2b635 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true require "decidim/core/test/factories" +require "decidim/centers/test/factories" diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb new file mode 100644 index 0000000..71b521e --- /dev/null +++ b/spec/lib/overrides_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require "spec_helper" + +# We make sure that the checksum of the file overriden is the same +# as the expected. If this test fails, it means that the overriden +# file should be updated to match any change/bug fix introduced in the core +checksums = [ + { + package: "decidim-centers", + files: { + "/app/forms/concerns/decidim/centers/account_form_override.rb" => "e68397eccf208adef7c77fcfb679d8cf" + } + }, + { + package: "decidim-extra_user_fields", + files: { + "/app/forms/concerns/decidim/extra_user_fields/forms_definitions.rb" => "b59f5bf2a48e27213a8cacf22aaf6723" + } + } +] + +describe "Overriden files", type: :view do + checksums.each do |item| + # rubocop:disable Rails/DynamicFindBy + spec = ::Gem::Specification.find_by_name(item[:package]) + # rubocop:enable Rails/DynamicFindBy + item[:files].each do |file, signature| + it "#{spec.gem_dir}#{file} matches checksum" do + expect(md5("#{spec.gem_dir}#{file}")).to eq(signature) + end + end + end + + private + + def md5(file) + Digest::MD5.hexdigest(File.read(file)) + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9afc3d1..e3250f9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -10,17 +10,18 @@ require "rspec/rails" require "decidim/dev" -require "simplecov" -SimpleCov.start "rails" + +Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "..")) + +require "decidim/dev/test/base_spec_helper" +SimpleCov.start "rails" if ENV["SIMPLECOV"] if ENV["CODECOV"] require "codecov" SimpleCov.formatter = SimpleCov::Formatter::Codecov end -Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "..")) - -require "decidim/dev/test/base_spec_helper" +require "support/database_cleaner" # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 0000000..d519216 --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.before(:suite) do + DatabaseCleaner.clean_with :truncation, except: %w(ar_internal_metadata) + end + + config.before do + DatabaseCleaner.strategy = :transaction + end + + config.before do + DatabaseCleaner.start + end + + config.after do + DatabaseCleaner.clean + end +end diff --git a/spec/system/account_spec.rb b/spec/system/account_spec.rb new file mode 100644 index 0000000..cd47a8d --- /dev/null +++ b/spec/system/account_spec.rb @@ -0,0 +1,289 @@ +# frozen_string_literal: true + +require "rails_helper" +require "decidim/centers/test/shared_contexts" + +describe "Account", type: :system do + let(:organization) { create :organization, extra_user_fields: { "enabled" => true, "document_id" => { "enabled" => true } } } + let(:user) { create :user, :confirmed, organization: organization } + let!(:center) { create :center, organization: organization } + let!(:other_center) { create :center, organization: organization } + let!(:scope) { create :scope, organization: organization } + let!(:other_scope) { create :scope, organization: organization } + let(:document_id) { Faker::IDNumber.spanish_citizen_number } + let(:other_document_id) { Faker::IDNumber.spanish_citizen_number } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + end + + shared_context "when visiting account path" do + before do + visit decidim.account_path + end + end + + shared_context "with authorization" do + let!(:authorization) { create :authorization, name: "center", user: user, metadata: { centers: [center.id], scopes: [scope&.id].compact } } + end + + shared_context "with user with center" do + let!(:center_user) { create :center_user, center: center, user: user } + end + + shared_context "with user with scope" do + let!(:scope_user) { create :scope_user, scope: scope, user: user } + end + + shared_context "with user with document id" do + let(:user) { create :user, :confirmed, organization: organization, extended_data: { document_id: document_id } } + end + + shared_examples_for "user without center changes the center" do + include_context "when visiting account path" + + it "shows an empty value on the center input" do + expect(find("#user_center_id").value).to eq("") + end + + include_examples "user changes the center" + end + + shared_examples_for "user with center changes the center" do + include_context "when visiting account path" + + it "has an authorization for the center" do + check_center_authorization(Decidim::Authorization.last, user, center) + end + + it "shows the current center on the center input" do + expect(find("#user_center_id").value).to eq(center.id.to_s) + end + + include_examples "user changes the center" + end + + shared_examples_for "user cannot be saved without changes" do + include_context "when visiting account path" + + it "cannot save without selecting center" do + within "form.edit_user" do + find("*[type=submit]").click + end + + expect(page).to have_content("There's an error in this field").or have_content("can't be blank") + end + end + + shared_examples_for "user changes the center" do + it "can update the center and changes the authorization" do + within "form.edit_user" do + within "#user_center_id" do + find("option[value='#{other_center.id}']").click + end + + find("*[type=submit]").click + end + + within_flash_messages do + expect(page).to have_content("successfully") + end + + expect(find("#user_center_id").value).to eq(other_center.id.to_s) + + perform_enqueued_jobs + check_center_authorization(Decidim::Authorization.last, user, other_center) + end + end + + shared_examples_for "user without scope changes the scope" do + include_context "when visiting account path" + + it "shows an empty value on the scope input" do + within "#user_scope_id" do + expect(page).to have_content("Global scope") + end + end + + include_examples "user changes the scope", false + end + + shared_examples_for "user with scope changes the scope" do + include_context "when visiting account path" + + it "has an authorization for the center and the scope" do + check_center_authorization(Decidim::Authorization.last, user, center, scope) + end + + it "shows the current scope on the scope input" do + within "#user_scope_id" do + expect(page).to have_content(scope.name["en"]) + end + end + + include_examples "user changes the scope", true + end + + shared_examples_for "user changes the scope" do |has_scope| + it "can update the scope and changes the authorization" do + within "form.edit_user" do + if has_scope + scope_repick :user_scope_id, scope, other_scope + else + scope_pick select_data_picker(:user_scope_id), other_scope + end + + find("*[type=submit]").click + end + + within_flash_messages do + expect(page).to have_content("successfully") + end + + within "#user_scope_id .picker-values" do + expect(page).to have_content(other_scope.name["en"]) + end + + perform_enqueued_jobs + check_center_authorization(Decidim::Authorization.last, user, center, other_scope) + end + end + + shared_examples_for "user without document id changes the document id" do + include_context "when visiting account path" + + it "shows an empty value on the document input" do + expect(find("#user_document_id").value).to eq("") + end + + include_examples "user changes the document id" + end + + shared_examples_for "user with document id changes the document id" do + include_context "when visiting account path" + + it "has a document id" do + expect(user.extended_data["document_id"]).to eq(document_id) + end + + it "shows the current document id on the document id input" do + expect(find("#user_document_id").value).to eq(document_id) + end + + include_examples "user changes the document id" + end + + shared_examples_for "user changes the document id" do + it "can update the document id" do + within "form.edit_user" do + fill_in :user_document_id, with: other_document_id, currently_with: user.extended_data["document_id"] || "" + + find("*[type=submit]").click + end + + within_flash_messages do + expect(page).to have_content("successfully") + end + + expect(find("#user_document_id").value).to eq(other_document_id) + end + end + + context "when the user doesn't have scope" do + context "when the user doesn't have center" do + context "when the user doesn't have document id" do + include_examples "user cannot be saved without changes" + end + + context "when the user has document id" do + include_context "with user with document id" + + include_examples "user cannot be saved without changes" + end + end + + context "when the user has center" do + include_context "with user with center" + include_context "with authorization" + + context "when the user doesn't have document id" do + include_examples "user cannot be saved without changes" + end + + context "when the user has document id" do + include_context "with user with document id" + + include_examples "user cannot be saved without changes" + end + end + end + + context "when the user has scope" do + include_context "with user with scope" + + context "when the user doesn't have center" do + context "when the user doesn't have document id" do + include_examples "user cannot be saved without changes" + end + + context "when the user has document id" do + include_context "with user with document id" + + include_examples "user cannot be saved without changes" + end + end + + context "when the user has center" do + include_context "with user with center" + include_context "with authorization" + + context "when the user doesn't have document id" do + include_examples "user cannot be saved without changes" + include_examples "user without document id changes the document id" + end + + context "when the user has document id" do + include_context "with user with document id" + + include_examples "user with document id changes the document id" + end + end + end + + context "when the user has document id" do + include_context "with user with document id" + + context "when the user has center" do + include_context "with user with center" + include_context "with authorization" + + context "when the user doesn't have scope" do + include_examples "user cannot be saved without changes" + include_examples "user without scope changes the scope" + end + + context "when the user has scope" do + include_context "with user with scope" + + include_examples "user with scope changes the scope" + end + end + + context "when the user has scope" do + include_context "with user with scope" + include_context "with authorization" + + context "when the user doesn't have center" do + include_examples "user cannot be saved without changes" + include_examples "user without center changes the center" + end + + context "when the user has center" do + include_context "with user with center" + + include_examples "user with center changes the center" + end + end + end +end diff --git a/spec/system/registration_spec.rb b/spec/system/registration_spec.rb new file mode 100644 index 0000000..c81db82 --- /dev/null +++ b/spec/system/registration_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require "rails_helper" +require "decidim/centers/test/shared_contexts" + +describe "Registration spec", type: :system do + let(:organization) { create :organization, extra_user_fields: { "enabled" => true, "document_id" => { "enabled" => true } } } + let(:email) { Faker::Internet.email } + let(:name) { Faker::Name.name } + let(:nickname) { Faker::Internet.username(separators: []) } + let(:password) { Faker::Internet.password(min_length: 17) } + let!(:center) { create :center, organization: organization } + let!(:other_center) { create :center, organization: organization } + let!(:scope) { create :scope, organization: organization } + let!(:other_scope) { create :scope, organization: organization } + let(:document_id) { Faker::IDNumber.spanish_citizen_number } + + before do + switch_to_host(organization.host) + visit decidim.new_user_registration_path + end + + it "contains custom fields as mandatory" do + within ".card__centers" do + expect(page).to have_content("Center") + end + within ".card__centers label[for='registration_user_center_id']" do + expect(page).to have_css("span.label-required") + end + within all(".card__centers label").last do + expect(page).to have_css("span.label-required") + end + + within ".card__centers" do + expect(page).to have_content("Scope") + end + + expect(page).to have_content("Document ID") + + within ".card__extra_user_fields label[for='registration_user_document_id']" do + expect(page).to have_css("span.label-required") + end + end + + it "allows to create a new account and authorizes the user with the center and scope provided" do + fill_in :registration_user_name, with: name + fill_in :registration_user_nickname, with: nickname + fill_in :registration_user_email, with: email + fill_in :registration_user_password, with: password + fill_in :registration_user_password_confirmation, with: password + fill_in :registration_user_document_id, with: document_id + + within ".card__centers" do + within "#registration_user_center_id" do + find("option[value='#{center.id}']").click + end + + scope_pick select_data_picker(:registration_user), scope + end + + page.check("registration_user_newsletter") + page.check("registration_user_tos_agreement") + + within "form.new_user" do + find("*[type=submit]").click + end + + expect(page).to have_content("message with a confirmation link has been sent") + expect(Decidim::User.last.center).to eq(center) + expect(Decidim::User.last.scope).to eq(scope) + expect(Decidim::User.last.extended_data["document_id"]).to eq(document_id) + + perform_enqueued_jobs + check_center_authorization(Decidim::Authorization.last, Decidim::User.last, center, scope) + end +end