openstax_accounts 7.8.0 → 7.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -7
  3. data/app/handlers/openstax/accounts/sessions_callback.rb +0 -1
  4. data/app/models/openstax/accounts/account.rb +1 -0
  5. data/app/models/openstax/accounts/group.rb +47 -24
  6. data/app/routines/openstax/accounts/search_local_accounts.rb +30 -17
  7. data/db/migrate/10_assign_missing_uuids_for_local_accounts.rb +11 -0
  8. data/lib/openstax/accounts/engine.rb +5 -6
  9. data/lib/openstax/accounts/version.rb +1 -1
  10. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
  11. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
  12. data/spec/dummy/config/database.yml +5 -15
  13. data/spec/dummy/db/development.sqlite3 +0 -0
  14. data/spec/dummy/db/schema.rb +29 -25
  15. data/spec/dummy/db/test.sqlite3 +0 -0
  16. data/spec/dummy/log/development.log +2152 -4613
  17. data/spec/dummy/log/test.log +55163 -102384
  18. data/spec/factories/openstax_accounts_account.rb +6 -6
  19. data/spec/factories/openstax_accounts_group.rb +1 -1
  20. data/spec/factories/openstax_accounts_group_member.rb +1 -1
  21. data/spec/factories/openstax_accounts_group_nesting.rb +1 -1
  22. data/spec/factories/openstax_accounts_group_owner.rb +1 -1
  23. data/spec/handlers/openstax/accounts/accounts_search_spec.rb +5 -5
  24. data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +5 -5
  25. data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +7 -5
  26. data/spec/lib/openstax/accounts/api_spec.rb +9 -9
  27. data/spec/lib/openstax/accounts/current_user_manager_spec.rb +1 -1
  28. data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +3 -3
  29. data/spec/models/openstax/accounts/account_spec.rb +6 -6
  30. data/spec/models/openstax/accounts/group_spec.rb +4 -4
  31. data/spec/routines/openstax/accounts/create_group_spec.rb +1 -1
  32. data/spec/routines/openstax/accounts/search_accounts_spec.rb +13 -13
  33. data/spec/routines/openstax/accounts/sync_accounts_spec.rb +26 -7
  34. data/spec/routines/openstax/accounts/sync_groups_spec.rb +51 -14
  35. data/spec/spec_helper.rb +2 -2
  36. metadata +64 -211
  37. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-4/-4AigB7SRNxiHWeamN5uh_JTU4pT-99hUByQ7hhtfM4.cache +0 -1
  38. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-B/-BM2LkGo9LiZel0dx2cTeIoUiOvZvzvQX-qrY-PefDc.cache +0 -0
  39. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0d/0dqBuwbmRqLO9AM5KdttlIvUSbOG2uS9fJsm4TRuY8M.cache +0 -0
  40. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/1b/1bCIjOPcmZWjhnOiOIrEUVDFzGzCezkm0dIrzY7q22A.cache +0 -2
  41. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2GcGY034bmlAWeI-bC8yjSfggr98_D1ysvB0hcR9PaI.cache +0 -3
  42. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2gGPkwl7LddZxTKkA0XQ6NKsdgK7mDG6PfvKrqKYsAs.cache +0 -0
  43. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4W/4WJLh0PRMuTwbFf44QcjwkcJ57BXKVgwtaRnUiMxlbc.cache +0 -1
  44. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5T/5TLgAp4XC6JjXz-MP4IR8UIli3l091nGGpp0xomd_g0.cache +0 -0
  45. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5g/5g7dhxVp4YbZmFw_-T3aU2oYq2Z9Jgtps0CKneXYSS0.cache +0 -2
  46. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5u/5uKXJe6QpDEzhvxGUSwHZS2uGrjr0-ex9LVlRQZaQnI.cache +0 -1
  47. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6H/6HAlvBZ_na7ir9ELSAcCJ1GTAwGaO565PgVOt7rgitw.cache +0 -1
  48. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6b/6bUhHw6Kpj9FgN8vIU0BBQNdA1sgsa0pyhDOdq4U1a8.cache +0 -2
  49. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8w/8whA2ROqlMHhJJiXDf0onGPb8mLmBGb5UUPY7yZZuMs.cache +0 -1
  50. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9S/9SfcyOi0r3UamY1lEOb94zdm_ybDACE3pzfyMeUnoJc.cache +0 -0
  51. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Af/AfzRuN8Wm6MIHDZEpwWkiSl3zNDMJ1tOvSt2SOmVCio.cache +0 -1
  52. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DB/DB4PIoupKZcosm_IvLp0-MJ1hiXfVw01ZdY1IOnnPsE.cache +0 -0
  53. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DR/DRPKqdpBdXQEzG7sFT6-8d_LgGF72B8IFqYLhVsyNqw.cache +0 -1
  54. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhSAf3h0VMpFRp_tvO8VIqn12P-Mnp3WFyVH4ORR-gs.cache +0 -0
  55. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/E3/E35l_cFnSYnnYWJwxWXR76R17KJ3tqL_-UG0Tjrp5DI.cache +0 -0
  56. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ET/ETdvBR0__vhxzfl_I4mu0h3Jrcwy0jvIvEf-AcGHuxU.cache +0 -1
  57. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EZ/EZkBau1uUbmU8TAtNy_21ZEq6hQ-pQY-jNbMnaAlNYM.cache +0 -1
  58. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IV/IVl_wFSpYKfB-OI07E_GP9JLqGpf6VStaDO-Pl-EcUA.cache +0 -1
  59. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/It/ItWlWNmHD7ZeVOFbsyan26cbPWTR9XFqNBmZhIsyr8k.cache +0 -2
  60. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JB/JBrtwWy2SgF1Nl6siXGeTqdnlMdXo6F-OOkAKCHx3gw.cache +0 -1
  61. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Je/JeDnsbKYU6WfXwmBfUedz09ThQX9iPI8-sgit9Um1yE.cache +0 -1
  62. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Jr/JrzNmQmTkr6QS1BoAOEeGnCip0CCneRNMyvtaelWV1w.cache +0 -2
  63. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KE/KEIyyOl_ruT7KuaNvukGN8LnSUVMk4MQmDUOg9oo0XE.cache +0 -0
  64. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LK/LK8fShpIirD6_e29A0YY7pTPZbISgiHuY3QOMzj-c4c.cache +0 -1
  65. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lr/LrK9U2KWZskR0G2rWalGnOM8fgZvGwEajG7_WYkK-Rc.cache +0 -1
  66. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/MH/MHc26ZBwFN93Q3ggSv0QW4WDhXzTQV6YvzIUUt6Su7Q.cache +0 -1
  67. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Nj/NjMmwEjtqJiXWQtb2qVmb2Js1DikSD_MgMHDlCNzLP4.cache +0 -1
  68. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1IElAqy9O60bh7c8syJLSGSTIxOL_WDNftM2SNTsgI.cache +0 -1
  69. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QW/QWLUd5oxFsWTwKa1IXwWsaP8RlLh_GMPdypbqJx0VoA.cache +0 -1
  70. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TZ/TZlHN1bHx2lwu7SRM5Y3Qp_OpbrtidFt-6223MTPMH4.cache +0 -1
  71. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VN/VNCapNKJLeponthNeFJhaBYs92UBT3P8PugENHP0474.cache +0 -2
  72. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WX/WXy-lTrCCH38uK_ld4QeQrhZuZZDOyHGBBrhZ0PDZyY.cache +0 -2
  73. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Yr/YrbMyaVyJ69SVCY3y1ZPJAdUcuUpzzHP7LMQNT2pGfk.cache +0 -1
  74. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Z-/Z-tPXaNX9WvhVHKT_twh9-sJ_NvUPatXyDZ48rWasiE.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/aYOmaJvT9wpA9a2IfP3f-6A6guRGAezZCHz_3lSCE0A.cache +0 -1
  76. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/ayvQApV55-bf3brcKBVUc8_o-8aLmUhKYv9b7OPRXV8.cache +0 -1
  77. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bR/bRCnhDQ4uJkiX7RMvyDbsvopysp32eYxD0SYAsEpDzc.cache +0 -1
  78. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bz/bzY1-207qUxPHd6HAeNvY34UEmIZlAnGJUuiwkGLqTw.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/cj/cjLyKHfhNSrjEff7p2VGJz6ColftKx69unhJqv0UK1g.cache +0 -2
  80. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e2/e28DqqHF8GN5VTAz03mRnOV5AV_np1CNwB_xuV03NUw.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hh/hh_1YpicqmoKC8uz92Sh3iba0TBhh9GEXtUyrUlEzEU.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/iKFb6K0z7xwr53FXp9Qy4qO5L6lryDOpXjMnw-48oVg.cache +0 -2
  83. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/jn/jnRNObm7DziGmbZR3TPAC-vAE-qmrP0tLBH9W9m6yJs.cache +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kS/kSXVJZ4BJAsy2L9DxKUntzr90Nd9VWD0G7L2n05ISOw.cache +0 -1
  85. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kq/kq0VL9PQ2HRlksqNC7YPlqlWFBvkHk2uIac_HZb0wEE.cache +0 -1
  86. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/l0/l0BYOaBq08_FGl4jzpCnd80-zLPHNMXs7xCHtqTcUVI.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lx/lxYKD42Es9n2EKrNchxPYKveAzYo6VAGr_CxhxvyO-c.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mW/mWLVMCpv8dHPkBK4y4SLLXukqtLhRXWtNC3gm5vgwPk.cache +0 -3
  89. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mx/mxoipKjbqPo_gvG86AgUPk6o6-OB-uqI5sGMnNqGW4A.cache +0 -1
  90. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nZ/nZY2kcE7t2EMdrdtEQueW9UYmtEBjQv3FNpous5k1tM.cache +0 -2
  91. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/o3/o3Bz1eWxZ7poUlQGzlkJX5fFeNxKD5VEuFZSctl6Oe4.cache +0 -1
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p-/p-j1kEkMIDywvXn2EG-FF_CVz9U75IYIDMJj4U2ksCk.cache +0 -2
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pZ/pZXUaTdXV2XMj_KgBsHVED1ocjtpQrIqBR3lGYSMZVc.cache +0 -2
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +0 -2
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r0/r0S88W86F754buOO-eLMVX5f9YdQzd-ZkpvwEJc6hAg.cache +0 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r3/r3X66JZPGDKB-xMv9rLIyo0WKYWnPrSB2qL0giC2T6g.cache +0 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/t7/t7deseLVHWCZ7z2LMl1YvpZi-RIhvURhm0-MSDE3qvY.cache +0 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tl/tl1nInky090OX02bJpJWDa-RFuv1vogrbeY5T4K1M_Q.cache +0 -0
  99. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uf/uf8xlrN24XDdqvg97XSNrPFSYWGELN2cEHkKsu52zJQ.cache +0 -3
  100. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wD/wDQfpqPktQEUJYqGBoTlKAOHJhn7hzFSg9lUtfzUSHM.cache +0 -1
  101. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +0 -2
  102. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y4/y4wKs_D3Zp3A5ItE5hfD5dkJEr-mnvfyNon1lhrxKKY.cache +0 -3
  103. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yp/yp55Nm9xYM0wvHSoLvfP6mrhrUIKrig6v9Q_Yb0kZpQ.cache +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e2fb6f3993c4913a847ecd653f5745e75294ac7
