Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc modernization #919

Draft
wants to merge 13 commits into
base: 2024-upgrades-main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ call_tool_api_key=xyz

storage=s3
amazon_region=us-west-1
amazon_bucket=actioncenter-staging
amazon_bucket_url=actioncentertest.s3-us-west-1.amazonaws.com
amazon_bucket=actioncenter-test
amazon_bucket_url=actioncenter-testurl.s3-us-west-1.amazonaws.com

supporters_api_key=xyz
supporters_host=https://civicrm.test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ public/webshims

# Ignore dotenv file
/.env
/public/uploads
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ source "https://rails-assets.org" do
end

# File upload
gem "kt-paperclip", "~> 6"
gem "carrierwave", "~> 3.0"
gem "fog-aws"

# Email preformatting
gem "nokogiri", "~> 1" # Required for premailer-rails
Expand Down Expand Up @@ -111,7 +112,6 @@ end
group :development, :test do
gem "byebug"
gem "capybara", "~> 3"
gem "database_cleaner", "~> 1"
gem "factory_bot_rails", "~> 6.2"
gem "rails-controller-testing"
gem "rspec-rails", "~> 6.1"
Expand Down
48 changes: 33 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
carrierwave (3.0.7)
activemodel (>= 6.0.0)
activesupport (>= 6.0.0)
addressable (~> 2.6)
image_processing (~> 1.1)
marcel (~> 1.0.0)
ssrf_filter (~> 1.0)
cgi (0.4.1)
chartkick (3.4.2)
chronic (0.10.2)
climate_control (0.2.0)
cocoon (1.2.15)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
Expand All @@ -168,7 +174,6 @@ GEM
css_parser (1.16.0)
addressable
daemons (1.4.1)
database_cleaner (1.99.0)
date (3.3.4)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
Expand Down Expand Up @@ -196,6 +201,7 @@ GEM
email_validator (1.6.0)
activemodel
erubi (1.12.0)
excon (0.110.0)
execjs (2.9.1)
factory_bot (6.2.1)
activesupport (>= 5.0.0)
Expand All @@ -211,6 +217,22 @@ GEM
activerecord (>= 4.1.0)
fastly (2.5.3)
ffi (1.16.2)
fog-aws (3.22.0)
fog-core (~> 2.1)
fog-json (~> 1.1)
fog-xml (~> 0.1)
fog-core (2.4.0)
builder
excon (~> 0.71)
formatador (>= 0.2, < 2.0)
mime-types
fog-json (1.2.0)
fog-core
multi_json (~> 1.10)
fog-xml (0.1.4)
fog-core
nokogiri (>= 1.5.11, < 2.0.0)
formatador (1.1.0)
friendly_id (5.5.0)
activerecord (>= 4.0.0)
geocoder (1.8.2)
Expand All @@ -234,6 +256,9 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
invisible_captcha (0.13.0)
rails (>= 3.2.0)
iso_country_codes (0.7.8)
Expand All @@ -242,12 +267,6 @@ GEM
activesupport (>= 5.0.0)
jmespath (1.6.2)
json (2.6.3)
kt-paperclip (6.4.2)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
language_server-protocol (3.17.0.3)
loofah (2.22.0)
crass (~> 1.0.2)
Expand All @@ -263,9 +282,7 @@ GEM
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.2)
Expand Down Expand Up @@ -414,6 +431,8 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
ruby-vips (2.2.1)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
safely_block (0.4.0)
Expand Down Expand Up @@ -454,8 +473,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
ssrf_filter (1.1.2)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
Expand Down Expand Up @@ -505,11 +523,11 @@ DEPENDENCIES
bundler (>= 1.8.4)
byebug
capybara (~> 3)
carrierwave (~> 3.0)
chartkick (~> 3)
cocoon (~> 1)
counter_culture (~> 2.0)
daemons (~> 1)
database_cleaner (~> 1)
delayed_job_active_record (~> 4)
devise (~> 4.7)
dotenv-rails (~> 2)
Expand All @@ -519,6 +537,7 @@ DEPENDENCIES
factory_bot_rails (~> 6.2)
fast_inserter (~> 2.0)
fastly (~> 2)
fog-aws
friendly_id (~> 5.0)
going_postal (~> 0)
gravatar-ultimate (~> 2)
Expand All @@ -527,7 +546,6 @@ DEPENDENCIES
invisible_captcha (~> 0)
iso_country_codes (~> 0)
jbuilder (~> 2)
kt-paperclip (~> 6)
nokogiri (~> 1)
oauth (~> 0)
pg (~> 1.1)
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/application/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ $(function() {
});
}

