Skip to content

Commit

Permalink
add adopter status to user as string
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Oct 13, 2023
1 parent e142ed9 commit d701bff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/representers/api/v1/user_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class UserRepresenter < Roar::Decorator
readable: true,
writeable: false

property :adopter_status,
if: ->(user_options:, **) { user_options.try(:fetch, :include_private_data, false) },
type: String,
readable: true,
writeable: false

property :salesforce_contact_id,
type: String,
readable: true,
Expand Down
2 changes: 2 additions & 0 deletions app/routines/update_user_contact_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def call
:unknown_school_location
end

# TODO: This can be removed once OSWeb is migated to using the new adopter_status field for renewal forms
unless sf_contact.adoption_status.blank?
user.using_openstax = ADOPTION_STATUSES[sf_contact.adoption_status]
end

user.adopter_status = sf_contact.adoption_status
user.is_kip = sf_school&.is_kip || sf_school&.is_child_of_kip
user.grant_tutor_access = sf_contact.grant_tutor_access
user.is_b_r_i_user = sf_contact.b_r_i_marketing
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231004175741_add_adopter_status_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdopterStatusToUser < ActiveRecord::Migration[5.2]
def change
add_column :users, :adopter_status, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_08_10_185800) do
ActiveRecord::Schema.define(version: 2023_10_04_175741) do

# These are extensions that must be enabled in order to support this database
enable_extension "citext"
Expand Down Expand Up @@ -483,6 +483,7 @@
t.boolean "needs_sync"
t.boolean "sheer_id_webhook_received"
t.jsonb "books_used_details"
t.string "adopter_status"
t.index "lower((first_name)::text)", name: "index_users_on_first_name"
t.index "lower((last_name)::text)", name: "index_users_on_last_name"
t.index "lower((username)::text)", name: "index_users_on_username_case_insensitive"
Expand Down
19 changes: 19 additions & 0 deletions lib/tasks/accounts/update_adopter_status.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace :accounts do
desc 'Update newly created field for adopter status from Salesforce'
# rake accounts:update_adopter_status
task update_adopter_status: [:environment] do
contacts ||= OpenStax::Salesforce::Remote::Contact.select(
:id,
:adoption_status,
:accounts_uuid
)
.where("Accounts_UUID__c != null")
.to_a

contacts.each { | contact |
u = User.where(salesforce_contact_id: contact.id)
u.adopter_status = contact.adoption_status
u.save!
}
end
end

0 comments on commit d701bff

Please sign in to comment.