4
- data.tar.gz: 8b27e285cdc80bda53772124a57acfb9db3d9c13
3
+ metadata.gz: 3bef0159179b28deec9d472b9cb27364f042ab36
4
+ data.tar.gz: 896f0a36f899d4151cb8c262b59be7e463a726aa
5
5
  SHA512:
6
- metadata.gz: c344bc633749967e366d6a80147c4b34cfa5721695f0dca7ce5984c5ba803c73f73eceed5567f8f4c01d5f4f328ce80228859121f680ce87d11d7af8965e02bb
7
- data.tar.gz: bfc6844d37c3fbe70cf3c6735960d504d6982743b4b000d678ff3b6848cd9d879b293db7271187251cc4767461f5bf22ad767fddb041574a995f876a880dde21
6
+ metadata.gz: 5e882df36bb92b078455d41fff3b98585f11f9c5a79758f52644be6ca3de0beabd5d00f81f2f0d96f79fce0184c66a9aef617d75bb71d3546d0ce94c6cddad1d
7
+ data.tar.gz: c08ecff3ccc0285ee52f4ec1003fd901571c2d1db40a6c3cf70b39908169113af456c55ed4fee971cb269094cd716287a68230a16e19359975084f5d1dc5fca6
data/Rakefile CHANGED
@@ -11,12 +11,12 @@ load 'rails/tasks/engine.rake'
11
11
 
