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
@@ -1,42 +0,0 @@
|
|
1
|
-
class ActionController::Base
|
2
|
-
|
3
|
-
# Returns the current app user
|
4
|
-
def current_user
|
5
|
-
current_user_manager.current_user
|
6
|
-
end
|
7
|
-
|
8
|
-
# Signs in the given user; the argument can be either an accounts user or
|
9
|
-
# an app user
|
10
|
-
def sign_in(user)
|
11
|
-
current_user_manager.sign_in(user)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Signs out the current user
|
15
|
-
def sign_out!
|
16
|
-
current_user_manager.sign_out!
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns true iff there is a user signed in
|
20
|
-
def signed_in?
|
21
|
-
current_user_manager.signed_in?
|
22
|
-
end
|
23
|
-
|
24
|
-
# Useful in before_filters
|
25
|
-
def authenticate_user!
|
26
|
-
return if signed_in?
|
27
|
-
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
|
28
|
-
redirect_to openstax_accounts.login_path
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
helper_method :current_user, :signed_in?
|
34
|
-
|
35
|
-
def current_user_manager
|
36
|
-
@current_user_manager ||= OpenStax::Accounts::CurrentUserManager.new(request,
|
37
|
-
session,
|
38
|
-
cookies)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateOpenStaxAccountsUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :openstax_accounts_users do |t|
|
4
|
-
t.integer :openstax_uid
|
5
|
-
t.string :username
|
6
|
-
t.string :first_name
|
7
|
-
t.string :last_name
|
8
|
-
t.string :full_name
|
9
|
-
t.string :title
|
10
|
-
t.string :access_token
|
11
|
-
|
12
|
-
t.timestamps
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :openstax_accounts_users, :openstax_uid, :unique => true
|
16
|
-
add_index :openstax_accounts_users, :username, :unique => true
|
17
|
-
end
|
18
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
class ActionList
|
4
|
-
|
5
|
-
def initialize(options={})
|
6
|
-
@options = options
|
7
|
-
|
8
|
-
raise IllegalArgument, "must supply data procs" if options[:data_procs].nil?
|
9
|
-
|
10
|
-
if options[:headings].present? && options[:data_procs].size != options[:headings].size
|
11
|
-
raise IllegalArgument, "if you supply headings, you must supply one for each column"
|
12
|
-
end
|
13
|
-
|
14
|
-
if options[:widths].present? && options[:data_procs].size != options[:widths].size
|
15
|
-
raise IllegalArgument, "if you supply widths, you must supply one for each column"
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def num_columns
|
21
|
-
@options[:data_procs].size
|
22
|
-
end
|
23
|
-
|
24
|
-
def has_headings?
|
25
|
-
@options[:headings].present?
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_heading(column)
|
29
|
-
@options[:headings].nil? ? nil : @options[:headings][column]
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_width(column)
|
33
|
-
@options[:widths].nil? ? nil : @options[:widths][column]
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_data(column, *args)
|
37
|
-
@options[:data_procs][column].call(*args)
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
class RouteHelper
|
6
|
-
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
# Registers a path against a canonical name. An optional
|
10
|
-
# block can be provided to give the stubbed path
|
11
|
-
def self.register_path(canonical_name, path, &block)
|
12
|
-
instance.paths[canonical_name] = path
|
13
|
-
if block.present? && OpenStax::Accounts.configuration.enable_stubbing?
|
14
|
-
instance.stubbed_paths[canonical_name] = block.call
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.get_path(canonical_name)
|
19
|
-
OpenStax::Accounts.configuration.enable_stubbing? ?
|
20
|
-
instance.stubbed_paths[canonical_name] :
|
21
|
-
instance.paths[canonical_name]
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
self.paths = {}
|
26
|
-
self.stubbed_paths = {}
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_accessor :paths
|
30
|
-
attr_accessor :stubbed_paths
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax::Accounts
|
4
|
-
module Dev
|
5
|
-
describe UsersController do
|
6
|
-
routes { OpenStax::Accounts::Engine.routes }
|
7
|
-
|
8
|
-
let!(:user) { user = FactoryGirl.create :openstax_accounts_user,
|
9
|
-
username: 'some_user',
|
10
|
-
openstax_uid: 10 }
|
11
|
-
|
12
|
-
it 'should allow users not in production to become other users' do
|
13
|
-
expect(controller.current_user).to eq(OpenStax::Accounts::User.anonymous)
|
14
|
-
expect(controller.current_user.is_anonymous?).to eq(true)
|
15
|
-
post :become, id: user.id
|
16
|
-
expect(controller.current_user).to eq(user)
|
17
|
-
expect(controller.current_user.is_anonymous?).to eq(false)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax::Accounts
|
4
|
-
describe User do
|
5
|
-
it 'can return an AnonymousUser' do
|
6
|
-
anon = User.anonymous
|
7
|
-
expect(anon.is_anonymous?).to eq true
|
8
|
-
expect(anon.first_name).to eq 'Guest'
|
9
|
-
expect(anon.last_name).to eq 'User'
|
10
|
-
expect(anon.openstax_uid).to be_nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
module Dev
|
6
|
-
|
7
|
-
describe CreateUser do
|
8
|
-
|
9
|
-
it 'creates users' do
|
10
|
-
|
11
|
-
expect(User.where(username: 'bob').first).to be_nil
|
12
|
-
|
13
|
-
outputs = CreateUser.call(username: 'bob', last_name: 'jones').outputs
|
14
|
-
|
15
|
-
expect(outputs[:user]).not_to be_nil
|
16
|
-
expect(outputs[:user].username).to eq 'bob'
|
17
|
-
expect(outputs[:user].last_name).to eq 'jones'
|
18
|
-
expect(User.where(username: 'bob').first).to eq outputs[:user]
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|