openstax_accounts 8.0.1 → 9.0.2

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/openstax/accounts/application_controller.rb +0 -4
  3. data/app/controllers/openstax/accounts/dev/accounts_controller.rb +16 -10
  4. data/app/controllers/openstax/accounts/dev/base_controller.rb +1 -5
  5. data/app/controllers/openstax/accounts/sessions_controller.rb +2 -5
  6. data/app/handlers/openstax/accounts/accounts_search.rb +3 -5
  7. data/app/handlers/openstax/accounts/dev/accounts_create.rb +1 -7
  8. data/app/handlers/openstax/accounts/dev/accounts_search.rb +0 -2
  9. data/app/handlers/openstax/accounts/sessions_callback.rb +2 -4
  10. data/app/models/openstax/accounts/account.rb +1 -19
  11. data/app/models/openstax/accounts/anonymous_account.rb +1 -2
  12. data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -7
  13. data/app/routines/openstax/accounts/dev/create_account.rb +23 -21
  14. data/app/routines/openstax/accounts/find_or_create_account.rb +16 -25
  15. data/app/routines/openstax/accounts/find_or_create_from_sso.rb +2 -8
  16. data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
  17. data/app/views/layouts/openstax/accounts/application.html.erb +2 -2
  18. data/app/views/openstax/accounts/dev/accounts/_search_results.html.erb +9 -10
  19. data/app/views/openstax/accounts/dev/accounts/index.html.erb +7 -10
  20. data/app/views/openstax/accounts/dev/accounts/{search.js.erb → index.js.erb} +0 -0
  21. data/app/views/openstax/accounts/shared/_attention.html.erb +9 -1
  22. data/app/views/openstax/accounts/shared/accounts/_search.html.erb +12 -8
  23. data/config/routes.rb +2 -5
  24. data/db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb +9 -0
  25. data/db/migrate/15_drop_accounts_groups.rb +42 -0
  26. data/lib/omniauth/strategies/openstax.rb +1 -1
  27. data/lib/openstax/accounts/api.rb +0 -149
  28. data/lib/openstax/accounts/current_user_manager.rb +1 -5
  29. data/lib/openstax/accounts/engine.rb +1 -1
  30. data/lib/openstax/accounts/sso.rb +4 -3
  31. data/lib/openstax/accounts/version.rb +1 -1
  32. data/lib/tasks/sync.rake +0 -8
  33. metadata +10 -26
  34. data/app/models/openstax/accounts/application_group.rb +0 -7
  35. data/app/models/openstax/accounts/group.rb +0 -169
  36. data/app/models/openstax/accounts/group_member.rb +0 -37
  37. data/app/models/openstax/accounts/group_nesting.rb +0 -55
  38. data/app/models/openstax/accounts/group_owner.rb +0 -37
  39. data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +0 -48
  40. data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -20
  41. data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +0 -31
  42. data/app/representers/openstax/accounts/api/v1/group_representer.rb +0 -71
  43. data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +0 -34
  44. data/app/routines/openstax/accounts/create_group.rb +0 -26
  45. data/app/routines/openstax/accounts/sync_groups.rb +0 -67
  46. data/app/routines/openstax/accounts/update_group_caches.rb +0 -27
  47. data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +0 -51
  48. data/spec/factories/openstax_accounts_group.rb +0 -7
  49. data/spec/factories/openstax_accounts_group_member.rb +0 -6
  50. data/spec/factories/openstax_accounts_group_nesting.rb +0 -6
  51. data/spec/factories/openstax_accounts_group_owner.rb +0 -6
@@ -12,7 +12,7 @@ require 'roar'
12
12
  require 'roar/decorator'
13
13
  require 'roar/json'
14
14
  require 'openstax/accounts/action_controller/base'
15
- require 'openstax/accounts/has_many_through_groups/active_record/base'
15
+ require 'omniauth'
16
16
 
17
17
  module OpenStax
18
18
  module Accounts
@@ -14,7 +14,7 @@ module OpenStax
14
14
  extend self
15
15
 
16
16
  def user_uuid(request)
17
- decrypt(request)['user_uuid']
17
+ (decrypt(request) || {}).dig("user", "uuid")
18
18
  end
19
19
 
20
20
  # https://github.com/rails/rails/blob/4-2-stable/activesupport/lib/active_support/message_encryptor.rb#L90
@@ -40,14 +40,15 @@ module OpenStax
40
40
  key = OpenStax::Accounts.configuration.sso_secret_key
41
41
  raise InvalidSecretsConfiguration, 'Missing sso_secret_key configuration' if key.blank?
