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 +4 -4
- data/app/models/openstax/accounts/account.rb +4 -4
- data/app/models/openstax/accounts/application_account.rb +1 -2
- data/app/representers/openstax/accounts/api/v1/account_representer.rb +18 -4
- data/app/representers/openstax/accounts/api/v1/account_search_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/application_account_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/application_account_search_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/application_accounts_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/group_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +1 -0
- data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -0
- data/app/routines/openstax/accounts/find_or_create_account.rb +8 -3
- data/lib/openstax/accounts/api.rb +5 -9
- data/lib/openstax/accounts/version.rb +1 -1
- data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee92a3b64d5e3e96b74bb4991cc34bd70ffafba
|
4
|
+
data.tar.gz: b8799ffbc096a017d7f2d084de72fef2e25bd3c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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, :
|
28
|
-
validates :username, :
|
29
|
-
:
|
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, :
|
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,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
|
@@ -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) ||
|
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
|
-
|
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
|
@@ -29,18 +29,23 @@ module OpenStax
|
|
29
29
|
expect(account_2).not_to eq(account_3)
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'passes
|
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',
|
43
|
-
|
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.
|
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-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|