12
12
  Bundler::GemHelper.install_tasks
13
13
 
14
- begin
15
- require 'rspec/core/rake_task'
14
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
16
15
 
17
- RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
16
+ require 'rspec/core'
17
+ require 'rspec/core/rake_task'
18
18
 
19
- task default: :spec
20
- rescue LoadError
21
- # no rspec available
22
- end
19
+ desc 'Run all specs in spec directory (excluding plugin specs)'
20
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
21
+
22
+ task default: :spec
@@ -45,7 +45,6 @@ module OpenStax
45
45
  end
46
46
 
47
47
  account.uuid = raw_info['uuid']
48
-
49
48
  end
50
49
  end
51
50
 
@@ -31,6 +31,7 @@ module OpenStax::Accounts
31
31
 
32
32
  validates :openstax_uid, uniqueness: { allow_nil: true }
33
33
  validates :username, uniqueness: { allow_nil: true }
34
+ validates :uuid, uniqueness: { allow_nil: true }
34
35
 
35
36
  before_update :update_openstax_accounts, if: :should_send_updates_to_accounts?
36
37
 
@@ -13,17 +13,23 @@ module OpenStax::Accounts
13
13
 
14
14
  has_many :group_members, dependent: :destroy,
15
15
  class_name: 'OpenStax::Accounts::GroupMember',
