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.
- checksums.yaml +4 -4
- data/Rakefile +7 -7
- data/app/handlers/openstax/accounts/sessions_callback.rb +0 -1
- data/app/models/openstax/accounts/account.rb +1 -0
- data/app/models/openstax/accounts/group.rb +47 -24
- data/app/routines/openstax/accounts/search_local_accounts.rb +30 -17
- data/db/migrate/10_assign_missing_uuids_for_local_accounts.rb +11 -0
- data/lib/openstax/accounts/engine.rb +5 -6
- data/lib/openstax/accounts/version.rb +1 -1
- data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
- data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
- data/spec/dummy/config/database.yml +5 -15
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +29 -25
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +2152 -4613
- data/spec/dummy/log/test.log +55163 -102384
- data/spec/factories/openstax_accounts_account.rb +6 -6
- data/spec/factories/openstax_accounts_group.rb +1 -1
- data/spec/factories/openstax_accounts_group_member.rb +1 -1
- data/spec/factories/openstax_accounts_group_nesting.rb +1 -1
- data/spec/factories/openstax_accounts_group_owner.rb +1 -1
- data/spec/handlers/openstax/accounts/accounts_search_spec.rb +5 -5
- data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +5 -5
- data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +7 -5
- data/spec/lib/openstax/accounts/api_spec.rb +9 -9
- data/spec/lib/openstax/accounts/current_user_manager_spec.rb +1 -1
- data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +3 -3
- data/spec/models/openstax/accounts/account_spec.rb +6 -6
- data/spec/models/openstax/accounts/group_spec.rb +4 -4
- data/spec/routines/openstax/accounts/create_group_spec.rb +1 -1
- data/spec/routines/openstax/accounts/search_accounts_spec.rb +13 -13
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +26 -7
- data/spec/routines/openstax/accounts/sync_groups_spec.rb +51 -14
- data/spec/spec_helper.rb +2 -2
- metadata +64 -211
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-4/-4AigB7SRNxiHWeamN5uh_JTU4pT-99hUByQ7hhtfM4.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-B/-BM2LkGo9LiZel0dx2cTeIoUiOvZvzvQX-qrY-PefDc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0d/0dqBuwbmRqLO9AM5KdttlIvUSbOG2uS9fJsm4TRuY8M.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/1b/1bCIjOPcmZWjhnOiOIrEUVDFzGzCezkm0dIrzY7q22A.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2GcGY034bmlAWeI-bC8yjSfggr98_D1ysvB0hcR9PaI.cache +0 -3
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2G/2gGPkwl7LddZxTKkA0XQ6NKsdgK7mDG6PfvKrqKYsAs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4W/4WJLh0PRMuTwbFf44QcjwkcJ57BXKVgwtaRnUiMxlbc.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5T/5TLgAp4XC6JjXz-MP4IR8UIli3l091nGGpp0xomd_g0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5g/5g7dhxVp4YbZmFw_-T3aU2oYq2Z9Jgtps0CKneXYSS0.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5u/5uKXJe6QpDEzhvxGUSwHZS2uGrjr0-ex9LVlRQZaQnI.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6H/6HAlvBZ_na7ir9ELSAcCJ1GTAwGaO565PgVOt7rgitw.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6b/6bUhHw6Kpj9FgN8vIU0BBQNdA1sgsa0pyhDOdq4U1a8.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8w/8whA2ROqlMHhJJiXDf0onGPb8mLmBGb5UUPY7yZZuMs.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9S/9SfcyOi0r3UamY1lEOb94zdm_ybDACE3pzfyMeUnoJc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Af/AfzRuN8Wm6MIHDZEpwWkiSl3zNDMJ1tOvSt2SOmVCio.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DB/DB4PIoupKZcosm_IvLp0-MJ1hiXfVw01ZdY1IOnnPsE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DR/DRPKqdpBdXQEzG7sFT6-8d_LgGF72B8IFqYLhVsyNqw.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhSAf3h0VMpFRp_tvO8VIqn12P-Mnp3WFyVH4ORR-gs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/E3/E35l_cFnSYnnYWJwxWXR76R17KJ3tqL_-UG0Tjrp5DI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ET/ETdvBR0__vhxzfl_I4mu0h3Jrcwy0jvIvEf-AcGHuxU.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EZ/EZkBau1uUbmU8TAtNy_21ZEq6hQ-pQY-jNbMnaAlNYM.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IV/IVl_wFSpYKfB-OI07E_GP9JLqGpf6VStaDO-Pl-EcUA.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/It/ItWlWNmHD7ZeVOFbsyan26cbPWTR9XFqNBmZhIsyr8k.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JB/JBrtwWy2SgF1Nl6siXGeTqdnlMdXo6F-OOkAKCHx3gw.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Je/JeDnsbKYU6WfXwmBfUedz09ThQX9iPI8-sgit9Um1yE.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Jr/JrzNmQmTkr6QS1BoAOEeGnCip0CCneRNMyvtaelWV1w.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KE/KEIyyOl_ruT7KuaNvukGN8LnSUVMk4MQmDUOg9oo0XE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LK/LK8fShpIirD6_e29A0YY7pTPZbISgiHuY3QOMzj-c4c.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lr/LrK9U2KWZskR0G2rWalGnOM8fgZvGwEajG7_WYkK-Rc.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/MH/MHc26ZBwFN93Q3ggSv0QW4WDhXzTQV6YvzIUUt6Su7Q.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Nj/NjMmwEjtqJiXWQtb2qVmb2Js1DikSD_MgMHDlCNzLP4.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1IElAqy9O60bh7c8syJLSGSTIxOL_WDNftM2SNTsgI.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QW/QWLUd5oxFsWTwKa1IXwWsaP8RlLh_GMPdypbqJx0VoA.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TZ/TZlHN1bHx2lwu7SRM5Y3Qp_OpbrtidFt-6223MTPMH4.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VN/VNCapNKJLeponthNeFJhaBYs92UBT3P8PugENHP0474.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WX/WXy-lTrCCH38uK_ld4QeQrhZuZZDOyHGBBrhZ0PDZyY.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Yr/YrbMyaVyJ69SVCY3y1ZPJAdUcuUpzzHP7LMQNT2pGfk.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Z-/Z-tPXaNX9WvhVHKT_twh9-sJ_NvUPatXyDZ48rWasiE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/aYOmaJvT9wpA9a2IfP3f-6A6guRGAezZCHz_3lSCE0A.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ay/ayvQApV55-bf3brcKBVUc8_o-8aLmUhKYv9b7OPRXV8.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bR/bRCnhDQ4uJkiX7RMvyDbsvopysp32eYxD0SYAsEpDzc.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bz/bzY1-207qUxPHd6HAeNvY34UEmIZlAnGJUuiwkGLqTw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/cj/cjLyKHfhNSrjEff7p2VGJz6ColftKx69unhJqv0UK1g.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e2/e28DqqHF8GN5VTAz03mRnOV5AV_np1CNwB_xuV03NUw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hh/hh_1YpicqmoKC8uz92Sh3iba0TBhh9GEXtUyrUlEzEU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/iKFb6K0z7xwr53FXp9Qy4qO5L6lryDOpXjMnw-48oVg.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/jn/jnRNObm7DziGmbZR3TPAC-vAE-qmrP0tLBH9W9m6yJs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kS/kSXVJZ4BJAsy2L9DxKUntzr90Nd9VWD0G7L2n05ISOw.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kq/kq0VL9PQ2HRlksqNC7YPlqlWFBvkHk2uIac_HZb0wEE.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/l0/l0BYOaBq08_FGl4jzpCnd80-zLPHNMXs7xCHtqTcUVI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lx/lxYKD42Es9n2EKrNchxPYKveAzYo6VAGr_CxhxvyO-c.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mW/mWLVMCpv8dHPkBK4y4SLLXukqtLhRXWtNC3gm5vgwPk.cache +0 -3
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mx/mxoipKjbqPo_gvG86AgUPk6o6-OB-uqI5sGMnNqGW4A.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nZ/nZY2kcE7t2EMdrdtEQueW9UYmtEBjQv3FNpous5k1tM.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/o3/o3Bz1eWxZ7poUlQGzlkJX5fFeNxKD5VEuFZSctl6Oe4.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p-/p-j1kEkMIDywvXn2EG-FF_CVz9U75IYIDMJj4U2ksCk.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pZ/pZXUaTdXV2XMj_KgBsHVED1ocjtpQrIqBR3lGYSMZVc.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r0/r0S88W86F754buOO-eLMVX5f9YdQzd-ZkpvwEJc6hAg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/r3/r3X66JZPGDKB-xMv9rLIyo0WKYWnPrSB2qL0giC2T6g.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/t7/t7deseLVHWCZ7z2LMl1YvpZi-RIhvURhm0-MSDE3qvY.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tl/tl1nInky090OX02bJpJWDa-RFuv1vogrbeY5T4K1M_Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uf/uf8xlrN24XDdqvg97XSNrPFSYWGELN2cEHkKsu52zJQ.cache +0 -3
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wD/wDQfpqPktQEUJYqGBoTlKAOHJhn7hzFSg9lUtfzUSHM.cache +0 -1
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +0 -2
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y4/y4wKs_D3Zp3A5ItE5hfD5dkJEr-mnvfyNon1lhrxKKY.cache +0 -3
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bef0159179b28deec9d472b9cb27364f042ab36
|
4
|
+
data.tar.gz: 896f0a36f899d4151cb8c262b59be7e463a726aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
-
require 'rspec/core/rake_task'
|
14
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
16
15
|
|
17
|
-
|
16
|
+
require 'rspec/core'
|
17
|
+
require 'rspec/core/rake_task'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
@@ -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,
|
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',
|
21
|
-
|
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,
|
25
|
-
class_name: 'OpenStax::Accounts::GroupNesting',
|
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
|
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
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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] + (
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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] +
|
109
|
-
|
110
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
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
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
:
|
25
|
-
|
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, :
|
30
|
-
g.fixture_replacement :
|
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
|
-
:
|
56
|
+
setup: SETUP_PROC
|
58
57
|
end
|
59
58
|
end
|
60
59
|
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) {
|
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) {
|
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:
|
9
|
-
|
10
|
-
|
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:
|
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:
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *default
|
25
|
-
database: db/production.sqlite3
|
15
|
+
database: <%= ENV['OX_AR_TEST_DB'] || 'ox_tutor_test' %>
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -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",
|
25
|
-
t.datetime "updated_at",
|
26
|
-
t.integer "faculty_status", default: 0,
|
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.
|
29
|
-
t.integer "role", default: 0,
|
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
|