openstax_accounts 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70c240f393002aa5b92f64613b50bfe2ed7a004c
4
- data.tar.gz: f0a1f4118d6aa83a0d3bc44fd2147eb55dd2f7ae
3
+ metadata.gz: 8ee92a3b64d5e3e96b74bb4991cc34bd70ffafba
4
+ data.tar.gz: b8799ffbc096a017d7f2d084de72fef2e25bd3c7
5
5
  SHA512:
6
- metadata.gz: 6ecd133133d1b4ab89dd39d80f44164825e2ba4a72c0e4adb2f9f61b7a83d07f85880f1d768ea39bd7b3a10dff4d5cdcd44153880a5d5e01ecac97714fcb5ea0
7
- data.tar.gz: f9fdb8b59d9ae93bb8449d0ff21bb36a4e1f0316c97abe9a4e0585b21c16bc18dee361f8769d0b469b5d5d5e9dbfb7e3f28aa6d740959b78ee5256508fed2134
6
+ metadata.gz: 842e2e8e5fa4200b2baf160a183409cdaace616495bfe614ae5da8b8de15097ca9e219e66881a404dc321114b4297aa9f0ea3f3dfed34fde2046b3a67039ab88
7
+ data.tar.gz: 69763b3c8b3d2d40a2a49e0f1986807c2e8b54c7784605848a45c9058cc582651c1ecdf7d6bfdaff33a0afa354de4a2cf01a39f61339e862bfa0d8a61ffdf95c
@@ -24,11 +24,11 @@ module OpenStax::Accounts
24
24
  after_initialize { self.faculty_status ||= :no_faculty_info }
25
25
  validates :faculty_status, presence: true
26
26
 
27
- validates :openstax_uid, :presence => true, :uniqueness => true
28
- validates :username, :presence => true, :uniqueness => true,
29
- :unless => :syncing_or_stubbing
27
+ validates :openstax_uid, presence: true, uniqueness: true
28
+ validates :username, presence: true, uniqueness: true,
29
+ unless: :syncing_or_stubbing
30
30
 
31
- before_update :update_openstax_accounts, :unless => :syncing_or_stubbing
31
+ before_update :update_openstax_accounts, unless: :syncing_or_stubbing
32
32
 
33
33
  def name
34
34
  (first_name || last_name) ? [first_name, last_name].compact.join(" ") : username
@@ -1,8 +1,7 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  class ApplicationAccount
4
- attr_accessor :id, :application_id, :account,
5
- :unread_updates, :default_contact_info_id
4
+ attr_accessor :id, :application_id, :account, :unread_updates, :default_contact_info_id
6
5
  end
7
6
  end
8
7
  end
@@ -1,8 +1,4 @@
1
1
  # A representer for Accounts
2
- #
3
- # This representer can be used directly or subclassed for an object that
4
- # delegates openstax_uid, username, first_name, last_name, full_name and
5
- # title to an account
6
2
 
7
3
  module OpenStax
8
4
  module Accounts
@@ -12,6 +8,10 @@ module OpenStax
12
8
 
13
9
  # This representer is used to communicate with Accounts
14
10
  # and so must allow read/write on all properties
11
+ # Do not use it in create/update APIs!
12
+
13
+ # Otherwise, this representer can be used directly or subclassed
14
+ # for an object that delegates openstax_uid, username, first_name, last_name, full_name, # title, faculty_status and salesforce_contact_id to an account
15
15
 
16
16
  include Roar::JSON
17
17
 
@@ -54,6 +54,20 @@ module OpenStax
54
54
  description: "The user's title"
55
55
  }
56
56
 
57
+ property :salesforce_contact_id,
58
+ type: String,
59
+ schema_info: {
60
+ description: "The user's salesforce contact id"
61
+ }
62
+
63
+ property :faculty_status,
64
+ type: String,
65
+ schema_info: {
66
+ description: "One of #{
67
+ OpenStax::Accounts::Account.faculty_statuses.keys.map(&:to_s).inspect
68
+ }"
69
+ }
70
+
57
71
  end
58
72
  end
59
73
  end
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  property :total_count,
11
12
  inherit: true,
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  collection :application_accounts,
11
12
  as: :application_users,
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Representable::JSON::Collection
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Representable::JSON::Collection
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -6,6 +6,7 @@ module OpenStax
6
6
 
7
7
  # This representer is used to communicate with Accounts
8
8
  # and so must allow read/write on all properties
9
+ # Do not use it in create/update APIs!
9
10
 
10
11
  include Roar::JSON
11
12
 
@@ -7,18 +7,21 @@ module OpenStax
7
7
  protected
8
8
 
9
9
  def exec(email: nil, username: nil, password: nil,
10
- first_name: nil, last_name: nil, full_name: nil, title: nil)
10
+ first_name: nil, last_name: nil, full_name: nil, title: nil,
11
+ salesforce_contact_id: nil, faculty_status: nil)
11
12
  raise ArgumentError,
