openstax_accounts 8.1.1 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/openstax/accounts/dev/accounts_controller.rb +1 -2
  3. data/app/controllers/openstax/accounts/sessions_controller.rb +1 -2
  4. data/app/handlers/openstax/accounts/sessions_callback.rb +2 -4
  5. data/app/models/openstax/accounts/account.rb +1 -19
  6. data/app/models/openstax/accounts/anonymous_account.rb +1 -2
  7. data/app/routines/openstax/accounts/find_or_create_account.rb +7 -8
  8. data/app/routines/openstax/accounts/find_or_create_from_sso.rb +2 -8
  9. data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
  10. data/app/views/openstax/accounts/dev/accounts/_search_results.html.erb +3 -3
  11. data/config/routes.rb +1 -3
  12. data/db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb +9 -0
  13. data/db/migrate/15_drop_accounts_groups.rb +42 -0
  14. data/lib/omniauth/strategies/openstax.rb +1 -1
  15. data/lib/openstax/accounts/api.rb +0 -149
  16. data/lib/openstax/accounts/current_user_manager.rb +1 -5
  17. data/lib/openstax/accounts/engine.rb +1 -1
  18. data/lib/openstax/accounts/version.rb +1 -1
  19. data/lib/tasks/sync.rake +0 -8
  20. metadata +5 -22
  21. data/app/models/openstax/accounts/application_group.rb +0 -7
  22. data/app/models/openstax/accounts/group.rb +0 -169
  23. data/app/models/openstax/accounts/group_member.rb +0 -37
  24. data/app/models/openstax/accounts/group_nesting.rb +0 -55
  25. data/app/models/openstax/accounts/group_owner.rb +0 -37
  26. data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +0 -48
  27. data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -20
  28. data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +0 -31
  29. data/app/representers/openstax/accounts/api/v1/group_representer.rb +0 -71
  30. data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +0 -34
  31. data/app/routines/openstax/accounts/create_group.rb +0 -26
  32. data/app/routines/openstax/accounts/sync_groups.rb +0 -67
  33. data/app/routines/openstax/accounts/update_group_caches.rb +0 -27
  34. data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +0 -51
  35. data/spec/factories/openstax_accounts_group.rb +0 -7
  36. data/spec/factories/openstax_accounts_group_member.rb +0 -6
  37. data/spec/factories/openstax_accounts_group_nesting.rb +0 -6
  38. data/spec/factories/openstax_accounts_group_owner.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edf27a81aef8f196ab5b804f38903395d24367628209a9eeb001a37f258f33d5
4
- data.tar.gz: af2ac3a3de4ab707958bc03b0faf561e876b99521f82a8695a55cfcbbd1bc740
3
+ metadata.gz: e3fe1e9662df1f455d7506864c26c6143134196a7e191b6606a4644db5e564b2
4
+ data.tar.gz: 13778e9ea7baf42944c3fdfe3ccd590e1bcf8100771956dbbc12a2e1295042d9
5
5
  SHA512:
6
- metadata.gz: 3f8b506ad52a7bb2b59ed822f0347c7bb5343728dbedf7fa166f7ffc2aabc7ce9c3b8a6113d09aab44795a04e79e74595583e2335e825b0e682e7be3604b4a8c
7
- data.tar.gz: fca6c2d52b5540bac193bc099c905ca4a6aa860c7353b411259ae95c878e872fb7c0f46f67c7b0a3813b7ae853dd967e969839c524384a07d1b30e3754677874
6
+ metadata.gz: e74e04ebbf93d4703146f94f23d63ec69a9d68fd9437bee355789a36f51ec010857fd5b1805b79bfb6e5880b5eac73cb883d8e51163c6ec28ea599247ae85675
7
+ data.tar.gz: 9aa7d1ddfd8c37e9de254403c51469fad5a317406d5eab74001421131deef5b94e3078f3378567e3a141f1ff461cf65d741a5969fe809d3e50b0dcf320799dfa
@@ -18,7 +18,7 @@ module OpenStax
18
18
  end
