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
@@ -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.0"
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
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.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: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2019-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -315,31 +315,18 @@ 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
@@ -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,8 +383,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
383
  - !ruby/object:Gem::Version
400
384
  version: '0'
401
385
  requirements: []
402
- rubyforge_project:
403
- rubygems_version: 2.7.3
386
+ rubygems_version: 3.0.3
404
387
  signing_key:
405
388
  specification_version: 4
406
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