openstax_accounts 7.2.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -7
  3. data/app/controllers/openstax/accounts/sessions_controller.rb +4 -1
  4. data/app/models/openstax/accounts/account.rb +21 -7
  5. data/app/models/openstax/accounts/group.rb +6 -6
  6. data/app/models/openstax/accounts/group_member.rb +4 -4
  7. data/app/models/openstax/accounts/group_nesting.rb +5 -5
  8. data/app/models/openstax/accounts/group_owner.rb +4 -4
  9. data/app/routines/openstax/accounts/dev/create_account.rb +4 -4
  10. data/app/routines/openstax/accounts/sync_accounts.rb +2 -2
  11. data/db/migrate/0_create_openstax_accounts_accounts.rb +1 -1
  12. data/db/migrate/1_create_openstax_accounts_groups.rb +1 -1
  13. data/db/migrate/2_create_openstax_accounts_group_members.rb +1 -1
  14. data/db/migrate/3_create_openstax_accounts_group_owners.rb +1 -1
  15. data/db/migrate/4_create_openstax_accounts_group_nestings.rb +1 -1
  16. data/db/migrate/7_change_accounts_openstax_uid_to_be_nullable.rb +5 -0
  17. data/db/migrate/8_change_accounts_username_to_be_nullable.rb +5 -0
  18. data/lib/openstax/accounts/action_controller/base.rb +12 -2
  19. data/lib/openstax/accounts/configuration.rb +5 -0
  20. data/lib/openstax/accounts/engine.rb +15 -3
  21. data/lib/openstax/accounts/version.rb +1 -1
  22. data/spec/controllers/openstax/accounts/forwards_params_spec.rb +68 -0
  23. data/spec/dummy/config.ru +1 -0
  24. data/spec/dummy/db/development.sqlite3 +0 -0
  25. data/spec/dummy/db/migrate/1000_create_users.rb +2 -2
  26. data/spec/dummy/db/migrate/1001_create_ownerships.rb +3 -3
  27. data/spec/dummy/db/schema.rb +23 -23
  28. data/spec/dummy/db/test.sqlite3 +0 -0
  29. data/spec/dummy/log/development.log +4946 -399
  30. data/spec/dummy/log/test.log +14740 -94815
  31. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-4/-4AigB7SRNxiHWeamN5uh_JTU4pT-99hUByQ7hhtfM4.cache +1 -0
  32. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-B/-BM2LkGo9LiZel0dx2cTeIoUiOvZvzvQX-qrY-PefDc.cache +0 -0
  33. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0d/0dqBuwbmRqLO9AM5KdttlIvUSbOG2uS9fJsm4TRuY8M.cache +0 -0
  34. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/1b/1bCIjOPcmZWjhnOiOIrEUVDFzGzCezkm0dIrzY7q22A.cache +2 -0
  35. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2GcGY034bmlAWeI-bC8yjSfggr98_D1ysvB0hcR9PaI.cache +3 -0
  36. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2gGPkwl7LddZxTKkA0XQ6NKsdgK7mDG6PfvKrqKYsAs.cache +0 -0
  37. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4W/4WJLh0PRMuTwbFf44QcjwkcJ57BXKVgwtaRnUiMxlbc.cache +1 -0
  38. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5T/5TLgAp4XC6JjXz-MP4IR8UIli3l091nGGpp0xomd_g0.cache +0 -0
  39. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5g/5g7dhxVp4YbZmFw_-T3aU2oYq2Z9Jgtps0CKneXYSS0.cache +2 -0
  40. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5u/5uKXJe6QpDEzhvxGUSwHZS2uGrjr0-ex9LVlRQZaQnI.cache +1 -0
  41. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6H/6HAlvBZ_na7ir9ELSAcCJ1GTAwGaO565PgVOt7rgitw.cache +1 -0
  42. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6b/6bUhHw6Kpj9FgN8vIU0BBQNdA1sgsa0pyhDOdq4U1a8.cache +2 -0
  43. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8w/8whA2ROqlMHhJJiXDf0onGPb8mLmBGb5UUPY7yZZuMs.cache +1 -0
  44. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9S/9SfcyOi0r3UamY1lEOb94zdm_ybDACE3pzfyMeUnoJc.cache +0 -0
  45. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Af/AfzRuN8Wm6MIHDZEpwWkiSl3zNDMJ1tOvSt2SOmVCio.cache +1 -0
  46. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DB/DB4PIoupKZcosm_IvLp0-MJ1hiXfVw01ZdY1IOnnPsE.cache +0 -0
  47. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DR/DRPKqdpBdXQEzG7sFT6-8d_LgGF72B8IFqYLhVsyNqw.cache +1 -0
  48. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhSAf3h0VMpFRp_tvO8VIqn12P-Mnp3WFyVH4ORR-gs.cache +0 -0
  49. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/E3/E35l_cFnSYnnYWJwxWXR76R17KJ3tqL_-UG0Tjrp5DI.cache +0 -0
  50. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ET/ETdvBR0__vhxzfl_I4mu0h3Jrcwy0jvIvEf-AcGHuxU.cache +1 -0
  51. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EZ/EZkBau1uUbmU8TAtNy_21ZEq6hQ-pQY-jNbMnaAlNYM.cache +1 -0
  52. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IV/IVl_wFSpYKfB-OI07E_GP9JLqGpf6VStaDO-Pl-EcUA.cache +1 -0
  53. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/It/ItWlWNmHD7ZeVOFbsyan26cbPWTR9XFqNBmZhIsyr8k.cache +2 -0
  54. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JB/JBrtwWy2SgF1Nl6siXGeTqdnlMdXo6F-OOkAKCHx3gw.cache +1 -0
  55. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Je/JeDnsbKYU6WfXwmBfUedz09ThQX9iPI8-sgit9Um1yE.cache +1 -0
  56. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Jr/JrzNmQmTkr6QS1BoAOEeGnCip0CCneRNMyvtaelWV1w.cache +2 -0
  57. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KE/KEIyyOl_ruT7KuaNvukGN8LnSUVMk4MQmDUOg9oo0XE.cache +0 -0
  58. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LK/LK8fShpIirD6_e29A0YY7pTPZbISgiHuY3QOMzj-c4c.cache +1 -0
  59. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lr/LrK9U2KWZskR0G2rWalGnOM8fgZvGwEajG7_WYkK-Rc.cache +1 -0
  60. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/MH/MHc26ZBwFN93Q3ggSv0QW4WDhXzTQV6YvzIUUt6Su7Q.cache +1 -0
  61. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Nj/NjMmwEjtqJiXWQtb2qVmb2Js1DikSD_MgMHDlCNzLP4.cache +1 -0
  62. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1IElAqy9O60bh7c8syJLSGSTIxOL_WDNftM2SNTsgI.cache +1 -0
  63. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QW/QWLUd5oxFsWTwKa1IXwWsaP8RlLh_GMPdypbqJx0VoA.cache +1 -0
  64. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TZ/TZlHN1bHx2lwu7SRM5Y3Qp_OpbrtidFt-6223MTPMH4.cache +1 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VN/VNCapNKJLeponthNeFJhaBYs92UBT3P8PugENHP0474.cache +2 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WX/WXy-lTrCCH38uK_ld4QeQrhZuZZDOyHGBBrhZ0PDZyY.cache +2 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Yr/YrbMyaVyJ69SVCY3y1ZPJAdUcuUpzzHP7LMQNT2pGfk.cache +1 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Z-/Z-tPXaNX9WvhVHKT_twh9-sJ_NvUPatXyDZ48rWasiE.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/aYOmaJvT9wpA9a2IfP3f-6A6guRGAezZCHz_3lSCE0A.cache +1 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/ayvQApV55-bf3brcKBVUc8_o-8aLmUhKYv9b7OPRXV8.cache +1 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bR/bRCnhDQ4uJkiX7RMvyDbsvopysp32eYxD0SYAsEpDzc.cache +1 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bz/bzY1-207qUxPHd6HAeNvY34UEmIZlAnGJUuiwkGLqTw.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/cj/cjLyKHfhNSrjEff7p2VGJz6ColftKx69unhJqv0UK1g.cache +2 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e2/e28DqqHF8GN5VTAz03mRnOV5AV_np1CNwB_xuV03NUw.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hh/hh_1YpicqmoKC8uz92Sh3iba0TBhh9GEXtUyrUlEzEU.cache +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/iKFb6K0z7xwr53FXp9Qy4qO5L6lryDOpXjMnw-48oVg.cache +2 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/jn/jnRNObm7DziGmbZR3TPAC-vAE-qmrP0tLBH9W9m6yJs.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kS/kSXVJZ4BJAsy2L9DxKUntzr90Nd9VWD0G7L2n05ISOw.cache +1 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kq/kq0VL9PQ2HRlksqNC7YPlqlWFBvkHk2uIac_HZb0wEE.cache +1 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/l0/l0BYOaBq08_FGl4jzpCnd80-zLPHNMXs7xCHtqTcUVI.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lx/lxYKD42Es9n2EKrNchxPYKveAzYo6VAGr_CxhxvyO-c.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mW/mWLVMCpv8dHPkBK4y4SLLXukqtLhRXWtNC3gm5vgwPk.cache +3 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mx/mxoipKjbqPo_gvG86AgUPk6o6-OB-uqI5sGMnNqGW4A.cache +1 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nZ/nZY2kcE7t2EMdrdtEQueW9UYmtEBjQv3FNpous5k1tM.cache +2 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/o3/o3Bz1eWxZ7poUlQGzlkJX5fFeNxKD5VEuFZSctl6Oe4.cache +1 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p-/p-j1kEkMIDywvXn2EG-FF_CVz9U75IYIDMJj4U2ksCk.cache +2 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pZ/pZXUaTdXV2XMj_KgBsHVED1ocjtpQrIqBR3lGYSMZVc.cache +2 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +2 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r0/r0S88W86F754buOO-eLMVX5f9YdQzd-ZkpvwEJc6hAg.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r3/r3X66JZPGDKB-xMv9rLIyo0WKYWnPrSB2qL0giC2T6g.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/t7/t7deseLVHWCZ7z2LMl1YvpZi-RIhvURhm0-MSDE3qvY.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tl/tl1nInky090OX02bJpJWDa-RFuv1vogrbeY5T4K1M_Q.cache +0 -0
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uf/uf8xlrN24XDdqvg97XSNrPFSYWGELN2cEHkKsu52zJQ.cache +3 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wD/wDQfpqPktQEUJYqGBoTlKAOHJhn7hzFSg9lUtfzUSHM.cache +1 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +2 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y4/y4wKs_D3Zp3A5ItE5hfD5dkJEr-mnvfyNon1lhrxKKY.cache +3 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yp/yp55Nm9xYM0wvHSoLvfP6mrhrUIKrig6v9Q_Yb0kZpQ.cache +0 -0
  98. data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +10 -0
  99. data/spec/models/openstax/accounts/account_spec.rb +87 -7
  100. data/spec/spec_helper.rb +18 -3
  101. metadata +141 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ee92a3b64d5e3e96b74bb4991cc34bd70ffafba