19
19
 
20
20
  def become
21
- @account = Account.find_by(openstax_uid: params[:id])
21
+ @account = Account.find(params[:id])
22
22
  sign_in(@account)
23
23
  redirect_back key: :accounts_return_to, strategies: [:session]
24
24
  end
@@ -28,7 +28,6 @@ module OpenStax
28
28
  def allow_iframe_access
29
29
  response.headers.except! 'X-Frame-Options'
30
30
  end
31
-
32
31
  end
33
32
  end
34
33
  end
@@ -40,8 +40,7 @@ module OpenStax
40
40
  end
41
41
 
42
42
  def failure
43
- redirect_back key: :accounts_return_to,
44
- alert: "Authentication failed, please try again."
43
+ redirect_back key: :accounts_return_to, alert: "Authentication failed, please try again."
45
44
  end
46
45
 
47
46
  def profile
@@ -15,15 +15,13 @@ module OpenStax
15
15
 
16
16
  def handle
17
17
  # Don't worry if the account is logged in or not beforehand. Just assume that they aren't.
18
-
19
18
  # tap is used because we want the block to always run (not just when initializing)
20
19
  begin
21
- outputs.account = Account.find_or_initialize_by(
22
- openstax_uid: @auth_data.uid
23
- ).tap do |account|
20
+ outputs.account = Account.find_or_initialize_by(uuid: @auth_data.uid).tap do |account|
24
21
  account.access_token = @auth_data.credentials.token
25
22
 
26
23
  raw_info = @auth_data.extra.raw_info
24
+ raw_info = raw_info.merge openstax_uid: raw_info[:id]
27
25
  OpenStax::Accounts::Account::SYNC_ATTRIBUTES.each do |attribute|
28
26
  begin
29
27
  account.send "#{attribute}=", raw_info[attribute]
@@ -1,9 +1,9 @@
1
1
  module OpenStax::Accounts
2
2
  class Account < ActiveRecord::Base
3
-
4
3
  USERNAME_DISCARDED_CHAR_REGEX = /[^A-Za-z\d_]/
5
4
  USERNAME_MAX_LENGTH = 50
6
5
  SYNC_ATTRIBUTES = [
6
+ :openstax_uid,
7
7
  :username,
8
8
  :first_name,
9
9
  :last_name,
@@ -13,27 +13,12 @@ module OpenStax::Accounts
13
13
  :faculty_status,
14
14
  :school_type,
15
15
  :salesforce_contact_id,
16
- :uuid,
17
16
  :support_identifier,
18
17
  :is_test
19
18
  ]
20
19
 
21
20
  attr_accessor :syncing
22
21
 
23
- has_many :group_owners, dependent: :destroy,
24
- class_name: 'OpenStax::Accounts::GroupOwner',
25
- primary_key: :openstax_uid,
26
- foreign_key: :user_id,
27
- inverse_of: :user
28
- has_many :groups_as_owner, through: :group_owners, source: :group
29
-
30
- has_many :group_members, dependent: :destroy,
31
- class_name: 'OpenStax::Accounts::GroupMember',
32
- primary_key: :openstax_uid,
33
- foreign_key: :user_id,
34
- inverse_of: :user
35
- has_many :groups_as_member, through: :group_members, source: :group
36
-
37
22
  enum faculty_status: [:no_faculty_info, :pending_faculty, :confirmed_faculty, :rejected_faculty]