16
- primary_key: :openstax_uid, inverse_of: :group
16
+ primary_key: :openstax_uid,
17
+ inverse_of: :group
17
18
  has_many :members, through: :group_members, source: :user
18
19
 
19
20
  has_one :container_group_nesting, dependent: :destroy,
20
- class_name: 'OpenStax::Accounts::GroupNesting', primary_key: :openstax_uid,
21
- foreign_key: :member_group_id, inverse_of: :member_group
21
+ class_name: 'OpenStax::Accounts::GroupNesting',
22
+ primary_key: :openstax_uid,
23
+ foreign_key: :member_group_id,
24
+ inverse_of: :member_group
22
25
  has_one :container_group, through: :container_group_nesting
23
26
 
24
- has_many :member_group_nestings, dependent: :destroy,
25
- class_name: 'OpenStax::Accounts::GroupNesting', primary_key: :openstax_uid,
26
- foreign_key: :container_group_id, inverse_of: :container_group
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
27
33
  has_many :member_groups, through: :member_group_nestings
28
34
 
29
35
  validates :openstax_uid, uniqueness: true, presence: true
@@ -34,14 +40,31 @@ module OpenStax::Accounts
34
40
  before_update :update_openstax_accounts_group, unless: :syncing_or_stubbing?
35
41
  before_destroy :destroy_openstax_accounts_group, unless: :syncing_or_stubbing?
36
42
 
37
- scope :visible_for, lambda { |account|
38
- next where(is_public: true) unless account.is_a? OpenStax::Accounts::Account
39
-
40
- includes(:group_members).includes(:group_owners)
41
- .where{((is_public.eq true) |\
42
- (group_members.user_id.eq my{account.id}) |\
43
- (group_owners.user_id.eq my{account.id}))}
44
- }
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
+ )
45
68
 
46
69
  def has_owner?(account)
47
70
  return false unless account.is_a? OpenStax::Accounts::Account
@@ -91,11 +114,12 @@ module OpenStax::Accounts
91
114
  return [] unless persisted?
92
115
  reload
93
116
 
94
- gids = [openstax_uid] + (Group.includes(:member_group_nestings)
95
- .where(member_group_nestings: {
96
- member_group_id: openstax_uid
97
- })
98
- .first.try(:supertree_group_ids) || [])
117
+ gids = [openstax_uid] + (
118
+ self.class.joins(:member_group_nestings)
119
+ .where(openstax_accounts_group_nestings: { member_group_id: openstax_uid })
120
+ .first
121
+ .try!(:supertree_group_ids) || []
122
+ )
99
123
  update_column(:cached_supertree_group_ids, gids)
100
124
  self.cached_supertree_group_ids = gids
101
125
  end
@@ -105,11 +129,10 @@ module OpenStax::Accounts
105
129
  return [] unless persisted?
106
130
  reload
107
131
 
108
- gids = [openstax_uid] + Group.includes(:container_group_nesting)
109
- .where(container_group_nesting: {
110
- container_group_id: openstax_uid
111
- })
112
- .collect{|g| g.subtree_group_ids}.flatten
132
+ gids = [openstax_uid] +
133
+ self.class.joins(:container_group_nesting)
134
+ .where(openstax_accounts_group_nestings: { container_group_id: openstax_uid })
135
+ .map { |group| group.subtree_group_ids }.flatten
113
136
  update_column(:cached_subtree_group_ids, gids)
114
137
  self.cached_subtree_group_ids = gids
115
138
  end
@@ -2,6 +2,8 @@ module OpenStax
2
2
  module Accounts
3
3
  class SearchLocalAccounts
4
4
 