4
- data.tar.gz: b8799ffbc096a017d7f2d084de72fef2e25bd3c7
3
+ metadata.gz: f6c2574a839a5d9ac9bca06bd2d2f4ec74c684b6
4
+ data.tar.gz: 352c193b6685610b0025a67253ffc2313f84b9ca
5
5
  SHA512:
6
- metadata.gz: 842e2e8e5fa4200b2baf160a183409cdaace616495bfe614ae5da8b8de15097ca9e219e66881a404dc321114b4297aa9f0ea3f3dfed34fde2046b3a67039ab88
7
- data.tar.gz: 69763b3c8b3d2d40a2a49e0f1986807c2e8b54c7784605848a45c9058cc582651c1ecdf7d6bfdaff33a0afa354de4a2cf01a39f61339e862bfa0d8a61ffdf95c
6
+ metadata.gz: 4d27f3a0211633e06103c3e2c033c43f6e0a421def89a601b7405e4ecc58610b4959333fc2e1da6aaecccd886416e72dfe63882ea6ffd2a9e38b5d0e55ad0b84
7
+ data.tar.gz: 8847dcc227f640e2d76009919e16ed9aab8d0687083598be9f0df1979b5eeb3315524ba9d6f2df540218108d6027fb1b8e51a799182b19f33e03c2851c19dd50
data/Rakefile CHANGED
@@ -11,12 +11,12 @@ load 'rails/tasks/engine.rake'
11
11
 
