openstax_accounts 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +89 -58
- data/app/controllers/openstax/accounts/application_controller.rb +3 -12
- data/app/controllers/openstax/accounts/dev/accounts_controller.rb +19 -0
- data/app/controllers/openstax/accounts/dev/base_controller.rb +2 -8
- data/app/controllers/openstax/accounts/sessions_controller.rb +31 -19
- data/app/handlers/openstax/accounts/dev/{users_index.rb → accounts_index.rb} +4 -4
- data/app/handlers/openstax/accounts/sessions_callback.rb +43 -0
- data/app/models/openstax/accounts/{user.rb → account.rb} +7 -22
- data/app/models/openstax/accounts/anonymous_account.rb +24 -0
- data/app/models/openstax/accounts/application_account.rb +7 -0
- data/app/representers/openstax/accounts/api/v1/{user_representer.rb → account_representer.rb} +1 -1
- data/app/representers/openstax/accounts/api/v1/{user_search_representer.rb → account_search_representer.rb} +7 -6
- data/app/representers/openstax/accounts/api/v1/{application_user_representer.rb → application_account_representer.rb} +5 -4
- data/app/representers/openstax/accounts/api/v1/application_account_search_representer.rb +20 -0
- data/app/representers/openstax/accounts/api/v1/{application_users_representer.rb → application_accounts_representer.rb} +3 -3
- data/app/routines/openstax/accounts/dev/{search_users.rb → search_accounts.rb} +5 -5
- data/app/routines/openstax/accounts/{search_users.rb → search_accounts.rb} +55 -46
- data/app/routines/openstax/accounts/sync_accounts.rb +47 -0
- data/app/views/openstax/accounts/dev/{users → accounts}/_search_results.html.erb +13 -13
- data/app/views/openstax/accounts/dev/{users/login.html.erb → accounts/index.html.erb} +3 -3
- data/app/views/openstax/accounts/dev/{users → accounts}/index.js.erb +1 -1
- data/app/views/openstax/accounts/shared/{users → accounts}/_index.html.erb +4 -1
- data/config/initializers/action_interceptor.rb +14 -0
- data/config/routes.rb +18 -15
- data/db/migrate/0_create_openstax_accounts_accounts.rb +22 -0
- data/lib/generators/openstax/accounts/schedule/USAGE +1 -1
- data/lib/generators/openstax/accounts/schedule/templates/schedule.rb +1 -1
- data/lib/openstax/accounts/current_user_manager.rb +74 -65
- data/lib/openstax/accounts/default_account_user_mapper.rb +15 -0
- data/lib/openstax/accounts/engine.rb +2 -0
- data/lib/openstax/accounts/extend_builtins.rb +37 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/openstax_accounts.rb +46 -25
- data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +21 -0
- data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +12 -9
- data/spec/dummy/app/controllers/api/application_users_controller.rb +0 -4
- data/spec/dummy/app/controllers/api/users_controller.rb +7 -0
- data/spec/dummy/app/models/anonymous_user.rb +48 -0
- data/spec/dummy/app/models/user.rb +26 -0
- data/spec/dummy/config/initializers/openstax_accounts.rb +3 -2
- data/spec/dummy/config/routes.rb +5 -3
- data/spec/dummy/db/migrate/1_create_users.rb +11 -0
- data/spec/dummy/db/schema.rb +18 -6
- data/spec/factories/openstax_accounts_account.rb +6 -0
- data/spec/lib/openstax/accounts/current_user_manager_spec.rb +151 -0
- data/spec/lib/openstax_accounts_spec.rb +16 -9
- data/spec/models/openstax/accounts/account_spec.rb +9 -0
- data/spec/models/openstax/accounts/anonymous_account_spec.rb +9 -0
- data/spec/routines/openstax/accounts/{search_users_spec.rb → search_accounts_spec.rb} +38 -38
- metadata +87 -50
- data/app/controllers/openstax/accounts/dev/users_controller.rb +0 -22
- data/app/handlers/openstax/accounts/sessions_omniauth_authenticated.rb +0 -48
- data/app/models/openstax/accounts/application_user.rb +0 -7
- data/app/representers/openstax/accounts/api/v1/application_user_search_representer.rb +0 -19
- data/app/routines/openstax/accounts/dev/create_user.rb +0 -37
- data/app/routines/openstax/accounts/sync_users.rb +0 -44
- data/config/initializers/extend_builtins.rb +0 -42
- data/db/migrate/0_create_openstax_accounts_users.rb +0 -18
- data/lib/openstax/accounts/action_list.rb +0 -42
- data/lib/openstax/accounts/route_helper.rb +0 -34
- data/lib/openstax/accounts/user_provider.rb +0 -15
- data/spec/controllers/openstax/accounts/dev/users_controller_spec.rb +0 -21
- data/spec/factories/openstax_accounts_user.rb +0 -6
- data/spec/models/openstax/accounts/user_spec.rb +0 -13
- data/spec/routines/openstax/accounts/dev/create_user_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmE5M2NiMTk1MWUzMTg1OTY1MDA5MzVjMGExNzEwMmVlMDY2NTFiMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmMwMGI2MTRkYTkzZDg2NTlhZmE2Njc5NjZjOTgyMTUyNDJkZDU5MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmZhOWE1OTA5Y2U5M2ViZTJlNzQzMjNjYmUwM2FkMmFlNTczNDU5ZDVmZmEz
|
10
|
+
NjFmNmI4NGU4OGRiNDE2OTI2ZDRhYTdiNjFlMjc1NTA3ZWFiM2E4NWM4OTY3
|
11
|
+
YTZhZTVlYjVjODhkY2YzMmYxZGRhZWQxNmM1YmUyNzE0MmJhOGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmJiODkwZGVjZTRlNzZmNGMwNDJmNWJkMTE1ZTE2MjQzNDc2YWM5YjRmYzlk
|
14
|
+
MjVjODkyYTNmNDZmMjQ4NTQyMDliY2YxYmY4MWNhMmY4NzA1OTcwMzNlNmFm
|
15
|
+
YTQwOTQxOWE5Y2NlYzJiMmQ2ZDdjYjBkYTZkOTg1ZTIxZTc2YTU=
|
data/README.md
CHANGED
@@ -6,82 +6,115 @@ accounts-rails
|
|
6
6
|
|
7
7
|
A rails engine for interfacing with OpenStax's accounts server.
|
8
8
|
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Make sure to install the engine's migrations:
|
13
|
+
|
14
|
+
```sh
|
15
|
+
$ rake openstax_accounts:install:migrations
|
16
|
+
```
|
17
|
+
|
9
18
|
Usage
|
10
19
|
-----
|
11
20
|
|
12
|
-
Add the engine to your Gemfile and then run `bundle install`.
|
21
|
+
Add the engine to your Gemfile and then run `bundle install`.
|
13
22
|
|
14
23
|
Mount the engine your application's `routes.rb` file:
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
```rb
|
26
|
+
MyApplication::Application.routes.draw do
|
27
|
+
# ...
|
28
|
+
mount OpenStax::Accounts::Engine, at: "/accounts"
|
29
|
+
# ...
|
30
|
+
end
|
31
|
+
```
|
21
32
|
|
22
|
-
You can use whatever path you want instead of `/accounts`,
|
33
|
+
You can use whatever path you want instead of `/accounts`,
|
34
|
+
just make sure to make the appropriate changes below.
|
23
35
|
|
24
|
-
Create an `openstax_accounts.rb` initializer in `config/initializers`,
|
36
|
+
Create an `openstax_accounts.rb` initializer in `config/initializers`,
|
37
|
+
with at least the following contents:
|
25
38
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
```rb
|
40
|
+
OpenStax::Accounts.configure do |config|
|
41
|
+
config.openstax_application_id = 'value_from_openstax_accounts_here'
|
42
|
+
config.openstax_application_secret = 'value_from_openstax_accounts_here'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
If you're running the OpenStax Accounts server in a dev instance on your
|
47
|
+
machine, you can specify that instance's local URL with:
|
30
48
|
|
31
|
-
|
49
|
+
```rb
|
50
|
+
config.openstax_accounts_url = 'http://localhost:2999/'
|
51
|
+
```
|
52
|
+
|
53
|
+
To have users login, direct them to the login path using the
|
54
|
+
`openstax_accounts.login_path` route helper with Action Interceptor, e.g:
|
55
|
+
|
56
|
+
```erb
|
57
|
+
<%= link_to 'Sign in!', with_interceptor { openstax_accounts.login_path } %>
|
58
|
+
```
|
32
59
|
|
33
|
-
|
60
|
+
The `with_interceptor` block is necessary if you don't want to
|
61
|
+
depend on the user's browser setting referers properly.
|
34
62
|
|
35
|
-
|
63
|
+
You can also add the `authenticate_user!` interceptor to your controllers:
|
36
64
|
|
37
|
-
|
65
|
+
```rb
|
66
|
+
interceptor :authenticate_user!
|
67
|
+
```
|
38
68
|
|
39
|
-
|
69
|
+
There is also a logout path helper, given by `logout_path`.
|
70
|
+
By default this expects a `GET` request.
|
71
|
+
If you'd prefer a `DELETE` request, add this configuration:
|
40
72
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
that references the OpenStax Accounts User object.
|
73
|
+
```rb
|
74
|
+
config.logout_via = :delete
|
75
|
+
```
|
45
76
|
|
46
|
-
OpenStax Accounts
|
47
|
-
|
48
|
-
your own custom
|
49
|
-
you can teach OpenStax Accounts how to translate between your app's custom User
|
50
|
-
object and OpenStax Accounts's built-in User object.
|
77
|
+
OpenStax Accounts provides you with an `OpenStax::Accounts::Account` object.
|
78
|
+
You can modify it and use this as your app's User object (not recommended),
|
79
|
+
or you can provide your own custom user object that references one account.
|
51
80
|
|
52
|
-
|
81
|
+
OpenStax Accounts also provides you methods for getting and setting the current
|
82
|
+
signed in user (`current_user` and `current_user=` methods). If you choose to
|
83
|
+
create your own custom user object, you can teach this gem how to translate
|
84
|
+
between a user object and an account object.
|
53
85
|
|
54
|
-
|
86
|
+
To do this, you need to set a `account_user_mapper` in this configuration.
|
55
87
|
|
56
|
-
|
88
|
+
config.account_user_mapper = MyAccountUserMapper
|
57
89
|
|
58
|
-
|
59
|
-
|
60
|
-
|
90
|
+
The account_user_mapper is a class that provides two class methods:
|
91
|
+
|
92
|
+
def self.account_to_user(account)
|
93
|
+
# Converts the given account to a user.
|
94
|
+
# If you want to cache the account in the user,
|
61
95
|
# this is the place to do it.
|
62
|
-
# If no
|
96
|
+
# If no user exists for this account, one should
|
63
97
|
# be created.
|
64
98
|
end
|
65
99
|
|
66
|
-
def self.
|
67
|
-
# Converts the given
|
100
|
+
def self.user_to_account(user)
|
101
|
+
# Converts the given user to an account.
|
68
102
|
end
|
69
103
|
|
70
|
-
Accounts
|
71
|
-
|
72
|
-
pattern in your app or you can use nil for the current user.
|
73
|
-
the anonymous status of accounts
|
74
|
-
|
75
|
-
The default `user_provider` just uses OpenStax::Accounts::User as the app user.
|
104
|
+
Accounts are never nil. When a user is signed out, the current account is the
|
105
|
+
AnonymousAccount (responding true to `is_anonymous?`). You can follow the same
|
106
|
+
pattern in your app or you can use nil for the current user. Just remember to
|
107
|
+
check the anonymous status of accounts when doing your account <-> user
|
108
|
+
translations.
|
76
109
|
|
77
|
-
|
78
|
-
|
79
|
-
rake openstax_accounts:install:migrations
|
110
|
+
The default `account_user_mapper` assumes the account object and
|
111
|
+
the user object are the same in your application.
|
80
112
|
|
81
113
|
Syncing with Accounts
|
82
114
|
---------------------
|
83
115
|
|
84
|
-
OpenStax
|
116
|
+
OpenStax Accounts requires your app to periodically sync user information with
|
117
|
+
the Accounts server. The easiest way to do this is to use the "whenever" gem.
|
85
118
|
|
86
119
|
To create or append to the schedule.rb file, run the following command:
|
87
120
|
|
@@ -89,7 +122,8 @@ To create or append to the schedule.rb file, run the following command:
|
|
89
122
|
rails g openstax:accounts:schedule
|
90
123
|
```
|
91
124
|
|
92
|
-
Then, after installing the "whenever" gem, run the `whenever` command for
|
125
|
+
Then, after installing the "whenever" gem, run the `whenever` command for
|
126
|
+
instructions to set up your crontab:
|
93
127
|
|
94
128
|
```sh
|
95
129
|
whenever
|
@@ -98,19 +132,16 @@ whenever
|
|
98
132
|
Accounts API
|
99
133
|
------------
|
100
134
|
|
101
|
-
OpenStax
|
102
|
-
|
103
|
-
`OpenStax:: Accounts.create_application_user(accounts_user, version = nil)` takes
|
104
|
-
an OpenStax::Accounts::User and, optionally, an API version argument, and creates
|
105
|
-
an ApplicationUser for the configured application and the given user. Call this method
|
106
|
-
when users finish the registration process in your app. This lets Accounts know that the given user is using your app, allowing Accounts to push user information to it whenever it changes.
|
135
|
+
OpenStax Accounts provides convenience methods for accessing
|
136
|
+
the Accounts server API.
|
107
137
|
|
108
|
-
`OpenStax::Accounts.api_call(http_method, url, options = {})` provides a
|
109
|
-
convenience method capable of making API calls to Accounts. `http_method` can
|
110
|
-
any valid HTTP method, and `url` is the desired API URL, without the 'api/'
|
111
|
-
Options is a hash that can contain any option that
|
112
|
-
as :headers, :params, :body, etc,
|
113
|
-
|
138
|
+
`OpenStax::Accounts.api_call(http_method, url, options = {})` provides a
|
139
|
+
convenience method capable of making API calls to Accounts. `http_method` can
|
140
|
+
be any valid HTTP method, and `url` is the desired API URL, without the 'api/'
|
141
|
+
prefix. Options is a hash that can contain any option that
|
142
|
+
OAuth2 requests accept, such as :headers, :params, :body, etc,
|
143
|
+
plus the optional values :api_version (to specify an API version) and
|
144
|
+
:access_token (to specify an OAuth access token).
|
114
145
|
|
115
146
|
Example Application
|
116
147
|
-------------------
|
@@ -2,21 +2,12 @@ module OpenStax
|
|
2
2
|
module Accounts
|
3
3
|
|
4
4
|
class ApplicationController < ActionController::Base
|
5
|
-
include Lev::HandleWith
|
6
5
|
|
7
|
-
|
8
|
-
def current_user
|
9
|
-
current_user_manager.accounts_current_user
|
10
|
-
end
|
6
|
+
include Lev::HandleWith
|
11
7
|
|
12
|
-
|
8
|
+
acts_as_interceptor :override_url_options => false
|
13
9
|
|
14
|
-
|
15
|
-
referrer = include_referrer ? request.referrer : nil
|
16
|
-
# Always clear the session
|
17
|
-
session_return_to = session.delete(:return_to)
|
18
|
-
params[:return_to] || session_return_to || referrer || main_app.root_url
|
19
|
-
end
|
10
|
+
skip_interceptor :authenticate_user!
|
20
11
|
|
21
12
|
end
|
22
13
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OpenStax
|
2
|
+
module Accounts
|
3
|
+
module Dev
|
4
|
+
class AccountsController < OpenStax::Accounts::Dev::BaseController
|
5
|
+
|
6
|
+
def index
|
7
|
+
handle_with(AccountsIndex)
|
8
|
+
end
|
9
|
+
|
10
|
+
def become
|
11
|
+
@account = Account.find(params[:id])
|
12
|
+
sign_in(@account)
|
13
|
+
redirect_back
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,15 +3,9 @@ module OpenStax
|
|
3
3
|
module Dev
|
4
4
|
class BaseController < OpenStax::Accounts::ApplicationController
|
5
5
|
|
6
|
-
before_filter
|
6
|
+
before_filter do
|
7
7
|
raise SecurityTransgression if Rails.env.production?
|
8
|
-
|
9
|
-
|
10
|
-
skip_before_filter :authenticate_user!
|
11
|
-
skip_before_filter :require_registration!
|
12
|
-
|
13
|
-
fine_print_skip_signatures :general_terms_of_use, :privacy_policy \
|
14
|
-
if respond_to?(:fine_print_skip_signatures)
|
8
|
+
end
|
15
9
|
|
16
10
|
end
|
17
11
|
end
|
@@ -3,20 +3,23 @@ module OpenStax
|
|
3
3
|
class SessionsController < OpenStax::Accounts::ApplicationController
|
4
4
|
|
5
5
|
def new
|
6
|
-
|
7
|
-
|
6
|
+
if OpenStax::Accounts.configuration.enable_stubbing?
|
7
|
+
with_interceptor { redirect_to dev_accounts_path }
|
8
|
+
else
|
9
|
+
redirect_to openstax_login_path
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
|
-
def
|
11
|
-
handle_with(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def callback
|
14
|
+
handle_with(
|
15
|
+
SessionsCallback,
|
16
|
+
success: lambda {
|
17
|
+
sign_in(@handler_result.outputs[:account])
|
18
|
+
redirect_back
|
19
|
+
},
|
20
|
+
failure: lambda {
|
21
|
+
failure
|
22
|
+
})
|
20
23
|
end
|
21
24
|
|
22
25
|
def destroy
|
@@ -24,16 +27,25 @@ module OpenStax
|
|
24
27
|
|
25
28
|
# If we're using the Accounts server, need to sign out of it so can't
|
26
29
|
# log back in automagically
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
if OpenStax::Accounts.configuration.enable_stubbing?
|
31
|
+
redirect_back
|
32
|
+
else
|
33
|
+
without_interceptor do
|
34
|
+
|
35
|
+
redirect_to(
|
36
|
+
OpenStax::Utilities.generate_url(
|
37
|
+
OpenStax::Accounts.configuration.openstax_accounts_url,
|
38
|
+
"logout",
|
39
|
+
return_to: intercepted_url
|
40
|
+
)
|
41
|
+
)
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
def failure
|
36
|
-
|
48
|
+
redirect_back alert: "Authentication failed, please try again."
|
37
49
|
end
|
38
50
|
|
39
51
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OpenStax
|
2
2
|
module Accounts
|
3
3
|
module Dev
|
4
|
-
class
|
4
|
+
class AccountsIndex
|
5
5
|
|
6
6
|
lev_handler transaction: :no_transaction
|
7
7
|
|
@@ -11,8 +11,8 @@ module OpenStax
|
|
11
11
|
attribute :page, type: Integer
|
12
12
|
end
|
13
13
|
|
14
|
-
uses_routine OpenStax::Accounts::Dev::
|
15
|
-
as: :
|
14
|
+
uses_routine OpenStax::Accounts::Dev::SearchAccounts,
|
15
|
+
as: :search_accounts,
|
16
16
|
translations: { outputs: {type: :verbatim} }
|
17
17
|
|
18
18
|
protected
|
@@ -30,7 +30,7 @@ module OpenStax
|
|
30
30
|
else
|
31
31
|
query = search_params.terms || ''
|
32
32
|
end
|
33
|
-
run(:
|
33
|
+
run(:search_accounts, query, page: search_params.page || 0)
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module OpenStax
|
2
|
+
module Accounts
|
3
|
+
|
4
|
+
class SessionsCallback
|
5
|
+
|
6
|
+
lev_handler
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@auth_data = request.env['omniauth.auth']
|
12
|
+
end
|
13
|
+
|
14
|
+
def authorized?
|
15
|
+
@auth_data.provider == "openstax"
|
16
|
+
end
|
17
|
+
|
18
|
+
def handle
|
19
|
+
# Don't worry if the account is logged in or not beforehand.
|
20
|
+
# Just assume that they aren't.
|
21
|
+
|
22
|
+
existing_account = Account.where(openstax_uid: @auth_data.uid).first
|
23
|
+
return outputs[:account] = existing_account if !existing_account.nil?
|
24
|
+
|
25
|
+
new_account = Account.create do |account|
|
26
|
+
account.openstax_uid = @auth_data.uid
|
27
|
+
account.username = @auth_data.info.nickname
|
28
|
+
account.first_name = @auth_data.info.first_name
|
29
|
+
account.last_name = @auth_data.info.last_name
|
30
|
+
account.full_name = @auth_data.info.name
|
31
|
+
account.title = @auth_data.info.title
|
32
|
+
account.access_token = @auth_data.credentials.token
|
33
|
+
end
|
34
|
+
|
35
|
+
transfer_errors_from(new_account, {type: :verbatim})
|
36
|
+
|
37
|
+
outputs[:account] = new_account
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module OpenStax
|
2
2
|
module Accounts
|
3
|
-
class
|
3
|
+
class Account < ActiveRecord::Base
|
4
4
|
|
5
5
|
USERNAME_DISCARDED_CHAR_REGEX = /[^A-Za-z\d_]/
|
6
6
|
USERNAME_MAX_LENGTH = 50
|
7
7
|
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :syncing_with_accounts
|
9
9
|
|
10
10
|
validates :username, uniqueness: true, presence: true
|
11
|
-
validates :openstax_uid, presence: true
|
11
|
+
validates :openstax_uid, uniqueness: true, presence: true
|
12
|
+
validates :access_token, uniqueness: true, allow_nil: true
|
12
13
|
|
13
14
|
attr_accessible :username, :first_name, :last_name, :full_name, :title
|
14
15
|
|
@@ -23,30 +24,14 @@ module OpenStax
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def is_anonymous?
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_accessor :is_anonymous
|
30
|
-
|
31
|
-
def self.anonymous
|
32
|
-
@@anonymous ||= AnonymousUser.new
|
27
|
+
false
|
33
28
|
end
|
34
29
|
|
35
30
|
def update_openstax_accounts
|
36
|
-
return if
|
31
|
+
return if syncing_with_accounts || \
|
37
32
|
OpenStax::Accounts.configuration.enable_stubbing?
|
38
|
-
OpenStax::Accounts.user_update(self)
|
39
|
-
end
|
40
33
|
|
41
|
-
|
42
|
-
before_save { false }
|
43
|
-
def initialize(attributes=nil)
|
44
|
-
super
|
45
|
-
self.is_anonymous = true
|
46
|
-
self.first_name = 'Guest'
|
47
|
-
self.last_name = 'User'
|
48
|
-
self.openstax_uid = nil
|
49
|
-
end
|
34
|
+
OpenStax::Accounts.update_account(self)
|
50
35
|
end
|
51
36
|
|
52
37
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OpenStax
|
2
|
+
module Accounts
|
3
|
+
class AnonymousAccount < Account
|
4
|
+
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
before_save { false }
|
8
|
+
|
9
|
+
def initialize(attributes=nil)
|
10
|
+
super
|
11
|
+
self.id = nil
|
12
|
+
self.openstax_uid = nil
|
13
|
+
self.username = 'anonymous'
|
14
|
+
self.first_name = 'Guest'
|
15
|
+
self.last_name = 'User'
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_anonymous?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,10 +2,11 @@ module OpenStax
|
|
2
2
|
module Accounts
|
3
3
|
module Api
|
4
4
|
module V1
|
5
|
-
class
|
5
|
+
class AccountSearchRepresenter < Roar::Decorator
|
6
6
|
include Roar::Representer::JSON
|
7
7
|
|
8
|
-
property :
|
8
|
+
property :num_matching_accounts,
|
9
|
+
as: :num_matching_users,
|
9
10
|
type: Integer
|
10
11
|
|
11
12
|
property :page,
|
@@ -17,10 +18,10 @@ module OpenStax
|
|
17
18
|
property :order_by,
|
18
19
|
type: String
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
class:
|
23
|
-
decorator:
|
21
|
+
collection :accounts,
|
22
|
+
as: :users,
|
23
|
+
class: Account,
|
24
|
+
decorator: AccountRepresenter
|
24
25
|
|
25
26
|
end
|
26
27
|
end
|
@@ -2,7 +2,7 @@ module OpenStax
|
|
2
2
|
module Accounts
|
3
3
|
module Api
|
4
4
|
module V1
|
5
|
-
class
|
5
|
+
class ApplicationAccountRepresenter < Roar::Decorator
|
6
6
|
include Roar::Representer::JSON
|
7
7
|
|
8
8
|
property :id,
|
@@ -11,9 +11,10 @@ module OpenStax
|
|
11
11
|
property :application_id,
|
12
12
|
type: Integer
|
13
13
|
|
14
|
-
property :
|
15
|
-
|
16
|
-
|
14
|
+
property :account,
|
15
|
+
as: :user,
|
16
|
+
class: OpenStax::Accounts::Account,
|
17
|
+
decorator: AccountRepresenter
|
17
18
|
|
18
19
|
property :unread_updates,
|
19
20
|
type: Integer
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenStax
|
2
|
+
module Accounts
|
3
|
+
module Api
|
4
|
+
module V1
|
5
|
+
class ApplicationAccountSearchRepresenter < AccountSearchRepresenter
|
6
|
+
|
7
|
+
collection :application_accounts,
|
8
|
+
as: :application_users,
|
9
|
+
class: OpenStax::Accounts::ApplicationAccount,
|
10
|
+
decorator: ApplicationAccountRepresenter,
|
11
|
+
schema_info: {
|
12
|
+
description: "The matching accounts that have used this app",
|
13
|
+
minItems: 0
|
14
|
+
}
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,11 +4,11 @@ module OpenStax
|
|
4
4
|
module Accounts
|
5
5
|
module Api
|
6
6
|
module V1
|
7
|
-
class
|
7
|
+
class ApplicationAccountsRepresenter < Roar::Decorator
|
8
8
|
include Representable::JSON::Collection
|
9
9
|
|
10
|
-
items class: OpenStax::Accounts::
|
11
|
-
decorator:
|
10
|
+
items class: OpenStax::Accounts::ApplicationAccount,
|
11
|
+
decorator: ApplicationAccountRepresenter
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# Routine for searching for
|
1
|
+
# Routine for searching for accounts
|
2
2
|
#
|
3
3
|
# Caller provides a query and some options. The query follows the rules of
|
4
4
|
# https://github.com/bruce/keyword_search, e.g.:
|
5
5
|
#
|
6
|
-
# "username:jps,richb" --> returns the "jps" and "richb"
|
7
|
-
# "name:John" --> returns
|
6
|
+
# "username:jps,richb" --> returns the "jps" and "richb" accounts
|
7
|
+
# "name:John" --> returns accounts with first, last, or full name starting with "John"
|
8
8
|
#
|
9
9
|
# Query terms can be combined, e.g. "username:jp first_name:john"
|
10
10
|
#
|
@@ -16,9 +16,9 @@
|
|
16
16
|
module OpenStax
|
17
17
|
module Accounts
|
18
18
|
module Dev
|
19
|
-
class
|
19
|
+
class SearchAccounts < OpenStax::Accounts::SearchAccounts
|
20
20
|
def exec(query, options={})
|
21
|
-
options = options.merge!(:
|
21
|
+
options = options.merge!(:max_matching_accounts => Float::INFINITY)
|
22
22
|
super
|
23
23
|
end
|
24
24
|
end
|