openstax_accounts 8.0.1 → 9.0.2
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.
- checksums.yaml +4 -4
- data/app/controllers/openstax/accounts/application_controller.rb +0 -4
- data/app/controllers/openstax/accounts/dev/accounts_controller.rb +16 -10
- data/app/controllers/openstax/accounts/dev/base_controller.rb +1 -5
- data/app/controllers/openstax/accounts/sessions_controller.rb +2 -5
- data/app/handlers/openstax/accounts/accounts_search.rb +3 -5
- data/app/handlers/openstax/accounts/dev/accounts_create.rb +1 -7
- data/app/handlers/openstax/accounts/dev/accounts_search.rb +0 -2
- data/app/handlers/openstax/accounts/sessions_callback.rb +2 -4
- data/app/models/openstax/accounts/account.rb +1 -19
- data/app/models/openstax/accounts/anonymous_account.rb +1 -2
- data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -7
- data/app/routines/openstax/accounts/dev/create_account.rb +23 -21
- data/app/routines/openstax/accounts/find_or_create_account.rb +16 -25
- data/app/routines/openstax/accounts/find_or_create_from_sso.rb +2 -8
- data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
- data/app/views/layouts/openstax/accounts/application.html.erb +2 -2
- data/app/views/openstax/accounts/dev/accounts/_search_results.html.erb +9 -10
- data/app/views/openstax/accounts/dev/accounts/index.html.erb +7 -10
- data/app/views/openstax/accounts/dev/accounts/{search.js.erb → index.js.erb} +0 -0
- data/app/views/openstax/accounts/shared/_attention.html.erb +9 -1
- data/app/views/openstax/accounts/shared/accounts/_search.html.erb +12 -8
- data/config/routes.rb +2 -5
- data/db/migrate/14_drop_openstax_uid_and_username_uniqueness.rb +9 -0
- data/db/migrate/15_drop_accounts_groups.rb +42 -0
- data/lib/omniauth/strategies/openstax.rb +1 -1
- data/lib/openstax/accounts/api.rb +0 -149
- data/lib/openstax/accounts/current_user_manager.rb +1 -5
- data/lib/openstax/accounts/engine.rb +1 -1
- data/lib/openstax/accounts/sso.rb +4 -3
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/tasks/sync.rake +0 -8
- metadata +10 -26
- data/app/models/openstax/accounts/application_group.rb +0 -7
- data/app/models/openstax/accounts/group.rb +0 -169
- data/app/models/openstax/accounts/group_member.rb +0 -37
- data/app/models/openstax/accounts/group_nesting.rb +0 -55
- data/app/models/openstax/accounts/group_owner.rb +0 -37
- data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +0 -48
- data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -20
- data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +0 -31
- data/app/representers/openstax/accounts/api/v1/group_representer.rb +0 -71
- data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +0 -34
- data/app/routines/openstax/accounts/create_group.rb +0 -26
- data/app/routines/openstax/accounts/sync_groups.rb +0 -67
- data/app/routines/openstax/accounts/update_group_caches.rb +0 -27
- data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +0 -51
- data/spec/factories/openstax_accounts_group.rb +0 -7
- data/spec/factories/openstax_accounts_group_member.rb +0 -6
- data/spec/factories/openstax_accounts_group_nesting.rb +0 -6
- data/spec/factories/openstax_accounts_group_owner.rb +0 -6
@@ -1,48 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
class ApplicationGroupRepresenter < Roar::Decorator
|
6
|
-
|
7
|
-
# This representer is used to communicate with Accounts
|
8
|
-
# and so must allow read/write on all properties
|
9
|
-
# Do not use it in create/update APIs!
|
10
|
-
|
11
|
-
include Roar::JSON
|
12
|
-
|
13
|
-
property :id,
|
14
|
-
type: Integer,
|
15
|
-
schema_info: {
|
16
|
-
description: "A unique ID number for the record that associates this group with this application",
|
17
|
-
required: true
|
18
|
-
}
|
19
|
-
|
20
|
-
property :application_id,
|
21
|
-
type: Integer,
|
22
|
-
schema_info: {
|
23
|
-
description: "The associated application's unique ID number",
|
24
|
-
required: true
|
25
|
-
}
|
26
|
-
|
27
|
-
property :group,
|
28
|
-
instance: ->(*) do
|
29
|
-
OpenStax::Accounts::Group.new.tap{ |group| group.syncing = true }
|
30
|
-
end,
|
31
|
-
decorator: GroupRepresenter,
|
32
|
-
schema_info: {
|
33
|
-
description: "The associated group",
|
34
|
-
required: true
|
35
|
-
}
|
36
|
-
|
37
|
-
property :unread_updates,
|
38
|
-
type: Integer,
|
39
|
-
schema_info: {
|
40
|
-
description: "The number of updates applied to the associated group unread by the associated application",
|
41
|
-
required: true
|
42
|
-
}
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
class ApplicationGroupsRepresenter < Roar::Decorator
|
6
|
-
|
7
|
-
# This representer is used to communicate with Accounts
|
8
|
-
# and so must allow read/write on all properties
|
9
|
-
# Do not use it in create/update APIs!
|
10
|
-
|
11
|
-
include Representable::JSON::Collection
|
12
|
-
|
13
|
-
items class: OpenStax::Accounts::ApplicationGroup,
|
14
|
-
decorator: ApplicationGroupRepresenter
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
class GroupNestingRepresenter < Roar::Decorator
|
6
|
-
|
7
|
-
# This representer is used to communicate with Accounts
|
8
|
-
# and so must allow read/write on all properties
|
9
|
-
# Do not use it in create/update APIs!
|
10
|
-
|
11
|
-
include Roar::JSON
|
12
|
-
|
13
|
-
property :container_group_id,
|
14
|
-
type: Integer,
|
15
|
-
schema_info: {
|
16
|
-
description: "The unique ID number of the associated containing group",
|
17
|
-
required: true
|
18
|
-
}
|
19
|
-
|
20
|
-
property :member_group_id,
|
21
|
-
type: Integer,
|
22
|
-
schema_info: {
|
23
|
-
description: "The unique ID number of the associated contained group",
|
24
|
-
required: true
|
25
|
-
}
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
class GroupRepresenter < Roar::Decorator
|
6
|
-
|
7
|
-
# This representer is used to communicate with Accounts
|
8
|
-
# and so must allow read/write on all properties
|
9
|
-
# Do not use it in create/update APIs!
|
10
|
-
|
11
|
-
include Roar::JSON
|
12
|
-
|
13
|
-
property :openstax_uid,
|
14
|
-
as: :id,
|
15
|
-
type: Integer,
|
16
|
-
schema_info: {
|
17
|
-
description: "The group's unique ID number",
|
18
|
-
required: true
|
19
|
-
}
|
20
|
-
|
21
|
-
property :name,
|
22
|
-
type: String,
|
23
|
-
schema_info: {
|
24
|
-
description: "The group's name"
|
25
|
-
}
|
26
|
-
|
27
|
-
property :is_public,
|
28
|
-
schema_info: {
|
29
|
-
type: "boolean",
|
30
|
-
description: "The group's visibility setting"
|
31
|
-
}
|
32
|
-
|
33
|
-
collection :group_owners,
|
34
|
-
as: :owners,
|
35
|
-
class: GroupOwner,
|
36
|
-
decorator: GroupUserRepresenter,
|
37
|
-
schema_info: { description: "The owners of this group" }
|
38
|
-
|
39
|
-
collection :group_members,
|
40
|
-
as: :members,
|
41
|
-
class: GroupMember,
|
42
|
-
decorator: GroupUserRepresenter,
|
43
|
-
schema_info: { description: "The direct members of this group" }
|
44
|
-
|
45
|
-
collection :member_group_nestings,
|
46
|
-
as: :nestings,
|
47
|
-
class: GroupNesting,
|
48
|
-
decorator: GroupNestingRepresenter,
|
49
|
-
schema_info: { description: "The groups directly nested within this group" }
|
50
|
-
|
51
|
-
property :cached_supertree_group_ids,
|
52
|
-
as: :supertree_group_ids,
|
53
|
-
type: Array,
|
54
|
-
schema_info: {
|
55
|
-
items: "integer",
|
56
|
-
description: "The ID's of all groups that should be updated if this group is changed; For caching purposes"
|
57
|
-
}
|
58
|
-
|
59
|
-
property :cached_subtree_group_ids,
|
60
|
-
as: :subtree_group_ids,
|
61
|
-
type: Array,
|
62
|
-
schema_info: {
|
63
|
-
items: "integer",
|
64
|
-
description: "The ID's of all groups nested in this group's subtree, including this one; For caching purposes"
|
65
|
-
}
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
class GroupUserRepresenter < Roar::Decorator
|
6
|
-
|
7
|
-
# This representer is used to communicate with Accounts
|
8
|
-
# and so must allow read/write on all properties
|
9
|
-
# Do not use it in create/update APIs!
|
10
|
-
|
11
|
-
include Roar::JSON
|
12
|
-
|
13
|
-
property :group_id,
|
14
|
-
type: Integer,
|
15
|
-
schema_info: {
|
16
|
-
required: true,
|
17
|
-
description: "The associated group's unique ID number"
|
18
|
-
}
|
19
|
-
|
20
|
-
nested :user do
|
21
|
-
property :user_id,
|
22
|
-
as: :id,
|
23
|
-
type: Integer,
|
24
|
-
schema_info: {
|
25
|
-
required: true,
|
26
|
-
description: "The associated user's unique ID number"
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
class CreateGroup
|
4
|
-
|
5
|
-
lev_routine express_output: :group
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def exec(owner:, name: nil, is_public: false)
|
10
|
-
group = OpenStax::Accounts::Group.new(name: name, is_public: is_public)
|
11
|
-
group.requestor = owner
|
12
|
-
|
13
|
-
if OpenStax::Accounts.configuration.enable_stubbing? || !owner.has_authenticated?
|
14
|
-
group.openstax_uid = -SecureRandom.hex(4).to_i(16)/2
|
15
|
-
group.add_owner(owner)
|
16
|
-
end
|
17
|
-
|
18
|
-
group.save
|
19
|
-
|
20
|
-
transfer_errors_from(group, {type: :verbatim}, true)
|
21
|
-
outputs.group = group
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# Routine for getting group updates from the Accounts server
|
2
|
-
#
|
3
|
-
# Should be scheduled to run regularly
|
4
|
-
|
5
|
-
module OpenStax
|
6
|
-
module Accounts
|
7
|
-
|
8
|
-
class SyncGroups
|
9
|
-
|
10
|
-
SYNC_ATTRIBUTES = ['name', 'is_public', 'group_members',
|
11
|
-
'group_owners', 'member_group_nestings',
|
12
|
-
'cached_supertree_group_ids', 'cached_subtree_group_ids']
|
13
|
-
|
14
|
-
lev_routine transaction: :no_transaction
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def exec(options={})
|
19
|
-
|
20
|
-
return if OpenStax::Accounts.configuration.enable_stubbing?
|
21
|
-
|
22
|
-
response = OpenStax::Accounts::Api.get_application_group_updates
|
23
|
-
|
24
|
-
app_groups = []
|
25
|
-
app_groups_rep = OpenStax::Accounts::Api::V1::ApplicationGroupsRepresenter.new(app_groups)
|
26
|
-
app_groups_rep.from_json(response.body)
|
27
|
-
|
28
|
-
return if app_groups.empty?
|
29
|
-
|
30
|
-
updated_app_groups = []
|
31
|
-
updated_groups = app_groups.each_with_object({}) do |app_group, hash|
|
32
|
-
openstax_uid = app_group.group.openstax_uid
|
33
|
-
group = OpenStax::Accounts::Group.where(
|
34
|
-
openstax_uid: openstax_uid
|
35
|
-
).first || app_group.group
|
36
|
-
group.syncing = true
|
37
|
-
|
38
|
-
next unless group.persisted? || group.save
|
39
|
-
|
40
|
-
hash[openstax_uid] = group
|
41
|
-
end
|
42
|
-
|
43
|
-
app_groups.each do |app_group|
|
44
|
-
openstax_uid = app_group.group.openstax_uid
|
45
|
-
group = updated_groups[openstax_uid]
|
46
|
-
|
47
|
-
next if group.nil?
|
48
|
-
|
49
|
-
if group != app_group.group
|
50
|
-
SYNC_ATTRIBUTES.each do |attribute|
|
51
|
-
group.send("#{attribute}=", app_group.group.send(attribute))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
next unless group.save
|
56
|
-
|
57
|
-
updated_app_groups << { group_id: openstax_uid, read_updates: app_group.unread_updates }
|
58
|
-
end
|
59
|
-
|
60
|
-
OpenStax::Accounts::Api.mark_group_updates_as_read(updated_app_groups)
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Routine for updating group caches when a group_nesting is created or destroyed
|
2
|
-
#
|
3
|
-
# Caller provides the group_nesting object
|
4
|
-
|
5
|
-
module OpenStax
|
6
|
-
module Accounts
|
7
|
-
|
8
|
-
class UpdateGroupCaches
|
9
|
-
|
10
|
-
# This transaction needs :repeatable_read to prevent missed updates
|
11
|
-
lev_routine transaction: :repeatable_read
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def exec(group_nesting)
|
16
|
-
subtree_group_ids = group_nesting.member_group.subtree_group_ids
|
17
|
-
supertree_group_ids = group_nesting.container_group.supertree_group_ids
|
18
|
-
tree_group_ids = (subtree_group_ids + supertree_group_ids).uniq
|
19
|
-
|
20
|
-
Group.where(id: subtree_group_ids).update_all(cached_supertree_group_ids: nil)
|
21
|
-
Group.where(id: supertree_group_ids).update_all(cached_subtree_group_ids: nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module HasManyThroughGroups
|
4
|
-
module ActiveRecord
|
5
|
-
module Base
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(ClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def has_many_through_groups(groups_name, name, options = {})
|
12
|
-
options = {class_name: name.to_s.classify}.merge(options)
|
13
|
-
association_name = "direct_#{name.to_s}".to_sym
|
14
|
-
|
15
|
-
OpenStax::Accounts::Group.class_exec do
|
16
|
-
has_many association_name, options
|
17
|
-
|
18
|
-
define_method(name) do
|
19
|
-
OpenStax::Accounts::Group.includes(association_name)
|
20
|
-
.where(openstax_uid: supertree_group_ids)
|
21
|
-
.map { |g| g.send(association_name).to_a }.flatten.uniq
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class_exec do
|
26
|
-
has_many association_name, options if options[:as]
|
27
|
-
|
28
|
-
define_method(name) do
|
29
|
-
direct_records = respond_to?(association_name) ? \
|
30
|
-
send(association_name).to_a : []
|
31
|
-
indirect_records = OpenStax::Accounts::Group
|
32
|
-
.includes(association_name).where(
|
33
|
-
openstax_uid: send(groups_name).map do |g|
|
34
|
-
g.supertree_group_ids
|
35
|
-
end.flatten.uniq
|
36
|
-
)
|
37
|
-
.map { |g| g.send(association_name).to_a }
|
38
|
-
(direct_records + indirect_records).flatten.uniq
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
::ActiveRecord::Base.send(
|
50
|
-
:include, OpenStax::Accounts::HasManyThroughGroups::ActiveRecord::Base
|
51
|
-
)
|