12
12
  Bundler::GemHelper.install_tasks
13
13
 
14
- require 'rake/testtask'
14
+ begin
15
+ require 'rspec/core/rake_task'
15
16
 
16
- Rake::TestTask.new(:spec => 'app:db:test:prepare') do |t|
17
- t.libs << 'spec'
18
- t.pattern = 'spec/**/*_spec.rb'
19
- t.verbose = false
20
- end
17
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
21
18
 
22
- task :default => :spec
19
+ task default: :spec
20
+ rescue LoadError
21
+ # no rspec available
22
+ end
@@ -10,7 +10,10 @@ module OpenStax
10
10
  store_url url: params[:return_to], key: :accounts_return_to, strategies: [:session]
11
11
  end
12
12
  store_fallback key: :accounts_return_to, strategies: [:session]
13
- redirect_to openstax_login_path
13
+
14
+ forwardable_params =
15
+ params.slice(*configuration.forwardable_login_param_keys.map(&:to_s))
16
+ redirect_to openstax_login_path(forwardable_params)
14
17
  end
15
18
  end
16
19
 
@@ -20,15 +20,17 @@ module OpenStax::Accounts
20
20
  inverse_of: :user
21
21
  has_many :groups_as_member, through: :group_members, source: :group
22
22
 
23
- enum faculty_status: [:no_faculty_info, :pending_faculty, :confirmed_faculty, :rejected_faculty]
24
- after_initialize { self.faculty_status ||= :no_faculty_info }
23
+ enum faculty_status: [:no_faculty_info, :pending_faculty,
24
+ :confirmed_faculty, :rejected_faculty]
25
+
26
+ after_initialize :set_default_faculty_status
27
+
25
28
  validates :faculty_status, presence: true
