openstax_accounts 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjM3YTQ1MzUyNzQ1ZDcxY2U4OWJhMTEzNzlhOTZhMDAwNDk5YzI1Ng==
4
+ NmM3YWJkNTYyYjhiNzE5YmQ3NmYxZDBmYTNiMDhmNzk3MTJmNjE3MQ==
5
5
  data.tar.gz: !binary |-
6
- ZTQ1NjI3MTRiMTk0YjQ0N2M4OTRhZmMzYTg2YjNjODYyMWViMjFmMA==
6
+ ZDljZjliNzE0NDFjY2M5NjI0ZGJiZWE2ZTY0MTVkZjYxOGI0YjIxZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTJiNWU0ZmVlYzI4NjhmMjY4YjNlYjhjMTk0NjNjM2MwYmU5YTcyMDRkYTQ4
10
- MzEyN2YyMTFlMDM3MTBhYTEwYmVmMTZlOTkxNWY2MDhmYmU2NGZiMTQ0MmQz
11
- ZTkyNmJjMDNjMGI5ZGExZjM5YTBlNjQzMmE3N2E4YmI3NWQ5MWM=
9
+ ODk1MzM5MThkNGQ3NTVkMzYyNjE4MmY2OGRhZTAyY2I5ZjBkZDViNDI2NDQz
10
+ YjdjYTkzMDI2OTk2YjJmN2E1YzhjODRhNTNjZThiNTM2MmNlNTdiYTQxZDAx
11
+ ZWZiODI1MzU1ZmQ4NjVkNzUxODljMjZhMDRjMWU4OGVmNmYyNjI=
12
12
  data.tar.gz: !binary |-
13
- ZGFjNDAwZmU3NGUyNThlMTMwMjI3ZjFiYWQzYzY3MWNiM2RjN2I0NzY4MWYy
14
- M2NlYWU5MmFlOGJhOGZhZDViZDQzOTMwMTBhNGI2MDA5OGNmOTcyYTgyNDBk
15
- YmVkYTEzYTZmM2I5YmUzOWVlNjA2ZTFkMDVjMWZlM2U1ZmRhZDg=
13
+ YmRiN2RlZmUzZTgxMTA1NWI3ZTEwMjY3Yzc0NmI3ZjE4NjcxYjNlOWI3MTM4
14
+ ODFjNDU5ZTcxZWNmMjA2YzFhYTMwMjkxNTEzZmUyMDFiNWFmNDQ2YjhlMzE1
15
+ MDhjZWE2ZTA2MzM5NGQ5N2QxOWVkZTkwY2U1NWViODRkMmY3MDI=
@@ -4,7 +4,15 @@ module OpenStax
4
4
  class AccountsController < OpenStax::Accounts::Dev::BaseController
5
5
 
6
6
  def index
7
- handle_with(AccountsIndex)
7
+ end
8
+
9
+ def search
10
+ handle_with(AccountsSearch)
11
+ end
12
+
13
+ def create
14
+ handle_with(AccountsCreate,
15
+ complete: lambda { redirect_back })
8
16
  end
9
17
 
10
18
  def become
@@ -0,0 +1,33 @@
1
+ module OpenStax
2
+ module Accounts
3
+
4
+ module Dev
5
+ class AccountsCreate
6
+
7
+ lev_handler
8
+
9
+ paramify :create do
10
+ attribute :username, type: String
11
+ validates :username, presence: true
12
+ end
13
+
14
+ uses_routine OpenStax::Accounts::Dev::CreateAccount,
15
+ as: :create_account,
16
+ translations: { inputs: { scope: :create },
17
+ outputs: { type: :verbatim } }
18
+
19
+ protected
20
+
21
+ def authorized?
22
+ !Rails.env.production? && OpenStax::Accounts.configuration.enable_stubbing?
23
+ end
24
+
25
+ def handle
26
+ run(:create_account, create_params.as_hash(:username))
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -1,7 +1,7 @@
1
1
  module OpenStax
2
2
  module Accounts
3
3
  module Dev
