openstax_accounts 9.1.0 → 9.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94c7f3a9d37b020069be2c39b96a1f7beacb918d50e87aa84d70fe24d437025c
4
- data.tar.gz: 9a857efcee527418bd4287d6b8a61c369fa424541358de01b3dc41f1ae8e3aa7
3
+ metadata.gz: 3bbc4f9d4b0e45a223ac13d149012a2f27fc8ab8b77d71aa2213f447974ae0ee
4
+ data.tar.gz: fed8b3ecbf12bbd0cf45ca9f11a0e73a98c4a4157f97733ce3b2672ecb8bc7ff
5
5
  SHA512:
6
- metadata.gz: 831790e591d38994596ff471d0828b773a8fd770253bf7040ed4c1106b2979e944b9a5ce5777cc89271c552cdb8fb50b7cfb239e316b1251713fe81f960e9237
7
- data.tar.gz: fa14a2404033df1bc6131f6a1b91c134c98bda24d16af737f3442b52ea9b3de1c1933f463ac7c46060cef64fac02e73628990d936f35a7a0bdf1b93a99d6290c
6
+ metadata.gz: eaf4336be588df387e67d9f79633f398053f655c10d624f29d2d0dfe027854a5def31a12c70e088edd7069633762c12707e481cf078e12ea9a389d98b43658be
7
+ data.tar.gz: 98a1fd1915f40aaf349112a28d91a359cc5ec2b8fbeb230d7192e423b07aaab0a65a367367c400bf2ac3ed3180158561a3abcd9a4e930ea6e2c0af18e0dc88d3
@@ -27,14 +27,18 @@ module OpenStax
27
27
  end
28
28
 
29
29
  def destroy
30
- sign_out!
31
-
32
- # Unless we are stubbing, we redirect to a configurable URL, which is normally
33
- # (or at least eventually) the Accounts logout URL so that users can't sign back
34
- # in automagically.
35
- redirect_to configuration.enable_stubbing? ?
36
- main_app.root_url :
37
- configuration.logout_redirect_url(request)
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?
@@ -12,14 +12,23 @@ module OpenStax::Accounts
12
12
  :self_reported_role,
13
13
  :faculty_status,
14
14
  :school_type,
15
+ :school_location,
15
16
  :salesforce_contact_id,
16
17
  :support_identifier,
17
- :is_test
18
+ :is_test,
19
+ :is_kip,
20
+ :grant_tutor_access
18
21
  ]
19
22
 
20
23
  attr_accessor :syncing
21
24
 
22
- enum faculty_status: [:no_faculty_info, :pending_faculty, :confirmed_faculty, :rejected_faculty]
25
+ enum faculty_status: [
26
+ :no_faculty_info,
27
+ :pending_faculty,
28
+ :confirmed_faculty,
29
+ :rejected_faculty
30
+ ]
31
+
23
32
  enum role: [
24
33
  :unknown_role,
25
34
  :student,
@@ -31,9 +40,23 @@ module OpenStax::Accounts
31
40
  :adjunct,
32
41
  :homeschool
33
42
  ]
34
- enum school_type: [:unknown_school_type, :other_school_type, :college]
35
43
 
36
- validates :faculty_status, :role, :school_type, presence: true
44
+ enum school_type: [
45
+ :unknown_school_type,
46
+ :other_school_type,
47
+ :college,
48
+ :high_school,
49
+ :k12_school,
50
+ :home_school
51
+ ]
52
+
53
+ enum school_location: [
54
+ :unknown_school_location,
55
+ :domestic_school,
56
+ :foreign_school
57
+ ]
58
+
59
+ validates :faculty_status, :role, :school_type, :school_location, presence: true
37
60
 
38
61
  validates :uuid, presence: true, uniqueness: true
39
62
  validates :support_identifier, uniqueness: { allow_nil: true }
@@ -5,13 +5,13 @@ module OpenStax
5
5
  module Api
6
6
  module V1
7
7
  class AccountRepresenter < Roar::Decorator
8
-
9
8
  # This representer is used to communicate with Accounts
10
9
  # and so must allow read/write on all properties
11
10
  # Do not use it in create/update APIs!
12
11
 
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, role, school_type and salesforce_contact_id to an account
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
15
15
 