12
13
  'You must specify either an email address or a username (and an optional password)' \
13
14
  if email.nil? && username.nil?
14
15
 
15
16
  if OpenStax::Accounts.configuration.enable_stubbing
16
17
  # We can only stub finding by username b/c accounts-rails doesn't persist emails
17
- id = Account.find_by(username: username).try(:openstax_uid) || -SecureRandom.hex(4).to_i(16)/2
18
+ id = Account.find_by(username: username).try!(:openstax_uid) ||
19
+ -SecureRandom.hex(4).to_i(16)/2
18
20
  else
19
21
  response = Api.find_or_create_account(
20
22
  email: email, username: username, password: password,
21
- first_name: first_name, last_name: last_name, full_name: full_name)
23
+ first_name: first_name, last_name: last_name, full_name: full_name,
24
+ salesforce_contact_id: salesforce_contact_id, faculty_status: faculty_status)
22
25
  fatal_error(code: :invalid_inputs) unless (200..202).include?(response.status)
23
26
 
24
27
  struct = OpenStruct.new
@@ -37,6 +40,8 @@ module OpenStax
37
40
  account.last_name = last_name
38
41
  account.full_name = full_name
39
42
  account.title = title
43
+ account.salesforce_contact_id = salesforce_contact_id
44
+ account.faculty_status = faculty_status || :no_faculty_info
40
45
  account.save!
41
46
  end
42
47
 
@@ -92,9 +92,7 @@ module OpenStax
92
92
  # On failure, throws an Exception, just like the request method.
93
93
  # On success, returns an OAuth2::Response object.
94
94
  def self.mark_account_updates_as_read(application_users, options = {})
95
- request(:put, 'application_users/updated', options.merge(
96
- body: application_users.to_json
97
- ))
95
+ request(:put, 'application_users/updated', options.merge(body: application_users.to_json))
98
96
  end
99
97
 
100
98
  # Retrieves information about groups that have been
@@ -157,8 +155,7 @@ module OpenStax
157
155
  # On failure, throws an Exception, just like the request method.
158
156
  # On success, returns an OAuth2::Response object.
159
157
  def self.destroy_group(account, group, options = {})
160
- request_for_account(account, :delete,
161
- "groups/#{group.openstax_uid}", options)
158
+ request_for_account(account, :delete, "groups/#{group.openstax_uid}", options)
162
159
  end
163
160
 
164
161
  # Creates a group_member in the Accounts server.
@@ -228,7 +225,8 @@ module OpenStax
228
225
  :post,
229
226
  "groups/#{group_nesting.container_group_id}/nestings/#{
230
227
  group_nesting.member_group_id}",
231
- options)
228
+ options
229
+ )
232
230
  end
233
231
 
234
232
  # Deletes a group_nesting from the Accounts server.
@@ -251,9 +249,7 @@ module OpenStax
251
249
  # On failure, throws an Exception, just like the request method.
252
250
  # On success, returns an OAuth2::Response object.
253
251
  def self.find_or_create_account(attributes, options = {})
254
- request(:post, "user/find-or-create", options.merge(
255
- body: attributes.to_json
256
- ))
252
+ request(:post, "user/find-or-create", options.merge(body: attributes.to_json))
257
253
  end
258
254
 
259
255
  protected
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "7.1.0"
3
+ VERSION = "7.2.0"
4
4
  end
5
5
  end
@@ -29,18 +29,23 @@ module OpenStax
29
29
  expect(account_2).not_to eq(account_3)
30
30
  end
31
31
 
32
- it 'passes names to the API when creating users' do
32
+ it 'passes params to the API when creating users' do
33
33
  find_or_create_account_response = double('Response')
34
34
  allow(find_or_create_account_response).to receive(:status).and_return(201)
35
35
  allow(find_or_create_account_response).to receive(:body).and_return('{"id":1}')
36
36
  expect(OpenStax::Accounts::Api).to receive(:find_or_create_account).with(
37
37
  email: 'bob@example.com', username: nil, password: nil,
38
- first_name: 'Bob', last_name: 'Smith', full_name: 'Bob Smith'
38
+ first_name: 'Bob', last_name: 'Smith', full_name: 'Bob Smith',
39
+ salesforce_contact_id: 'b0b', faculty_status: :rejected_faculty
39
40
  ).and_return(find_or_create_account_response)
40
41
 
41
42
  FindOrCreateAccount.call(
42
- email: 'bob@example.com', first_name: 'Bob', last_name: 'Smith',
43
- full_name: 'Bob Smith'
43
+ email: 'bob@example.com',
44
+ first_name: 'Bob',
45
+ last_name: 'Smith',
46
+ full_name: 'Bob Smith',
47
+ salesforce_contact_id: 'b0b',
48
+ faculty_status: :rejected_faculty
44
49
  )
45
50
  end
46
51
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails