openstax_accounts 1.0.0 → 2.0.0

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 (66) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +89 -58
  3. data/app/controllers/openstax/accounts/application_controller.rb +3 -12
  4. data/app/controllers/openstax/accounts/dev/accounts_controller.rb +19 -0
  5. data/app/controllers/openstax/accounts/dev/base_controller.rb +2 -8
  6. data/app/controllers/openstax/accounts/sessions_controller.rb +31 -19
  7. data/app/handlers/openstax/accounts/dev/{users_index.rb → accounts_index.rb} +4 -4
  8. data/app/handlers/openstax/accounts/sessions_callback.rb +43 -0
  9. data/app/models/openstax/accounts/{user.rb → account.rb} +7 -22
  10. data/app/models/openstax/accounts/anonymous_account.rb +24 -0
  11. data/app/models/openstax/accounts/application_account.rb +7 -0
  12. data/app/representers/openstax/accounts/api/v1/{user_representer.rb → account_representer.rb} +1 -1
  13. data/app/representers/openstax/accounts/api/v1/{user_search_representer.rb → account_search_representer.rb} +7 -6
  14. data/app/representers/openstax/accounts/api/v1/{application_user_representer.rb → application_account_representer.rb} +5 -4
  15. data/app/representers/openstax/accounts/api/v1/application_account_search_representer.rb +20 -0
  16. data/app/representers/openstax/accounts/api/v1/{application_users_representer.rb → application_accounts_representer.rb} +3 -3
  17. data/app/routines/openstax/accounts/dev/{search_users.rb → search_accounts.rb} +5 -5
  18. data/app/routines/openstax/accounts/{search_users.rb → search_accounts.rb} +55 -46
  19. data/app/routines/openstax/accounts/sync_accounts.rb +47 -0
  20. data/app/views/openstax/accounts/dev/{users → accounts}/_search_results.html.erb +13 -13
  21. data/app/views/openstax/accounts/dev/{users/login.html.erb → accounts/index.html.erb} +3 -3
  22. data/app/views/openstax/accounts/dev/{users → accounts}/index.js.erb +1 -1
  23. data/app/views/openstax/accounts/shared/{users → accounts}/_index.html.erb +4 -1
  24. data/config/initializers/action_interceptor.rb +14 -0
  25. data/config/routes.rb +18 -15
  26. data/db/migrate/0_create_openstax_accounts_accounts.rb +22 -0
  27. data/lib/generators/openstax/accounts/schedule/USAGE +1 -1
  28. data/lib/generators/openstax/accounts/schedule/templates/schedule.rb +1 -1
  29. data/lib/openstax/accounts/current_user_manager.rb +74 -65
  30. data/lib/openstax/accounts/default_account_user_mapper.rb +15 -0
  31. data/lib/openstax/accounts/engine.rb +2 -0
  32. data/lib/openstax/accounts/extend_builtins.rb +37 -0
  33. data/lib/openstax/accounts/version.rb +1 -1
  34. data/lib/openstax_accounts.rb +46 -25
  35. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +21 -0
  36. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +12 -9
  37. data/spec/dummy/app/controllers/api/application_users_controller.rb +0 -4
  38. data/spec/dummy/app/controllers/api/users_controller.rb +7 -0
  39. data/spec/dummy/app/models/anonymous_user.rb +48 -0
  40. data/spec/dummy/app/models/user.rb +26 -0
  41. data/spec/dummy/config/initializers/openstax_accounts.rb +3 -2
  42. data/spec/dummy/config/routes.rb +5 -3
  43. data/spec/dummy/db/migrate/1_create_users.rb +11 -0
  44. data/spec/dummy/db/schema.rb +18 -6
  45. data/spec/factories/openstax_accounts_account.rb +6 -0
  46. data/spec/lib/openstax/accounts/current_user_manager_spec.rb +151 -0
  47. data/spec/lib/openstax_accounts_spec.rb +16 -9
  48. data/spec/models/openstax/accounts/account_spec.rb +9 -0
  49. data/spec/models/openstax/accounts/anonymous_account_spec.rb +9 -0
  50. data/spec/routines/openstax/accounts/{search_users_spec.rb → search_accounts_spec.rb} +38 -38
  51. metadata +87 -50
  52. data/app/controllers/openstax/accounts/dev/users_controller.rb +0 -22
  53. data/app/handlers/openstax/accounts/sessions_omniauth_authenticated.rb +0 -48
  54. data/app/models/openstax/accounts/application_user.rb +0 -7
  55. data/app/representers/openstax/accounts/api/v1/application_user_search_representer.rb +0 -19
  56. data/app/routines/openstax/accounts/dev/create_user.rb +0 -37
  57. data/app/routines/openstax/accounts/sync_users.rb +0 -44
  58. data/config/initializers/extend_builtins.rb +0 -42
  59. data/db/migrate/0_create_openstax_accounts_users.rb +0 -18
  60. data/lib/openstax/accounts/action_list.rb +0 -42
  61. data/lib/openstax/accounts/route_helper.rb +0 -34
  62. data/lib/openstax/accounts/user_provider.rb +0 -15
  63. data/spec/controllers/openstax/accounts/dev/users_controller_spec.rb +0 -21
  64. data/spec/factories/openstax_accounts_user.rb +0 -6
  65. data/spec/models/openstax/accounts/user_spec.rb +0 -13
  66. data/spec/routines/openstax/accounts/dev/create_user_spec.rb +0 -26