attachGalleryImage('#image-gallery', '#action_page_featured_image', '#attached-featured_image');
attachGalleryImage('#image-gallery', '#action_page_background_image', '#attached-background_image');
attachGalleryImage('#image-gallery', '#action_page_og_image', '#attached-og_image');
attachGalleryImage('#image-gallery', '#action_page_remote_featured_image_url', '#attached-featured_image');
attachGalleryImage('#image-gallery', '#action_page_remote_background_image_url', '#attached-background_image');
attachGalleryImage('#image-gallery', '#action_page_remote_og_image_url', '#attached-og_image');

$('.tweet-target').each(function(i, target) {
attachGalleryImage('#image-gallery', $(target).find('.image-input'), target);
Expand Down
19 changes: 0 additions & 19 deletions app/assets/stylesheets/action_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1236,25 +1236,6 @@ html.js #affiliations {
}
}

.partner-logos {
display: flex;
align-items: center;
justify-content: space-evenly;
flex-wrap: wrap;
@media screen and (min-width: $lg) {
flex-wrap: nowrap;
}
img {
width: 100%;
height: auto;
max-width: 200px;
padding: 1em;
@media screen and (min-width: $md) {
padding: 0 1em;
}
}
}

#congress-message-create {
position: relative;

Expand Down
8 changes: 2 additions & 6 deletions app/controllers/admin/action_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ def edit_partners
end

def update
@actionPage.background_image = nil if params[:destroy_background_image]
@actionPage.featured_image = nil if params[:destroy_featured_image]
@actionPage.og_image = nil if params[:destroy_og_image]

@actionPage.update(action_page_params)
if (institutions_params[:reset] && institutions_params[:reset] == "1") ||
(institutions_params[:category] && @actionPage.institutions.empty?)
Expand Down Expand Up @@ -175,9 +171,9 @@ def set_partners

