Skip to content

Commit

Permalink
feat: Addition of private proposal fields (#43)
Browse files Browse the repository at this point in the history
* feat: Addition of Private Proposal Fields

* fix: Extend the serializer to fix the export

* merge: Add conflicted files

* fix: Fix the locks
  • Loading branch information
AyakorK authored Jul 22, 2024
1 parent b4ac6d6 commit de74d19
Show file tree
Hide file tree
Showing 11 changed files with 4,465 additions and 3,093 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gem "decidim", "~> #{DECIDIM_VERSION}.0"

# External Decidim gems
gem "decidim-cache_cleaner"
gem "decidim-decidim_awesome", "~> 0.9.1"
gem "decidim-decidim_awesome", git: "https://github.com/octree-gva/decidim-module-decidim_awesome.git", branch: "feat/awesome_decidim_private_fields"
gem "decidim-friendly_signup", git: "https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git"
gem "decidim-spam_detection"
gem "decidim-term_customizer", git: "https://github.com/opensourcepolitics/decidim-module-term_customizer.git", branch: "fix/multi-threading-compliant"
Expand Down
16 changes: 11 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ GIT
decidim-friendly_signup (0.4.5)
decidim-core (~> 0.27)

GIT
remote: https://github.com/octree-gva/decidim-module-decidim_awesome.git
revision: afa824a79faa42f99eee5c0dcb4944e3a78b4a1d
branch: feat/awesome_decidim_private_fields
specs:
decidim-decidim_awesome (0.9.2)
decidim-admin (>= 0.26.0, < 0.28)
decidim-core (>= 0.26.0, < 0.28)
sassc (~> 2.3)

GIT
remote: https://github.com/opensourcepolitics/decidim-module-term_customizer.git
revision: 8a6b73e58fbdd7f38daf983a310d37c510ec9baf
Expand Down Expand Up @@ -304,10 +314,6 @@ GEM
decidim-debates (0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-decidim_awesome (0.9.3)
decidim-admin (>= 0.26.0, < 0.28)
decidim-core (>= 0.26.0, < 0.28)
sassc (~> 2.3)
decidim-dev (0.27.5)
axe-core-rspec (~> 4.1.0)
byebug (~> 11.0)
Expand Down Expand Up @@ -943,7 +949,7 @@ DEPENDENCIES
dalli
decidim (~> 0.27.0)
decidim-cache_cleaner
decidim-decidim_awesome (~> 0.9.1)
decidim-decidim_awesome!
decidim-dev (~> 0.27.0)
decidim-friendly_signup!
decidim-spam_detection
Expand Down
7 changes: 7 additions & 0 deletions app/views/layouts/decidim/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<%= invisible_captcha_styles %>
<%= organization_colors %>
<%= javascript_pack_tag "decidim_core", defer: false %>
<%= javascript_pack_tag "decidim_admin", defer: false %>
<%= render partial: "layouts/decidim/head_extra" %>
<%== current_organization.header_snippets if Decidim.enable_html_header_snippets %>
Expand All @@ -34,3 +36,8 @@
<%= stylesheet_pack_tag "decidim_decidim_awesome", media: "all" %>
<%= render(partial: "layouts/decidim/decidim_awesome/custom_styles") if awesome_custom_styles %>
<%= javascript_pack_tag "decidim_decidim_awesome_custom_fields" if awesome_proposal_custom_fields %>
<%= render partial: "layouts/decidim/decidim_awesome/awesome_config" %>

9 changes: 6 additions & 3 deletions app/views/layouts/decidim/admin/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
<%= favicon %>
<%= apple_favicon %>
<%= stylesheet_pack_tag "decidim_admin", media: "all" %>
<%= javascript_pack_tag "decidim_admin", defer: false %>
<%= organization_colors %>
<%= snippets.display(:head) %>
<%= render partial: "layouts/decidim/decidim_awesome/awesome_config" %>
<%= javascript_pack_tag "decidim_decidim_awesome" %>
<%= javascript_pack_tag "decidim_decidim_awesome_custom_fields" if awesome_proposal_custom_fields %>
<%= javascript_pack_tag "decidim_admin_decidim_awesome", defer: false %>
<%= javascript_pack_tag "decidim_decidim_awesome_custom_fields", defer: false %>
<%= javascript_pack_tag "decidim_admin_decidim_awesome_custom_fields", defer: false %>
<%= stylesheet_pack_tag "decidim_admin_decidim_awesome", media: "all" %>
3 changes: 3 additions & 0 deletions config/initializers/extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require "extends/serializers/decidim/decidim_awesome/private_proposal_serializer_extends"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# This migration comes from decidim_decidim_awesome (originally 20230309124413)

class CreatePrivateProposalFields < ActiveRecord::Migration[5.2]
def change
create_table :decidim_awesome_private_proposal_fields do |t|
t.text :private_body, default: "<xml></xml>"

t.references :proposal, null: false, foreign_key: { to_table: :decidim_proposals_proposals }, index: { name: "decidim_awesome_private_proposal_fields_idx" }
t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_07_02_145155) do
ActiveRecord::Schema.define(version: 2024_07_15_133031) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -324,6 +324,14 @@
t.index ["decidim_organization_id"], name: "decidim_awesome_editor_images_constraint_organization"
end

create_table "decidim_awesome_private_proposal_fields", force: :cascade do |t|
t.text "private_body", default: "<xml></xml>"
t.bigint "proposal_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["proposal_id"], name: "decidim_awesome_private_proposal_fields_idx"
end

create_table "decidim_blogs_posts", id: :serial, force: :cascade do |t|
t.jsonb "title"
t.jsonb "body"
Expand Down Expand Up @@ -1809,6 +1817,7 @@
add_foreign_key "decidim_awesome_config_constraints", "decidim_awesome_config"
add_foreign_key "decidim_awesome_editor_images", "decidim_organizations"
add_foreign_key "decidim_awesome_editor_images", "decidim_users", column: "decidim_author_id"
add_foreign_key "decidim_awesome_private_proposal_fields", "decidim_proposals_proposals", column: "proposal_id"
add_foreign_key "decidim_budgets_budgets", "decidim_scopes"
add_foreign_key "decidim_budgets_orders", "decidim_budgets_budgets"
add_foreign_key "decidim_budgets_projects", "decidim_budgets_budgets"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module PrivateProposalSerializerExtends
def serialize_private_custom_fields(payload)
private_custom_fields = Decidim::DecidimAwesome::CustomFields.new(awesome_private_proposal_custom_fields)
return payload if private_custom_fields.blank?

private_body = proposal.awesome_private_proposal_field.present? ? proposal.awesome_private_proposal_field.private_body : ""
fields_entries(private_custom_fields, private_body) do |key, value|
payload["secret/#{key}".to_sym] = value
end

payload
end
end

Decidim::DecidimAwesome::PrivateProposalSerializer.class_eval do
prepend(PrivateProposalSerializerExtends)
end
Loading

0 comments on commit de74d19

Please sign in to comment.