38
23
  enum role: [
39
24
  :unknown_role,
@@ -50,8 +35,6 @@ module OpenStax::Accounts
50
35
 
51
36
  validates :faculty_status, :role, :school_type, presence: true
52
37
 
53
- validates :openstax_uid, uniqueness: { allow_nil: true }
54
- validates :username, uniqueness: { allow_nil: true }
55
38
  validates :uuid, presence: true, uniqueness: true
56
39
  validates :support_identifier, uniqueness: { allow_nil: true }
57
40
 
@@ -98,6 +81,5 @@ module OpenStax::Accounts
98
81
  def update_openstax_accounts
99
82
  OpenStax::Accounts::Api.update_account(self)
100
83
  end
101
-
102
84
  end
103
85
  end
@@ -1,7 +1,6 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  class AnonymousAccount < Account
4
-
5
4
  include Singleton
6
5
 
7
6
  before_save { false }
@@ -9,6 +8,7 @@ module OpenStax
9
8
  def initialize(attributes=nil)
10
9
  super
11
10
  self.id = nil
11
+ self.uuid = nil
12
12
  self.openstax_uid = nil
13
13
  self.username = 'anonymous'
14
14
  self.first_name = 'Guest'
@@ -18,7 +18,6 @@ module OpenStax
18
18
  def is_anonymous?
19
19
  true
20
20
  end
21
-
22
21
  end
23
22
  end
24
23
  end
@@ -1,7 +1,6 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  class FindOrCreateAccount
4
-
5
4
  lev_routine
6
5
 
7
6
  protected
@@ -16,8 +15,8 @@ module OpenStax
16
15
 
17
16
  if OpenStax::Accounts.configuration.enable_stubbing
18
17
  # We can only stub finding by username b/c accounts-rails doesn't persist emails
19
- id = Account.find_by(username: username).try!(:openstax_uid) ||
20
- -SecureRandom.hex(4).to_i(16)/2
18
+ openstax_uid = Account.find_by(username: username)&.openstax_uid ||
19
+ -SecureRandom.hex(4).to_i(16)/2
21
20
  uuid = SecureRandom.uuid
22
21
  support_identifier = "cs_#{SecureRandom.hex(4)}"
23
22
  else
@@ -25,17 +24,18 @@ module OpenStax
25
24
  email: email, username: username, password: password,
26
25
  first_name: first_name, last_name: last_name, full_name: full_name,
27
26
  salesforce_contact_id: salesforce_contact_id, faculty_status: faculty_status,
28
- role: role, school_type: school_type, is_test: is_test)
27
+ role: role, school_type: school_type, is_test: is_test
28
+ )
29
29
  fatal_error(code: :invalid_inputs) unless (200..202).include?(response.status)
30
30
 
31
31
  struct = OpenStruct.new
32
32
  Api::V1::UnclaimedAccountRepresenter.new(struct).from_json(response.body)
33
- id = struct.id
33
+ openstax_uid = struct.id
34
34
  uuid = struct.uuid
35
35
  support_identifier = struct.support_identifier
36
36
  end
37
37
 
38
- account = Account.find_or_initialize_by(openstax_uid: id)
38
+ account = Account.find_or_initialize_by(uuid: uuid)
39
39
 
40
40
  unless account.persisted?
41
41
  while username.nil? || Account.where(username: username).exists? do
@@ -50,7 +50,7 @@ module OpenStax
50
50
  account.faculty_status = faculty_status || :no_faculty_info
51
51
  account.role = role || :unknown_role
52
52
  account.school_type = school_type || :unknown_school_type
53
- account.uuid = uuid
53
+ account.openstax_uid = openstax_uid
54
54
  account.support_identifier = support_identifier
55
55
  account.is_test = is_test
56
56
  account.save!
@@ -59,7 +59,6 @@ module OpenStax
59
59
  transfer_errors_from(account, {type: :verbatim}, true)
60
60
  outputs.account = account
61
61
  end
62
-
63
62
  end
64
63
  end
65
64
  end
@@ -1,23 +1,17 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  class FindOrCreateFromSso
4
-
5
4
  lev_routine express_output: :account
6
5
 
7
6
  def exec(attrs)
8
7
  attrs.stringify_keys!
9
8
  uid = attrs.delete('id')
10
9
  uuid = attrs.delete('uuid')