26
29
 
27
- validates :openstax_uid, presence: true, uniqueness: true
28
- validates :username, presence: true, uniqueness: true,
29
- unless: :syncing_or_stubbing
30
+ validates :openstax_uid, uniqueness: { allow_nil: true }
31
+ validates :username, uniqueness: { allow_nil: true }
30
32
 
31
- before_update :update_openstax_accounts, unless: :syncing_or_stubbing
33
+ before_update :update_openstax_accounts, if: :should_send_updates_to_accounts?
32
34
 
33
35
  def name
34
36
  (first_name || last_name) ? [first_name, last_name].compact.join(" ") : username
@@ -46,12 +48,24 @@ module OpenStax::Accounts
46
48
  !access_token.nil?
47
49
  end
48
50
 
51
+ def valid_openstax_uid?
52
+ !openstax_uid.nil? && openstax_uid > 0
53
+ end
54
+
49
55
  protected
50
56
 
51
- def syncing_or_stubbing
57
+ def set_default_faculty_status
58
+ self.faculty_status ||= :no_faculty_info
59
+ end
60
+
61
+ def syncing_or_stubbing?
52
62
  syncing || OpenStax::Accounts.configuration.enable_stubbing?
53
63
  end
54
64
 
65
+ def should_send_updates_to_accounts?
66
+ !syncing_or_stubbing? && valid_openstax_uid?
67
+ end
68
+
55
69
  def update_openstax_accounts
56
70
  OpenStax::Accounts::Api.update_account(self)
57
71
  end
@@ -27,12 +27,12 @@ module OpenStax::Accounts
27
27
  has_many :member_groups, through: :member_group_nestings
28
28
 
29
29
  validates :openstax_uid, uniqueness: true, presence: true
30
- validates_presence_of :requestor, unless: :syncing_or_stubbing
31
- validates_uniqueness_of :name, allow_nil: true, unless: :syncing_or_stubbing
30
+ validates_presence_of :requestor, unless: :syncing_or_stubbing?
31
+ validates_uniqueness_of :name, allow_nil: true, unless: :syncing_or_stubbing?
32
32
 
33
- before_validation :create_openstax_accounts_group, on: :create, unless: :syncing_or_stubbing
34
- before_update :update_openstax_accounts_group, unless: :syncing_or_stubbing
35
- before_destroy :destroy_openstax_accounts_group, unless: :syncing_or_stubbing
33
+ before_validation :create_openstax_accounts_group, on: :create, unless: :syncing_or_stubbing?
34
+ before_update :update_openstax_accounts_group, unless: :syncing_or_stubbing?
35
+ before_destroy :destroy_openstax_accounts_group, unless: :syncing_or_stubbing?
36
36
 