4
- class AccountsIndex
4
+ class AccountsSearch
5
5
 
6
6
  lev_handler transaction: :no_transaction
7
7
 
@@ -0,0 +1,37 @@
1
+ # Routine for creating an account, only for use when stubbing and
2
+ # not on production.
3
+
4
+ module OpenStax
5
+ module Accounts
6
+ module Dev
7
+ class CreateAccount
8
+ lev_routine
9
+
10
+ protected
11
+
12
+ def exec(inputs={})
13
+ fatal_error(:code => :cannot_create_account_in_production) if Rails.env.production?
14
+ fatal_error(:code => :can_only_create_account_when_stubbing) if !OpenStax::Accounts.configuration.enable_stubbing?
15
+
16
+ username = inputs[:username]
17
+ while username.nil? || Account.where(username: username).exists? do
18
+ username = SecureRandom.hex(3).to_s
19
+ end
20
+
21
+ account = OpenStax::Accounts::Account.new
22
+
23
+ account.openstax_uid = -SecureRandom.hex.to_i(16)
24
+ account.access_token = SecureRandom.hex.to_s
25
+ account.username = username
26
+
27
+ account.save
28
+
29
+ transfer_errors_from(account, {type: :verbatim}, true)
30
+
31
+ outputs[:account] = account
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -30,21 +30,23 @@
30
30
  <% end %>
31
31
  </div>
32
32
 
33
- <%= osu.action_list(
34
- records: accounts,
35
- list: {
36
- headings: ['Username', 'First Name', 'Last Name', ''],
37
- widths: ['25%', '25%', '25%', '25%'],
33
+ <div id='search-results-list'>
34
+ <%= osu.action_list(
35
+ records: accounts,
36
+ list: {
37
+ headings: ['Username', 'Title', 'Name', 'Actions'],
38
+ widths: ['30%', '10%', '40%', '20%'],
38
39
  data_procs:
39
40
  [
40
- Proc.new { |account| account.username },
41
- Proc.new { |account| account.first_name || '---' },
42
- Proc.new { |account| account.last_name || '---' },
43
- Proc.new { |account|
44
- link_to 'Sign in as',
45
- with_interceptor { become_dev_account_path(account) },
46
- method: :post
47
- }
41
+ lambda { |account| account.username },
42
+ lambda { |account| account.title || '---' },
43
+ lambda { |account| account.name || '---' },
44
+ lambda { |account|
45
+ link_to 'Sign in as',
46
+ with_interceptor { become_dev_account_path(account) },
47
+ method: :post
48
+ }
48
49
  ]
49
- }
50
- ) %>
50
+ }
51
+ ) %>
52
+ </div>
@@ -4,15 +4,28 @@
4
4
  <%= error.translate %>
5
5
  <% end %>
6
6
 
7
- <%= osu.section_block "Development Login" do %>
7
+ <h3>Create an Account</h3>
8
8
 
9
- <p>You need to login, but we're not connected to the Accounts server.
10
- Search for a user below and click the sign in link next to him or her.</p>
9
+ <%= lev_form_for :create,
10
+ url: openstax_accounts.dev_accounts_path,
11
+ method: :post do |f| %>
11
12
 
12
- <%= with_interceptor { render 'openstax/accounts/shared/accounts/index',
13
- :search_action_path => openstax_accounts.dev_accounts_path,
14
- :remote => true } %>
13
+ Username
14
+ <%= f.text_field :username, style: 'width:300px' %>
15
+ <%= f.submit 'Create', class: 'btn btn-primary' %>
15
16
 
16
17
  <% end %>
17
18
 
19
+ <h3>Development Login</h3>
20
+
21
+ <p>You need to login, but we're not connected to the Accounts server.
22
+ Search for a user below and click the sign in link next to him or her.</p>
23
+
24
+ <%= with_interceptor {
25
+ render :partial => 'openstax/accounts/shared/accounts/search',
26
+ :locals => { :search_action_path => openstax_accounts.search_dev_accounts_path,
27
+ :remote => true, :method => :get } } %>
28
+
29
+ <br>
30
+ <div id="search-results"></div>
18
31
  </div>
