-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Triplicate conferences hacking the hashtag (#7)
* add custom menu items * controller override, add routes * change add item menu * Apply suggestions from code review Co-authored-by: Ivan Vergés <ivan@pokecode.net> * add options if to add_item * add rspec, refactoring * fix lint * promoted conferences override, add tests * remove global config from secret, refactoring controller's methods * change tests * add controller spec * fix robocop * move initializers and overrides to initializers folder * refactoring model and tests * Update config/locales/en.yml Co-authored-by: Ivan Vergés <ivan@pokecode.net> * fix initializers * fix initialize * gitignore * add actions * add config --------- Co-authored-by: Ivan Vergés <ivan@pokecode.net>
- Loading branch information
1 parent
de4ba74
commit 21226b7
Showing
23 changed files
with
714 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- staging | ||
pull_request: | ||
|
||
env: | ||
RUBY_VERSION: 3.0.6 | ||
NODE_VERSION: 16.9.1 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:11 | ||
ports: | ||
- 5432:5432 | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_USERNAME: postgres | ||
DATABASE_PASSWORD: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ env.RUBY_VERSION }} | ||
bundler-cache: true | ||
|
||
- run: bundle exec rubocop -P | ||
name: Lint Ruby files | ||
|
||
- name: Setup & create Database | ||
run: | | ||
bundle exec rails db:create db:schema:load | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_USERNAME: postgres | ||
DATABASE_PASSWORD: postgres | ||
|
||
- name: Precompile assets | ||
run: | | ||
npm ci | ||
bundle exec rake assets:precompile | ||
env: | ||
RAILS_ENV: production | ||
DB_ADAPTER: nulldb | ||
SECRET_KEY_BASE: 1234567890 | ||
|
||
- name: Run RSpec | ||
run: SIMPLECOV=1 CODECOV=1 bundle exec rspec | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_USERNAME: postgres | ||
DATABASE_PASSWORD: postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,5 @@ yarn-debug.log* | |
.rbenv-vars | ||
public/decidim-packs | ||
public/sw.js* | ||
coverage/* | ||
.rspec-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -872,6 +872,7 @@ GEM | |
|
||
PLATFORMS | ||
x86_64-darwin-22 | ||
x86_64-darwin-23 | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
|
60 changes: 60 additions & 0 deletions
60
app/controllers/concerns/conferences_controller_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConferencesControllerOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def hashtag_for_current_url | ||
@hashtag_for_current_url ||= Rails.application.secrets.custom_conference_types.find do |item| | ||
item[:url] == request.path | ||
end&.dig(:hashtag) | ||
end | ||
|
||
def published_conferences | ||
@published_conferences ||= conferences_query(Decidim::Conferences::OrganizationPublishedConferences) | ||
end | ||
|
||
def conferences | ||
@conferences ||= conferences_query(Decidim::Conferences::OrganizationPrioritizedConferences) | ||
end | ||
|
||
alias_method :collection, :conferences | ||
|
||
def promoted_conferences | ||
@promoted_conferences ||= hashtag_for_current_url ? promoted_filtered_by_hashtag(conferences) : promoted_conferences_without_custom_hashtag(Decidim::Conference.promoted) | ||
end | ||
|
||
private | ||
|
||
def custom_hashtags | ||
@custom_hashtags ||= Rails.application.secrets.custom_conference_types.map { |item| item[:hashtag] } | ||
end | ||
|
||
def conferences_query(conference_class) | ||
conferences = conference_class.new(current_organization, current_user) | ||
hashtag_for_current_url ? conferences_with_custom_hashtag_filter(conferences) : conferences_without_custom_hashtag(conferences) | ||
end | ||
|
||
def conferences_with_custom_hashtag_filter(conferences) | ||
conferences.query.merge(Decidim::Conference.filtered_by_hashtag(hashtag_for_current_url)) | ||
end | ||
|
||
def conferences_without_custom_hashtag(conferences) | ||
conferences.query.to_a.reject do |conference| | ||
conference_hashtags = conference.hashtag.split | ||
(conference_hashtags & custom_hashtags).any? | ||
end | ||
end | ||
|
||
def promoted_filtered_by_hashtag(conferences) | ||
conferences.merge(Decidim::Conference.promoted.filtered_by_hashtag(hashtag_for_current_url)) | ||
end | ||
|
||
def promoted_conferences_without_custom_hashtag(conferences) | ||
conferences.select do |conference| | ||
conference_hashtags = conference.hashtag.split | ||
(conference_hashtags & custom_hashtags).empty? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConferenceOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def self.filtered_by_hashtag(hashtag) | ||
where("(CONCAT(' ', hashtag, ' ') ILIKE ?) OR (CONCAT(' ', hashtag, ' ') ILIKE ?)", "% #{hashtag} %", "% ##{hashtag} %") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
# extra menus defined in secrets.yml | ||
Decidim.menu :menu do |menu| | ||
custom_conference_types = Rails.application.secrets.custom_conference_types || [] | ||
custom_conference_types.each do |item| | ||
hashtag = item[:hashtag] | ||
options = {} | ||
options[:position] = item[:position].to_i if item[:position] | ||
options[:active] = item[:active].to_sym if item[:active] | ||
options[:icon_name] = item[:icon_name].to_s if item[:icon_name] | ||
options[:if] = Decidim::Conference.exists?(Decidim::Conference.filtered_by_hashtag(hashtag)) | ||
menu.add_item item[:key], I18n.t(item[:key], scope: "decidim.conferences.custom_conference_types"), item[:url], options | ||
end | ||
end | ||
|
||
Rails.application.config.to_prepare do | ||
Decidim::StatisticCell.include(Decidim::StatisticCellOverride) | ||
Decidim::Conference.include(ConferenceOverride) | ||
end | ||
|
||
Rails.application.config.after_initialize do | ||
Decidim::Conferences::ConferencesController.include(ConferencesControllerOverride) | ||
end | ||
|
||
Rails.application.config do | ||
initializer "capitalitat.homepage_content_blocks" do | ||
config.to_prepare do | ||
Decidim.content_blocks.register(:homepage, :active_processes) do |content_block| | ||
content_block.cell = "decidim/content_blocks/active_processes" | ||
content_block.settings_form_cell = "decidim/content_blocks/active_processes_settings_form" | ||
content_block.public_name_key = "decidim.content_blocks.active_processes.name" | ||
|
||
content_block.settings do |settings| | ||
settings.attribute :button_text, type: :text, translated: true | ||
settings.attribute :button_url, type: :text | ||
|
||
(1..3).each do |i| | ||
settings.attribute "link_url_#{i}".to_sym, type: :text | ||
settings.attribute "link_text_#{i}".to_sym, type: :text, translated: true | ||
settings.attribute "text_color_#{i}".to_sym, type: :string | ||
end | ||
end | ||
|
||
(1..3).each do |i| | ||
content_block.images << { | ||
name: "image_#{i}".to_sym, | ||
uploader: "Decidim::ActiveProcessesImageUploader" | ||
} | ||
end | ||
|
||
content_block.default! | ||
end | ||
|
||
Decidim.content_blocks.register(:homepage, :extended_hero) do |content_block| | ||
content_block.cell = "decidim/content_blocks/extended_hero" | ||
content_block.settings_form_cell = "decidim/content_blocks/extended_hero_settings_form" | ||
content_block.public_name_key = "decidim.content_blocks.extended_hero.name" | ||
|
||
content_block.settings do |settings| | ||
settings.attribute :welcome_title, type: :text, translated: true | ||
settings.attribute :subtitle, type: :text, translated: true | ||
end | ||
|
||
content_block.images = [ | ||
{ | ||
name: :background_image, | ||
uploader: "Decidim::HomepageImageUploader" | ||
} | ||
] | ||
|
||
content_block.default! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.