37
37
  scope :visible_for, lambda { |account|
38
38
  next where(is_public: true) unless account.is_a? OpenStax::Accounts::Account
@@ -116,7 +116,7 @@ module OpenStax::Accounts
116
116
 
117
117
  protected
118
118
 
119
- def syncing_or_stubbing
119
+ def syncing_or_stubbing?
120
120
  syncing || OpenStax::Accounts.configuration.enable_stubbing?
121
121
  end
122
122
 
@@ -10,14 +10,14 @@ module OpenStax::Accounts
10
10
 
11
11
  validates :group, presence: true
12
12
  validates :user, presence: true, uniqueness: { scope: :group }
13
- validates :requestor, presence: true, unless: :syncing_or_stubbing
13
+ validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
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
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
17
 
18
18
  protected
19
19
 
20
- def syncing_or_stubbing
20
+ def syncing_or_stubbing?
21
21
  syncing || OpenStax::Accounts.configuration.enable_stubbing?
22
22
  end
23
23
 
@@ -10,18 +10,18 @@ module OpenStax::Accounts
10
10
 
11
11
  validates :container_group, presence: true
12
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
13
+ validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
+ validate :no_loops, unless: :syncing_or_stubbing?
15
15
 
16
16
  before_create :update_group_caches, unless: :syncing
17
17
  before_destroy :update_group_caches, unless: :syncing
18
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
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
21
 
22
22
  protected
23
23
 
24
- def syncing_or_stubbing
24
+ def syncing_or_stubbing?
25
25
  syncing || OpenStax::Accounts.configuration.enable_stubbing?
26
26
  end
27
27
 
@@ -10,14 +10,14 @@ module OpenStax::Accounts
10
10
 
11
11
  validates :group, presence: true
12
12
  validates :user, presence: true, uniqueness: { scope: :group }
13
- validates :requestor, presence: true, unless: :syncing_or_stubbing
13
+ validates :requestor, presence: true, unless: :syncing_or_stubbing?
14
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
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
17
 
18
18
  protected
19
19
 
20
- def syncing_or_stubbing
20
+ def syncing_or_stubbing?
21
21
  syncing || OpenStax::Accounts.configuration.enable_stubbing?
22
22
  end
23
23
 
@@ -6,15 +6,15 @@ module OpenStax
6
6
  module Dev
7
7
  class CreateAccount
8
8
  lev_routine
9
-
9
+
10
10
  protected
11
11
 
12
12
  def exec(inputs={})
13
- fatal_error(:code => :cannot_create_account_in_production) if Rails.env.production?
14
- fatal_error(:code => :can_only_create_account_when_stubbing) if !OpenStax::Accounts.configuration.enable_stubbing?
13
+ fatal_error(code: :cannot_create_account_in_production) if Rails.env.production?
14
+ fatal_error(code: :can_only_create_account_when_stubbing) if !OpenStax::Accounts.configuration.enable_stubbing?
15
15
 
16
16
  username = inputs[:username]
17
- while username.nil? || Account.where(username: username).exists? do
17
+ while username.nil? || Account.where(username: username).exists? do
18
18
  username = SecureRandom.hex(3).to_s
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ module OpenStax
22
22
 
23
23
  app_accounts = []
24
24
  app_accounts_rep = OpenStax::Accounts::Api::V1::ApplicationAccountsRepresenter
25
- .new(app_accounts)
25
+ .new(app_accounts)
26
26
  app_accounts_rep.from_json(response.body)
27
27
 
28
28
  return if app_accounts.empty?
@@ -30,7 +30,7 @@ module OpenStax
30
30
  updated_app_accounts = []
31
31
  app_accounts.each do |app_account|
32
32
  account = OpenStax::Accounts::Account.where(
33
- :openstax_uid => app_account.account.openstax_uid
33
+ openstax_uid: app_account.account.openstax_uid
34
34
  ).first || app_account.account
35
35
  account.syncing = true
36
36
 
@@ -9,7 +9,7 @@ class CreateOpenStaxAccountsAccounts < ActiveRecord::Migration
9
9
  t.string :full_name
10
10
  t.string :title
11
11
 
12
- t.timestamps
12
+ t.timestamps null: false
13
13
  end
14
14
 
15
15
  add_index :openstax_accounts_accounts, :openstax_uid, unique: true
@@ -7,7 +7,7 @@ class CreateOpenStaxAccountsGroups < ActiveRecord::Migration
7
7
  t.text :cached_subtree_group_ids
8
8
  t.text :cached_supertree_group_ids
9
9
 
10
- t.timestamps
10
+ t.timestamps null: false
11
11
  end
12
12
 
13
13
  add_index :openstax_accounts_groups, :openstax_uid, unique: true
@@ -4,7 +4,7 @@ class CreateOpenStaxAccountsGroupMembers < ActiveRecord::Migration
4
4
  t.references :group, null: false
5
5
  t.references :user, null: false
6
6
 
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
 
10
10
  add_index :openstax_accounts_group_members, [:group_id, :user_id], unique: true
@@ -4,7 +4,7 @@ class CreateOpenStaxAccountsGroupOwners < ActiveRecord::Migration
4
4
  t.references :group, null: false
5
5
  t.references :user, null: false
6
6
 
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
 
10
10
  add_index :openstax_accounts_group_owners, [:group_id, :user_id], unique: true
@@ -4,7 +4,7 @@ class CreateOpenStaxAccountsGroupNestings < ActiveRecord::Migration
4
4
  t.references :member_group, null: false
5
5
  t.references :container_group, null: false
6
6
 
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
 
10
10
  add_index :openstax_accounts_group_nestings, :member_group_id, unique: true
@@ -0,0 +1,5 @@
1
+ class ChangeAccountsOpenStaxUidToBeNullable < ActiveRecord::Migration
2
+ def change
3
+ change_column_null :openstax_accounts_accounts, :openstax_uid, true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeAccountsUsernameToBeNullable < ActiveRecord::Migration
2
+ def change
3
+ change_column_null :openstax_accounts_accounts, :username, true
4
+ end
5
+ end
@@ -4,7 +4,7 @@ module OpenStax
4
4
  module Base
5
5
 
6
6
  def self.included(base)
7
- base.helper_method :current_user, :signed_in?
7
+ base.helper_method :current_user, :signed_in?, :openstax_accounts_login_path
8
8
  end
9
9
 
10
10
  # Returns the current user
@@ -39,6 +39,14 @@ module OpenStax
39
39
  OpenStax::Accounts::CurrentUserManager.new(request, session, cookies)
40
40
  end
41
41
 
42
+ def login_params
43
+ @login_params ||= {}
44
+ end
45
+
46
+ def openstax_accounts_login_path
47
+ openstax_accounts.login_path(login_params)
48
+ end
49
+
42
50
  def authenticate_user!
43
51
  account = current_account
44
52
 
@@ -48,7 +56,9 @@ module OpenStax
48
56
 
49
57
  respond_to do |format|
50
58
  format.json { head(:forbidden) }
51
- format.any { redirect_to openstax_accounts.login_url }
59
+ format.any {
60
+ redirect_to openstax_accounts_login_path
61
+ }
52
62
  end
53
63
  end
54
64
 
@@ -60,6 +60,10 @@ module OpenStax
60
60
  # to the default Accounts logout URL.
61
61
  attr_writer :logout_redirect_url
62
62
 
63
+ # forwardable_login_param_keys
64
+ # Which params are forwarded on the accounts login path
65
+ attr_accessor :forwardable_login_param_keys
66
+
63
67
  def logout_redirect_url(request)
64
68
  (@logout_redirect_url.is_a?(Proc) ?
65
69
  @logout_redirect_url.call(request) :
@@ -94,6 +98,7 @@ module OpenStax
94
98
  @max_search_items = 10
95
99
  @logout_redirect_url = nil
96
100
  @return_to_url_approver = nil
101
+ @forwardable_login_param_keys = [:signup_at, :go]
97
102
  super
98
103
  end
99
104
 
@@ -19,7 +19,7 @@ module OpenStax
19
19
  module Accounts
20
20
  class Engine < ::Rails::Engine
21
21
  isolate_namespace OpenStax::Accounts
22
-
22
+
23
23
  initializer "openstax_accounts.factories",
24
24
  :after => "factory_girl.set_factory_paths" do
25
25
  FactoryGirl.definition_file_paths << File.join(root, 'spec', 'factories') if defined?(FactoryGirl)
@@ -33,13 +33,25 @@ module OpenStax
33
33
  end
34
34
 
35
35
  SETUP_PROC = lambda do |env|
36
- env['omniauth.strategy'].options[:client_options][:site] = OpenStax::Accounts.configuration.openstax_accounts_url
36
+ # Useful link for how to pass params through omniauth/doorkeeper:
37
+ # https://github.com/doorkeeper-gem/doorkeeper/wiki/Passing-parameters-from-a-devise-client-to-doorkeeper-(like-locale)
38
+
39
+ # request spec `env` doesn't honor "rack.request.query_hash" shortcut, so we fallback
40
+ # to manually parsing the query string. Also make sure to use an extra fallback of an
41
+ # empty hash because setting the authorize_params to nil upsets Omniauth.
42
+ query_hash = env["rack.request.query_hash"] ||
43
+ Rack::Utils.parse_nested_query(env["QUERY_STRING"]) ||
44
+ {}
45
+ env['omniauth.strategy'].options.authorize_params = query_hash
46
+
47
+ env['omniauth.strategy'].options[:client_options][:site] =
48
+ OpenStax::Accounts.configuration.openstax_accounts_url
37
49
  end
38
50
 
39
51
  # Doesn't work to put this omniauth code in an engine initializer, instead:
40
52
  # https://gist.github.com/pablomarti/5243118
41
53
  middleware.use ::OmniAuth::Builder do
42
- provider :openstax,
54
+ provider :openstax,
43
55
  OpenStax::Accounts.configuration.openstax_application_id,
44
56
  OpenStax::Accounts.configuration.openstax_application_secret,
45
57
  :setup => SETUP_PROC
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "7.2.0"
3
+ VERSION = "7.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Forwards params", type: :request do
4
+
5
+ class ForwardsParamsController < OpenStax::Accounts::ApplicationController
6
+ before_filter :set_login_param
7
+ before_filter :authenticate_user!
8
+
9
+ def action_needing_authentication; end
10
+
11
+ def set_login_param
12
+ login_params[:signup_at] = "foo"
13
+ login_params[:go] = "bar"
14
+ end
15
+ end
16
+
17
+ before(:all) do
18
+ Rails.application.routes.send(:eval_block, Proc.new do
19
+ get '/forwards_params_route' => 'forwards_params#action_needing_authentication'
20
+ end)
21
+ end
22
+
23
+ it 'should forward signup_at' do
24
+ test_forwards(key: :signup_at, value: "foo")
25
+ end
26
+
27
+ it "should forward go" do
28
+ test_forwards(key: :go, value: "bar")
29
+ end
30
+
31
+ def test_forwards(key:, value:)
32
+ get '/forwards_params_route'
33
+
34
+ expect(redirect_path).to eq "/accounts/login"
35
+ expect(redirect_query_hash).to include(key => value)
36
+
37
+ with_stubbing(false) do
38
+ get redirect_path_and_query
39
+ end
40
+
41
+ expect(redirect_path).to eq "/accounts/auth/openstax"
42
+ expect(redirect_query_hash).to include(key => value)
43
+
44
+ get redirect_path_and_query
45
+
46
+ expect(redirect_path).to eq("/oauth/authorize")
47
+ expect(redirect_query_hash).to include(key => value)
48
+
49
+ # This last redirect was to Accounts, so we don't follow it
50
+ end
51
+
52
+ def redirect_path
53
+ redirect_uri.path
54
+ end
55
+
56
+ def redirect_path_and_query
57
+ "#{redirect_uri.path}?#{redirect_uri.query}"
58
+ end
59
+
60
+ def redirect_query_hash
61
+ Rack::Utils.parse_nested_query(redirect_uri.query).symbolize_keys
62
+ end
63
+
64
+ def redirect_uri
65
+ expect(response.code).to eq "302"
66
+ uri = URI.parse(response.headers["Location"])
67
+ end
68
+ end