Sponsorship: remove old columns (step 3) (#3446)

* Remove old sponsorship columns

* Rename redundant param names
This commit is contained in:
rhymes 2019-07-11 21:35:24 +02:00 committed by Ben Halpern
parent d13712f2a2
commit 611f4b8675
11 changed files with 41 additions and 111 deletions

View file

@ -36,7 +36,6 @@ module Admin
text_color_hex
keywords_for_search
buffer_profile_id_code
sponsor_organization_id
]
convert_empty_string_to_nil
params.require(:tag).permit(accessible)

View file

@ -18,10 +18,10 @@ class PartnershipsController < ApplicationController
@organization = Organization.find(sponsorship_params[:organization_id])
authorize @organization, :admin_of_org?
@level = sponsorship_params[:sponsorship_level]
@level = sponsorship_params[:level]
@number_of_credits_needed = Sponsorship::CREDITS[@level]
if @level == "media" && @number_of_credits_needed.nil?
@number_of_credits_needed = sponsorship_params[:sponsorship_amount].to_i
@number_of_credits_needed = sponsorship_params[:amount].to_i
end
@available_org_credits = @organization.credits.unspent
@ -47,7 +47,7 @@ class PartnershipsController < ApplicationController
private
def sponsorship_params
allowed_params = %i[organization_id sponsorship_level sponsorship_amount tag_name sponsorship_instructions]
allowed_params = %i[organization_id level amount tag_name instructions]
params.permit(allowed_params)
end
@ -62,8 +62,8 @@ class PartnershipsController < ApplicationController
}
create_params[:sponsorable] = sponsorable if sponsorable
if sponsorship_params[:sponsorship_instructions]
create_params[:instructions] = sponsorship_params[:sponsorship_instructions]
if sponsorship_params[:instructions]
create_params[:instructions] = sponsorship_params[:instructions]
# NOTE: why are we storing the updated_at of the instructions?
create_params[:instructions_updated_at] = Time.current
end

View file

@ -34,14 +34,7 @@ class OrganizationDashboard < Administrate::BaseDashboard
approved: Field::Boolean,
cta_button_text: Field::String,
cta_button_url: Field::String,
cta_body_markdown: Field::Text,
sponsorship_url: Field::Text,
sponsorship_tagline: Field::Text,
sponsorship_status: Field::Text,
sponsorship_level: Field::Text,
sponsorship_instructions: Field::Text,
sponsorship_blurb_html: Field::Text,
sponsorship_featured_number: Field::Number
cta_body_markdown: Field::Text
}.freeze
# COLLECTION_ATTRIBUTES
@ -88,12 +81,6 @@ class OrganizationDashboard < Administrate::BaseDashboard
cta_button_text
cta_button_url
cta_body_markdown
sponsorship_url
sponsorship_tagline
sponsorship_blurb_html
sponsorship_level
sponsorship_status
sponsorship_featured_number
].freeze
def display_resource(organization)

View file

@ -22,8 +22,6 @@ class TagDashboard < Administrate::BaseDashboard
pretty_name: Field::String,
profile_image: CarrierwaveField,
social_image: CarrierwaveField,
sponsor_organization: Field::BelongsTo.with_options(class_name: "Organization"),
sponsorship_status: Field::String,
bg_color_hex: Field::String,
text_color_hex: Field::String,
keywords_for_search: Field::String,
@ -41,7 +39,6 @@ class TagDashboard < Administrate::BaseDashboard
name
supported
taggings_count
sponsor_organization
].freeze
# SHOW_PAGE_ATTRIBUTES
@ -65,7 +62,6 @@ class TagDashboard < Administrate::BaseDashboard
text_color_hex
keywords_for_search
buffer_profile_id_code
sponsor_organization
].freeze
# FORM_ATTRIBUTES
@ -85,8 +81,6 @@ class TagDashboard < Administrate::BaseDashboard
social_image
bg_color_hex
text_color_hex
sponsor_organization
sponsorship_status
keywords_for_search
buffer_profile_id_code
].freeze

View file

@ -27,7 +27,6 @@ class Organization < ApplicationRecord
validates :jobs_email, email: true, allow_blank: true
validates :text_color_hex, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true
validates :bg_color_hex, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true
validates :sponsorship_level, inclusion: { in: %w[gold silver bronze] }, allow_nil: true
validates :slug,
presence: true,
uniqueness: { case_sensitive: false },
@ -42,7 +41,6 @@ class Organization < ApplicationRecord
message: "Integer only. No sign allowed.",
allow_blank: true }
validates :tech_stack, :story, length: { maximum: 640 }
validates :sponsorship_status, inclusion: { in: %w[none pending live] }
validates :cta_button_url,
url: { allow_blank: true, no_local: true, schemes: %w[https http] }
validates :cta_button_text, length: { maximum: 20 }

View file

