diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 26fa4df18..7d643962f 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -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) diff --git a/app/controllers/partnerships_controller.rb b/app/controllers/partnerships_controller.rb index 4d4253b69..fc559963b 100644 --- a/app/controllers/partnerships_controller.rb +++ b/app/controllers/partnerships_controller.rb @@ -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 diff --git a/app/dashboards/organization_dashboard.rb b/app/dashboards/organization_dashboard.rb index 592abe0e0..fe633d491 100644 --- a/app/dashboards/organization_dashboard.rb +++ b/app/dashboards/organization_dashboard.rb @@ -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) diff --git a/app/dashboards/tag_dashboard.rb b/app/dashboards/tag_dashboard.rb index 10cb5c668..c51054247 100644 --- a/app/dashboards/tag_dashboard.rb +++ b/app/dashboards/tag_dashboard.rb @@ -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 diff --git a/app/models/organization.rb b/app/models/organization.rb index ecc00b7a3..20a2530b8 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -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 } diff --git a/app/models/tag.rb b/app/models/tag.rb index 63e179492..7b7af4fd8 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 diff --git a/app/views/partnerships/_form.html.erb b/app/views/partnerships/_form.html.erb index e14c48a17..b0d5bd2f9 100644 --- a/app/views/partnerships/_form.html.erb +++ b/app/views/partnerships/_form.html.erb @@ -57,9 +57,9 @@
@@ -74,9 +74,9 @@
@@ -118,7 +118,7 @@
You will be contacted by the DEV team within one day of signing up for this service.
diff --git a/db/migrate/20190711070019_remove_sponsorship_old_columns.rb b/db/migrate/20190711070019_remove_sponsorship_old_columns.rb
new file mode 100644
index 000000000..9e4a7d7a7
--- /dev/null
+++ b/db/migrate/20190711070019_remove_sponsorship_old_columns.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 3e54acf9d..4198f99ca 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/lib/tasks/temporary/sponsorships.rake b/lib/tasks/temporary/sponsorships.rake
deleted file mode 100644
index 9e73fcf91..000000000
--- a/lib/tasks/temporary/sponsorships.rake
+++ /dev/null
@@ -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
diff --git a/spec/requests/partnerships_spec.rb b/spec/requests/partnerships_spec.rb
index 4cb996e06..22569a76d 100644
--- a/spec/requests/partnerships_spec.rb
+++ b/spec/requests/partnerships_spec.rb
@@ -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)
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
- <%= hidden_field_tag(:sponsorship_level, level) %>
+ <%= hidden_field_tag(:level, level) %>
Sponsorship message/brand instructions:
- <%= 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| %>
<%= 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") %>
<%= form_tag "/partnerships" do %>
<%= hidden_field_tag(:organization_id, org.id) %>
- <%= hidden_field_tag(:sponsorship_level, level) %>
+ <%= hidden_field_tag(:level, level) %>