11
- account = Account.find_or_initialize_by(
12
- uuid: uuid, openstax_uid: uid
13
- )
14
- account.update_attributes!(
15
- attrs.slice(*Account.column_names)
16
- )
10
+ account = Account.find_or_initialize_by(uuid: uuid)
11
+ account.update_attributes!(attrs.slice(*Account.column_names))
17
12
  transfer_errors_from(account, {type: :verbatim})
18
13
  outputs.account = account
19
14
  end
20
-
21
15
  end
22
16
  end
23
17
  end
@@ -4,9 +4,7 @@
4
4
 
5
5
  module OpenStax
6
6
  module Accounts
7
-
8
7
  class SyncAccounts
9
-
10
8
  lev_routine transaction: :no_transaction
11
9
 
12
10
  protected
@@ -27,7 +25,7 @@ module OpenStax
27
25
  updated_app_accounts = []
28
26
  app_accounts.each do |app_account|
29
27
  account = OpenStax::Accounts::Account.find_by(
30
- openstax_uid: app_account.account.openstax_uid
28
+ uuid: app_account.account.uuid
31
29
  ) || app_account.account
32
30
  account.syncing = true
33
31
 
@@ -45,10 +43,7 @@ module OpenStax
45
43
  end
46
44
 
47
45
  OpenStax::Accounts::Api.mark_account_updates_as_read(updated_app_accounts)
48
-
49
46
  end
50
-
51
47
  end
52
-
53
48
  end
54
49
  end
@@ -12,13 +12,13 @@
12
12
  headings: ['UID', 'Username (click to sign in as)', 'Name'],
13
13
  widths: ['20%', '40%', '40%'],
14
14
  data_procs: [
15
- lambda { |account| account.openstax_uid },
16
- lambda { |account|
15
+ ->(account) { account.openstax_uid },
16
+ ->(account) {
17
17
  link_to account.username, become_dev_account_path(
18
18
  account.openstax_uid
19
19
  ), method: :post
20
20
  },
21
- lambda { |account| account.name || '---' }
21
+ ->(account) { account.name || '---' }
22
22
  ]
23
23
  }
24
24
  ) %>
@@ -1,5 +1,4 @@
1
1
  OpenStax::Accounts::Engine.routes.draw do
2
-
3
2
  # Redirect here if we don't know what to do (theoretically should not happen)
4
3
  root to: 'sessions#new'
5
4
 
@@ -7,8 +6,8 @@ OpenStax::Accounts::Engine.routes.draw do
7
6
  # This is provided by OmniAuth and is not in the SessionsController
8
7
  get '/auth/openstax', as: 'openstax_login'
9
8
 
10
- # User profile route
11
9
  if OpenStax::Accounts.configuration.enable_stubbing?
10
+ # User profile route
12
11
  namespace :dev do
13
12
  resources :accounts, only: [:index, :create] do
14
13
  post 'become', on: :member
@@ -27,5 +26,4 @@ OpenStax::Accounts::Engine.routes.draw do
27
26
  via: OpenStax::Accounts.configuration.logout_via
28
27
  get 'profile', action: :profile # Redirects to profile path or stub
29
28
  end
30
-
31
29
  end
