openstax_salesforce 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -46
- data/Rakefile +2 -5
- data/config/initializers/openstax_salesforce.rb +9 -38
- data/db/migrate/0_install_openstax_salesforce.rb +1 -0
- data/db/migrate/1_drop_openstax_salesforce_users.rb +14 -0
- data/lib/openstax/salesforce/active_force.rb +0 -4
- data/lib/openstax/salesforce/client.rb +11 -17
- data/lib/openstax/salesforce/remote/campaign.rb +0 -2
- data/lib/openstax/salesforce/remote/campaign_member.rb +0 -1
- data/lib/openstax/salesforce/remote/opportunity.rb +0 -2
- data/lib/openstax/salesforce/remote/term_year.rb +0 -2
- data/lib/openstax/salesforce/remote/tutor_course_period.rb +0 -2
- data/lib/openstax/salesforce/spec_helpers.rb +119 -26
- data/lib/openstax/salesforce/version.rb +1 -1
- data/lib/openstax_salesforce.rb +13 -29
- data/lib/tasks/openstax_salesforce_tasks.rake +1 -26
- metadata +6 -179
- data/app/controllers/openstax/salesforce/application_controller.rb +0 -7
- data/app/controllers/openstax/salesforce/settings_controller.rb +0 -20
- data/app/helpers/openstax/salesforce/application_helper.rb +0 -11
- data/app/models/openstax/salesforce/user.rb +0 -31
- data/app/views/openstax/salesforce/settings/show.html.erb +0 -33
- data/config/initializers/omniauth.rb +0 -8
- data/config/routes.rb +0 -11
- data/lib/openstax/salesforce/spec_helpers/salesforce_proxy.rb +0 -121
- data/lib/openstax/salesforce/user_missing.rb +0 -3
- data/spec/client_spec.rb +0 -10
- data/spec/dummy/README.md +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config/application.rb +0 -25
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/schema.rb +0 -25
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +0 -2673
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/user.rb +0 -17
- data/spec/openstax/salesforce/controllers/application_controller_spec.rb +0 -22
- data/spec/openstax/salesforce/controllers/settings_controller_spec.rb +0 -80
- data/spec/openstax/salesforce/remote/opportunity_spec.rb +0 -11
- data/spec/openstax/salesforce/remote/term_year_spec.rb +0 -81
- data/spec/openstax/salesforce/remote/tutor_course_period_spec.rb +0 -30
- data/spec/openstax/salesforce/spec_helpers_spec.rb +0 -31
- data/spec/rails_helper.rb +0 -99
- data/spec/routing_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1891856e6a19e2b9751c9982a4ff21edb8195877f9ae5c7f37a0c10b5a0671e6
|
4
|
+
data.tar.gz: 05e146e80fe6385684ba0058b824475c2bfdac63c4941c53efebfa72bf7435db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bcee3d33ea59128302bc97e8ff9695cabefd98af6ba1b0388a12749b4e7692ed53446bd1791aa99c9ab43dde3f166f896879850bb3c7b7dca68a0e1b7a0df96
|
7
|
+
data.tar.gz: 32062d09ecb6b86ab30cd0964a5bc6f7aa76fa55f49bcf5888877f358c54ce784a46b790477152a78ccc0643d4c32462815f0f8519354c6b33429f5e412f7057
|
data/README.md
CHANGED
@@ -4,17 +4,15 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/openstax/openstax_salesforce.svg?branch=master)](https://travis-ci.org/openstax/openstax_salesforce)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/openstax/openstax_salesforce/badges/gpa.svg)](https://codeclimate.com/github/openstax/openstax_salesforce)
|
6
6
|
|
7
|
-
OpenStax::Salesforce is a Rails engine used by OpenStax projects to communicate
|
7
|
+
OpenStax::Salesforce is a Rails engine used by OpenStax projects to communicate
|
8
|
+
with the OpenStax Salesforce instance.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
11
|
-
Add
|
12
|
+
Add this line to your application's Gemfile:
|
12
13
|
|
13
14
|
```rb
|
14
15
|
gem 'openstax_salesforce'
|
15
|
-
|
16
|
-
# ActiveForce fork that supports Ruby >= 2.1 and stubbable stdout
|
17
|
-
gem 'active_force', git: 'https://github.com/openstax/active_force', ref: '7caac17'
|
18
16
|
```
|
19
17
|
|
20
18
|
And then execute:
|
@@ -29,65 +27,38 @@ Or install it yourself:
|
|
29
27
|
$ gem install openstax_salesforce
|
30
28
|
```
|
31
29
|
|
32
|
-
Then execute the following command to copy the necessary
|
30
|
+
Then execute the following command to copy the necessary initializer to your application:
|
33
31
|
|
34
32
|
```sh
|
35
33
|
$ rake openstax_salesforce:install
|
36
34
|
```
|
37
35
|
|
38
|
-
And then migrate your database:
|
39
|
-
|
40
|
-
```sh
|
41
|
-
$ rake db:migrate
|
42
|
-
```
|
43
|
-
|
44
|
-
Also add OpenStax::Salesforce to your application's routes:
|
45
|
-
|
46
|
-
```rb
|
47
|
-
mount OpenStax::Salesforce::Engine, at: "/salesforce"
|
48
|
-
OpenStax::Salesforce.set_top_level_routes(self)
|
49
|
-
```
|
50
|
-
|
51
|
-
The `set_top_level_routes` should be called at the top level inside `routes.rb`. It adds oauth callback
|
52
|
-
routes at the top level.
|
53
|
-
|
54
|
-
And provide a link on your site for administrators to access the engine.
|
55
|
-
|
56
|
-
```erb
|
57
|
-
<%= link_to 'Salesforce Setup', openstax_salesforce_path %>
|
58
|
-
```
|
59
|
-
|
60
36
|
## Configuration
|
61
37
|
|
62
38
|
After installation, the initializer for OpenStax::Salesforce will be located under
|
63
|
-
`config/initializers/openstax_salesforce.rb`. Make sure to configure it to suit
|
64
|
-
|
65
|
-
|
66
|
-
|
39
|
+
`config/initializers/openstax_salesforce.rb`. Make sure to configure it to suit your needs.
|
40
|
+
|
41
|
+
You will need the following information from Salesforce:
|
42
|
+
- Your username (append .sandboxname if using a sandbox)
|
43
|
+
- Your password
|
44
|
+
- Your security token
|
45
|
+
- Connected App's client key
|
46
|
+
- Connected App's client secret
|
47
|
+
Enter all the above information in the initializer, secrets.yml or environment variables.
|
67
48
|
|
68
49
|
## Testing
|
69
50
|
|
70
|
-
From the gem's main folder, run `bundle install
|
71
|
-
`bundle exec rake db:migrate` and then
|
72
|
-
`bundle exec rake` to run all the specs.
|
51
|
+
From the gem's main folder, run `bundle install` and then `bundle exec rake` to run all the specs.
|
73
52
|
|
74
|
-
|
53
|
+
### Specs in Parent App
|
75
54
|
|
76
|
-
There's a helper you can include in your parent app's salesforce specs.
|
77
|
-
required by this engine, so you have to do it manually in your spec:
|
55
|
+
There's a helper you can include in your parent app's salesforce specs.
|
56
|
+
It isn't automatically required by this engine, so you have to do it manually in your spec:
|
78
57
|
|
79
58
|
```ruby
|
80
59
|
require 'openstax/salesforce/spec_helper'
|
81
60
|
```
|
82
61
|
|
83
|
-
If the oauth token in `OpenStax::Salesforce::User.first` expires, you can update it with
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
OpenStax::Salesforce::User.first.refresh_oauth_token!
|
87
|
-
```
|
88
|
-
|
89
|
-
and then copy that token into your spec setup.
|
90
|
-
|
91
62
|
## Contributing
|
92
63
|
|
93
64
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -14,9 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
17
|
load 'rails/tasks/statistics.rake'
|
21
18
|
|
22
19
|
Bundler::GemHelper.install_tasks
|
@@ -25,6 +22,6 @@ require 'rspec/core'
|
|
25
22
|
require 'rspec/core/rake_task'
|
26
23
|
|
27
24
|
desc 'Run all specs in spec directory (excluding plugin specs)'
|
28
|
-
RSpec::Core::RakeTask.new
|
25
|
+
RSpec::Core::RakeTask.new :spec
|
29
26
|
|
30
|
-
task :
|
27
|
+
task default: :spec
|
@@ -2,45 +2,16 @@
|
|
2
2
|
# also be copied to the application's initializers by running the install
|
3
3
|
# task. Because this code can get run multiple times, make sure to only put
|
4
4
|
# code here that is amenable to that.
|
5
|
-
|
6
5
|
OpenStax::Salesforce.configure do |config|
|
7
|
-
|
8
|
-
config.layout = 'application'
|
9
|
-
|
10
|
-
# Proc called with an argument of the controller where this is called.
|
11
|
-
# This proc is called when a user tries to access the engine's controllers.
|
12
|
-
# Should raise an exception, render or redirect unless the user is a manager
|
13
|
-
# or admin. The default renders 403 Forbidden for all users.
|
14
|
-
config.authenticate_admin_proc = ->(controller) {
|
15
|
-
controller.head(:forbidden)
|
16
|
-
}
|
17
|
-
|
18
|
-
# Consumer key and secret for connecting to the Salesforce app
|
19
|
-
config.salesforce_client_key = 'put_real_key_value_here'
|
20
|
-
config.salesforce_client_secret = 'put_real_secret_value_here'
|
21
|
-
|
22
|
-
# Uncomment this to override the login site for sandbox instances; ok to be nil
|
23
|
-
# config.salesforce_login_site = 'https://test.salesforce.com'
|
6
|
+
salesforce_secrets = Rails.application.secrets.salesforce
|
24
7
|
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
8
|
+
# Username, client id, instance url and private key for connecting to the Salesforce app
|
9
|
+
config.username = salesforce_secrets[:username]
|
10
|
+
config.password = salesforce_secrets[:password]
|
11
|
+
config.security_token = salesforce_secrets[:security_token]
|
12
|
+
config.consumer_key = salesforce_secrets[:consumer_key]
|
13
|
+
config.consumer_secret = salesforce_secrets[:consumer_secret]
|
32
14
|
|
33
|
-
|
34
|
-
config.
|
35
|
-
|
36
|
-
# If `check_sandbox_instance_url` is true (default), the spec helper that
|
37
|
-
# uses the instance URL will checks that the URL starts with "cs", which
|
38
|
-
# indicates that the instance is a sandbox.
|
39
|
-
config.check_sandbox_instance_url = true
|
40
|
-
|
41
|
-
# A way to customize page headings. Sometimes apps fold the page heading
|
42
|
-
# into the layout in different ways.
|
43
|
-
config.page_heading_proc = ->(view, text) { "<h2>#{text}</h2>".html_safe }
|
15
|
+
config.api_version = salesforce_secrets.fetch :api_version, '37.0'
|
16
|
+
config.login_domain = salesforce_secrets.fetch :login_domain, 'test.salesforce.com'
|
44
17
|
end
|
45
|
-
|
46
|
-
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# TODO: Remove after all servers have been migrated
|
2
|
+
class DropOpenStaxSalesforceUsers < ActiveRecord::Migration[4.2]
|
3
|
+
def change
|
4
|
+
drop_table :openstax_salesforce_users do |t|
|
5
|
+
t.string :name
|
6
|
+
t.string :uid, null: false
|
7
|
+
t.string :oauth_token, null: false
|
8
|
+
t.string :refresh_token, null: false
|
9
|
+
t.string :instance_url, null: false
|
10
|
+
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# Monkey patching
|
2
2
|
|
3
3
|
module ActiveForce
|
4
|
-
|
5
4
|
class << self
|
6
|
-
|
7
5
|
# Use a lazy setting of the client so that migrations etc are in place
|
8
6
|
# to allow the Client to be successfully instantiated.
|
9
7
|
alias_method :original_sfdc_client, :sfdc_client
|
@@ -17,7 +15,6 @@ module ActiveForce
|
|
17
15
|
def clear_sfdc_client!
|
18
16
|
self.sfdc_client = nil
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
19
|
|
23
20
|
class SObject
|
@@ -34,5 +31,4 @@ module ActiveForce
|
|
34
31
|
# access to the original implementation
|
35
32
|
singleton_class.send(:alias_method, :original_query, :query)
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
@@ -1,25 +1,19 @@
|
|
1
1
|
module OpenStax::Salesforce
|
2
2
|
class Client < ::Restforce::Data::Client
|
3
|
-
|
4
3
|
def initialize
|
5
|
-
|
6
|
-
|
7
|
-
raise(UserMissing, "The Salesforce client was requested but no user is available.") if user.nil?
|
4
|
+
configuration = OpenStax::Salesforce.configuration
|
8
5
|
|
9
|
-
|
10
|
-
client_secret = OpenStax::Salesforce.configuration.salesforce_client_secret
|
6
|
+
configuration.validate!
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
api_version: '37.0')
|
8
|
+
super(
|
9
|
+
username: configuration.username,
|
10
|
+
password: configuration.password,
|
11
|
+
security_token: configuration.security_token,
|
12
|
+
client_id: configuration.consumer_key,
|
13
|
+
client_secret: configuration.consumer_secret,
|
14
|
+
api_version: configuration.api_version,
|
15
|
+
host: configuration.login_domain
|
16
|
+
)
|
22
17
|
end
|
23
|
-
|
24
18
|
end
|
25
19
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class Opportunity < ActiveForce::SObject
|
3
|
-
|
4
3
|
field :term_year, from: "TermYear__c"
|
5
4
|
field :book_name, from: "Book_Text__c"
|
6
5
|
field :contact_id, from: "Contact__c"
|
@@ -11,6 +10,5 @@ module OpenStax::Salesforce::Remote
|
|
11
10
|
def term_year_object
|
12
11
|
@term_year_object ||= OpenStax::Salesforce::Remote::TermYear.from_string(term_year)
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
16
14
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class TermYear
|
3
|
-
|
4
3
|
# TermYear strings in Salesforce look like:
|
5
4
|
# 2015 - 16 Fall
|
6
5
|
# 2015 - 16 Spring
|
@@ -75,6 +74,5 @@ module OpenStax::Salesforce::Remote
|
|
75
74
|
end
|
76
75
|
|
77
76
|
class ParseError < StandardError; end
|
78
|
-
|
79
77
|
end
|
80
78
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class TutorCoursePeriod < ActiveForce::SObject
|
3
|
-
|
4
3
|
field :num_teachers, from: "Active_Teachers__c", as: :int
|
5
4
|
field :base_year, from: "Base_Year__c", as: :int
|
6
5
|
field :book_name, from: "Book_Name__c"
|
@@ -44,6 +43,5 @@ module OpenStax::Salesforce::Remote
|
|
44
43
|
|
45
44
|
STATUS_APPROVED = "Approved"
|
46
45
|
STATUS_ARCHIVED = "ArchivedPeriod"
|
47
|
-
|
48
46
|
end
|
49
47
|
end
|
@@ -1,30 +1,4 @@
|
|
1
|
-
require 'openstax/salesforce/spec_helpers/salesforce_proxy'
|
2
|
-
|
3
1
|
module OpenStax::Salesforce::SpecHelpers
|
4
|
-
|
5
|
-
def load_salesforce_user
|
6
|
-
clear_salesforce_user
|
7
|
-
|
8
|
-
config = OpenStax::Salesforce.configuration
|
9
|
-
sf_user = OpenStax::Salesforce::User.new
|
10
|
-
|
11
|
-
sf_user.name = "some name"
|
12
|
-
sf_user.uid = "whatever"
|
13
|
-
sf_user.oauth_token = config.sandbox_oauth_token
|
14
|
-
sf_user.refresh_token = config.sandbox_refresh_token
|
15
|
-
sf_user.instance_url = config.sandbox_instance_url.tap do |url|
|
16
|
-
if config.check_sandbox_instance_url && !url.match(/\/\/cs/)
|
17
|
-
raise "Salesforce sandbox instance URL (#{url}) does not have the expected form!"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
sf_user.save!
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear_salesforce_user
|
25
|
-
OpenStax::Salesforce::User.destroy_all
|
26
|
-
end
|
27
|
-
|
28
2
|
# Uses knowledge of how `SalesforceProxy` methods create new SF records using its
|
29
3
|
# `unique_token` to create the conditions you'd otherwise have to manually set
|
30
4
|
# when calling `limit_salesforce_queries`.
|
@@ -81,4 +55,123 @@ module OpenStax::Salesforce::SpecHelpers
|
|
81
55
|
end
|
82
56
|
end
|
83
57
|
|
58
|
+
class SalesforceProxy
|
59
|
+
include OpenStax::Salesforce::Remote
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
# For cassette consistency, to ensure specs always get new tokens
|
63
|
+
ActiveForce.clear_sfdc_client!
|
64
|
+
end
|
65
|
+
|
66
|
+
# Used to filter records to the scope of one spec
|
67
|
+
def reset_unique_token(token = SecureRandom.hex(10))
|
68
|
+
@unique_token = token
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear_unique_token
|
72
|
+
@unique_token = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_contact(first_name: nil, last_name: nil, school_name: "JP University",
|
76
|
+
email: nil, email_alt: nil, faculty_verified: nil, school_type: nil)
|
77
|
+
ensure_schools_exist([school_name])
|
78
|
+
|
79
|
+
Contact.new(
|
80
|
+
first_name: first_name || Faker::Name.first_name,
|
81
|
+
last_name: last_name!(last_name),
|
82
|
+
school_id: school_id(school_name),
|
83
|
+
email: email,
|
84
|
+
email_alt: email_alt,
|
85
|
+
faculty_verified: faculty_verified,
|
86
|
+
school_type: school_type
|
87
|
+
).tap do |contact|
|
88
|
+
if !contact.save
|
89
|
+
raise "Could not save SF contact: #{contact.errors}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def new_lead(email:, status: nil, last_name: nil, source: nil, school_name: "JP University")
|
95
|
+
Lead.new(
|
96
|
+
email: email,
|
97
|
+
status: status,
|
98
|
+
last_name: last_name!(last_name),
|
99
|
+
school: school_name,
|
100
|
+
source: source
|
101
|
+
).tap do |lead|
|
102
|
+
if !lead.save
|
103
|
+
raise "Could not save SF lead: #{lead.errors}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def new_campaign(name: SecureRandom.hex(8))
|
109
|
+
Campaign.new(
|
110
|
+
name: name
|
111
|
+
).tap do |campaign|
|
112
|
+
if !campaign.save
|
113
|
+
raise "Could not save SF Campaign: #{campaign.errors}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def new_campaign_member(contact_id:, campaign_id:)
|
119
|
+
CampaignMember.new(
|
120
|
+
contact_id: contact_id,
|
121
|
+
campaign_id: campaign_id
|
122
|
+
).tap do |campaign_member|
|
123
|
+
if !campaign_member.save
|
124
|
+
raise "Could not save SF Campaign Member: #{campaign_member.errors}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def last_name!(input)
|
130
|
+
"#{input || Faker::Name.last_name}#{@unique_token if @unique_token.present?}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def ensure_books_exist(book_names)
|
134
|
+
book_names.each do |book_name|
|
135
|
+
if books.none? {|bb| bb.name == book_name}
|
136
|
+
book = Book.new(name: book_name)
|
137
|
+
book.save!
|
138
|
+
books.push(book)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def ensure_schools_exist(school_names)
|
144
|
+
school_names.compact.each do |school_name|
|
145
|
+
if schools.none? {|ss| ss.name == school_name}
|
146
|
+
school = School.new(name: school_name)
|
147
|
+
school.save!
|
148
|
+
schools.push(school)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def books
|
154
|
+
@books ||= Book.all
|
155
|
+
end
|
156
|
+
|
157
|
+
def book(name)
|
158
|
+
books.find { |bb| bb.name == name }
|
159
|
+
end
|
160
|
+
|
161
|
+
def book_id(name)
|
162
|
+
book(name).id
|
163
|
+
end
|
164
|
+
|
165
|
+
def schools
|
166
|
+
@schools ||= School.all
|
167
|
+
end
|
168
|
+
|
169
|
+
def school_id(name)
|
170
|
+
school(name).try(:id)
|
171
|
+
end
|
172
|
+
|
173
|
+
def school(name)
|
174
|
+
schools.find { |ss| ss.name == name }
|
175
|
+
end
|
176
|
+
end
|
84
177
|
end
|
data/lib/openstax_salesforce.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require "restforce"
|
2
2
|
require "active_force"
|
3
|
-
require "omniauth-salesforce"
|
4
3
|
|
5
4
|
require "openstax/salesforce/active_force"
|
6
5
|
|
7
6
|
require "openstax/salesforce/engine"
|
8
|
-
require "openstax/salesforce/user_missing"
|
9
7
|
require "openstax/salesforce/client"
|
10
8
|
|
11
9
|
require "openstax/salesforce/remote/term_year"
|
@@ -20,7 +18,6 @@ require "openstax/salesforce/remote/campaign_member"
|
|
20
18
|
|
21
19
|
module OpenStax
|
22
20
|
module Salesforce
|
23
|
-
|
24
21
|
def self.configure
|
25
22
|
yield configuration
|
26
23
|
end
|
@@ -31,40 +28,27 @@ module OpenStax
|
|
31
28
|
|
32
29
|
# See `config/initializers/openstax_salesforce.rb` for documentation on options
|
33
30
|
class Configuration
|
34
|
-
|
35
|
-
attr_accessor :
|
36
|
-
attr_accessor :salesforce_client_key
|
37
|
-
attr_accessor :salesforce_client_secret
|
38
|
-
attr_writer :salesforce_login_site
|
39
|
-
attr_accessor :sandbox_oauth_token
|
40
|
-
attr_accessor :sandbox_refresh_token
|
41
|
-
attr_accessor :sandbox_instance_url
|
42
|
-
attr_accessor :check_sandbox_instance_url
|
43
|
-
attr_accessor :skip_automatic_omniauth_setup
|
44
|
-
attr_accessor :page_heading_proc
|
31
|
+
attr_writer :api_version, :login_domain
|
32
|
+
attr_accessor :username, :password, :security_token, :consumer_key, :consumer_secret
|
45
33
|
|
46
|
-
def
|
47
|
-
@
|
34
|
+
def api_version
|
35
|
+
@api_version ||= '37.0'
|
48
36
|
end
|
49
37
|
|
50
|
-
def
|
51
|
-
|
38
|
+
def login_domain
|
39
|
+
@login_domain ||= 'test.salesforce.com'
|
52
40
|
end
|
53
41
|
|
54
|
-
def
|
55
|
-
|
42
|
+
def validate!
|
43
|
+
raise(IllegalState, "The Salesforce username is missing") if username.nil?
|
44
|
+
raise(IllegalState, "The Salesforce password is missing") if password.nil?
|
45
|
+
raise(IllegalState, "The Salesforce security token is missing") if security_token.nil?
|
46
|
+
raise(IllegalState, "The Salesforce consumer key is missing") if consumer_key.nil?
|
47
|
+
raise(IllegalState, "The Salesforce consumer secret is missing") if consumer_secret.nil?
|
56
48
|
end
|
57
49
|
end
|
58
50
|
|
59
|
-
|
60
|
-
router.match '/auth/salesforce/callback',
|
61
|
-
to: 'openstax/salesforce/settings#callback',
|
62
|
-
via: [:get, :post]
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.ready_for_api_usage?
|
66
|
-
OpenStax::Salesforce::User.any?
|
51
|
+
module Remote
|
67
52
|
end
|
68
|
-
|
69
53
|
end
|
70
54
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
OPENSTAX_SALESFORCE_COPY_PATHS = [
|
2
|
-
'views',
|
3
|
-
'controllers'
|
4
|
-
]
|
5
|
-
|
6
1
|
namespace :openstax_salesforce do
|
7
2
|
namespace :install do
|
8
3
|
desc 'Copy initializers from openstax_salesforce to application'
|
@@ -18,30 +13,10 @@ namespace :openstax_salesforce do
|
|
18
13
|
end
|
19
14
|
end
|
20
15
|
|
21
|
-
|
22
|
-
OPENSTAX_SALESFORCE_COPY_PATHS.each do |path|
|
23
|
-
name = File.basename(path)
|
24
|
-
desc "Copy #{name} from openstax_salesforce to application"
|
25
|
-
task name.to_sym do
|
26
|
-
cp_r File.expand_path("../../../app/#{path}/openstax/salesforce", __FILE__),
|
27
|
-
"app/#{path}",
|
28
|
-
verbose: false
|
29
|
-
print "Copied #{name} from openstax_salesforce\n"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
16
|
+
# TODO: Remove after all servers have been migrated
|
34
17
|
desc 'Copy migrations from openstax_salesforce to application'
|
35
18
|
task :install do
|
36
19
|
Rake::Task['openstax_salesforce:install:initializers'].invoke
|
37
20
|
Rake::Task['openstax_salesforce:install:migrations'].invoke
|
38
21
|
end
|
39
|
-
|
40
|
-
desc 'Copy all customizable files from openstax_salesforce to application'
|
41
|
-
task :copy do
|
42
|
-
OPENSTAX_SALESFORCE_COPY_PATHS.each do |path|
|
43
|
-
Rake::Task["openstax_salesforce:copy:#{File.basename(path)}"].invoke
|
44
|
-
end
|
45
|
-
end
|
46
22
|
end
|
47
|
-
|