@@ -0,0 +1,3 @@
1
+ <%= unless_errors alerts_html_id: 'dialog-local-alerts' do %>
2
+ $("#search-results").html("<%= j(render 'openstax/accounts/dev/accounts/search_results') %>");
3
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <%
2
2
  # Clients of this partial can override the following variables:
3
3
  search_action_path ||= nil
4
- method ||= :post
4
+ method ||= :get
5
5
  remote ||= false
6
6
  form_html ||= {id: 'search-form',
7
7
  class: 'form-inline'}
data/config/routes.rb CHANGED
@@ -8,7 +8,7 @@ OpenStax::Accounts::Engine.routes.draw do
8
8
  get '/auth/openstax', :as => 'openstax_login'
9
9
 
10
10
  # OmniAuth local routes (SessionsController)
11
- resource :session, :only => [], :path => '', :as => '' do
11
+ scope module: 'sessions' do
12
12
  get 'callback', :path => 'auth/:provider/callback' # Authentication success
13
13
  get 'failure', :path => 'auth/failure' # Authentication failure
14
14
 
@@ -19,9 +19,9 @@ OpenStax::Accounts::Engine.routes.draw do
19
19
 
20
20
  if OpenStax::Accounts.configuration.enable_stubbing?
21
21
  namespace :dev do
22
- resources :accounts, :only => [:index] do
23
- post 'index', :on => :collection
22
+ resources :accounts, :only => [:index, :create] do
24
23
  post 'become', :on => :member
24
+ get 'search', :on => :collection
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "3.0.0"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-22 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -251,7 +251,8 @@ files:
251
251
  - app/controllers/openstax/accounts/dev/accounts_controller.rb
252
252
  - app/controllers/openstax/accounts/dev/base_controller.rb
253
253
  - app/controllers/openstax/accounts/sessions_controller.rb
254
- - app/handlers/openstax/accounts/dev/accounts_index.rb
254
+ - app/handlers/openstax/accounts/dev/accounts_create.rb
255
+ - app/handlers/openstax/accounts/dev/accounts_search.rb
255
256
  - app/handlers/openstax/accounts/sessions_callback.rb
256
257
  - app/helpers/openstax/accounts/application_helper.rb
257
258
  - app/models/openstax/accounts/account.rb
@@ -272,6 +273,7 @@ files:
272
273
  - app/representers/openstax/accounts/api/v1/group_nesting_representer.rb
273
274
  - app/representers/openstax/accounts/api/v1/group_representer.rb
274
275
  - app/representers/openstax/accounts/api/v1/group_user_representer.rb
276
+ - app/routines/openstax/accounts/dev/create_account.rb
275
277
  - app/routines/openstax/accounts/dev/search_accounts.rb
276
278
  - app/routines/openstax/accounts/search_accounts.rb
277
279
  - app/routines/openstax/accounts/sync_accounts.rb
@@ -280,9 +282,9 @@ files:
280
282
  - app/views/layouts/openstax/accounts/application.html.erb
281
283
  - app/views/openstax/accounts/dev/accounts/_search_results.html.erb
282
284
  - app/views/openstax/accounts/dev/accounts/index.html.erb
283
- - app/views/openstax/accounts/dev/accounts/index.js.erb
285
+ - app/views/openstax/accounts/dev/accounts/search.js.erb
284
286
  - app/views/openstax/accounts/shared/_attention.html.erb
285
- - app/views/openstax/accounts/shared/accounts/_index.html.erb
287
+ - app/views/openstax/accounts/shared/accounts/_search.html.erb
286
288
  - config/initializers/action_interceptor.rb
287
289
  - config/routes.rb
288
290
  - db/migrate/0_create_openstax_accounts_accounts.rb
@@ -1,3 +0,0 @@
1
- <%= unless_errors alerts_html_id: 'dialog-local-alerts' do %>
2
- $("#search-results-list").html("<%= j(render 'openstax/accounts/dev/accounts/search_results') %>");
3
- <% end %>