@@ -0,0 +1,9 @@
1
+ class DropOpenStaxUidAndUsernameUniqueness < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_index :openstax_accounts_accounts, column: [ :openstax_uid ], unique: true
4
+ remove_index :openstax_accounts_accounts, column: [ :username ], unique: true
5
+
6
+ add_index :openstax_accounts_accounts, :openstax_uid
7
+ add_index :openstax_accounts_accounts, :username
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ class DropAccountsGroups < ActiveRecord::Migration[5.2]
2
+ def change
3
+ drop_table "openstax_accounts_group_members" do |t|
4
+ t.integer "group_id", null: false
5
+ t.integer "user_id", null: false
6
+ t.datetime "created_at", null: false
7
+ t.datetime "updated_at", null: false
8
+ t.index ["group_id", "user_id"], name: "index_openstax_accounts_group_members_on_group_id_and_user_id", unique: true
9
+ t.index ["user_id"], name: "index_openstax_accounts_group_members_on_user_id"
10
+ end
11
+
12
+ drop_table "openstax_accounts_group_nestings" do |t|
13
+ t.integer "member_group_id", null: false
14
+ t.integer "container_group_id", null: false
15
+ t.datetime "created_at", null: false
16
+ t.datetime "updated_at", null: false
17
+ t.index ["container_group_id"], name: "index_openstax_accounts_group_nestings_on_container_group_id"
18
+ t.index ["member_group_id"], name: "index_openstax_accounts_group_nestings_on_member_group_id", unique: true
19
+ end
20
+
21
+ drop_table "openstax_accounts_group_owners" do |t|
22
+ t.integer "group_id", null: false
23
+ t.integer "user_id", null: false
24
+ t.datetime "created_at", null: false
25
+ t.datetime "updated_at", null: false
26
+ t.index ["group_id", "user_id"], name: "index_openstax_accounts_group_owners_on_group_id_and_user_id", unique: true
27
+ t.index ["user_id"], name: "index_openstax_accounts_group_owners_on_user_id"
28
+ end
29
+
30
+ drop_table "openstax_accounts_groups" do |t|
31
+ t.integer "openstax_uid", null: false
32
+ t.boolean "is_public", default: false, null: false
33
+ t.string "name"
34
+ t.text "cached_subtree_group_ids"
35
+ t.text "cached_supertree_group_ids"
36
+ t.datetime "created_at", null: false
37
+ t.datetime "updated_at", null: false
38
+ t.index ["is_public"], name: "index_openstax_accounts_groups_on_is_public"
39
+ t.index ["openstax_uid"], name: "index_openstax_accounts_groups_on_openstax_uid", unique: true
40
+ end
41
+ end
42
+ end
@@ -11,7 +11,7 @@ module OmniAuth
11
11
  authorize_url: "/oauth/authorize"
12
12
  }
13
13
 
14
- uid { raw_info[:id] }
14
+ uid { raw_info[:uuid] }
15
15
 
16
16
  info do
17
17
  # Changed to conform to the omniauth schema
@@ -97,155 +97,6 @@ module OpenStax
97
97
  request(:put, 'application_users/updated', options.merge(body: application_users.to_json))
98
98
  end
99
99
 
