openstax_accounts 8.1.1 → 9.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) 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 +3 -4
  10. data/app/models/openstax/accounts/account.rb +27 -23
  11. data/app/models/openstax/accounts/anonymous_account.rb +1 -2
  12. data/app/representers/openstax/accounts/api/v1/account_representer.rb +19 -6
  13. data/app/routines/openstax/accounts/dev/create_account.rb +25 -21
  14. data/app/routines/openstax/accounts/find_or_create_account.rb +11 -19
  15. data/app/routines/openstax/accounts/find_or_create_from_sso.rb +2 -8
  16. data/app/routines/openstax/accounts/sync_accounts.rb +1 -7
  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/db/migrate/16_add_is_kip_to_openstax_accounts_accounts.rb +5 -0
  27. data/db/migrate/17_add_school_location_to_openstax_accounts_accounts.rb +5 -0
  28. data/lib/omniauth/strategies/openstax.rb +1 -1
  29. data/lib/openstax/accounts/api.rb +0 -149
  30. data/lib/openstax/accounts/current_user_manager.rb +1 -5
  31. data/lib/openstax/accounts/engine.rb +1 -1
  32. data/lib/openstax/accounts/version.rb +1 -1
  33. data/lib/tasks/sync.rake +0 -8
  34. data/spec/factories/openstax_accounts_account.rb +1 -0
  35. metadata +8 -23
  36. data/app/models/openstax/accounts/application_group.rb +0 -7
  37. data/app/models/openstax/accounts/group.rb +0 -169
  38. data/app/models/openstax/accounts/group_member.rb +0 -37
  39. data/app/models/openstax/accounts/group_nesting.rb +0 -55
  40. data/app/models/openstax/accounts/group_owner.rb +0 -37
  41. data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +0 -48
  42. data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -20
  43. data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +0 -31
  44. data/app/representers/openstax/accounts/api/v1/group_representer.rb +0 -71
  45. data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +0 -34
  46. data/app/routines/openstax/accounts/create_group.rb +0 -26
  47. data/app/routines/openstax/accounts/sync_groups.rb +0 -67
  48. data/app/routines/openstax/accounts/update_group_caches.rb +0 -27
  49. data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +0 -51
  50. data/spec/factories/openstax_accounts_group.rb +0 -7
  51. data/spec/factories/openstax_accounts_group_member.rb +0 -6
  52. data/spec/factories/openstax_accounts_group_nesting.rb +0 -6
  53. data/spec/factories/openstax_accounts_group_owner.rb +0 -6
@@ -1,7 +1,6 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  class CurrentUserManager
4
-
5
4
  def initialize(request, session, cookies)
6
5
  @request = request
7
6
  @session = session
@@ -22,9 +21,7 @@ module OpenStax
22
21
 
23
22
  # Signs in the given user or account
24
23
  def sign_in!(user)
25
- user.is_a?(Account) ?
26
- self.current_account = user :
27
- self.current_user = user
24
+ user.is_a?(Account) ? self.current_account = user : self.current_user = user
28
25
  end
29
26
 
30
27
  alias_method :sign_in, :sign_in!
@@ -126,7 +123,6 @@ module OpenStax
126
123
  def account_user_mapper
127
124
  OpenStax::Accounts.configuration.account_user_mapper
128
125
  end
129
-
130
126
  end
131
127
  end
132
128
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "8.1.1"
3
+ VERSION = '9.0.4'
4
4
  end
5
5
  end
@@ -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
@@ -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: 8.1.1
4
+ version: 9.0.4
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-11-06 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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,10 @@ 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
344
+ - db/migrate/16_add_is_kip_to_openstax_accounts_accounts.rb
345
+ - db/migrate/17_add_school_location_to_openstax_accounts_accounts.rb
355
346
  - db/migrate/1_create_openstax_accounts_groups.rb
356
347
  - db/migrate/2_create_openstax_accounts_group_members.rb
357
348
  - db/migrate/3_create_openstax_accounts_group_owners.rb
@@ -371,16 +362,11 @@ files:
371
362
  - lib/openstax/accounts/current_user_manager.rb
372
363
  - lib/openstax/accounts/default_account_user_mapper.rb
373
364
  - lib/openstax/accounts/engine.rb
374
- - lib/openstax/accounts/has_many_through_groups/active_record/base.rb
375
365
  - lib/openstax/accounts/sso.rb
376
366
  - lib/openstax/accounts/version.rb
377
367
  - lib/openstax_accounts.rb
378
368
  - lib/tasks/sync.rake
379
369
  - 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
370
  homepage: http://github.com/openstax/accounts-rails
385
371
  licenses: []
386
372
  metadata: {}
@@ -399,8 +385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
385
  - !ruby/object:Gem::Version
400
386
  version: '0'
401
387
  requirements: []
402
- rubyforge_project:
403
- rubygems_version: 2.7.3
388
+ rubygems_version: 3.0.3
404
389
  signing_key:
405
390
  specification_version: 4
406
391
  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