@ -18,7 +18,6 @@ class Tag < ActsAsTaggableOn::Tag
attr_accessor :tag_moderator_id, :remove_moderator_id
belongs_to :badge, optional: true
belongs_to :sponsor_organization, class_name: "Organization", optional: true
has_one :sponsorship, as: :sponsorable, inverse_of: :sponsorable, dependent: :destroy
mount_uploader :profile_image, ProfileImageUploader
@ -29,7 +28,6 @@ class Tag < ActsAsTaggableOn::Tag
validates :bg_color_hex,
format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_nil: true
validates :category, inclusion: { in: ALLOWED_CATEGORIES }
validates :sponsorship_status, inclusion: { in: %w[none pending live] }
validate :validate_alias
before_validation :evaluate_markdown

View file

@ -57,9 +57,9 @@
<h2><%= level.capitalize %> Sponsor Subscription</h2>
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
<%= hidden_field_tag(:sponsorship_level, level) %>
<%= hidden_field_tag(:level, level) %>
<h4>Sponsorship message/brand instructions:</h4>
<%= text_area_tag(:sponsorship_instructions, nil, placeholder: "Include brand guideline links and detailed instructions about the message you are trying to get across. DEV editors will use these guidelines contextually depending on sponsorship.") %>
<%= text_area_tag(:instructions, nil, placeholder: "Include brand guideline links and detailed instructions about the message you are trying to get across. DEV editors will use these guidelines contextually depending on sponsorship.") %>
<button>Subscribe for <%= Sponsorship::CREDITS[level] %> credits</button>
<p style="font-size: 0.88em;">
<em>
@ -74,9 +74,9 @@
<br />
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
<%= hidden_field_tag(:sponsorship_level, level) %>
<%= hidden_field_tag(:level, level) %>
<h4>Sponsorship message/brand instructions:</h4>
<%= text_area_tag(:sponsorship_instructions, nil, placeholder: "Include brand guideline links and detailed instructions about the message you are trying to get across. DEV editors will use these guidelines contextually depending on sponsorship.") %>
<%= text_area_tag(:instructions, nil, placeholder: "Include brand guideline links and detailed instructions about the message you are trying to get across. DEV editors will use these guidelines contextually depending on sponsorship.") %>
<% org.sponsorships.where(level: :tag).find_each do |sponsorship| %>
<div class="partner-explainer-notice">
🎉 You are Subscribed as the sponsor of #<%= sponsorship.sponsorable.name %>.
@ -102,8 +102,8 @@
<br />
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
<%= hidden_field_tag(:sponsorship_level, level) %>
<%= number_field_tag(:sponsorship_amount, nil, placeholder: "Number of credits") %>
<%= hidden_field_tag(:level, level) %>
<%= number_field_tag(:amount, nil, placeholder: "Number of credits") %>
<button>Add spend to your media sponsorship</button>
<p style="font-size: 0.88em;">
<em>
@ -118,7 +118,7 @@
<br />
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
<%= hidden_field_tag(:sponsorship_level, level) %>
<%= hidden_field_tag(:level, level) %>
<button>Sign Up for DevRel Consulting</button>
<p style="font-size: 1.1em;">
You will be contacted by the DEV team within one day of signing up for this service.

View file

@ -0,0 +1,17 @@
class RemoveSponsorshipOldColumns < ActiveRecord::Migration[5.2]
def change
remove_column :organizations, :is_gold_sponsor, :boolean, default: false
remove_column :organizations, :sponsorship_blurb_html, :text
remove_column :organizations, :sponsorship_expires_at, :datetime
remove_column :organizations, :sponsorship_featured_number, :integer, default: 0
remove_column :organizations, :sponsorship_instructions, :text, default: ""
remove_column :organizations, :sponsorship_instructions_updated_at, :datetime
remove_column :organizations, :sponsorship_level, :string
remove_column :organizations, :sponsorship_status, :string, default: "none"
remove_column :organizations, :sponsorship_tagline, :string
remove_column :organizations, :sponsorship_url, :string
remove_column :tags, :sponsor_organization_id, :integer
remove_column :tags, :sponsorship_status, :string, default: "none"
end
end

View file

@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_07_10_081915) do
ActiveRecord::Schema.define(version: 2019_07_11_070019) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -575,7 +575,6 @@ ActiveRecord::Schema.define(version: 2019_07_10_081915) do
t.string "dark_nav_image"
t.string "email"
t.string "github_username"
t.boolean "is_gold_sponsor", default: false
t.string "jobs_email"
t.string "jobs_url"
t.datetime "last_article_at", default: "2017-01-01 05:00:00"
@ -590,15 +589,6 @@ ActiveRecord::Schema.define(version: 2019_07_10_081915) do
t.string "secret"
t.string "slug"
t.integer "spent_credits_count", default: 0, null: false
t.text "sponsorship_blurb_html"
t.datetime "sponsorship_expires_at"
t.integer "sponsorship_featured_number", default: 0
t.text "sponsorship_instructions", default: ""
t.datetime "sponsorship_instructions_updated_at"
t.string "sponsorship_level"
t.string "sponsorship_status", default: "none"
t.string "sponsorship_tagline"
t.string "sponsorship_url"
t.string "state"
t.string "story"
t.text "summary"
@ -891,8 +881,6 @@ ActiveRecord::Schema.define(version: 2019_07_10_081915) do
t.text "rules_markdown"
t.string "short_summary"
t.string "social_image"
t.integer "sponsor_organization_id"
t.string "sponsorship_status", default: "none"
t.string "submission_rules_headsup"
t.text "submission_template"
t.boolean "supported", default: false