42
42
 
43
+ cipher = 'aes-256-cbc'
43
44
  salt = OpenStax::Accounts.configuration.sso_secret_salt
44
45
  signed_salt = "signed encrypted #{salt}"
45
46
  key_generator = ActiveSupport::KeyGenerator.new(key, iterations: 1000)
46
47
  secret = key_generator.generate_key(salt)[
47
- 0, OpenSSL::Cipher.new('aes-256-cbc').key_len
48
+ 0, OpenSSL::Cipher.new(cipher).key_len
48
49
  ]
49
50
  sign_secret = key_generator.generate_key(signed_salt)
50
- ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON)
51
+ ActiveSupport::MessageEncryptor.new(secret, sign_secret, cipher: cipher, serializer: JSON)
51
52
  end
52
53
  end
53
54
 
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "8.0.1"
3
+ VERSION = '9.0.2'
4
4
  end
5
5
  end
data/lib/tasks/sync.rake CHANGED
@@ -5,14 +5,6 @@ namespace :openstax do
5
5
  task accounts: :environment do
6
6
  OpenStax::Accounts::SyncAccounts.call
7
7
  end
8
-
9
- desc "Sync Groups with OpenStax Accounts"
10
- task groups: :environment do
11
- OpenStax::Accounts::SyncGroups.call
12
- end
13
-
14
- desc "Sync Accounts and Groups with OpenStax Accounts"
15
- task all: [:accounts, :groups]
16
8
  end
17
9
  end
18
10
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.1
4
+ version: 9.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2020-01-24 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
- version: '0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: omniauth
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -315,35 +315,22 @@ files:
315
315
  - app/models/openstax/accounts/account.rb
316
316
  - app/models/openstax/accounts/anonymous_account.rb
317
317
  - app/models/openstax/accounts/application_account.rb
318
- - app/models/openstax/accounts/application_group.rb
319
- - app/models/openstax/accounts/group.rb
320
- - app/models/openstax/accounts/group_member.rb
321
- - app/models/openstax/accounts/group_nesting.rb
322
- - app/models/openstax/accounts/group_owner.rb
323
318
  - app/representers/openstax/accounts/api/v1/account_representer.rb
324
319
  - app/representers/openstax/accounts/api/v1/account_search_representer.rb
325
320
  - app/representers/openstax/accounts/api/v1/application_account_representer.rb
326
321
  - app/representers/openstax/accounts/api/v1/application_account_search_representer.rb
327
322
  - app/representers/openstax/accounts/api/v1/application_accounts_representer.rb
328
- - app/representers/openstax/accounts/api/v1/application_group_representer.rb
329
- - app/representers/openstax/accounts/api/v1/application_groups_representer.rb
330
- - app/representers/openstax/accounts/api/v1/group_nesting_representer.rb
331
- - app/representers/openstax/accounts/api/v1/group_representer.rb
332
- - app/representers/openstax/accounts/api/v1/group_user_representer.rb
333
323
  - app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb
334
- - app/routines/openstax/accounts/create_group.rb
335
324
  - app/routines/openstax/accounts/dev/create_account.rb
336
325
  - app/routines/openstax/accounts/find_or_create_account.rb
337
326
  - app/routines/openstax/accounts/find_or_create_from_sso.rb
338
327
  - app/routines/openstax/accounts/search_accounts.rb
339
328
  - app/routines/openstax/accounts/search_local_accounts.rb
340
329
  - app/routines/openstax/accounts/sync_accounts.rb
341
- - app/routines/openstax/accounts/sync_groups.rb
342
- - app/routines/openstax/accounts/update_group_caches.rb
343
330
  - app/views/layouts/openstax/accounts/application.html.erb
344
331
  - app/views/openstax/accounts/dev/accounts/_search_results.html.erb
345
332
  - app/views/openstax/accounts/dev/accounts/index.html.erb
346
- - app/views/openstax/accounts/dev/accounts/search.js.erb
333
+ - app/views/openstax/accounts/dev/accounts/index.js.erb
347
334
  - app/views/openstax/accounts/shared/_attention.html.erb
348
335
  - app/views/openstax/accounts/shared/accounts/_search.html.erb
349
336
  - config/routes.rb
@@ -352,6 +339,8 @@ files:
352
339
  - db/migrate/11_add_support_identifier_to_accounts_accounts.rb
353
340
  - db/migrate/12_add_is_test_to_accounts_accounts.rb
354
341
  - db/migrate/13_add_school_type_to_accounts_accounts.rb