16
16
  include Roar::JSON
17
17
 
@@ -86,24 +86,43 @@ module OpenStax
86
86
  }"
87
87
  }
88
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
+
89
97
  property :uuid,
90
98
  type: String,
91
99
  schema_info: {
92
- description: "The UUID as set by Accounts"
100
+ description: 'The UUID as set by Accounts'
93
101
  }
94
102
 
95
103
  property :support_identifier,
96
104
  type: String,
97
105
  schema_info: {
98
- description: "The support_identifier as set by Accounts"
106
+ description: 'The support_identifier as set by Accounts'
99
107
  }
100
108
 
101
109
  property :is_test,
102
110
  type: :boolean,
103
111
  schema_info: {
104
- description: "Whether or not this is a test account"
112
+ description: 'Whether or not this is a test account'
105
113
  }
106
114
 
115
+ property :is_kip,
116
+ type: :boolean,
117
+ schema_info: {
118
+ description: 'Whether or not this is a Key Institutional Partner account'
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
+ }
107
126
  end
108
127
  end
109
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, is_test: 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, is_test: is_test
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
 
@@ -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
@@ -10,39 +8,42 @@ module OpenStax
10
8
  protected
11
9
 
12
10
  def exec(options={})
13
-
14
11
  return if OpenStax::Accounts.configuration.enable_stubbing?
15
12
 
16
- response = OpenStax::Accounts::Api.get_application_account_updates
13
+ loop do
14
+ response = OpenStax::Accounts::Api.get_application_account_updates
17
15
 
18
- app_accounts = []
19
- app_accounts_rep = OpenStax::Accounts::Api::V1::ApplicationAccountsRepresenter
20
- .new(app_accounts)
21
- app_accounts_rep.from_json(response.body)
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)
22
21
 
23
- return if app_accounts.empty?
22
+ num_accounts = app_accounts.size
23
+ return if num_accounts == 0
24
24
 
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
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
31
31
 
32
- if account != app_account.account
33
32
  OpenStax::Accounts::Account::SYNC_ATTRIBUTES.each do |attribute|
34
- account.send("#{attribute}=", app_account.account.send(attribute))
35
- 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
+ }
36
41
  end
37
42
 
38
- next unless account.save
43
+ OpenStax::Accounts::Api.mark_account_updates_as_read(updated_app_accounts)
39
44
 
40
- updated_app_accounts << {
41
- user_id: account.openstax_uid, read_updates: app_account.unread_updates
42
- }
45
+ return if num_accounts < OpenStax::Accounts.configuration.max_user_updates_per_request
43
46
  end
44
-
45
- OpenStax::Accounts::Api.mark_account_updates_as_read(updated_app_accounts)
46
47
  end
47
48
  end
48
49
  end
@@ -0,0 +1,5 @@
1
+ class AddIsKipToOpenStaxAccountsAccounts < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :openstax_accounts_accounts, :is_kip, :boolean
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddSchoolLocationToOpenStaxAccountsAccounts < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :openstax_accounts_accounts, :school_location, :integer, default: 0, null: false
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddGrantTutorAccessToOpenStaxAccountsAccounts < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :openstax_accounts_accounts, :grant_tutor_access, :boolean
4
+ end
5
+ 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(:get, "application_users/updates#{ '?limit=' + limit.to_s if !limit.blank? }", options)
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 = [
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = '9.1.0'
3
+ VERSION = '9.5.1'
4
4
  end
5
5
  end
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-10 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -341,6 +341,9 @@ files:
341
341
  - db/migrate/13_add_school_type_to_accounts_accounts.rb
342
342
  - db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb
343
343
  - db/migrate/15_drop_accounts_groups.rb
344
+ - db/migrate/16_add_is_kip_to_openstax_accounts_accounts.rb
345
+ - db/migrate/17_add_school_location_to_openstax_accounts_accounts.rb
346
+ - db/migrate/18_add_grant_tutor_access_to_openstax_accounts_accounts.rb
344
347
  - db/migrate/1_create_openstax_accounts_groups.rb
345
348
  - db/migrate/2_create_openstax_accounts_group_members.rb
346
349
  - db/migrate/3_create_openstax_accounts_group_owners.rb