View file

@ -1,51 +0,0 @@
namespace :sponsorships do
desc "Migrate existing sponsorships data to the Sponsorship model"
task migrate_data: :environment do
ActiveRecord::Base.transaction do
puts "Migrating organization data..."
Organization.find_each do |org|
next unless org.sponsorship_level
org_admin = org.users.where(organization_memberships: { type_of_user: "admin" }).take!
Sponsorship.create!(
organization: org,
user: org_admin,
level: org.sponsorship_level,
status: org.sponsorship_status,
expires_at: org.sponsorship_expires_at,
blurb_html: org.sponsorship_blurb_html,
featured_number: org.sponsorship_featured_number,
instructions: org.sponsorship_instructions,
instructions_updated_at: org.sponsorship_instructions_updated_at,
tagline: org.sponsorship_tagline,
url: org.sponsorship_url,
)
puts "Migrated organization '#{org.name}'"
end
puts "Migrating Tag sponsorship data..."
Tag.where.not(sponsor_organization_id: nil).includes(:sponsor_organization).find_each do |tag|
org = tag.sponsor_organization
org_admin = org.users.where(organization_memberships: { type_of_user: "admin" }).take!
Sponsorship.create!(
organization: org,
user: org_admin,
level: "tag",
# when an org purchases a tag sponsorship, its status isn't set
# so I ise tag.sponsorship_status (which was previously checked in app/views/tags/index.html.erb)
status: tag.sponsorship_status,
sponsorable: tag,
)
puts "Migrated tag '#{tag.name}' sponsorship by '#{org.name}'"
end
end
puts "All done now!"
puts "Sponsorships without any traceable info in the DB need to be created manually!"
end
end

View file

@ -83,7 +83,7 @@ RSpec.describe "Pages", type: :request do
# to the high amount of required credits
context "when purchasing a silver sponsorship" do
let(:params) { { sponsorship_level: :silver, organization_id: org.id } }
let(:params) { { level: :silver, organization_id: org.id } }
before do
Credit.add_to_org(org, Sponsorship::CREDITS[:silver])
@ -118,7 +118,7 @@ RSpec.describe "Pages", type: :request do
end
context "when purchasing a bronze sponsorship" do
let(:params) { { sponsorship_level: :bronze, organization_id: org.id } }
let(:params) { { level: :bronze, organization_id: org.id } }
before do
Credit.add_to_org(org, Sponsorship::CREDITS[:bronze])
@ -153,7 +153,7 @@ RSpec.describe "Pages", type: :request do
end
context "when purchasing a devrel sponsorship" do
let(:params) { { sponsorship_level: :devrel, organization_id: org.id } }
let(:params) { { level: :devrel, organization_id: org.id } }
before do
Credit.add_to_org(org, Sponsorship::CREDITS[:devrel])
@ -189,11 +189,11 @@ RSpec.describe "Pages", type: :request do
context "when purchasing a media sponsorship" do
let(:params) do
{ sponsorship_level: :media, organization_id: org.id, sponsorship_amount: 10 }
{ level: :media, organization_id: org.id, amount: 10 }
end
before do
Credit.add_to_org(org, params[:sponsorship_amount])
Credit.add_to_org(org, params[:amount])
end
it "creates a new sponsorship" do
@ -218,7 +218,7 @@ RSpec.describe "Pages", type: :request do
it "detracts the correct amount of credits" do
expect do
post "/partnerships", params: params
end.to change(org.credits.spent, :size).by(params[:sponsorship_amount])
end.to change(org.credits.spent, :size).by(params[:amount])
credit = org.credits.spent.last
expect(credit.purchase.is_a?(Sponsorship)).to be(true)
end
@ -226,7 +226,7 @@ RSpec.describe "Pages", type: :request do
context "when purchasing a tag sponsorship" do
let(:tag) { create(:tag) }
let(:params) { { sponsorship_level: :tag, organization_id: org.id, tag_name: tag.name } }
let(:params) { { level: :tag, organization_id: org.id, tag_name: tag.name } }
before do
Credit.add_to_org(org, Sponsorship::CREDITS[:tag])
@ -264,9 +264,9 @@ RSpec.describe "Pages", type: :request do
Credit.add_to_org(org, Sponsorship::CREDITS[:bronze])
post "/partnerships", params: {
sponsorship_level: :bronze,
level: :bronze,
organization_id: org.id,
sponsorship_instructions: "hello there"
instructions: "hello there"
}
sponsorship = org.sponsorships.bronze.last
expect(sponsorship.instructions).to include("hello there")
@ -284,7 +284,7 @@ RSpec.describe "Pages", type: :request do
it "does not subscribe to a bronze sponsorship" do
expect do
post "/partnerships", params: {
sponsorship_level: "bronze",
level: "bronze",
organization_id: org.id
}
end.to raise_error(Pundit::NotAuthorizedError)