@@ -3,77 +3,77 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe SearchUsers do
6
+ describe SearchAccounts do
7
7
 
8
- let!(:user_1) { FactoryGirl.create :openstax_accounts_user,
8
+ let!(:account_1) { FactoryGirl.create :openstax_accounts_account,
9
9
  first_name: 'John',
10
10
  last_name: 'Stravinsky',
11
11
  username: 'jstrav' }
12
- let!(:user_2) { FactoryGirl.create :openstax_accounts_user,
12
+ let!(:account_2) { FactoryGirl.create :openstax_accounts_account,
13
13
  first_name: 'Mary',
14
14
  last_name: 'Mighty',
15
15
  full_name: 'Mary Mighty',
16
16
  username: 'mary' }
17
- let!(:user_3) { FactoryGirl.create :openstax_accounts_user,
17
+ let!(:account_3) { FactoryGirl.create :openstax_accounts_account,
18
18
  first_name: 'John',
19
19
  last_name: 'Stead',
20
20
  username: 'jstead' }
21
21
 
22
- let!(:user_4) { FactoryGirl.create :openstax_accounts_user,
22
+ let!(:account_4) { FactoryGirl.create :openstax_accounts_account,
23
23
  first_name: 'Bob',
24
24
  last_name: 'JST',
25
25
  username: 'bigbear' }
26
26
 
27
27
  it "should match based on username" do
28
- outcome = SearchUsers.call('username:jstra').outputs.users.all
29
- expect(outcome).to eq [user_1]
28
+ outcome = SearchAccounts.call('username:jstra').outputs.accounts.all
29
+ expect(outcome).to eq [account_1]
30
30
  end
31
31
 
32
32
  it "should ignore leading wildcards on username searches" do
33
- outcome = SearchUsers.call('username:%rav').outputs.users.all
33
+ outcome = SearchAccounts.call('username:%rav').outputs.accounts.all
34
34
  expect(outcome).to eq []
35
35
  end
36
36
 
37
37
  it "should match based on one first name" do
38
- outcome = SearchUsers.call('first_name:"John"').outputs.users.all
39
- expect(outcome).to eq [user_3, user_1]
38
+ outcome = SearchAccounts.call('first_name:"John"').outputs.accounts.all
39
+ expect(outcome).to eq [account_3, account_1]
40
40
  end
41
41
 
42
42
  it "should match based on one full name" do
43
- outcome = SearchUsers.call('full_name:"Mary Mighty"').outputs.users.all
44
- expect(outcome).to eq [user_2]
43
+ outcome = SearchAccounts.call('full_name:"Mary Mighty"').outputs.accounts.all
44
+ expect(outcome).to eq [account_2]
45
45
  end
46
46
 
47
47
  it "should return all results if the query is empty" do
48
- outcome = SearchUsers.call("").outputs.users.all
49
- expect(outcome).to eq [user_4, user_3, user_1, user_2]
48
+ outcome = SearchAccounts.call("").outputs.accounts.all
49
+ expect(outcome).to eq [account_4, account_3, account_1, account_2]
50
50
  end
51
51
 
52
52
  it "should match any field when no prefix given" do
53
- outcome = SearchUsers.call("jst").outputs.users.all
54
- expect(outcome).to eq [user_4, user_3, user_1]
53
+ outcome = SearchAccounts.call("jst").outputs.accounts.all
54
+ expect(outcome).to eq [account_4, account_3, account_1]
55
55
  end
56
56
 
57
57
  it "should match any field when no prefix given and intersect when prefix given" do
58
- outcome = SearchUsers.call("jst username:jst").outputs.users.all
59
- expect(outcome).to eq [user_3, user_1]
58
+ outcome = SearchAccounts.call("jst username:jst").outputs.accounts.all
59
+ expect(outcome).to eq [account_3, account_1]
60
60
  end
61
61
 
62
- it "shouldn't allow users to add their own wildcards" do
63
- outcome = SearchUsers.call("username:'%ar'").outputs.users.all
62
+ it "shouldn't allow accounts to add their own wildcards" do
63
+ outcome = SearchAccounts.call("username:'%ar'").outputs.accounts.all
64
64
  expect(outcome).to eq []
65
65
  end
66
66
 
67
67
  it "should gather space-separated unprefixed search terms" do
68
- outcome = SearchUsers.call("john mighty").outputs.users.all
69
- expect(outcome).to eq [user_3, user_1, user_2]
68
+ outcome = SearchAccounts.call("john mighty").outputs.accounts.all
69
+ expect(outcome).to eq [account_3, account_1, account_2]
70
70
  end
71
71
 
72
72
  context "pagination and sorting" do
73
73
 
74
- let!(:billy_users) {
74
+ let!(:billy_accounts) {
75
75
  (0..45).to_a.collect{|ii|
76
- FactoryGirl.create :openstax_accounts_user,
76
+ FactoryGirl.create :openstax_accounts_account,
77
77
  first_name: "Billy#{ii.to_s.rjust(2, '0')}",
78
78
  last_name: "Bob_#{(45-ii).to_s.rjust(2,'0')}",
79
79
  username: "billy_#{ii.to_s.rjust(2, '0')}"
@@ -81,27 +81,27 @@ module OpenStax
81
81
  }
82
82
 
83
83
  it "should return the first page of values by default in default order" do
84
- outcome = SearchUsers.call("username:billy").outputs.users.all
84
+ outcome = SearchAccounts.call("username:billy").outputs.accounts.all
85
85
  expect(outcome.length).to eq 20
86
- expect(outcome[0]).to eq User.where{username.eq "billy_00"}.first
87
- expect(outcome[19]).to eq User.where{username.eq "billy_19"}.first
86
+ expect(outcome[0]).to eq Account.where{username.eq "billy_00"}.first
87
+ expect(outcome[19]).to eq Account.where{username.eq "billy_19"}.first
88
88
  end
89
89
 
90
90
  it "should return the 2nd page when requested" do
91
- outcome = SearchUsers.call("username:billy", page: 1).outputs.users.all
91
+ outcome = SearchAccounts.call("username:billy", page: 1).outputs.accounts.all
92
92
  expect(outcome.length).to eq 20
93
- expect(outcome[0]).to eq User.where{username.eq "billy_20"}.first
94
- expect(outcome[19]).to eq User.where{username.eq "billy_39"}.first
93
+ expect(outcome[0]).to eq Account.where{username.eq "billy_20"}.first
94
+ expect(outcome[19]).to eq Account.where{username.eq "billy_39"}.first
95
95
  end
96
96
 
97
97
  it "should return the incomplete 3rd page when requested" do
98
- outcome = SearchUsers.call("username:billy", page: 2).outputs.users.all
98
+ outcome = SearchAccounts.call("username:billy", page: 2).outputs.accounts.all
99
99
  expect(outcome.length).to eq 6
100
- expect(outcome[5]).to eq User.where{username.eq "billy_45"}.first
100
+ expect(outcome[5]).to eq Account.where{username.eq "billy_45"}.first
101
101
  end
102
102
 
103
103
  it "should return no results if the limit is exceeded" do
104
- outcome = SearchUsers.call("").outputs.users.all
104
+ outcome = SearchAccounts.call("").outputs.accounts.all
105
105
  expect(outcome).to be_empty
106
106
  end
107
107
 
@@ -109,15 +109,15 @@ module OpenStax
109
109
 
110
110
  context "sorting" do
111
111
 
112
- let!(:bob_brown) { FactoryGirl.create :openstax_accounts_user, first_name: "Bob", last_name: "Brown", username: "foo_bb" }
113
- let!(:bob_jones) { FactoryGirl.create :openstax_accounts_user, first_name: "Bob", last_name: "Jones", username: "foo_bj" }
114
- let!(:tim_jones) { FactoryGirl.create :openstax_accounts_user, first_name: "Tim", last_name: "Jones", username: "foo_tj" }
112
+ let!(:bob_brown) { FactoryGirl.create :openstax_accounts_account, first_name: "Bob", last_name: "Brown", username: "foo_bb" }
113
+ let!(:bob_jones) { FactoryGirl.create :openstax_accounts_account, first_name: "Bob", last_name: "Jones", username: "foo_bj" }
114
+ let!(:tim_jones) { FactoryGirl.create :openstax_accounts_account, first_name: "Tim", last_name: "Jones", username: "foo_tj" }
115
115
 
116
116
  it "should allow sort by multiple fields in different directions" do
117
- outcome = SearchUsers.call("username:foo", order_by: "first_name, last_name DESC").outputs.users.all
117
+ outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name DESC").outputs.accounts.all
118
118
  expect(outcome).to eq [bob_jones, bob_brown, tim_jones]
119
119
 
120
- outcome = SearchUsers.call("username:foo", order_by: "first_name, last_name ASC").outputs.users.all
120
+ outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name ASC").outputs.accounts.all
121
121
  expect(outcome).to eq [bob_brown, bob_jones, tim_jones]
122
122
  end
123
123
 
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: 1.0.0
4
+ version: 2.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: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ! '>='
25
39
  - !ruby/object:Gem::Version
26
- version: '3.2'
40
+ version: '3.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: omniauth
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
- version: '2.0'
117
+ version: 2.1.1
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ! '>='
109
123
  - !ruby/object:Gem::Version
110
- version: '2.0'
124
+ version: 2.1.1
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: sass-rails
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,34 +150,48 @@ dependencies:
136
150
  - - ! '>='
137
151
  - !ruby/object:Gem::Version
138
152
  version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: keyword_search
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.0
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: openstax_utilities
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - ! '>='
144
172
  - !ruby/object:Gem::Version
145
- version: '1.2'
173
+ version: 2.2.3
146
174
  type: :runtime
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - ! '>='
151
179
  - !ruby/object:Gem::Version
152
- version: '1.2'
180
+ version: 2.2.3
153
181
  - !ruby/object:Gem::Dependency
154
- name: keyword_search
182
+ name: action_interceptor
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - ! '>='
158
186
  - !ruby/object:Gem::Version
159
- version: 1.0.0
187
+ version: '0.1'
160
188
  type: :runtime
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
192
  - - ! '>='
165
193
  - !ruby/object:Gem::Version
166
- version: 1.0.0
194
+ version: '0.1'
167
195
  - !ruby/object:Gem::Dependency
168
196
  name: sqlite3
169
197
  requirement: !ruby/object:Gem::Requirement
@@ -182,16 +210,16 @@ dependencies:
182
210
  name: rspec-rails
183
211
  requirement: !ruby/object:Gem::Requirement
184
212
  requirements:
185
- - - ! '>='
213
+ - - <
186
214
  - !ruby/object:Gem::Version
187
- version: '0'
215
+ version: '3.0'
188
216
  type: :development
189
217
  prerelease: false
190
218
  version_requirements: !ruby/object:Gem::Requirement
191
219
  requirements:
192
- - - ! '>='
220
+ - - <
193
221
  - !ruby/object:Gem::Version
194
- version: '0'
222
+ version: '3.0'
195
223
  - !ruby/object:Gem::Dependency
196
224
  name: capybara
197
225
  requirement: !ruby/object:Gem::Requirement
@@ -248,7 +276,7 @@ dependencies:
248
276
  - - ! '>='
249
277
  - !ruby/object:Gem::Version
250
278
  version: '0'
251
- description: Rails common code and bindings and for 'accounts' API
279
+ description: Rails common code and bindings and for the 'accounts' API
252
280
  email:
253
281
  - jps@kindlinglabs.com
254
282
  executables: []
@@ -262,44 +290,43 @@ files:
262
290
  - app/assets/stylesheets/openstax/accounts/application.css
263
291
  - app/assets/stylesheets/openstax/accounts/dev.css.scss
264
292
  - app/controllers/openstax/accounts/application_controller.rb
293
+ - app/controllers/openstax/accounts/dev/accounts_controller.rb
265
294
  - app/controllers/openstax/accounts/dev/base_controller.rb
266
- - app/controllers/openstax/accounts/dev/users_controller.rb
267
295
  - app/controllers/openstax/accounts/sessions_controller.rb
268
- - app/handlers/openstax/accounts/dev/users_index.rb
269
- - app/handlers/openstax/accounts/sessions_omniauth_authenticated.rb
296
+ - app/handlers/openstax/accounts/dev/accounts_index.rb
297
+ - app/handlers/openstax/accounts/sessions_callback.rb
270
298
  - app/helpers/openstax/accounts/application_helper.rb
271
- - app/models/openstax/accounts/application_user.rb
272
- - app/models/openstax/accounts/user.rb
273
- - app/representers/openstax/accounts/api/v1/application_user_representer.rb
274
- - app/representers/openstax/accounts/api/v1/application_user_search_representer.rb
275
- - app/representers/openstax/accounts/api/v1/application_users_representer.rb
276
- - app/representers/openstax/accounts/api/v1/user_representer.rb
277
- - app/representers/openstax/accounts/api/v1/user_search_representer.rb
278
- - app/routines/openstax/accounts/dev/create_user.rb
279
- - app/routines/openstax/accounts/dev/search_users.rb
280
- - app/routines/openstax/accounts/search_users.rb
281
- - app/routines/openstax/accounts/sync_users.rb
299
+ - app/models/openstax/accounts/account.rb
300
+ - app/models/openstax/accounts/anonymous_account.rb
301
+ - app/models/openstax/accounts/application_account.rb
302
+ - app/representers/openstax/accounts/api/v1/account_representer.rb
303
+ - app/representers/openstax/accounts/api/v1/account_search_representer.rb
304
+ - app/representers/openstax/accounts/api/v1/application_account_representer.rb
305
+ - app/representers/openstax/accounts/api/v1/application_account_search_representer.rb
306
+ - app/representers/openstax/accounts/api/v1/application_accounts_representer.rb
307
+ - app/routines/openstax/accounts/dev/search_accounts.rb
308
+ - app/routines/openstax/accounts/search_accounts.rb
309
+ - app/routines/openstax/accounts/sync_accounts.rb
282
310
  - app/views/layouts/openstax/accounts/application.html.erb
283
- - app/views/openstax/accounts/dev/users/_search_results.html.erb
284
- - app/views/openstax/accounts/dev/users/index.js.erb
285
- - app/views/openstax/accounts/dev/users/login.html.erb
311
+ - app/views/openstax/accounts/dev/accounts/_search_results.html.erb
312
+ - app/views/openstax/accounts/dev/accounts/index.html.erb
313
+ - app/views/openstax/accounts/dev/accounts/index.js.erb
286
314
  - app/views/openstax/accounts/shared/_attention.html.erb
287
- - app/views/openstax/accounts/shared/users/_index.html.erb
288
- - config/initializers/extend_builtins.rb
315
+ - app/views/openstax/accounts/shared/accounts/_index.html.erb
316
+ - config/initializers/action_interceptor.rb
289
317
  - config/routes.rb
290
- - db/migrate/0_create_openstax_accounts_users.rb
318
+ - db/migrate/0_create_openstax_accounts_accounts.rb
291
319
  - lib/generators/openstax/accounts/schedule/USAGE
292
320
  - lib/generators/openstax/accounts/schedule/schedule_generator.rb
293
321
  - lib/generators/openstax/accounts/schedule/templates/schedule.rb
294
322
  - lib/omniauth/strategies/openstax.rb
295
- - lib/openstax/accounts/action_list.rb
296
323
  - lib/openstax/accounts/current_user_manager.rb
324
+ - lib/openstax/accounts/default_account_user_mapper.rb
297
325
  - lib/openstax/accounts/engine.rb
298
- - lib/openstax/accounts/route_helper.rb
299
- - lib/openstax/accounts/user_provider.rb
326
+ - lib/openstax/accounts/extend_builtins.rb
300
327
  - lib/openstax/accounts/version.rb
301
328
  - lib/openstax_accounts.rb
302
- - spec/controllers/openstax/accounts/dev/users_controller_spec.rb
329
+ - spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb
303
330
  - spec/controllers/openstax/accounts/sessions_controller_spec.rb
304
331
  - spec/dummy/README.md
305
332
  - spec/dummy/Rakefile
@@ -307,9 +334,12 @@ files:
307
334
  - spec/dummy/app/assets/stylesheets/application.css
308
335
  - spec/dummy/app/controllers/api/application_users_controller.rb
309
336
  - spec/dummy/app/controllers/api/dummy_controller.rb
337
+ - spec/dummy/app/controllers/api/users_controller.rb
310
338
  - spec/dummy/app/controllers/application_controller.rb
311
339
  - spec/dummy/app/controllers/oauth_controller.rb
312
340
  - spec/dummy/app/helpers/application_helper.rb
341
+ - spec/dummy/app/models/anonymous_user.rb
342
+ - spec/dummy/app/models/user.rb
313
343
  - spec/dummy/config.ru
314
344
  - spec/dummy/config/application.rb
315
345
  - spec/dummy/config/boot.rb
@@ -327,17 +357,19 @@ files:
327
357
  - spec/dummy/config/initializers/wrap_parameters.rb
328
358
  - spec/dummy/config/locales/en.yml
329
359
  - spec/dummy/config/routes.rb
360
+ - spec/dummy/db/migrate/1_create_users.rb
330
361
  - spec/dummy/db/schema.rb
331
362
  - spec/dummy/public/404.html
332
363
  - spec/dummy/public/422.html
333
364
  - spec/dummy/public/500.html
334
365
  - spec/dummy/public/favicon.ico
335
366
  - spec/dummy/script/rails
336
- - spec/factories/openstax_accounts_user.rb
367
+ - spec/factories/openstax_accounts_account.rb
368
+ - spec/lib/openstax/accounts/current_user_manager_spec.rb
337
369
  - spec/lib/openstax_accounts_spec.rb
338
- - spec/models/openstax/accounts/user_spec.rb
339
- - spec/routines/openstax/accounts/dev/create_user_spec.rb
340
- - spec/routines/openstax/accounts/search_users_spec.rb
370
+ - spec/models/openstax/accounts/account_spec.rb
371
+ - spec/models/openstax/accounts/anonymous_account_spec.rb
372
+ - spec/routines/openstax/accounts/search_accounts_spec.rb
341
373
  - spec/spec_helper.rb
342
374
  homepage: http://github.com/openstax/accounts-rails
343
375
  licenses: []
@@ -361,17 +393,20 @@ rubyforge_project:
361
393
  rubygems_version: 2.2.2
362
394
  signing_key:
363
395
  specification_version: 4
364
- summary: Rails common code and bindings and for 'accounts' API
396
+ summary: Rails common code and bindings and for the 'accounts' API
365
397
  test_files:
366
- - spec/controllers/openstax/accounts/dev/users_controller_spec.rb
398
+ - spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb
367
399
  - spec/controllers/openstax/accounts/sessions_controller_spec.rb
368
400
  - spec/dummy/app/assets/javascripts/application.js
369
401
  - spec/dummy/app/assets/stylesheets/application.css
370
402
  - spec/dummy/app/controllers/api/application_users_controller.rb
371
403
  - spec/dummy/app/controllers/api/dummy_controller.rb
404
+ - spec/dummy/app/controllers/api/users_controller.rb
372
405
  - spec/dummy/app/controllers/application_controller.rb
373
406
  - spec/dummy/app/controllers/oauth_controller.rb
374
407
  - spec/dummy/app/helpers/application_helper.rb
408
+ - spec/dummy/app/models/anonymous_user.rb
409
+ - spec/dummy/app/models/user.rb
375
410
  - spec/dummy/config/application.rb
376
411
  - spec/dummy/config/boot.rb
377
412
  - spec/dummy/config/database.yml
@@ -389,6 +424,7 @@ test_files:
389
424
  - spec/dummy/config/locales/en.yml
390
425
  - spec/dummy/config/routes.rb
391
426
  - spec/dummy/config.ru
427
+ - spec/dummy/db/migrate/1_create_users.rb
392
428
  - spec/dummy/db/schema.rb
393
429
  - spec/dummy/public/404.html
394
430
  - spec/dummy/public/422.html
@@ -397,9 +433,10 @@ test_files:
397
433
  - spec/dummy/Rakefile
398
434
  - spec/dummy/README.md
399
435
  - spec/dummy/script/rails
400
- - spec/factories/openstax_accounts_user.rb
436
+ - spec/factories/openstax_accounts_account.rb
437
+ - spec/lib/openstax/accounts/current_user_manager_spec.rb
401
438
  - spec/lib/openstax_accounts_spec.rb
402
- - spec/models/openstax/accounts/user_spec.rb
403
- - spec/routines/openstax/accounts/dev/create_user_spec.rb
404
- - spec/routines/openstax/accounts/search_users_spec.rb
439
+ - spec/models/openstax/accounts/account_spec.rb
440
+ - spec/models/openstax/accounts/anonymous_account_spec.rb
441
+ - spec/routines/openstax/accounts/search_accounts_spec.rb
405
442
  - spec/spec_helper.rb
@@ -1,22 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
- module Dev
4
- class UsersController < OpenStax::Accounts::Dev::BaseController
5
-
6
- def index
7
- handle_with(UsersIndex,
8
- complete: lambda { render 'index' })
9
- end
10
-
11
- def login; end
12
-
13
- def become
14
- @user = User.find(params[:id])
15
- sign_in(@user)
16
- redirect_to return_url
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
@@ -1,48 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
-
4
- class SessionsOmniauthAuthenticated
5
-
6
- lev_handler
7
-
8
- protected
9
-
10
- def setup
11
- @auth_data = request.env['omniauth.auth']
12
- end
13
-
14
- def authorized?
15
- @auth_data.provider == "openstax"
16
- end
17
-
18
- def handle
19
- outputs[:accounts_user_to_sign_in] = user_to_sign_in
20
- end
21
-
22
- def user_to_sign_in
23
- return caller if
24
- !caller.nil? &&
25
- !caller.is_anonymous? &&
26
- caller.openstax_uid == @auth_data.uid
27
-
28
- existing_user = User.where(openstax_uid: @auth_data.uid).first
29
- return existing_user if !existing_user.nil?
30
-
31
- new_user = User.create do |user|
32
- user.openstax_uid = @auth_data.uid
33
- user.username = @auth_data.info.nickname
34
- user.first_name = @auth_data.info.first_name
35
- user.last_name = @auth_data.info.last_name
36
- user.full_name = @auth_data.info.name
37
- user.title = @auth_data.info.title
38
- user.access_token = @auth_data.credentials.token
39
- end
40
-
41
- transfer_errors_from(new_user, {type: :verbatim})
42
-
43
- new_user
44
- end
45
- end
46
-
47
- end
48
- end
@@ -1,7 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
- class ApplicationUser
4
- attr_accessor :id, :application_id, :user, :unread_updates, :default_contact_info_id
5
- end
6
- end
7
- end
@@ -1,19 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
- module Api
4
- module V1
5
- class ApplicationUserSearchRepresenter < UserSearchRepresenter
6
-
7
- collection :application_users,
8
- class: OpenStax::Accounts::ApplicationUser,
9
- decorator: ApplicationUserRepresenter,
10
- schema_info: {
11
- description: "The ApplicationUsers associated with the matching Users",
12
- minItems: 0
13
- }
14
-
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,37 +0,0 @@
1
- module OpenStax
2
- module Accounts
3
- module Dev
4
- class CreateUser
5
- lev_routine
6
-
7
- protected
8
-
9
- def exec(inputs={})
10
-
11
- username = inputs[:username]
12
-
13
- if username.nil? || inputs[:ensure_no_errors]
14
- loop do
15
- break if !username.nil? && OpenStax::Accounts::User.where(username: username).none?
16
- username = "#{inputs[:username] || 'user'}#{rand(1000000)}"
17
- end
18
- end
19
-
20
- outputs[:user] = OpenStax::Accounts::User.create do |user|
21
- user.first_name = inputs[:first_name]
22
- user.last_name = inputs[:last_name]
23
- user.username = username
24
- user.openstax_uid = available_negative_openstax_uid
25
- end
26
-
27
- transfer_errors_from(outputs[:user], {type: :verbatim})
28
- end
29
-
30
- def available_negative_openstax_uid
31
- (OpenStax::Accounts::User.order("openstax_uid DESC").last.try(:openstax_uid) || 0) - 1
32
- end
33
-
34
- end
35
- end
36
- end
37
- end
@@ -1,44 +0,0 @@
1
- # Routine for getting user updates from Accounts
2
- #
3
- # Should be scheduled to run regularly
4
-
5
- module OpenStax
6
- module Accounts
7
-
8
- class SyncUsers
9
-
10
- SYNC_ATTRIBUTES = ['username', 'first_name', 'last_name',
11
- 'full_name', 'title']
12
-
13
- lev_routine transaction: :no_transaction
14
-
15
- protected
16
-
17
- def exec(options={})
18
-
19
- return if OpenStax::Accounts.configuration.enable_stubbing?
20
-
21
- response = OpenStax::Accounts.application_users_updates
22
-
23
- app_users = []
24
- app_users_rep = OpenStax::Accounts::Api::V1::ApplicationUsersRepresenter.new(app_users)
25
- app_users_rep.from_json(response.body)
26
-
27
- return if app_users.empty?
28
-
29
- app_users_hash = {}
30
- app_users.each do |app_user|
31
- user = OpenStax::Accounts::User.where(:openstax_uid => app_user.user.openstax_uid).first
32
- user.updating_from_accounts = true
33
- next unless user.update_attributes(app_user.user.attributes.slice(*SYNC_ATTRIBUTES))
34
- app_users_hash[app_user.id] = app_user.unread_updates
35
- end
36
-
37
- OpenStax::Accounts.application_users_updated(app_users_hash)
38
-
39
- end
40
-
41
- end
42
-
43
- end
44
- end