def action_page_params
params.require(:action_page).permit(
:title, :summary, :description, :category_id, :related_content_url, :featured_image,
:title, :summary, :description, :category_id, :related_content_url, :remote_featured_image_url,
:enable_call, :enable_petition, :enable_email, :enable_tweet,
:enable_congress_message, :og_title, :og_image, :share_message, :published,
:enable_congress_message, :og_title, :remote_og_image_url, :share_message, :published,
:call_campaign_id, :what_to_say, :redirect_url, :email_text, :enable_redirect,
:victory, :victory_message, :archived_redirect_action_page_id, :archived, :status,
partner_ids: [],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create

update_user_data(email: email)
params[:subscription][:opt_in] = params[:subscription][:opt_in] || false
subscription = CiviCRM.subscribe params[:subscription]
subscription = Civicrm.subscribe params[:subscription]
if subscription["error"]
render json: { message: subscription["error_message"] }, status: 500
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def create_newsletter_subscription
source = "action center #{@action_page.class.name.downcase} :: " + @action_page.title
params[:subscription][:opt_in] = true
params[:subscription][:source] = source
CiviCRM.subscribe params[:subscription]
Civicrm.subscribe params[:subscription]
end
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions lib/civicrm.rb → app/lib/civicrm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "rest_client"
module CiviCRM
module Civicrm
module UserMethods
def contact_attributes
attributes.symbolize_keys.slice(
Expand All @@ -9,35 +9,35 @@ def contact_attributes
end

def subscribe!(opt_in: false, source: "action center")
return nil if CiviCRM.skip_crm?
return nil if Civicrm.skip_crm?

res = CiviCRM.subscribe contact_attributes.merge(opt_in: opt_in, source: source)
res = Civicrm.subscribe contact_attributes.merge(opt_in: opt_in, source: source)
update(contact_id: res["contact_id"]) if res && res["contact_id"]
res || {}
end

def contact_id!
return nil if CiviCRM.skip_crm?
return nil if Civicrm.skip_crm?

res = CiviCRM.import_contact contact_attributes
res = Civicrm.import_contact contact_attributes
update(contact_id: res["contact_id"]) if res && res["contact_id"]
contact_id
end

def add_civicrm_activity!(action_page_id)
return nil if CiviCRM.skip_crm?
return nil if Civicrm.skip_crm?

action_page = ActionPage.find_by(id: action_page_id)
return unless contact_id && action_page

CiviCRM.add_activity(
Civicrm.add_activity(
contact_id: contact_id,
subject: "Took Action #{action_page.id}: #{action_page.title}"
)
end

def manage_subscription_url!
checksum = CiviCRM.get_checksum(contact_id)
checksum = Civicrm.get_checksum(contact_id)
return nil unless checksum

"#{Rails.application.secrets.supporters[:host]}/update-your-preferences?" + {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 4 additions & 13 deletions app/models/action_page.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ActionPage < ApplicationRecord
extend AmazonCredentials
extend FriendlyId

include PgSearch::Model
Expand Down Expand Up @@ -46,18 +45,10 @@ class ActionPage < ApplicationRecord
:call_campaign, :congress_message_campaign, :affiliation_types, :partnerships,
reject_if: :all_blank

has_attached_file :featured_image, amazon_credentials.merge(default_url: "missing.png")
has_attached_file :background_image, amazon_credentials
has_attached_file :og_image, amazon_credentials
validates_media_type_spoof_detection :featured_image,
if: -> { featured_image.present? && featured_image_file_name_came_from_user? }
validates_media_type_spoof_detection :background_image,
if: -> { background_image.present? && background_image_file_name_came_from_user? }
validates_media_type_spoof_detection :og_image,
if: -> { og_image.present? && og_image_file_name_came_from_user? }
do_not_validate_attachment_file_type %i[featured_image background_image og_image]

# validates_length_of :og_title, maximum: 65
mount_uploader :featured_image, ActionPageImageUploader, mount_on: :featured_image_file_name
mount_uploader :background_image, ActionPageImageUploader, mount_on: :background_image_file_name
mount_uploader :og_image, ActionPageImageUploader, mount_on: :og_image_file_name

after_save :no_drafts_on_homepage
after_save :set_congress_tag, if: -> { enable_congress_message }

Expand Down
5 changes: 0 additions & 5 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
class Partner < ApplicationRecord
extend AmazonCredentials
acts_as_paranoid
has_many :subscriptions
has_many :users
has_many :partnerships
has_many :action_pages, through: :partnerships
has_attached_file :logo, amazon_credentials

validates_media_type_spoof_detection :logo,
if: -> { logo.present? && logo_file_name_came_from_user? }
do_not_validate_attachment_file_type [:logo]
validates :code, uniqueness: true

def to_csv(options = {})
Expand Down
2 changes: 1 addition & 1 deletion app/models/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def full_url
if ENV["amazon_bucket_url"]
"https://#{ENV['amazon_bucket_url']}/#{key}"
else # we have to build the url up from amazon information
"https://#{ENV['amazon_bucket']}.#{AmazonCredentials.build_s3_host_name}/#{key}"
"https://#{ENV['amazon_bucket']}.s3-#{Rails.application.secrets.amazon_region}.amazonaws.com/#{key}"
end
end

Expand Down
25 changes: 0 additions & 25 deletions app/models/tweet_target.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
class TweetTarget < ApplicationRecord
extend AmazonCredentials
require "open-uri"

belongs_to :tweet
has_attached_file :image, amazon_credentials
validates_media_type_spoof_detection :image, if: -> { image_file_name.present? }
do_not_validate_attachment_file_type :image
after_save :attach_twitter_image

def url
"https://twitter.com/#{twitter_id}"
end

delegate :url, to: :image, prefix: true

def attach_twitter_image
delay.attach_twitter_image_without_delay if image_file_name.nil? && Twitter.has_api_keys?
end

def attach_twitter_image_without_delay
access_token = Twitter.prepare_access_token Rails.application.secrets.twitter_oauth_token, Rails.application.secrets.twitter_oauth_token_secret

# ref: https://dev.twitter.com/overview/general/user-profile-images-and-banners
response = access_token.request(:get, "https://api.twitter.com/1.1/users/show.json?screen_name=#{twitter_id}")
user_info = JSON.parse response.body
user_image_url = user_info["profile_image_url_https"].gsub("_normal.", "_bigger.")

self.image = URI.parse(user_image_url)
save
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "civicrm"
class User < ApplicationRecord
include CiviCRM::UserMethods
include Civicrm::UserMethods

include PgSearch::Model
pg_search_scope :search, against: %i[email first_name last_name]
Expand Down
Loading