diff --git a/app/controllers/admin/budget_phases_controller.rb b/app/controllers/admin/budget_phases_controller.rb index 3dd08675b..0979e852f 100644 --- a/app/controllers/admin/budget_phases_controller.rb +++ b/app/controllers/admin/budget_phases_controller.rb @@ -17,13 +17,13 @@ class Admin::BudgetPhasesController < Admin::BaseController private - def load_phase - @phase = Budget::Phase.find(params[:id]) - end + def load_phase + @phase = Budget::Phase.find(params[:id]) + end - def budget_phase_params - valid_attributes = [:starts_at, :ends_at, :enabled] - params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase)) - end + def budget_phase_params + valid_attributes = [:starts_at, :ends_at, :enabled] + params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase)) + end end diff --git a/app/controllers/admin/debates_controller.rb b/app/controllers/admin/debates_controller.rb index 44ac33926..05fee888a 100644 --- a/app/controllers/admin/debates_controller.rb +++ b/app/controllers/admin/debates_controller.rb @@ -13,8 +13,8 @@ class Admin::DebatesController < Admin::BaseController private - def resource_model - Debate - end + def resource_model + Debate + end end diff --git a/app/controllers/admin/emails_download_controller.rb b/app/controllers/admin/emails_download_controller.rb index 434dc071f..3bafa7668 100644 --- a/app/controllers/admin/emails_download_controller.rb +++ b/app/controllers/admin/emails_download_controller.rb @@ -12,7 +12,7 @@ class Admin::EmailsDownloadController < Admin::BaseController private - def users_segment_emails_csv(users_segment) - UserSegments.user_segment_emails(users_segment).join(",") - end + def users_segment_emails_csv(users_segment) + UserSegments.user_segment_emails(users_segment).join(",") + end end diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb index 50a433df5..4c70827d4 100644 --- a/app/controllers/admin/homepage_controller.rb +++ b/app/controllers/admin/homepage_controller.rb @@ -9,20 +9,20 @@ class Admin::HomepageController < Admin::BaseController private - def load_header - @header = ::Widget::Card.header - end + def load_header + @header = ::Widget::Card.header + end - def load_recommendations - @recommendations = Setting.where(key: "feature.user.recommendations").first - end + def load_recommendations + @recommendations = Setting.where(key: "feature.user.recommendations").first + end - def load_cards - @cards = ::Widget::Card.body - end + def load_cards + @cards = ::Widget::Card.body + end - def load_feeds - @feeds = Widget::Feed.order("created_at") - end + def load_feeds + @feeds = Widget::Feed.order("created_at") + end end diff --git a/app/controllers/admin/milestone_statuses_controller.rb b/app/controllers/admin/milestone_statuses_controller.rb index b7cbb7b4d..f365629c0 100644 --- a/app/controllers/admin/milestone_statuses_controller.rb +++ b/app/controllers/admin/milestone_statuses_controller.rb @@ -41,11 +41,11 @@ class Admin::MilestoneStatusesController < Admin::BaseController private - def load_status - @status = Milestone::Status.find(params[:id]) - end + def load_status + @status = Milestone::Status.find(params[:id]) + end - def status_params - params.require(:milestone_status).permit([:name, :description]) - end + def status_params + params.require(:milestone_status).permit([:name, :description]) + end end diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb index 040272fc5..ff3996322 100644 --- a/app/controllers/communities_controller.rb +++ b/app/controllers/communities_controller.rb @@ -13,27 +13,27 @@ class CommunitiesController < ApplicationController private - def set_order - @order = valid_order? ? params[:order] : "newest" - end + def set_order + @order = valid_order? ? params[:order] : "newest" + end - def set_community - @community = Community.find(params[:id]) - end + def set_community + @community = Community.find(params[:id]) + end - def load_topics - @topics = @community.topics.send("sort_by_#{@order}").page(params[:page]) - end + def load_topics + @topics = @community.topics.send("sort_by_#{@order}").page(params[:page]) + end - def load_participants - @participants = @community.participants - end + def load_participants + @participants = @community.participants + end - def valid_order? - params[:order].present? && TOPIC_ORDERS.include?(params[:order]) - end + def valid_order? + params[:order].present? && TOPIC_ORDERS.include?(params[:order]) + end - def communitable_exists? - @community.proposal.present? || @community.investment.present? - end + def communitable_exists? + @community.proposal.present? || @community.investment.present? + end end diff --git a/app/controllers/direct_uploads_controller.rb b/app/controllers/direct_uploads_controller.rb index a2e089cdd..5b19977f7 100644 --- a/app/controllers/direct_uploads_controller.rb +++ b/app/controllers/direct_uploads_controller.rb @@ -39,10 +39,10 @@ class DirectUploadsController < ApplicationController private - def direct_upload_params - params.require(:direct_upload) - .permit(:resource, :resource_type, :resource_id, :resource_relation, - :attachment, :cached_attachment, attachment_attributes: []) - end + def direct_upload_params + params.require(:direct_upload) + .permit(:resource, :resource_type, :resource_id, :resource_relation, + :attachment, :cached_attachment, attachment_attributes: []) + end end diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 78185b5b4..4331a52eb 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -17,12 +17,12 @@ class FollowsController < ApplicationController private - def find_followable - params[:followable_type].constantize.find(params[:followable_id]) - end + def find_followable + params[:followable_type].constantize.find(params[:followable_id]) + end - def followable_translation_key(followable) - followable.class.name.parameterize(separator: "_") - end + def followable_translation_key(followable) + followable.class.name.parameterize(separator: "_") + end end diff --git a/app/controllers/installation_controller.rb b/app/controllers/installation_controller.rb index 79c244e5e..4a9174f53 100644 --- a/app/controllers/installation_controller.rb +++ b/app/controllers/installation_controller.rb @@ -10,14 +10,14 @@ class InstallationController < ApplicationController private - def consul_installation_details - { - release: "1.0.0" - }.merge(features: settings_feature_flags) - end + def consul_installation_details + { + release: "1.0.0" + }.merge(features: settings_feature_flags) + end - def settings_feature_flags - Setting.where("key LIKE 'feature.%'").each_with_object({}) { |x, n| n[x.key.remove("feature.")] = x.value } - end + def settings_feature_flags + Setting.where("key LIKE 'feature.%'").each_with_object({}) { |x, n| n[x.key.remove("feature.")] = x.value } + end end diff --git a/app/controllers/officing/ballot_sheets_controller.rb b/app/controllers/officing/ballot_sheets_controller.rb index 9a4f08401..835e8a23b 100644 --- a/app/controllers/officing/ballot_sheets_controller.rb +++ b/app/controllers/officing/ballot_sheets_controller.rb @@ -32,39 +32,39 @@ class Officing::BallotSheetsController < Officing::BaseController private - def namespace - "officing" - end + def namespace + "officing" + end - def load_poll - @poll = Poll.find(params[:poll_id]) - end + def load_poll + @poll = Poll.find(params[:poll_id]) + end - def load_ballot_sheets - @ballot_sheets = Poll::BallotSheet.where(poll: @poll) - end + def load_ballot_sheets + @ballot_sheets = Poll::BallotSheet.where(poll: @poll) + end - def load_ballot_sheet - @ballot_sheet = Poll::BallotSheet.find(params[:id]) - end + def load_ballot_sheet + @ballot_sheet = Poll::BallotSheet.find(params[:id]) + end - def load_officer_assignments - @officer_assignments = ::Poll::OfficerAssignment. - includes(booth_assignment: [:booth]). - joins(:booth_assignment). - final. - where(id: current_user.poll_officer.officer_assignment_ids). - where("poll_booth_assignments.poll_id = ?", @poll.id). - where(date: Date.current) - end + def load_officer_assignments + @officer_assignments = ::Poll::OfficerAssignment. + includes(booth_assignment: [:booth]). + joins(:booth_assignment). + final. + where(id: current_user.poll_officer.officer_assignment_ids). + where("poll_booth_assignments.poll_id = ?", @poll.id). + where(date: Date.current) + end - def load_officer_assignment - @officer_assignment = current_user.poll_officer.officer_assignments.final - .find_by(id: ballot_sheet_params[:officer_assignment_id]) - end + def load_officer_assignment + @officer_assignment = current_user.poll_officer.officer_assignments.final + .find_by(id: ballot_sheet_params[:officer_assignment_id]) + end - def ballot_sheet_params - params.permit(:data, :poll_id, :officer_assignment_id) - end + def ballot_sheet_params + params.permit(:data, :poll_id, :officer_assignment_id) + end end diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index 584c92de0..6da408e67 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -13,12 +13,12 @@ class Officing::BoothController < Officing::BaseController private - def booth_params - params.require(:booth).permit(:id) - end + def booth_params + params.require(:booth).permit(:id) + end - def set_booth(booth) - session[:booth_id] = booth.id - end + def set_booth(booth) + session[:booth_id] = booth.id + end end diff --git a/app/controllers/related_contents_controller.rb b/app/controllers/related_contents_controller.rb index ae18564b9..a36ba23f9 100644 --- a/app/controllers/related_contents_controller.rb +++ b/app/controllers/related_contents_controller.rb @@ -30,32 +30,32 @@ class RelatedContentsController < ApplicationController private - def score(action) - @related = RelatedContent.find params[:id] - @related.send("score_#{action}", current_user) + def score(action) + @related = RelatedContent.find params[:id] + @related.send("score_#{action}", current_user) - render template: "relationable/_refresh_score_actions" - end - - def valid_url? - params[:url].start_with?(Setting["url"]) - end - - def relationable_object - @relationable = params[:relationable_klass].singularize.camelize.constantize.find_by(id: params[:relationable_id]) - end - - def related_object - if valid_url? - url = params[:url] - - related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//) - .flatten.map { |i| i.to_s.singularize.camelize }.join("::") - related_id = url.match(/\/(\d+)(?!.*\/\d)/)[1] - - @related = related_klass.singularize.camelize.constantize.find_by(id: related_id) + render template: "relationable/_refresh_score_actions" + end + + def valid_url? + params[:url].start_with?(Setting["url"]) + end + + def relationable_object + @relationable = params[:relationable_klass].singularize.camelize.constantize.find_by(id: params[:relationable_id]) + end + + def related_object + if valid_url? + url = params[:url] + + related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//) + .flatten.map { |i| i.to_s.singularize.camelize }.join("::") + related_id = url.match(/\/(\d+)(?!.*\/\d)/)[1] + + @related = related_klass.singularize.camelize.constantize.find_by(id: related_id) + end + rescue + nil end - rescue - nil - end end diff --git a/app/controllers/sandbox_controller.rb b/app/controllers/sandbox_controller.rb index ec813c49f..ca18b4588 100644 --- a/app/controllers/sandbox_controller.rb +++ b/app/controllers/sandbox_controller.rb @@ -31,15 +31,15 @@ class SandboxController < ApplicationController private - def set_layout - if params[:template] && params[:template].split("_").first == "admin" - "admin" - else - "application" + def set_layout + if params[:template] && params[:template].split("_").first == "admin" + "admin" + else + "application" + end end - end - def namespace - "admin" - end + def namespace + "admin" + end end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 1c7b4732e..7c75e2fa0 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -46,15 +46,15 @@ class TopicsController < ApplicationController private - def topic_params - params.require(:topic).permit(:title, :description) - end + def topic_params + params.require(:topic).permit(:title, :description) + end - def load_community - @community = Community.find(params[:community_id]) - end + def load_community + @community = Community.find(params[:community_id]) + end - def load_topic - @topic = Topic.find(params[:id]) - end + def load_topic + @topic = Topic.find(params[:id]) + end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index b6bb138c4..fee05dfd1 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -33,9 +33,9 @@ class WelcomeController < ApplicationController private - def set_user_recommendations - @recommended_debates = Debate.recommendations(current_user).sort_by_recommendations.limit(3) - @recommended_proposals = Proposal.recommendations(current_user).sort_by_recommendations.limit(3) - end + def set_user_recommendations + @recommended_debates = Debate.recommendations(current_user).sort_by_recommendations.limit(3) + @recommended_proposals = Proposal.recommendations(current_user).sort_by_recommendations.limit(3) + end end diff --git a/app/helpers/flags_helper.rb b/app/helpers/flags_helper.rb index 9983b34ae..c02dcefad 100644 --- a/app/helpers/flags_helper.rb +++ b/app/helpers/flags_helper.rb @@ -10,20 +10,20 @@ module FlagsHelper private - def flagged?(flaggable) - if flaggable.is_a? Comment - @comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll" - else - Flag.flagged?(current_user, flaggable) + def flagged?(flaggable) + if flaggable.is_a? Comment + @comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll" + else + Flag.flagged?(current_user, flaggable) + end end - end - def own_flaggable?(flaggable) - if flaggable.is_a? Comment - flaggable.user_id == current_user.id - else - flaggable.author_id == current_user.id + def own_flaggable?(flaggable) + if flaggable.is_a? Comment + flaggable.user_id == current_user.id + else + flaggable.author_id == current_user.id + end end - end end diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index eeab8681a..d0f51f5f6 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -47,24 +47,24 @@ module MapLocationsHelper private - def prepare_map_settings(map_location, editable, parent_class, investments_coordinates=nil) - options = { - map: "", - map_center_latitude: map_location_latitude(map_location), - map_center_longitude: map_location_longitude(map_location), - map_zoom: map_location_zoom(map_location), - map_tiles_provider: Rails.application.secrets.map_tiles_provider, - map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, - marker_editable: editable, - marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", - latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", - longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", - zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}", - marker_investments_coordinates: investments_coordinates - } - options[:marker_latitude] = map_location.latitude if map_location.latitude.present? - options[:marker_longitude] = map_location.longitude if map_location.longitude.present? - options - end + def prepare_map_settings(map_location, editable, parent_class, investments_coordinates=nil) + options = { + map: "", + map_center_latitude: map_location_latitude(map_location), + map_center_longitude: map_location_longitude(map_location), + map_zoom: map_location_zoom(map_location), + map_tiles_provider: Rails.application.secrets.map_tiles_provider, + map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, + marker_editable: editable, + marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", + latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", + longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", + zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}", + marker_investments_coordinates: investments_coordinates + } + options[:marker_latitude] = map_location.latitude if map_location.latitude.present? + options[:marker_longitude] = map_location.longitude if map_location.longitude.present? + options + end end diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 7ea17baf2..965cbde4e 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -37,7 +37,7 @@ module ShiftsHelper private - def officer_shifts(task_id, booth) - @officer.shifts.where(task: task_id, booth: booth).map(&:date) - end + def officer_shifts(task_id, booth) + @officer.shifts.where(task: task_id, booth: booth).map(&:date) + end end diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index 9f1bb6f4e..89f2a76b6 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -5,9 +5,9 @@ class DeviseMailer < Devise::Mailer protected - def devise_mail(record, action, opts = {}) - I18n.with_locale record.locale do - super(record, action, opts) + def devise_mail(record, action, opts = {}) + I18n.with_locale record.locale do + super(record, action, opts) + end end - end end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 9defb0f15..b8c473980 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -129,16 +129,16 @@ class Mailer < ApplicationMailer private - def with_user(user, &block) - I18n.with_locale(user.locale) do - yield + def with_user(user, &block) + I18n.with_locale(user.locale) do + yield + end end - end - def prevent_delivery_to_users_without_email - if @email_to.blank? - mail.perform_deliveries = false + def prevent_delivery_to_users_without_email + if @email_to.blank? + mail.perform_deliveries = false + end end - end end diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index 5e86f3d28..3fdec9c16 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -35,14 +35,14 @@ class AdminNotification < ApplicationRecord private - def validate_segment_recipient - errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? - end - - def complete_link_url - return unless link.present? - unless self.link[/\Ahttp:\/\//] || self.link[/\Ahttps:\/\//] - self.link = "http://#{self.link}" + def validate_segment_recipient + errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? + end + + def complete_link_url + return unless link.present? + unless self.link[/\Ahttp:\/\//] || self.link[/\Ahttps:\/\//] + self.link = "http://#{self.link}" + end end - end end diff --git a/app/models/ahoy/data_source.rb b/app/models/ahoy/data_source.rb index ba8a2cf14..78c228fc4 100644 --- a/app/models/ahoy/data_source.rb +++ b/app/models/ahoy/data_source.rb @@ -32,17 +32,17 @@ module Ahoy private - def collections - @collections ||= [] - end + def collections + @collections ||= [] + end - def shared_keys - @shared_keys ||= [] - end + def shared_keys + @shared_keys ||= [] + end - def add_key(key) - shared_keys.push(key) unless shared_keys.include? key - end + def add_key(key) + shared_keys.push(key) unless shared_keys.include? key + end end diff --git a/app/models/budget.rb b/app/models/budget.rb index 5928209cf..8b8b7c6f6 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -205,28 +205,28 @@ class Budget < ApplicationRecord private - def sanitize_descriptions - s = WYSIWYGSanitizer.new - Budget::Phase::PHASE_KINDS.each do |phase| - sanitized = s.sanitize(send("description_#{phase}")) - send("description_#{phase}=", sanitized) + def sanitize_descriptions + s = WYSIWYGSanitizer.new + Budget::Phase::PHASE_KINDS.each do |phase| + sanitized = s.sanitize(send("description_#{phase}")) + send("description_#{phase}=", sanitized) + end end - end - def generate_phases - Budget::Phase::PHASE_KINDS.each do |phase| - Budget::Phase.create( - budget: self, - kind: phase, - prev_phase: phases&.last, - starts_at: phases&.last&.ends_at || Date.current, - ends_at: (phases&.last&.ends_at || Date.current) + 1.month - ) + def generate_phases + Budget::Phase::PHASE_KINDS.each do |phase| + Budget::Phase.create( + budget: self, + kind: phase, + prev_phase: phases&.last, + starts_at: phases&.last&.ends_at || Date.current, + ends_at: (phases&.last&.ends_at || Date.current) + 1.month + ) + end end - end - def generate_slug? - slug.nil? || drafting? - end + def generate_slug? + slug.nil? || drafting? + end end diff --git a/app/models/budget/group.rb b/app/models/budget/group.rb index 71eebb308..bcf217182 100644 --- a/app/models/budget/group.rb +++ b/app/models/budget/group.rb @@ -36,8 +36,8 @@ class Budget private - def generate_slug? - slug.nil? || budget.drafting? - end + def generate_slug? + slug.nil? || budget.drafting? + end end end diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 0e218d6fb..3e3d8b07d 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -56,8 +56,8 @@ class Budget private - def generate_slug? - slug.nil? || budget.drafting? - end + def generate_slug? + slug.nil? || budget.drafting? + end end end diff --git a/app/models/budget/investment/exporter.rb b/app/models/budget/investment/exporter.rb index e355600f3..cf4972198 100644 --- a/app/models/budget/investment/exporter.rb +++ b/app/models/budget/investment/exporter.rb @@ -14,54 +14,54 @@ class Budget::Investment::Exporter private - def headers - [ - I18n.t("admin.budget_investments.index.list.id"), - I18n.t("admin.budget_investments.index.list.title"), - I18n.t("admin.budget_investments.index.list.supports"), - I18n.t("admin.budget_investments.index.list.admin"), - I18n.t("admin.budget_investments.index.list.valuator"), - I18n.t("admin.budget_investments.index.list.valuation_group"), - I18n.t("admin.budget_investments.index.list.geozone"), - I18n.t("admin.budget_investments.index.list.feasibility"), - I18n.t("admin.budget_investments.index.list.valuation_finished"), - I18n.t("admin.budget_investments.index.list.selected"), - I18n.t("admin.budget_investments.index.list.visible_to_valuators"), - I18n.t("admin.budget_investments.index.list.author_username") - ] - end - - def csv_values(investment) - [ - investment.id.to_s, - investment.title, - investment.total_votes.to_s, - admin(investment), - investment.assigned_valuators || "-", - investment.assigned_valuation_groups || "-", - investment.heading.name, - price(investment), - investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"), - investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"), - investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"), - investment.author.username - ] - end - - def admin(investment) - if investment.administrator.present? - investment.administrator.name - else - I18n.t("admin.budget_investments.index.no_admin_assigned") + def headers + [ + I18n.t("admin.budget_investments.index.list.id"), + I18n.t("admin.budget_investments.index.list.title"), + I18n.t("admin.budget_investments.index.list.supports"), + I18n.t("admin.budget_investments.index.list.admin"), + I18n.t("admin.budget_investments.index.list.valuator"), + I18n.t("admin.budget_investments.index.list.valuation_group"), + I18n.t("admin.budget_investments.index.list.geozone"), + I18n.t("admin.budget_investments.index.list.feasibility"), + I18n.t("admin.budget_investments.index.list.valuation_finished"), + I18n.t("admin.budget_investments.index.list.selected"), + I18n.t("admin.budget_investments.index.list.visible_to_valuators"), + I18n.t("admin.budget_investments.index.list.author_username") + ] end - end - def price(investment) - price_string = "admin.budget_investments.index.feasibility.#{investment.feasibility}" - if investment.feasible? - "#{I18n.t(price_string)} (#{investment.formatted_price})" - else - I18n.t(price_string) + def csv_values(investment) + [ + investment.id.to_s, + investment.title, + investment.total_votes.to_s, + admin(investment), + investment.assigned_valuators || "-", + investment.assigned_valuation_groups || "-", + investment.heading.name, + price(investment), + investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"), + investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"), + investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"), + investment.author.username + ] + end + + def admin(investment) + if investment.administrator.present? + investment.administrator.name + else + I18n.t("admin.budget_investments.index.no_admin_assigned") + end + end + + def price(investment) + price_string = "admin.budget_investments.index.feasibility.#{investment.feasibility}" + if investment.feasible? + "#{I18n.t(price_string)} (#{investment.formatted_price})" + else + I18n.t(price_string) + end end - end end diff --git a/app/models/comment_notifier.rb b/app/models/comment_notifier.rb index 68b350e6b..be8a9d69a 100644 --- a/app/models/comment_notifier.rb +++ b/app/models/comment_notifier.rb @@ -11,25 +11,25 @@ class CommentNotifier private - def send_comment_email - unless @comment.commentable.is_a?(Legislation::Annotation) - Mailer.comment(@comment).deliver_later if email_on_comment? + def send_comment_email + unless @comment.commentable.is_a?(Legislation::Annotation) + Mailer.comment(@comment).deliver_later if email_on_comment? + end end - end - def send_reply_email - Mailer.reply(@comment).deliver_later if email_on_comment_reply? - end + def send_reply_email + Mailer.reply(@comment).deliver_later if email_on_comment_reply? + end - def email_on_comment? - commentable_author = @comment.commentable.author - commentable_author != @author && commentable_author.email_on_comment? - end + def email_on_comment? + commentable_author = @comment.commentable.author + commentable_author != @author && commentable_author.email_on_comment? + end - def email_on_comment_reply? - return false unless @comment.reply? - parent_author = @comment.parent.author - parent_author != @author && parent_author.email_on_comment_reply? - end + def email_on_comment_reply? + return false unless @comment.reply? + parent_author = @comment.parent.author + parent_author != @author && parent_author.email_on_comment_reply? + end end diff --git a/app/models/community.rb b/app/models/community.rb index c4430a2ca..3a40b682c 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -44,18 +44,18 @@ class Community < ApplicationRecord private - def users_who_commented - topics_ids = topics.pluck(:id) - query = "comments.commentable_id IN (?)and comments.commentable_type = 'Topic'" - User.by_comments(query, topics_ids) - end + def users_who_commented + topics_ids = topics.pluck(:id) + query = "comments.commentable_id IN (?)and comments.commentable_type = 'Topic'" + User.by_comments(query, topics_ids) + end - def users_who_topics_author - author_ids = topics.pluck(:author_id) - User.by_authors(author_ids) - end + def users_who_topics_author + author_ids = topics.pluck(:author_id) + User.by_authors(author_ids) + end - def author_from_community - from_proposal? ? User.where(id: proposal&.author_id) : User.where(id: investment&.author_id) - end + def author_from_community + from_proposal? ? User.where(id: proposal&.author_id) : User.where(id: investment&.author_id) + end end diff --git a/app/models/concerns/search_cache.rb b/app/models/concerns/search_cache.rb index e3e211647..fd01c98a0 100644 --- a/app/models/concerns/search_cache.rb +++ b/app/models/concerns/search_cache.rb @@ -12,23 +12,23 @@ module SearchCache private - def searchable_values_sql - searchable_values - .select{ |k, _| k.present? } - .collect{ |value, weight| set_tsvector(value, weight) } - .join(" || ") - end + def searchable_values_sql + searchable_values + .select{ |k, _| k.present? } + .collect{ |value, weight| set_tsvector(value, weight) } + .join(" || ") + end - def set_tsvector(value, weight) - "setweight(to_tsvector('spanish', unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})" - end + def set_tsvector(value, weight) + "setweight(to_tsvector('spanish', unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})" + end - def quote(value) - ActiveRecord::Base.connection.quote(value) - end + def quote(value) + ActiveRecord::Base.connection.quote(value) + end - def strip_html(value) - ActionController::Base.helpers.sanitize(value, tags: []) - end + def strip_html(value) + ActionController::Base.helpers.sanitize(value, tags: []) + end end diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index b45de3f6f..144367559 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -6,6 +6,42 @@ module Statisticable attr_reader :resource end + class_methods do + def stats_methods + base_stats_methods + gender_methods + age_methods + geozone_methods + end + + def base_stats_methods + %i[total_participants participations] + participation_check_methods + end + + def participation_check_methods + PARTICIPATIONS.map { |participation| :"#{participation}?" } + end + + def gender_methods + %i[total_male_participants total_female_participants male_percentage female_percentage] + end + + def age_methods + [:participants_by_age] + end + + def geozone_methods + %i[participants_by_geozone total_no_demographic_data] + end + + def stats_cache(*method_names) + method_names.each do |method_name| + alias_method :"raw_#{method_name}", method_name + + define_method method_name do + stats_cache(method_name) { send(:"raw_#{method_name}") } + end + end + end + end + def initialize(resource) @resource = resource end @@ -150,40 +186,4 @@ module Statisticable I18n.t("stats.age_range", start: start, finish: finish) end end - - class_methods do - def stats_methods - base_stats_methods + gender_methods + age_methods + geozone_methods - end - - def base_stats_methods - %i[total_participants participations] + participation_check_methods - end - - def participation_check_methods - PARTICIPATIONS.map { |participation| :"#{participation}?" } - end - - def gender_methods - %i[total_male_participants total_female_participants male_percentage female_percentage] - end - - def age_methods - [:participants_by_age] - end - - def geozone_methods - %i[participants_by_geozone total_no_demographic_data] - end - - def stats_cache(*method_names) - method_names.each do |method_name| - alias_method :"raw_#{method_name}", method_name - - define_method method_name do - stats_cache(method_name) { send(:"raw_#{method_name}") } - end - end - end - end end diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index 088c8ea64..277f1af6e 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -47,20 +47,20 @@ class DirectUpload private - def parent_resource_attachment_validations - @relation.valid? + def parent_resource_attachment_validations + @relation.valid? - if @relation.errors.key? :attachment - errors.add(:attachment, @relation.errors.full_messages_for(:attachment)) + if @relation.errors.key? :attachment + errors.add(:attachment, @relation.errors.full_messages_for(:attachment)) + end end - end - def relation_attributtes - { - attachment: @attachment, - cached_attachment: @cached_attachment, - user: @user - } - end + def relation_attributtes + { + attachment: @attachment, + cached_attachment: @cached_attachment, + user: @user + } + end end diff --git a/app/models/newsletter.rb b/app/models/newsletter.rb index bac4d8ef7..df088ce8e 100644 --- a/app/models/newsletter.rb +++ b/app/models/newsletter.rb @@ -55,16 +55,16 @@ class Newsletter < ApplicationRecord private - def validate_segment_recipient - errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? - end + def validate_segment_recipient + errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? + end - def valid_email?(email) - email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i) - end + def valid_email?(email) + email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i) + end - def log_delivery(recipient_email) - user = User.where(email: recipient_email).first - Activity.log(user, :email, self) - end + def log_delivery(recipient_email) + user = User.where(email: recipient_email).first + Activity.log(user, :email, self) + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index e5a8e2b95..66343ae6a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -82,16 +82,16 @@ class Notification < ApplicationRecord private - def self.batch_size - 10000 - end + def self.batch_size + 10000 + end - def self.batch_interval - 20.minutes - end + def self.batch_interval + 20.minutes + end - def self.first_batch_run_at - Time.current - end + def self.first_batch_run_at + Time.current + end end diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index 20fe1f0cb..3ea3ea906 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -56,8 +56,8 @@ class ProposalNotification < ApplicationRecord private - def set_author - self.update(author_id: self.proposal.author_id) if self.proposal - end + def set_author + self.update(author_id: self.proposal.author_id) if self.proposal + end end diff --git a/app/models/related_content.rb b/app/models/related_content.rb index 1ac79beec..25a46c6c4 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -36,28 +36,28 @@ class RelatedContent < ApplicationRecord private - def create_opposite_related_content - related_content = RelatedContent.create!(opposite_related_content: self, parent_relationable: child_relationable, - child_relationable: parent_relationable, author: author) - self.opposite_related_content = related_content - end + def create_opposite_related_content + related_content = RelatedContent.create!(opposite_related_content: self, parent_relationable: child_relationable, + child_relationable: parent_relationable, author: author) + self.opposite_related_content = related_content + end - def score(value, user) - score_with_opposite(value, user) - hide_with_opposite if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD - end + def score(value, user) + score_with_opposite(value, user) + hide_with_opposite if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD + end - def hide_with_opposite - hide - opposite_related_content.hide - end + def hide_with_opposite + hide + opposite_related_content.hide + end - def create_author_score - score_positive(author) - end + def create_author_score + score_positive(author) + end - def score_with_opposite(value, user) - RelatedContentScore.create(user: user, related_content: self, value: value) - RelatedContentScore.create(user: user, related_content: opposite_related_content, value: value) - end + def score_with_opposite(value, user) + RelatedContentScore.create(user: user, related_content: self, value: value) + RelatedContentScore.create(user: user, related_content: opposite_related_content, value: value) + end end diff --git a/lib/user_segments.rb b/lib/user_segments.rb index bc5419c78..17d609e68 100644 --- a/lib/user_segments.rb +++ b/lib/user_segments.rb @@ -60,11 +60,11 @@ class UserSegments private - def self.current_budget_investments - Budget.current.investments - end + def self.current_budget_investments + Budget.current.investments + end - def self.author_ids(author_ids) - all_users.where(id: author_ids) - end + def self.author_ids(author_ids) + all_users.where(id: author_ids) + end end