100
- # Retrieves information about groups that have been
101
- # recently updated.
102
- # Results are limited to groups that users of the current app
103
- # have access to.
104
- # Takes an options hash.
105
- # On failure, throws an Exception, just like the request method.
106
- # On success, returns an OAuth2::Response object.
107
- def self.get_application_group_updates(options = {})
108
- request(:get, 'application_groups/updates', options)
109
- end
110
-
111
- # Marks group updates as "read".
112
- # The application_groups parameter is an array of hashes.
113
- # Each hash has 2 required fields: 'id', which should contain the
114
- # application_group's id, and 'read_updates', which should contain
115
- # the last received value of unread_updates for that application_group.
116
- # Can only be called for application_groups that belong to the current app.
117
- # Also takes an options hash.
118
- # On failure, throws an Exception, just like the request method.
119
- # On success, returns an OAuth2::Response object.
120
- def self.mark_group_updates_as_read(application_groups, options = {})
121
- request(:put, 'application_groups/updated', options.merge(
122
- body: application_groups.to_json
123
- ))
124
- end
125
-
126
- # Creates a group in the Accounts server.
127
- # The given account will be the owner of the group.
128
- # Also takes an options hash.
129
- # On failure, throws an Exception, just like the request method.
130
- # On success, returns a hash containing the group attributes
131
- def self.create_group(account, group, options = {})
132
- response = ActiveSupport::JSON.decode(
133
- request_for_account(account, :post, 'groups', options.merge(
134
- body: group.attributes.slice('name', 'is_public').to_json
135
- )).body
136
- )
137
- group.openstax_uid = response['id']
138
- response
139
- end
140
-
141
- # Updates a group in the Accounts server.
142
- # The given account must own the group.
143
- # Also takes an options hash.
144
- # On failure, throws an Exception, just like the request method.
145
- # On success, returns an OAuth2::Response object.
146
- def self.update_group(account, group, options = {})
147
- request_for_account(account, :put, "groups/#{group.openstax_uid}",
148
- options.merge(
149
- body: group.attributes.slice('name', 'is_public').to_json
150
- )
151
- )
152
- end
153
-
154
- # Deletes a group from the Accounts server.
155
- # The given account must own the group.
156
- # Also takes an options hash.
157
- # On failure, throws an Exception, just like the request method.
158
- # On success, returns an OAuth2::Response object.
159
- def self.destroy_group(account, group, options = {})
160
- request_for_account(account, :delete, "groups/#{group.openstax_uid}", options)
161
- end
162
-
163
- # Creates a group_member in the Accounts server.
164
- # The given account must own the group.
165
- # Also takes an options hash.
166
- # On failure, throws an Exception, just like the request method.
167
- # On success, returns an OAuth2::Response object.
168
- def self.create_group_member(account, group_member, options = {})
169
- request_for_account(
170
- account,
171
- :post,
172
- "groups/#{group_member.group_id}/members/#{group_member.user_id}",
173
- options
174
- )
175
- end
176
-
177
- # Deletes a group_member from the Accounts server.
178
- # The given account must own the group.
179
- # Also takes an options hash.
180
- # On failure, throws an Exception, just like the request method.
181
- # On success, returns an OAuth2::Response object.
182
- def self.destroy_group_member(account, group_member, options = {})
183
- request_for_account(
184
- account,
185
- :delete,
186
- "groups/#{group_member.group_id}/members/#{group_member.user_id}",
187
- options
188
- )
189
- end
190
-
191
- # Creates a group_owner in the Accounts server.
192
- # The given account must own the group.
193
- # Also takes an options hash.
194
- # On failure, throws an Exception, just like the request method.
195
- # On success, returns an OAuth2::Response object.
196
- def self.create_group_owner(account, group_owner, options = {})
197
- request_for_account(
198
- account,
199
- :post,
200
- "groups/#{group_owner.group_id}/owners/#{group_owner.user_id}",
201
- options
202
- )
203
- end
204
-
205
- # Deletes a group_owner from the Accounts server.
206
- # The given account must own the group.
207
- # Also takes an options hash.
208
- # On failure, throws an Exception, just like the request method.
209
- # On success, returns an OAuth2::Response object.
210
- def self.destroy_group_owner(account, group_owner, options = {})
211
- request_for_account(
212
- account,
213
- :delete,
214
- "groups/#{group_owner.group_id}/owners/#{group_owner.user_id}",
215
- options
216
- )
217
- end
218
-
219
- # Creates a group_nesting in the Accounts server.
220
- # The given account must own both groups.
221
- # Also takes an an options hash.
222
- # On failure, throws an Exception, just like the request method.
223
- # On success, returns an OAuth2::Response object.
224
- def self.create_group_nesting(account, group_nesting, options = {})
225
- request_for_account(
226
- account,
227
- :post,
228
- "groups/#{group_nesting.container_group_id}/nestings/#{
229
- group_nesting.member_group_id}",
230
- options
231
- )
232
- end
233
-
234
- # Deletes a group_nesting from the Accounts server.
235
- # The given account must own either group.
236
- # Also takes an options hash.
237
- # On failure, throws an Exception, just like the request method.
238
- # On success, returns an OAuth2::Response object.
239
- def self.destroy_group_nesting(account, group_nesting, options = {})
240
- request_for_account(
241
- account,
242
- :delete,
243
- "groups/#{group_nesting.container_group_id}/nestings/#{
244
- group_nesting.member_group_id}",
245
- options
246
- )
247
- end
248
-
249
100
  # Finds an account matching the provided attributes or creates a new
250
101
  # account. Also takes an options hash.
251
102
  # On failure, throws an Exception, just like the request method.