342
+ - db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb
343
+ - db/migrate/15_drop_accounts_groups.rb
355
344
  - db/migrate/1_create_openstax_accounts_groups.rb
356
345
  - db/migrate/2_create_openstax_accounts_group_members.rb
357
346
  - db/migrate/3_create_openstax_accounts_group_owners.rb
@@ -371,16 +360,11 @@ files:
371
360
  - lib/openstax/accounts/current_user_manager.rb
372
361
  - lib/openstax/accounts/default_account_user_mapper.rb
373
362
  - lib/openstax/accounts/engine.rb
374
- - lib/openstax/accounts/has_many_through_groups/active_record/base.rb
375
363
  - lib/openstax/accounts/sso.rb
376
364
  - lib/openstax/accounts/version.rb
377
365
  - lib/openstax_accounts.rb
378
366
  - lib/tasks/sync.rake
379
367
  - spec/factories/openstax_accounts_account.rb
380
- - spec/factories/openstax_accounts_group.rb
381
- - spec/factories/openstax_accounts_group_member.rb
382
- - spec/factories/openstax_accounts_group_nesting.rb
383
- - spec/factories/openstax_accounts_group_owner.rb
384
368
  homepage: http://github.com/openstax/accounts-rails
385
369
  licenses: []
386
370
  metadata: {}
@@ -399,7 +383,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
383
  - !ruby/object:Gem::Version
400
384
  version: '0'
401
385
  requirements: []
402
- rubygems_version: 3.0.4
386
+ rubygems_version: 3.1.1
403
387
  signing_key:
404
388
  specification_version: 4
405
389
  summary: Rails common code and bindings for the 'accounts' API
