openstax_accounts 4.1.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/app/controllers/openstax/accounts/application_controller.rb +1 -1
- data/app/models/openstax/accounts/account.rb +11 -6
- data/app/models/openstax/accounts/anonymous_account.rb +1 -1
- data/app/models/openstax/accounts/application_account.rb +2 -1
- data/app/models/openstax/accounts/group.rb +14 -12
- data/app/models/openstax/accounts/group_member.rb +10 -10
- data/app/models/openstax/accounts/group_nesting.rb +7 -13
- data/app/models/openstax/accounts/group_owner.rb +10 -10
- data/app/representers/openstax/accounts/api/v1/account_representer.rb +4 -3
- data/app/representers/openstax/accounts/api/v1/application_account_representer.rb +7 -2
- data/app/representers/openstax/accounts/api/v1/application_accounts_representer.rb +0 -2
- data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +7 -2
- data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -2
- data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +1 -1
- data/app/representers/openstax/accounts/api/v1/group_representer.rb +1 -1
- data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +1 -1
- data/app/routines/openstax/accounts/search_accounts.rb +1 -1
- data/app/routines/openstax/accounts/sync_accounts.rb +24 -27
- data/app/routines/openstax/accounts/sync_groups.rb +22 -26
- data/lib/openstax/accounts/action_controller/base.rb +61 -0
- data/lib/openstax/accounts/api.rb +270 -0
- data/lib/openstax/accounts/configuration.rb +77 -0
- data/lib/openstax/accounts/engine.rb +13 -11
- data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +51 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/openstax_accounts.rb +8 -331
- data/spec/dummy/app/controllers/api/users_controller.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -1
- data/spec/dummy/log/test.log +152307 -0
- data/spec/lib/openstax/accounts/api_spec.rb +232 -0
- data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +57 -0
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +5 -9
- data/spec/routines/openstax/accounts/sync_groups_spec.rb +38 -39
- metadata +27 -16
- data/lib/openstax/accounts/extend_builtins.rb +0 -50
- data/lib/openstax/accounts/has_many_through_groups.rb +0 -47
- data/spec/lib/openstax/accounts/has_many_through_groups_spec.rb +0 -53
- data/spec/lib/openstax_accounts_spec.rb +0 -210
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c68309eb816447b9379cd570f95a2099ce13bfc
|
4
|
+
data.tar.gz: c598caec6b97bff42fe269e3bd8885b688842673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 969eaf95f5aa6a2d2cee9e19972ee2c0269abb4fa939ea32a3f49d7fb8b946cbddac8360b5b8438d62873c3672f6377a70cf3da88d01cde0418da682efb50a9c
|
7
|
+
data.tar.gz: 255d45ca40d05da9db31569db43b04bde685b534bc55efd3c9c5470f549c8a38ab34968993ba52c273bce5999c3520b28d72303a76611167b8c9f968f18d7290
|
data/README.md
CHANGED
@@ -136,7 +136,7 @@ Accounts API
|
|
136
136
|
OpenStax Accounts provides convenience methods for accessing
|
137
137
|
the Accounts server API.
|
138
138
|
|
139
|
-
`OpenStax::Accounts.
|
139
|
+
`OpenStax::Accounts::Api.request(http_method, url, options = {})` provides a
|
140
140
|
convenience method capable of making API calls to Accounts. `http_method` can
|
141
141
|
be any valid HTTP method, and `url` is the desired API URL, without the 'api/'
|
142
142
|
prefix. Options is a hash that can contain any option that
|
@@ -144,6 +144,9 @@ OAuth2 requests accept, such as :headers, :params, :body, etc,
|
|
144
144
|
plus the optional values :api_version (to specify an API version) and
|
145
145
|
:access_token (to specify an OAuth access token).
|
146
146
|
|
147
|
+
Individual methods to access each Accounts API, such as `search_accounts`,
|
148
|
+
are also available. See lib/openstax/accounts/api.rb for more details.
|
149
|
+
|
147
150
|
Example Application
|
148
151
|
-------------------
|
149
152
|
|
@@ -4,14 +4,20 @@ module OpenStax::Accounts
|
|
4
4
|
USERNAME_DISCARDED_CHAR_REGEX = /[^A-Za-z\d_]/
|
5
5
|
USERNAME_MAX_LENGTH = 50
|
6
6
|
|
7
|
+
attr_accessor :syncing
|
8
|
+
|
7
9
|
has_many :group_owners, dependent: :destroy,
|
8
10
|
class_name: 'OpenStax::Accounts::GroupOwner',
|
9
|
-
primary_key: :openstax_uid,
|
11
|
+
primary_key: :openstax_uid,
|
12
|
+
foreign_key: :user_id,
|
13
|
+
inverse_of: :user
|
10
14
|
has_many :groups_as_owner, through: :group_owners, source: :group
|
11
15
|
|
12
16
|
has_many :group_members, dependent: :destroy,
|
13
17
|
class_name: 'OpenStax::Accounts::GroupMember',
|
14
|
-
primary_key: :openstax_uid,
|
18
|
+
primary_key: :openstax_uid,
|
19
|
+
foreign_key: :user_id,
|
20
|
+
inverse_of: :user
|
15
21
|
has_many :groups_as_member, through: :group_members, source: :group
|
16
22
|
|
17
23
|
validates :openstax_uid, :presence => true, :uniqueness => true
|
@@ -37,13 +43,12 @@ module OpenStax::Accounts
|
|
37
43
|
protected
|
38
44
|
|
39
45
|
def syncing_or_stubbing
|
40
|
-
OpenStax::Accounts.
|
41
|
-
OpenStax::Accounts.configuration.enable_stubbing?
|
46
|
+
syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
42
47
|
end
|
43
48
|
|
44
49
|
def update_openstax_accounts
|
45
|
-
OpenStax::Accounts.update_account(self)
|
50
|
+
OpenStax::Accounts::Api.update_account(self)
|
46
51
|
end
|
47
52
|
|
48
53
|
end
|
49
|
-
end
|
54
|
+
end
|
@@ -4,7 +4,7 @@ module OpenStax::Accounts
|
|
4
4
|
serialize :cached_supertree_group_ids
|
5
5
|
serialize :cached_subtree_group_ids
|
6
6
|
|
7
|
-
attr_accessor :requestor
|
7
|
+
attr_accessor :requestor, :syncing
|
8
8
|
|
9
9
|
has_many :group_owners, dependent: :destroy,
|
10
10
|
class_name: 'OpenStax::Accounts::GroupOwner',
|
@@ -28,12 +28,15 @@ module OpenStax::Accounts
|
|
28
28
|
|
29
29
|
validates :openstax_uid, :uniqueness => true, :presence => true
|
30
30
|
validates_presence_of :requestor, :unless => :syncing_or_stubbing
|
31
|
-
validates_uniqueness_of :name, :allow_nil => true,
|
31
|
+
validates_uniqueness_of :name, :allow_nil => true,
|
32
|
+
:unless => :syncing_or_stubbing
|
32
33
|
|
33
34
|
before_validation :create_openstax_accounts_group,
|
34
35
|
:on => :create, :unless => :syncing_or_stubbing
|
35
|
-
before_update :update_openstax_accounts_group,
|
36
|
-
|
36
|
+
before_update :update_openstax_accounts_group,
|
37
|
+
:unless => :syncing_or_stubbing
|
38
|
+
before_destroy :destroy_openstax_accounts_group,
|
39
|
+
:unless => :syncing_or_stubbing
|
37
40
|
|
38
41
|
scope :visible_for, lambda { |account|
|
39
42
|
next where(is_public: true) unless account.is_a? OpenStax::Accounts::Account
|
@@ -110,26 +113,25 @@ module OpenStax::Accounts
|
|
110
113
|
protected
|
111
114
|
|
112
115
|
def syncing_or_stubbing
|
113
|
-
OpenStax::Accounts.
|
114
|
-
OpenStax::Accounts.configuration.enable_stubbing?
|
116
|
+
syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
115
117
|
end
|
116
118
|
|
117
119
|
def create_openstax_accounts_group
|
118
|
-
return
|
120
|
+
return false unless requestor
|
119
121
|
|
120
|
-
OpenStax::Accounts.create_group(requestor, self)
|
122
|
+
OpenStax::Accounts::Api.create_group(requestor, self)
|
121
123
|
end
|
122
124
|
|
123
125
|
def update_openstax_accounts_group
|
124
|
-
return
|
126
|
+
return false unless requestor
|
125
127
|
|
126
|
-
OpenStax::Accounts.update_group(requestor, self)
|
128
|
+
OpenStax::Accounts::Api.update_group(requestor, self)
|
127
129
|
end
|
128
130
|
|
129
131
|
def destroy_openstax_accounts_group
|
130
|
-
return
|
132
|
+
return false unless requestor
|
131
133
|
|
132
|
-
OpenStax::Accounts.destroy_group(requestor, self)
|
134
|
+
OpenStax::Accounts::Api.destroy_group(requestor, self)
|
133
135
|
end
|
134
136
|
|
135
137
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OpenStax::Accounts
|
2
2
|
class GroupMember < ActiveRecord::Base
|
3
3
|
|
4
|
-
|
4
|
+
delegate :requestor, :syncing, to: :group
|
5
5
|
|
6
6
|
belongs_to :group, class_name: 'OpenStax::Accounts::Group',
|
7
7
|
primary_key: :openstax_uid, inverse_of: :group_members
|
@@ -10,30 +10,30 @@ module OpenStax::Accounts
|
|
10
10
|
|
11
11
|
validates_presence_of :user_id, :group_id
|
12
12
|
validates_uniqueness_of :user_id, scope: :group_id
|
13
|
-
validates_presence_of :group, :user, :requestor,
|
13
|
+
validates_presence_of :group, :user, :requestor,
|
14
|
+
:unless => :syncing_or_stubbing
|
14
15
|
|
15
|
-
before_create :create_openstax_accounts_group_member,
|
16
|
-
|
16
|
+
before_create :create_openstax_accounts_group_member,
|
17
|
+
:unless => :syncing_or_stubbing
|
18
|
+
before_destroy :destroy_openstax_accounts_group_member,
|
19
|
+
:unless => :syncing_or_stubbing
|
17
20
|
|
18
21
|
protected
|
19
22
|
|
20
23
|
def syncing_or_stubbing
|
21
|
-
OpenStax::Accounts.
|
22
|
-
OpenStax::Accounts.configuration.enable_stubbing?
|
24
|
+
syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
23
25
|
end
|
24
26
|
|
25
27
|
def create_openstax_accounts_group_member
|
26
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
27
28
|
return false unless requestor
|
28
29
|
|
29
|
-
OpenStax::Accounts.create_group_member(requestor, self)
|
30
|
+
OpenStax::Accounts::Api.create_group_member(requestor, self)
|
30
31
|
end
|
31
32
|
|
32
33
|
def destroy_openstax_accounts_group_member
|
33
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
34
34
|
return false unless requestor
|
35
35
|
|
36
|
-
OpenStax::Accounts.destroy_group_member(requestor, self)
|
36
|
+
OpenStax::Accounts::Api.destroy_group_member(requestor, self)
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OpenStax::Accounts
|
2
2
|
class GroupNesting < ActiveRecord::Base
|
3
3
|
|
4
|
-
|
4
|
+
delegate :requestor, :syncing, to: :container_group
|
5
5
|
|
6
6
|
belongs_to :container_group, class_name: 'OpenStax::Accounts::Group',
|
7
7
|
primary_key: :openstax_uid, inverse_of: :member_group_nestings
|
@@ -14,22 +14,18 @@ module OpenStax::Accounts
|
|
14
14
|
:unless => :syncing_or_stubbing
|
15
15
|
validate :no_loops, :unless => :syncing_or_stubbing
|
16
16
|
|
17
|
-
before_create :update_group_caches, :unless => :syncing
|
18
|
-
before_destroy :update_group_caches, :unless => :syncing
|
17
|
+
before_create :update_group_caches, :unless => :syncing
|
18
|
+
before_destroy :update_group_caches, :unless => :syncing
|
19
19
|
|
20
20
|
before_create :create_openstax_accounts_group_nesting,
|
21
21
|
:unless => :syncing_or_stubbing
|
22
|
-
before_destroy :
|
22
|
+
before_destroy :destroy_openstax_accounts_group_nesting,
|
23
23
|
:unless => :syncing_or_stubbing
|
24
24
|
|
25
25
|
protected
|
26
26
|
|
27
|
-
def syncing?
|
28
|
-
OpenStax::Accounts.syncing
|
29
|
-
end
|
30
|
-
|
31
27
|
def syncing_or_stubbing
|
32
|
-
syncing
|
28
|
+
syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
33
29
|
end
|
34
30
|
|
35
31
|
def no_loops
|
@@ -45,17 +41,15 @@ module OpenStax::Accounts
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def create_openstax_accounts_group_nesting
|
48
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
49
44
|
return false unless requestor
|
50
45
|
|
51
|
-
OpenStax::Accounts.create_group_nesting(requestor, self)
|
46
|
+
OpenStax::Accounts::Api.create_group_nesting(requestor, self)
|
52
47
|
end
|
53
48
|
|
54
49
|
def destroy_openstax_accounts_group_nesting
|
55
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
56
50
|
return false unless requestor
|
57
51
|
|
58
|
-
OpenStax::Accounts.destroy_group_nesting(requestor, self)
|
52
|
+
OpenStax::Accounts::Api.destroy_group_nesting(requestor, self)
|
59
53
|
end
|
60
54
|
|
61
55
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OpenStax::Accounts
|
2
2
|
class GroupOwner < ActiveRecord::Base
|
3
3
|
|
4
|
-
|
4
|
+
delegate :requestor, :syncing, to: :group
|
5
5
|
|
6
6
|
belongs_to :group, class_name: 'OpenStax::Accounts::Group',
|
7
7
|
primary_key: :openstax_uid, inverse_of: :group_owners
|
@@ -10,30 +10,30 @@ module OpenStax::Accounts
|
|
10
10
|
|
11
11
|
validates_presence_of :user_id, :group_id
|
12
12
|
validates_uniqueness_of :user_id, scope: :group_id
|
13
|
-
validates_presence_of :group, :user, :requestor,
|
13
|
+
validates_presence_of :group, :user, :requestor,
|
14
|
+
:unless => :syncing_or_stubbing
|
14
15
|
|
15
|
-
before_create :create_openstax_accounts_group_owner,
|
16
|
-
|
16
|
+
before_create :create_openstax_accounts_group_owner,
|
17
|
+
:unless => :syncing_or_stubbing
|
18
|
+
before_destroy :destroy_openstax_accounts_group_owner,
|
19
|
+
:unless => :syncing_or_stubbing
|
17
20
|
|
18
21
|
protected
|
19
22
|
|
20
23
|
def syncing_or_stubbing
|
21
|
-
OpenStax::Accounts.
|
22
|
-
OpenStax::Accounts.configuration.enable_stubbing?
|
24
|
+
syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
23
25
|
end
|
24
26
|
|
25
27
|
def create_openstax_accounts_group_owner
|
26
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
27
28
|
return false unless requestor
|
28
29
|
|
29
|
-
OpenStax::Accounts.create_group_owner(requestor, self)
|
30
|
+
OpenStax::Accounts::Api.create_group_owner(requestor, self)
|
30
31
|
end
|
31
32
|
|
32
33
|
def destroy_openstax_accounts_group_owner
|
33
|
-
return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing?
|
34
34
|
return false unless requestor
|
35
35
|
|
36
|
-
OpenStax::Accounts.destroy_group_owner(requestor, self)
|
36
|
+
OpenStax::Accounts::Api.destroy_group_owner(requestor, self)
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# A representer for Accounts
|
2
2
|
#
|
3
|
-
# This representer can be used directly or subclassed for an object that
|
4
|
-
# openstax_uid, username, first_name, last_name, full_name and
|
3
|
+
# This representer can be used directly or subclassed for an object that
|
4
|
+
# delegates openstax_uid, username, first_name, last_name, full_name and
|
5
|
+
# title to an account
|
5
6
|
|
6
7
|
module OpenStax
|
7
8
|
module Accounts
|
8
9
|
module Api
|
9
10
|
module V1
|
10
11
|
class AccountRepresenter < Roar::Decorator
|
11
|
-
include Roar::
|
12
|
+
include Roar::JSON
|
12
13
|
|
13
14
|
property :openstax_uid,
|
14
15
|
as: :id,
|
@@ -3,7 +3,7 @@ module OpenStax
|
|
3
3
|
module Api
|
4
4
|
module V1
|
5
5
|
class ApplicationAccountRepresenter < Roar::Decorator
|
6
|
-
include Roar::
|
6
|
+
include Roar::JSON
|
7
7
|
|
8
8
|
property :id,
|
9
9
|
type: Integer
|
@@ -14,7 +14,12 @@ module OpenStax
|
|
14
14
|
property :account,
|
15
15
|
as: :user,
|
16
16
|
class: OpenStax::Accounts::Account,
|
17
|
-
decorator: AccountRepresenter
|
17
|
+
decorator: AccountRepresenter,
|
18
|
+
instance: ->(*) {
|
19
|
+
a = OpenStax::Accounts::Account.new
|
20
|
+
a.syncing = true
|
21
|
+
a
|
22
|
+
}
|
18
23
|
|
19
24
|
property :unread_updates,
|
20
25
|
type: Integer
|
@@ -3,7 +3,7 @@ module OpenStax
|
|
3
3
|
module Api
|
4
4
|
module V1
|
5
5
|
class ApplicationGroupRepresenter < Roar::Decorator
|
6
|
-
include Roar::
|
6
|
+
include Roar::JSON
|
7
7
|
|
8
8
|
property :id,
|
9
9
|
type: Integer
|
@@ -13,7 +13,12 @@ module OpenStax
|
|
13
13
|
|
14
14
|
property :group,
|
15
15
|
class: OpenStax::Accounts::Group,
|
16
|
-
decorator: GroupRepresenter
|
16
|
+
decorator: GroupRepresenter,
|
17
|
+
instance: ->(*) {
|
18
|
+
g = OpenStax::Accounts::Group.new
|
19
|
+
g.syncing = true
|
20
|
+
g
|
21
|
+
}
|
17
22
|
|
18
23
|
property :unread_updates,
|
19
24
|
type: Integer
|
@@ -21,7 +21,7 @@ module OpenStax
|
|
21
21
|
if !OpenStax::Accounts.configuration.enable_stubbing? && \
|
22
22
|
query =~ /email:/
|
23
23
|
# Delegate to Accounts
|
24
|
-
response = OpenStax::Accounts.search_application_accounts(query)
|
24
|
+
response = OpenStax::Accounts::Api.search_application_accounts(query)
|
25
25
|
OpenStax::Accounts::Api::V1::AccountSearchRepresenter \
|
26
26
|
.new(outputs).from_json(response.body)
|
27
27
|
else
|
@@ -16,43 +16,40 @@ module OpenStax
|
|
16
16
|
|
17
17
|
def exec(options={})
|
18
18
|
|
19
|
-
|
20
|
-
OpenStax::Accounts.syncing = true
|
19
|
+
return if OpenStax::Accounts.configuration.enable_stubbing?
|
21
20
|
|
22
|
-
|
21
|
+
response = OpenStax::Accounts::Api.get_application_account_updates
|
23
22
|
|
24
|
-
|
23
|
+
app_accounts = []
|
24
|
+
app_accounts_rep = OpenStax::Accounts::Api::V1::ApplicationAccountsRepresenter
|
25
|
+
.new(app_accounts)
|
26
|
+
app_accounts_rep.from_json(response.body)
|
25
27
|
|
26
|
-
|
27
|
-
app_accounts_rep = OpenStax::Accounts::Api::V1::ApplicationAccountsRepresenter
|
28
|
-
.new(app_accounts)
|
29
|
-
app_accounts_rep.from_json(response.body)
|
28
|
+
return if app_accounts.empty?
|
30
29
|
|
31
|
-
|
30
|
+
updated_app_accounts = []
|
31
|
+
app_accounts.each do |app_account|
|
32
|
+
account = OpenStax::Accounts::Account.where(
|
33
|
+
:openstax_uid => app_account.account.openstax_uid
|
34
|
+
).first || app_account.account
|
35
|
+
account.syncing = true
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
:openstax_uid => app_account.account.openstax_uid).first ||\
|
37
|
-
app_account.account
|
38
|
-
|
39
|
-
if account != app_account.account
|
40
|
-
SYNC_ATTRIBUTES.each do |attribute|
|
41
|
-
account.send("#{attribute}=", app_account.account.send(attribute))
|
42
|
-
end
|
37
|
+
if account != app_account.account
|
38
|
+
SYNC_ATTRIBUTES.each do |attribute|
|
39
|
+
account.send("#{attribute}=", app_account.account.send(attribute))
|
43
40
|
end
|
44
|
-
|
45
|
-
next unless account.save
|
46
|
-
|
47
|
-
updated_app_accounts << {user_id: account.openstax_uid,
|
48
|
-
read_updates: app_account.unread_updates}
|
49
41
|
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
next unless account.save
|
44
|
+
|
45
|
+
updated_app_accounts << {user_id: account.openstax_uid,
|
46
|
+
read_updates: app_account.unread_updates}
|
54
47
|
end
|
55
48
|
|
49
|
+
OpenStax::Accounts::Api.mark_account_updates_as_read(
|
50
|
+
updated_app_accounts
|
51
|
+
)
|
52
|
+
|
56
53
|
end
|
57
54
|
|
58
55
|
end
|