5
+ ACCOUNTS = OpenStax::Accounts::Account.arel_table
6
+
5
7
  SORTABLE_FIELDS = {
6
8
  'username' => :username,
7
9
  'first_name' => :first_name,
@@ -23,9 +25,11 @@ module OpenStax
23
25
  params[:pp] ||= args[2]
24
26
  params[:p] ||= args[3]
25
27
 
26
- run(:search, :relation => OpenStax::Accounts::Account.unscoped,
27
- :sortable_fields => SORTABLE_FIELDS,
28
- :params => params) do |with|
28
+
29
+
30
+ run(:search, relation: OpenStax::Accounts::Account.unscoped,
31
+ sortable_fields: SORTABLE_FIELDS,
32
+ params: params) do |with|
29
33
 
30
34
  with.default_keyword :any
31
35
 
@@ -33,7 +37,8 @@ module OpenStax
33
37
  names.each do |name|
34
38
  sanitized_names = to_string_array(name, append_wildcard: true)
35
39
  next @items = @items.none if sanitized_names.empty?
36
- @items = @items.where{username.like_any sanitized_names}
40
+
41
+ @items = @items.where(ACCOUNTS[:username].matches_any(sanitized_names))
37
42
  end
38
43
  end
39
44
 
@@ -41,7 +46,8 @@ module OpenStax
41
46
  names.each do |name|
42
47
  sanitized_names = to_string_array(name, append_wildcard: true)
43
48
  next @items = @items.none if sanitized_names.empty?
44
- @items = @items.where{first_name.like_any sanitized_names}
49
+
50
+ @items = @items.where(ACCOUNTS[:first_name].matches_any(sanitized_names))
45
51
  end
46
52
  end
47
53
 
@@ -49,7 +55,8 @@ module OpenStax
49
55
  names.each do |name|
50
56
  sanitized_names = to_string_array(name, append_wildcard: true)
51
57
  next @items = @items.none if sanitized_names.empty?
52
- @items = @items.where{last_name.like_any sanitized_names}
58
+
59
+ @items = @items.where(ACCOUNTS[:last_name].matches_any(sanitized_names))
53
60
  end
54
61
  end
55
62
 
@@ -57,7 +64,8 @@ module OpenStax
57
64
  names.each do |name|
58
65
  sanitized_names = to_string_array(name, append_wildcard: true)
59
66
  next @items = @items.none if sanitized_names.empty?
60
- @items = @items.where{full_name.like_any sanitized_names}
67
+
68
+ @items = @items.where(ACCOUNTS[:full_name].matches_any(sanitized_names))
61
69
  end
62
70
  end
63
71
 
@@ -65,10 +73,13 @@ module OpenStax
65
73
  names.each do |name|
66
74
  sanitized_names = to_string_array(name, append_wildcard: true)
67
75
  next @items = @items.none if sanitized_names.empty?
68
- @items = @items.where{(username.like_any sanitized_names) | \
69
- (first_name.like_any sanitized_names) | \
70
- (last_name.like_any sanitized_names) | \
71
- (full_name.like_any sanitized_names)}
76
+
77
+ @items = @items.where(
78
+ ACCOUNTS[:username].matches_any(sanitized_names)
79
+ .or(ACCOUNTS[:first_name].matches_any(sanitized_names))
80
+ .or(ACCOUNTS[:last_name].matches_any(sanitized_names))
81
+ .or(ACCOUNTS[:full_name].matches_any(sanitized_names))
82
+ )
72
83
  end
73
84
  end
74
85
 
@@ -76,7 +87,7 @@ module OpenStax
76
87
  ids.each do |id|
77
88
  sanitized_ids = to_string_array(id)
78
89
  next @items = @items.none if sanitized_ids.empty?
79
- @items = @items.where{(openstax_uid.eq_any sanitized_ids)}
90
+ @items = @items.where(ACCOUNTS[:openstax_uid].eq_any(sanitized_ids))
80
91
  end
81
92
  end
82
93
 
@@ -86,11 +97,13 @@ module OpenStax
86
97
  sanitized_ids = to_string_array(term)
87
98
  next @items = @items.none if sanitized_names.empty? || sanitized_ids.empty?
88
99
 
89
- @items = @items.where{(username.like_any sanitized_names) | \
90
- (first_name.like_any sanitized_names) | \
91
- (last_name.like_any sanitized_names) | \
92
- (full_name.like_any sanitized_names) | \
93
- (openstax_uid.eq_any sanitized_ids)}
100
+ @items = @items.where(
101
+ ACCOUNTS[:username].matches_any(sanitized_names)
102
+ .or(ACCOUNTS[:first_name].matches_any(sanitized_names))
103
+ .or(ACCOUNTS[:last_name].matches_any(sanitized_names))
104
+ .or(ACCOUNTS[:full_name].matches_any(sanitized_names))
105
+ .or(ACCOUNTS[:openstax_uid].eq_any(sanitized_ids))
106
+ )
94
107
  end
95
108
  end
96
109
 
@@ -0,0 +1,11 @@
1
+ class AssignMissingUuidsForLocalAccounts < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'pgcrypto'
4
+
5
+ OpenStax::Accounts::Account.where(uuid: nil).update_all('"uuid" = gen_random_uuid()')
6
+
7
+ change_column :openstax_accounts_accounts, :uuid, :uuid, using: 'uuid::uuid',
8
+ default: 'gen_random_uuid()',
9
+ null: false
10
+ end
11
+ end
@@ -11,7 +11,6 @@ require 'representable/json/collection'
11
11
  require 'roar'
12
12
  require 'roar/decorator'
13
13
  require 'roar/json'
14
- require 'squeel'
15
14
  require 'openstax/accounts/action_controller/base'
16
15
  require 'openstax/accounts/has_many_through_groups/active_record/base'
17
16
 
@@ -21,13 +20,13 @@ module OpenStax
21
20
  isolate_namespace OpenStax::Accounts
22
21
 
23
22
  initializer "openstax_accounts.factories",
24
- :after => "factory_girl.set_factory_paths" do
25
- FactoryGirl.definition_file_paths << File.join(root, 'spec', 'factories') if defined?(FactoryGirl)
23
+ after: "factory_bot.set_factory_paths" do
24
+ FactoryBot.definition_file_paths << File.join(root, 'spec', 'factories') if defined?(FactoryBot)
26
25
  end
27
26
 
28
27
  config.generators do |g|
29
- g.test_framework :rspec, :view_specs => false, :fixture => false
30
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
28
+ g.test_framework :rspec, view_specs: false, fixture: false
29
+ g.fixture_replacement :factory_bot, dir: 'spec/factories'
31
30
  g.assets false
32
31
  g.helper false
33
32
  end
@@ -54,7 +53,7 @@ module OpenStax
54
53
  provider :openstax,
55
54
  OpenStax::Accounts.configuration.openstax_application_id,
56
55
  OpenStax::Accounts.configuration.openstax_application_secret,
57
- :setup => SETUP_PROC
56
+ setup: SETUP_PROC
58
57
  end
59
58
  end
60
59
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "7.8.0"
3
+ VERSION = "7.9.0"
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ module OpenStax::Accounts
5
5
  describe AccountsController, type: :controller do
6
6
  routes { Engine.routes }
7
7
 
8
- let!(:account) { FactoryGirl.create :openstax_accounts_account,
8
+ let!(:account) { FactoryBot.create :openstax_accounts_account,
9
9
  username: 'some_user',
10
10
  openstax_uid: 10 }
11
11
 
@@ -4,7 +4,7 @@ module OpenStax::Accounts
4
4
  describe SessionsController, type: :controller do
5
5
  routes { Engine.routes }
6
6
 
7
- let!(:account) { FactoryGirl.create :openstax_accounts_account,
7
+ let!(:account) { FactoryBot.create :openstax_accounts_account,
8
8
  username: 'some_user',
9
9
  openstax_uid: 10 }
10
10
 
@@ -1,25 +1,15 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
1
  default: &default
8
- adapter: sqlite3
9
- pool: 5
10
- timeout: 5000
2
+ adapter: postgresql
3
+ username: <%= ENV['OX_AR_DB_USER'] || 'ox_accounts_rails' %>
4
+ password: <%= ENV['OX_AR_DB_PASS'] || 'ox_accounts_rails_secret_password' %>
11
5
 
12
6
  development:
13
7
  <<: *default
14
- database: db/development.sqlite3
8
+ database: <%= ENV['OX_AR_DEV_DB'] || 'ox_tutor_dev' %>
15
9
 
16
10
  # Warning: The database defined as "test" will be erased and
17
11
  # re-generated from your development database when you run "rake".
18
12
  # Do not set this db to the same as development or production.
19
13
  test:
20
14
  <<: *default
21
- database: db/test.sqlite3
22
-
23
- production:
24
- <<: *default
25
- database: db/production.sqlite3
15
+ database: <%= ENV['OX_AR_TEST_DB'] || 'ox_tutor_test' %>
Binary file
@@ -13,6 +13,10 @@
13
13
 
14
14
  ActiveRecord::Schema.define(version: 1001) do
15
15
 
16
+ # These are extensions that must be enabled in order to support this database
17
+ enable_extension "plpgsql"
18
+ enable_extension "pgcrypto"
19
+
16
20
  create_table "openstax_accounts_accounts", force: :cascade do |t|
17
21
  t.integer "openstax_uid"
18
22
  t.string "username"
@@ -21,24 +25,24 @@ ActiveRecord::Schema.define(version: 1001) do
21
25
  t.string "last_name"
22
26
  t.string "full_name"
23
27
  t.string "title"
24
- t.datetime "created_at", null: false
25
- t.datetime "updated_at", null: false
26
- t.integer "faculty_status", default: 0, null: false
28
+ t.datetime "created_at", null: false
29
+ t.datetime "updated_at", null: false
30
+ t.integer "faculty_status", default: 0, null: false
27
31
  t.string "salesforce_contact_id"
28
- t.string "uuid"
29
- t.integer "role", default: 0, null: false
32
+ t.uuid "uuid", default: "gen_random_uuid()", null: false
33
+ t.integer "role", default: 0, null: false
30
34
  end
31
35
 
32
- add_index "openstax_accounts_accounts", ["access_token"], name: "index_openstax_accounts_accounts_on_access_token", unique: true
33
- add_index "openstax_accounts_accounts", ["faculty_status"], name: "index_openstax_accounts_accounts_on_faculty_status"
34
- add_index "openstax_accounts_accounts", ["first_name"], name: "index_openstax_accounts_accounts_on_first_name"
35
- add_index "openstax_accounts_accounts", ["full_name"], name: "index_openstax_accounts_accounts_on_full_name"
36
- add_index "openstax_accounts_accounts", ["last_name"], name: "index_openstax_accounts_accounts_on_last_name"
37
- add_index "openstax_accounts_accounts", ["openstax_uid"], name: "index_openstax_accounts_accounts_on_openstax_uid", unique: true
38
- add_index "openstax_accounts_accounts", ["role"], name: "index_openstax_accounts_accounts_on_role"
39
- add_index "openstax_accounts_accounts", ["salesforce_contact_id"], name: "index_openstax_accounts_accounts_on_salesforce_contact_id"
40
- add_index "openstax_accounts_accounts", ["username"], name: "index_openstax_accounts_accounts_on_username", unique: true
41
- add_index "openstax_accounts_accounts", ["uuid"], name: "index_openstax_accounts_accounts_on_uuid", unique: true
36
+ add_index "openstax_accounts_accounts", ["access_token"], name: "index_openstax_accounts_accounts_on_access_token", unique: true, using: :btree
37
+ add_index "openstax_accounts_accounts", ["faculty_status"], name: "index_openstax_accounts_accounts_on_faculty_status", using: :btree
38
+ add_index "openstax_accounts_accounts", ["first_name"], name: "index_openstax_accounts_accounts_on_first_name", using: :btree
39
+ add_index "openstax_accounts_accounts", ["full_name"], name: "index_openstax_accounts_accounts_on_full_name", using: :btree
40
+ add_index "openstax_accounts_accounts", ["last_name"], name: "index_openstax_accounts_accounts_on_last_name", using: :btree
41
+ add_index "openstax_accounts_accounts", ["openstax_uid"], name: "index_openstax_accounts_accounts_on_openstax_uid", unique: true, using: :btree
42
+ add_index "openstax_accounts_accounts", ["role"], name: "index_openstax_accounts_accounts_on_role", using: :btree
43
+ add_index "openstax_accounts_accounts", ["salesforce_contact_id"], name: "index_openstax_accounts_accounts_on_salesforce_contact_id", using: :btree
44
+ add_index "openstax_accounts_accounts", ["username"], name: "index_openstax_accounts_accounts_on_username", unique: true, using: :btree
45
+ add_index "openstax_accounts_accounts", ["uuid"], name: "index_openstax_accounts_accounts_on_uuid", unique: true, using: :btree
42
46
 
43
47
  create_table "openstax_accounts_group_members", force: :cascade do |t|
44
48
  t.integer "group_id", null: false
@@ -47,8 +51,8 @@ ActiveRecord::Schema.define(version: 1001) do
47
51
  t.datetime "updated_at", null: false
48
52
  end
49
53
 
50
- add_index "openstax_accounts_group_members", ["group_id", "user_id"], name: "index_openstax_accounts_group_members_on_group_id_and_user_id", unique: true
51
- add_index "openstax_accounts_group_members", ["user_id"], name: "index_openstax_accounts_group_members_on_user_id"
54
+ add_index "openstax_accounts_group_members", ["group_id", "user_id"], name: "index_openstax_accounts_group_members_on_group_id_and_user_id", unique: true, using: :btree
55
+ add_index "openstax_accounts_group_members", ["user_id"], name: "index_openstax_accounts_group_members_on_user_id", using: :btree
52
56
 
53
57
  create_table "openstax_accounts_group_nestings", force: :cascade do |t|
54
58
  t.integer "member_group_id", null: false
@@ -57,8 +61,8 @@ ActiveRecord::Schema.define(version: 1001) do
57
61
  t.datetime "updated_at", null: false
58
62
  end
59
63
 
60
- add_index "openstax_accounts_group_nestings", ["container_group_id"], name: "index_openstax_accounts_group_nestings_on_container_group_id"
61
- add_index "openstax_accounts_group_nestings", ["member_group_id"], name: "index_openstax_accounts_group_nestings_on_member_group_id", unique: true
64
+ add_index "openstax_accounts_group_nestings", ["container_group_id"], name: "index_openstax_accounts_group_nestings_on_container_group_id", using: :btree
65
+ add_index "openstax_accounts_group_nestings", ["member_group_id"], name: "index_openstax_accounts_group_nestings_on_member_group_id", unique: true, using: :btree
62
66
 
63
67
  create_table "openstax_accounts_group_owners", force: :cascade do |t|
64
68
  t.integer "group_id", null: false
@@ -67,8 +71,8 @@ ActiveRecord::Schema.define(version: 1001) do
67
71
  t.datetime "updated_at", null: false
68
72
  end
69
73
 
70
- add_index "openstax_accounts_group_owners", ["group_id", "user_id"], name: "index_openstax_accounts_group_owners_on_group_id_and_user_id", unique: true
71
- add_index "openstax_accounts_group_owners", ["user_id"], name: "index_openstax_accounts_group_owners_on_user_id"
74
+ add_index "openstax_accounts_group_owners", ["group_id", "user_id"], name: "index_openstax_accounts_group_owners_on_group_id_and_user_id", unique: true, using: :btree
75
+ add_index "openstax_accounts_group_owners", ["user_id"], name: "index_openstax_accounts_group_owners_on_user_id", using: :btree
72
76
 
73
77
  create_table "openstax_accounts_groups", force: :cascade do |t|
74
78
  t.integer "openstax_uid", null: false
@@ -80,8 +84,8 @@ ActiveRecord::Schema.define(version: 1001) do
80
84
  t.datetime "updated_at", null: false
81
85
  end
82
86
 
83
- add_index "openstax_accounts_groups", ["is_public"], name: "index_openstax_accounts_groups_on_is_public"
84
- add_index "openstax_accounts_groups", ["openstax_uid"], name: "index_openstax_accounts_groups_on_openstax_uid", unique: true
87
+ add_index "openstax_accounts_groups", ["is_public"], name: "index_openstax_accounts_groups_on_is_public", using: :btree
88
+ add_index "openstax_accounts_groups", ["openstax_uid"], name: "index_openstax_accounts_groups_on_openstax_uid", unique: true, using: :btree
85
89
 
86
90
  create_table "ownerships", force: :cascade do |t|
87
91
  t.integer "owner_id", null: false
@@ -90,7 +94,7 @@ ActiveRecord::Schema.define(version: 1001) do
90
94
  t.datetime "updated_at", null: false
91
95
  end
92
96
 
93
- add_index "ownerships", ["owner_id", "owner_type"], name: "index_ownerships_on_owner_id_and_owner_type", unique: true
97
+ add_index "ownerships", ["owner_id", "owner_type"], name: "index_ownerships_on_owner_id_and_owner_type", unique: true, using: :btree
94
98
 
95
99
  create_table "users", force: :cascade do |t|
96
100
  t.integer "account_id", null: false
@@ -98,6 +102,6 @@ ActiveRecord::Schema.define(version: 1001) do
98
102
  t.datetime "updated_at", null: false
99
103
  end
100
104
 
101
- add_index "users", ["account_id"], name: "index_users_on_account_id", unique: true
105
+ add_index "users", ["account_id"], name: "index_users_on_account_id", unique: true, using: :btree
102
106
 
103
107
  end