@@ -1,7 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
- class ApplicationGroup
4
- attr_accessor :id, :application_id, :group, :unread_updates
5
- end
6
- end
7
- end
@@ -1,169 +0,0 @@
1
- module OpenStax::Accounts
2
- class Group < ActiveRecord::Base
3
-
4
- serialize :cached_supertree_group_ids
5
- serialize :cached_subtree_group_ids
6
-
7
- attr_accessor :requestor, :syncing
8
-
9
- has_many :group_owners, dependent: :destroy,
10
- class_name: 'OpenStax::Accounts::GroupOwner',
11
- primary_key: :openstax_uid, inverse_of: :group
12
- has_many :owners, through: :group_owners, source: :user
13
-
14
- has_many :group_members, dependent: :destroy,
15
- class_name: 'OpenStax::Accounts::GroupMember',
16
- primary_key: :openstax_uid,
17
- inverse_of: :group
18
- has_many :members, through: :group_members, source: :user
19
-
20
- has_one :container_group_nesting, dependent: :destroy,
21
- class_name: 'OpenStax::Accounts::GroupNesting',
22
- primary_key: :openstax_uid,
23
- foreign_key: :member_group_id,
24
- inverse_of: :member_group
25
- has_one :container_group, through: :container_group_nesting
26
-
27
- has_many :member_group_nestings,
28
- class_name: 'OpenStax::Accounts::GroupNesting',
29
- primary_key: :openstax_uid,
30
- foreign_key: :container_group_id,
31
- dependent: :destroy,
32
- inverse_of: :container_group
33
- has_many :member_groups, through: :member_group_nestings
34
-
35
- validates :openstax_uid, uniqueness: true, presence: true
36
- validates_presence_of :requestor, unless: :syncing_or_stubbing?
37
- validates_uniqueness_of :name, allow_nil: true, unless: :syncing_or_stubbing?
38
-
39
- before_validation :create_openstax_accounts_group, on: :create, unless: :syncing_or_stubbing?
40
- before_update :update_openstax_accounts_group, unless: :syncing_or_stubbing?
41
- before_destroy :destroy_openstax_accounts_group, unless: :syncing_or_stubbing?
42
-
43
- scope(
44
- :visible_for, ->(account) do
45
- next where(is_public: true) unless account.is_a? OpenStax::Accounts::Account
46
-
47
- groups = arel_table
48
- group_members = OpenStax::Accounts::GroupMember.arel_table
49
- group_owners = OpenStax::Accounts::GroupOwner.arel_table
50
-
51
- where(
52
- groups[:is_public].eq(true).or(
53
- OpenStax::Accounts::GroupMember.where(
54
- group_members[:group_id].eq(groups[:openstax_uid]).and(
55
- group_members[:user_id].eq(account.id)
56
- )
57
- ).exists
58
- ).or(
59
- OpenStax::Accounts::GroupOwner.where(
60
- group_owners[:group_id].eq(groups[:openstax_uid]).and(
61
- group_owners[:user_id].eq(account.id)
62
- )
63
- ).exists
64
- )
65
- )
66
- end
67
- )
68
-
69
- def has_owner?(account)
70
- return false unless account.is_a? OpenStax::Accounts::Account
71
-
72
- gos = group_owners
73
- gos = gos.preload(:user) if persisted?
74
- gos.any?{ |go| go.user == account }
75
- end
76
-
77
- def has_direct_member?(account)
78
- return false unless account.is_a? OpenStax::Accounts::Account
79
-
80
- gms = group_members
81
- gms = gms.preload(:user) if persisted?
82
- gms.any?{ |gm| gm.user == account }
83
- end
84
-
85
- def has_member?(account)
86
- return false unless account.is_a? OpenStax::Accounts::Account
87
- !account.group_members.where(group_id: subtree_group_ids).first.nil?
88
- end
89
-
90
- def add_owner(account)
91
- return unless account.is_a? OpenStax::Accounts::Account
92
- go = GroupOwner.new
93
- go.group = self
94
- go.user = account
95
- return unless go.valid?
96
- go.save if persisted?
97
- group_owners << go
98
- go
99
- end
100
-
101
- def add_member(account)
102
- return unless account.is_a? OpenStax::Accounts::Account
103
- gm = GroupMember.new
104
- gm.group = self
105
- gm.user = account
106
- return unless gm.valid?
107
- gm.save if persisted?
108
- group_members << gm
109
- gm
110
- end
111
-
112
- def supertree_group_ids
113
- return cached_supertree_group_ids unless cached_supertree_group_ids.nil?
114
- return [] unless persisted?
115
- reload
116
-
117
- gids = [openstax_uid] + (
118
- self.class.joins(:member_group_nestings).where(
119
- # This could have been:
120
- # member_group_nestings: { member_group_id: openstax_uid }
121
- # However that needs a monkeypatch to work in Rails 5 so we currently do this:
122
- openstax_accounts_group_nestings: { member_group_id: openstax_uid }
123
- ).first.try!(:supertree_group_ids) || []
124
- )
125
- update_column(:cached_supertree_group_ids, gids)
126
- self.cached_supertree_group_ids = gids
127
- end
128
-
129
- def subtree_group_ids
130
- return cached_subtree_group_ids unless cached_subtree_group_ids.nil?
131
- return [] unless persisted?
132
- reload
133
-
134
- gids = [openstax_uid] + self.class.joins(:container_group_nesting).where(
135
- # This could have been:
136
- # container_group_nesting: { container_group_id: openstax_uid }
137
- # However that needs a monkeypatch to work in Rails 5 so we currently do this:
138
- openstax_accounts_group_nestings: { container_group_id: openstax_uid }
139
- ).map { |group| group.subtree_group_ids }.flatten
140
- update_column(:cached_subtree_group_ids, gids)
141
- self.cached_subtree_group_ids = gids
142
- end
143
-
144
- protected
145
-
146
- def syncing_or_stubbing?
147
- syncing || OpenStax::Accounts.configuration.enable_stubbing?
148
- end
149
-
150
- def create_openstax_accounts_group
151
- return false if requestor.nil? || requestor.is_anonymous?
152
-
153
- OpenStax::Accounts::Api.create_group(requestor, self) if requestor.has_authenticated?
154
- end
155
-
156
- def update_openstax_accounts_group
157
- return false if requestor.nil? || requestor.is_anonymous?
158
-
159
- OpenStax::Accounts::Api.update_group(requestor, self) if requestor.has_authenticated?
160
- end
161
-
162
- def destroy_openstax_accounts_group
163
- return false if requestor.nil? || requestor.is_anonymous?
164
-
165
- OpenStax::Accounts::Api.destroy_group(requestor, self) if requestor.has_authenticated?
166
- end
167
-
168
- end
169
- end
@@ -1,37 +0,0 @@
1
- module OpenStax::Accounts
2
- class GroupMember < ActiveRecord::Base
3
-
4
- delegate :requestor, :syncing, to: :group
5
-
6
- belongs_to :group, class_name: 'OpenStax::Accounts::Group',
7
- primary_key: :openstax_uid, inverse_of: :group_members
8
- belongs_to :user, class_name: 'OpenStax::Accounts::Account',
9
- primary_key: :openstax_uid, inverse_of: :group_members
10
-
11
- validates :group, presence: true
12
- validates :user, presence: true, uniqueness: { scope: :group }
13
- validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
-
15
- before_create :create_openstax_accounts_group_member, unless: :syncing_or_stubbing?
16
- before_destroy :destroy_openstax_accounts_group_member, unless: :syncing_or_stubbing?
17
-
18
- protected
19
-
20
- def syncing_or_stubbing?
21
- syncing || OpenStax::Accounts.configuration.enable_stubbing?
22
- end
23
-
24
- def create_openstax_accounts_group_member
25
- return false if requestor.nil? || requestor.is_anonymous?
26
-
27
- OpenStax::Accounts::Api.create_group_member(requestor, self) if requestor.has_authenticated?
28
- end
29
-
30
- def destroy_openstax_accounts_group_member
31
- return false if requestor.nil? || requestor.is_anonymous?
32
-
33
- OpenStax::Accounts::Api.destroy_group_member(requestor, self) if requestor.has_authenticated?
34
- end
35
-
36
- end
37
- end
@@ -1,55 +0,0 @@
1
- module OpenStax::Accounts
2
- class GroupNesting < ActiveRecord::Base
3
-
4
- delegate :requestor, :syncing, to: :container_group
5
-
6
- belongs_to :container_group, class_name: 'OpenStax::Accounts::Group',
7
- primary_key: :openstax_uid, inverse_of: :member_group_nestings
8
- belongs_to :member_group, class_name: 'OpenStax::Accounts::Group',
9
- primary_key: :openstax_uid, inverse_of: :container_group_nesting
10
-
11
- validates :container_group, presence: true
12
- validates :member_group, presence: true, uniqueness: true
13
- validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
- validate :no_loops, unless: :syncing_or_stubbing?
15
-
16
- before_create :update_group_caches, unless: :syncing
17
- before_destroy :update_group_caches, unless: :syncing
18
-
19
- before_create :create_openstax_accounts_group_nesting, unless: :syncing_or_stubbing?
20
- before_destroy :destroy_openstax_accounts_group_nesting, unless: :syncing_or_stubbing?
21
-
22
- protected
23
-
24
- def syncing_or_stubbing?
25
- syncing || OpenStax::Accounts.configuration.enable_stubbing?
26
- end
27
-
28
- def no_loops
29
- return if member_group.nil? || !member_group.subtree_group_ids.include?(container_group_id)
30
-
31
- errors.add(:base, 'would create a loop') if errors[:base].blank?
32
- throw :abort
33
- end
34
-
35
- def update_group_caches
36
- UpdateGroupCaches.call(self)
37
-
38
- throw(:abort) if errors.any?
39
- end
40
-
41
- def create_openstax_accounts_group_nesting
42
- throw(:abort) if requestor.nil? || requestor.is_anonymous?
43
-
44
- OpenStax::Accounts::Api.create_group_nesting(requestor, self) if requestor.has_authenticated?
45
- end
46
-
47
- def destroy_openstax_accounts_group_nesting
48
- throw(:abort) if requestor.nil? || requestor.is_anonymous?
49
-
50
- OpenStax::Accounts::Api.destroy_group_nesting(requestor, self) \
51
- if requestor.has_authenticated?
52
- end
53
-
54
- end
55
- end
@@ -1,37 +0,0 @@
1
- module OpenStax::Accounts
2
- class GroupOwner < ActiveRecord::Base
3
-
4
- delegate :requestor, :syncing, to: :group
5
-
6
- belongs_to :group, class_name: 'OpenStax::Accounts::Group',
7
- primary_key: :openstax_uid, inverse_of: :group_owners
8
- belongs_to :user, class_name: 'OpenStax::Accounts::Account',
9
- primary_key: :openstax_uid, inverse_of: :group_owners
10
-
11
- validates :group, presence: true
12
- validates :user, presence: true, uniqueness: { scope: :group }
13
- validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
-
15
- before_create :create_openstax_accounts_group_owner, unless: :syncing_or_stubbing?
16
- before_destroy :destroy_openstax_accounts_group_owner, unless: :syncing_or_stubbing?
17
-
18
- protected
19
-
20
- def syncing_or_stubbing?
21
- syncing || OpenStax::Accounts.configuration.enable_stubbing?
22
- end
23
-
24
- def create_openstax_accounts_group_owner
25
- return false if requestor.nil? || requestor.is_anonymous?
26
-
27
- OpenStax::Accounts::Api.create_group_owner(requestor, self) if requestor.has_authenticated?
28
- end
29
-
30
- def destroy_openstax_accounts_group_owner
31
- return false if requestor.nil? || requestor.is_anonymous?
32
-
33
- OpenStax::Accounts::Api.destroy_group_owner(requestor, self) if requestor.has_authenticated?
34
- end
35
-
36
- end
37
- end