openstax_accounts 9.2.0 → 9.6.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/controllers/openstax/accounts/sessions_controller.rb +12 -8
- data/app/handlers/openstax/accounts/sessions_callback.rb +1 -0
- data/app/models/openstax/accounts/account.rb +15 -3
- data/app/representers/openstax/accounts/api/v1/account_representer.rb +17 -2
- data/app/routines/openstax/accounts/dev/create_account.rb +2 -0
- data/app/routines/openstax/accounts/find_or_create_account.rb +7 -2
- data/app/routines/openstax/accounts/find_or_create_from_sso.rb +1 -1
- data/app/routines/openstax/accounts/sync_accounts.rb +25 -23
- data/db/migrate/17_add_school_location_to_openstax_accounts_accounts.rb +5 -0
- data/db/migrate/18_add_grant_tutor_access_to_openstax_accounts_accounts.rb +5 -0
- data/db/migrate/19_add_is_administrator_to_openstax_accounts_accounts.rb +5 -0
- data/lib/openstax/accounts/api.rb +3 -1
- data/lib/openstax/accounts/configuration.rb +8 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/spec/factories/openstax_accounts_account.rb +1 -0
- metadata +18 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1364b5315f92f25857db5723efd47da0dda8a8d00f9d03171b30f9138cdfabab
|
4
|
+
data.tar.gz: 575fe4c6617a7f3e98ee876698cb8f719256d0d16982c9386692b98778cb92ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 981eda25a7e6aa4548d0a7af4d16bfeaead35d1626f7a4d22b1aad3288ad26af10b24cf84a84a456418f3a9ae0e1ae0afd0de2130f7c05d5cba314497c62ef0e
|
7
|
+
data.tar.gz: fba052fb63636e613e25188c25010092ffa520ce7377e3089644cd2d9b8b44b70c3999d182bbbbe772c0ee3b8c6dc1ca6bdb9496d77521e40c600c46d3d8c3ac
|
@@ -27,14 +27,18 @@ module OpenStax
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def destroy
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
# if a handler is configured, let it handle everything
|
31
|
+
if configuration.logout_handler
|
32
|
+
configuration.logout_handler.call(self)
|
33
|
+
else
|
34
|
+
# Unless we are stubbing, we redirect to a configurable URL, which is normally
|
35
|
+
# (or at least eventually) the Accounts logout URL so that users can't sign back
|
36
|
+
# in automagically.
|
37
|
+
sign_out!
|
38
|
+
redirect_to configuration.enable_stubbing? ?
|
39
|
+
main_app.root_url :
|
40
|
+
configuration.logout_redirect_url(request)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
def failure
|
@@ -34,6 +34,7 @@ module OpenStax
|
|
34
34
|
account.faculty_status ||= :no_faculty_info
|
35
35
|
account.role ||= :unknown_role
|
36
36
|
account.school_type ||= :unknown_school_type
|
37
|
+
account.school_location ||= :unknown_school_location
|
37
38
|
end
|
38
39
|
|
39
40
|
outputs.account.save if outputs.account.changed?
|
@@ -5,6 +5,7 @@ module OpenStax::Accounts
|
|
5
5
|
SYNC_ATTRIBUTES = [
|
6
6
|
:openstax_uid,
|
7
7
|
:username,
|
8
|
+
:is_administrator,
|
8
9
|
:first_name,
|
9
10
|
:last_name,
|
10
11
|
:full_name,
|
@@ -12,10 +13,12 @@ module OpenStax::Accounts
|
|
12
13
|
:self_reported_role,
|
13
14
|
:faculty_status,
|
14
15
|
:school_type,
|
16
|
+
:school_location,
|
15
17
|
:salesforce_contact_id,
|
16
18
|
:support_identifier,
|
17
19
|
:is_test,
|
18
|
-
:is_kip
|
20
|
+
:is_kip,
|
21
|
+
:grant_tutor_access
|
19
22
|
]
|
20
23
|
|
21
24
|
attr_accessor :syncing
|
@@ -26,6 +29,7 @@ module OpenStax::Accounts
|
|
26
29
|
:confirmed_faculty,
|
27
30
|
:rejected_faculty
|
28
31
|
]
|
32
|
+
|
29
33
|
enum role: [
|
30
34
|
:unknown_role,
|
31
35
|
:student,
|
@@ -37,15 +41,23 @@ module OpenStax::Accounts
|
|
37
41
|
:adjunct,
|
38
42
|
:homeschool
|
39
43
|
]
|
44
|
+
|
40
45
|
enum school_type: [
|
41
46
|
:unknown_school_type,
|
42
47
|
:other_school_type,
|
43
48
|
:college,
|
44
49
|
:high_school,
|
45
|
-
:k12_school
|
50
|
+
:k12_school,
|
51
|
+
:home_school
|
52
|
+
]
|
53
|
+
|
54
|
+
enum school_location: [
|
55
|
+
:unknown_school_location,
|
56
|
+
:domestic_school,
|
57
|
+
:foreign_school
|
46
58
|
]
|
47
59
|
|
48
|
-
validates :faculty_status, :role, :school_type, presence: true
|
60
|
+
validates :faculty_status, :role, :school_type, :school_location, presence: true
|
49
61
|
|
50
62
|
validates :uuid, presence: true, uniqueness: true
|
51
63
|
validates :support_identifier, uniqueness: { allow_nil: true }
|
@@ -9,8 +9,9 @@ module OpenStax
|
|
9
9
|
# and so must allow read/write on all properties
|
10
10
|
# Do not use it in create/update APIs!
|
11
11
|
|
12
|
-
#
|
13
|
-
#
|
12
|
+
# This representer can be used directly or subclassed for an object that delegates
|
13
|
+
# openstax_uid, username, first_name, last_name, full_name, title, faculty_status,
|
14
|
+
# role, school_type, school_location and salesforce_contact_id to an account
|
14
15
|
|
15
16
|
include Roar::JSON
|
16
17
|
|
@@ -85,6 +86,14 @@ module OpenStax
|
|
85
86
|
}"
|
86
87
|
}
|
87
88
|
|
89
|
+
property :school_location,
|
90
|
+
type: String,
|
91
|
+
schema_info: {
|
92
|
+
description: "One of #{
|
93
|
+
OpenStax::Accounts::Account.school_locations.keys.map(&:to_s).inspect
|
94
|
+
}"
|
95
|
+
}
|
96
|
+
|
88
97
|
property :uuid,
|
89
98
|
type: String,
|
90
99
|
schema_info: {
|
@@ -108,6 +117,12 @@ module OpenStax
|
|
108
117
|
schema_info: {
|
109
118
|
description: 'Whether or not this is a Key Institutional Partner account'
|
110
119
|
}
|
120
|
+
|
121
|
+
property :grant_tutor_access,
|
122
|
+
type: :boolean,
|
123
|
+
schema_info: {
|
124
|
+
description: 'Whether or not the account should be granted Tutor access'
|
125
|
+
}
|
111
126
|
end
|
112
127
|
end
|
113
128
|
end
|
@@ -32,6 +32,8 @@ module OpenStax
|
|
32
32
|
role: inputs[:role] || :unknown_role,
|
33
33
|
uuid: SecureRandom.uuid,
|
34
34
|
support_identifier: "cs_#{SecureRandom.hex(4)}",
|
35
|
+
school_type: inputs[:school_type] || :unknown_school_type,
|
36
|
+
school_location: inputs[:school_location] || :unknown_school_location,
|
35
37
|
is_test: true
|
36
38
|
)
|
37
39
|
|
@@ -7,7 +7,8 @@ module OpenStax
|
|
7
7
|
|
8
8
|
def exec(email: nil, username: nil, password: nil, first_name: nil, last_name: nil,
|
9
9
|
full_name: nil, title: nil, salesforce_contact_id: nil, faculty_status: nil,
|
10
|
-
role: nil, school_type: nil,
|
10
|
+
role: nil, school_type: nil, school_location: nil, is_kip: nil,
|
11
|
+
grant_tutor_access: nil, is_test: nil)
|
11
12
|
raise(
|
12
13
|
ArgumentError,
|
13
14
|
'You must specify either an email address or a username (and an optional password)'
|
@@ -23,7 +24,8 @@ module OpenStax
|
|
23
24
|
email: email, username: username, password: password,
|
24
25
|
first_name: first_name, last_name: last_name, full_name: full_name,
|
25
26
|
salesforce_contact_id: salesforce_contact_id, faculty_status: faculty_status,
|
26
|
-
role: role, school_type: school_type,
|
27
|
+
role: role, school_type: school_type, school_location: school_location,
|
28
|
+
is_kip: is_kip, grant_tutor_access: grant_tutor_access, is_test: is_test
|
27
29
|
)
|
28
30
|
fatal_error(code: :invalid_inputs) unless (200..202).include?(response.status)
|
29
31
|
|
@@ -45,7 +47,10 @@ module OpenStax
|
|
45
47
|
account.faculty_status = faculty_status || :no_faculty_info
|
46
48
|
account.role = role || :unknown_role
|
47
49
|
account.school_type = school_type || :unknown_school_type
|
50
|
+
account.school_location = school_location || :unknown_school_location
|
48
51
|
account.support_identifier = support_identifier
|
52
|
+
account.is_kip = is_kip
|
53
|
+
account.grant_tutor_access = grant_tutor_access
|
49
54
|
account.is_test = is_test
|
50
55
|
end
|
51
56
|
|
@@ -8,7 +8,7 @@ module OpenStax
|
|
8
8
|
uid = attrs.delete('id')
|
9
9
|
uuid = attrs.delete('uuid')
|
10
10
|
account = Account.find_or_initialize_by(uuid: uuid)
|
11
|
-
account.
|
11
|
+
account.update!(attrs.slice(*Account.column_names))
|
12
12
|
transfer_errors_from(account, {type: :verbatim})
|
13
13
|
outputs.account = account
|
14
14
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# Routine for getting account updates from the Accounts server
|
2
|
-
#
|
3
2
|
# Should be scheduled to run regularly
|
4
|
-
|
5
3
|
module OpenStax
|
6
4
|
module Accounts
|
7
5
|
class SyncAccounts
|
@@ -12,36 +10,40 @@ module OpenStax
|
|
12
10
|
def exec(options={})
|
13
11
|
return if OpenStax::Accounts.configuration.enable_stubbing?
|
14
12
|
|
15
|
-
|
13
|
+
loop do
|
14
|
+
response = OpenStax::Accounts::Api.get_application_account_updates
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
app_accounts = []
|
17
|
+
app_accounts_rep = OpenStax::Accounts::Api::V1::ApplicationAccountsRepresenter.new(
|
18
|
+
app_accounts
|
19
|
+
)
|
20
|
+
app_accounts_rep.from_json(response.body)
|
21
21
|
|
22
|
-
|
22
|
+
num_accounts = app_accounts.size
|
23
|
+
return if num_accounts == 0
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
updated_app_accounts = []
|
26
|
+
app_accounts.each do |app_account|
|
27
|
+
account = OpenStax::Accounts::Account.find_by(
|
28
|
+
uuid: app_account.account.uuid
|
29
|
+
) || app_account.account
|
30
|
+
account.syncing = true
|
30
31
|
|
31
|
-
if account != app_account.account
|
32
32
|
OpenStax::Accounts::Account::SYNC_ATTRIBUTES.each do |attribute|
|
33
|
-
account.send
|
34
|
-
end
|
33
|
+
account.send "#{attribute}=", app_account.account.send(attribute)
|
34
|
+
end if account != app_account.account
|
35
|
+
|
36
|
+
next unless account.save
|
37
|
+
|
38
|
+
updated_app_accounts << {
|
39
|
+
user_id: account.openstax_uid, read_updates: app_account.unread_updates
|
40
|
+
}
|
35
41
|
end
|
36
42
|
|
37
|
-
|
43
|
+
OpenStax::Accounts::Api.mark_account_updates_as_read(updated_app_accounts)
|
38
44
|
|
39
|
-
|
40
|
-
user_id: account.openstax_uid, read_updates: app_account.unread_updates
|
41
|
-
}
|
45
|
+
return if num_accounts < OpenStax::Accounts.configuration.max_user_updates_per_request
|
42
46
|
end
|
43
|
-
|
44
|
-
OpenStax::Accounts::Api.mark_account_updates_as_read(updated_app_accounts)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -81,7 +81,9 @@ module OpenStax
|
|
81
81
|
# On success, returns an OAuth2::Response object.
|
82
82
|
def self.get_application_account_updates(options = {})
|
83
83
|
limit = OpenStax::Accounts.configuration.max_user_updates_per_request
|
84
|
-
request(
|
84
|
+
request(
|
85
|
+
:get, "application_users/updates#{ '?limit=' + limit.to_s if !limit.blank? }", options
|
86
|
+
)
|
85
87
|
end
|
86
88
|
|
87
89
|
# Marks account updates as "read".
|
@@ -53,9 +53,16 @@ module OpenStax
|
|
53
53
|
# If more would be returned, the result will be empty instead
|
54
54
|
attr_accessor :max_search_items
|
55
55
|
|
56
|
+
# logout_handler
|
57
|
+
# Handles logging out and redirecting user when they've requested logout
|
58
|
+
# if specified, the logout_redirect_url has no effect
|
59
|
+
attr_accessor :logout_handler
|
60
|
+
|
56
61
|
# logout_redirect_url
|
57
62
|
# A URL to redirect to after the app logs out, can be a string or a Proc.
|
58
63
|
# If a Proc (or lambda), it will be called with the logout request.
|
64
|
+
#
|
65
|
+
# Only used if the logout_handler above is not specified
|
59
66
|
# If this field is nil or if the Proc returns nil, the logout will redirect
|
60
67
|
# to the default Accounts logout URL.
|
61
68
|
attr_writer :logout_redirect_url
|
@@ -117,6 +124,7 @@ module OpenStax
|
|
117
124
|
@account_user_mapper = OpenStax::Accounts::DefaultAccountUserMapper
|
118
125
|
@min_search_characters = 3
|
119
126
|
@max_search_items = 10
|
127
|
+
@logout_handler = nil
|
120
128
|
@logout_redirect_url = nil
|
121
129
|
@return_to_url_approver = nil
|
122
130
|
@forwardable_login_params = [
|
@@ -6,6 +6,7 @@ FactoryBot.define do
|
|
6
6
|
faculty_status { OpenStax::Accounts::Account.faculty_statuses[:no_faculty_info] }
|
7
7
|
role { OpenStax::Accounts::Account.roles[:unknown_role] }
|
8
8
|
school_type { OpenStax::Accounts::Account.school_types[:unknown_school_type] }
|
9
|
+
school_location { OpenStax::Accounts::Account.school_locations[:unknown_school_location] }
|
9
10
|
uuid { SecureRandom.uuid }
|
10
11
|
support_identifier { "cs_#{SecureRandom.hex(4)}" }
|
11
12
|
is_test { true }
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_accounts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.6.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:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: omniauth
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - "<"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
39
|
+
version: '2.0'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- - "
|
44
|
+
- - "<"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
46
|
+
version: '2.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: omniauth-oauth2
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -342,6 +348,9 @@ files:
|
|
342
348
|
- db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb
|
343
349
|
- db/migrate/15_drop_accounts_groups.rb
|
344
350
|
- db/migrate/16_add_is_kip_to_openstax_accounts_accounts.rb
|
351
|
+
- db/migrate/17_add_school_location_to_openstax_accounts_accounts.rb
|
352
|
+
- db/migrate/18_add_grant_tutor_access_to_openstax_accounts_accounts.rb
|
353
|
+
- db/migrate/19_add_is_administrator_to_openstax_accounts_accounts.rb
|
345
354
|
- db/migrate/1_create_openstax_accounts_groups.rb
|
346
355
|
- db/migrate/2_create_openstax_accounts_group_members.rb
|
347
356
|
- db/migrate/3_create_openstax_accounts_group_owners.rb
|
@@ -384,7 +393,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
384
393
|
- !ruby/object:Gem::Version
|
385
394
|
version: '0'
|
386
395
|
requirements: []
|
387
|
-
rubygems_version: 3.
|
396
|
+
rubygems_version: 3.1.4
|
388
397
|
signing_key:
|
389
398
|
specification_version: 4
|
390
399
|
summary: Rails common code and bindings for the 'accounts' API
|