orats 0.6.3 → 0.6.4

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.
@@ -77,6 +77,45 @@ module Orats
77
77
  exit 1
78
78
  end
79
79
  end
80
+
81
+ def exit_if_path_exists
82
+ log_task 'Check if this path exists'
83
+
84
+ if Dir.exist?(@active_path) || File.exist?(@active_path)
85
+ log_error 'error', 'A file or directory already exists at this location', 'path', @active_path
86
+ exit 1
87
+ end
88
+ end
89
+
90
+ def exit_if_process(check_for, *processes)
91
+ case check_for
92
+ when :not_found
93
+ command = 'which'
94
+ phrase = 'on your system path'
95
+ when :not_running
96
+ command = 'ps cax | grep'
97
+ phrase = 'running'
98
+ else
99
+ command = ''
100
+ phrase = ''
101
+ end
102
+
103
+ processes.each do |process|
104
+ log_task "Check if #{process} is #{phrase}"
105
+
106
+ exit 1 if process_unusable?("#{command} #{process}", process, phrase)
107
+ end
108
+ end
109
+
110
+ def process_unusable?(command, process, phrase)
111
+ command_output = run(command, capture: true)
112
+
113
+ log_error 'error', "Cannot detect #{process}", 'question', "Are you sure #{process} is #{phrase}?", true do
114
+ log_status_bottom 'tip', "#{process} must be #{phrase} before running this orats command", :white
115
+ end if command_output.empty?
116
+
117
+ command_output.empty?
118
+ end
80
119
  end
81
120
  end
82
121
  end
@@ -10,21 +10,21 @@ module Orats
10
10
  secrets_path = "#{@target_path}/secrets"
11
11
  create_secrets secrets_path
12
12
 
13
- log_thor_task 'shell', 'Modifying secrets path in group_vars/all.yml'
13
+ log_task 'Update secrets path in group_vars/all.yml'
14
14
  gsub_file "#{@target_path}/#{fix_path_for_user(Commands::Common::RELATIVE_PATHS[:inventory])}",
15
15
  '~/tmp/testproj/secrets/', File.expand_path(secrets_path)
16
16
 
17
- log_thor_task 'shell', 'Modifying the place holder app name in group_vars/all.yml'
17
+ log_task 'Update place holder app name in group_vars/all.yml'
18
18
  gsub_file "#{@target_path}/#{fix_path_for_user(Commands::Common::RELATIVE_PATHS[:inventory])}",
19
19
  'testproj', File.basename(@target_path)
20
20
 
21
- log_thor_task 'shell', 'Creating ssh keypair'
21
+ log_task 'Add ssh keypair'
22
22
  run "ssh-keygen -t rsa -P '' -f #{secrets_path}/id_rsa"
23
23
 
24
- log_thor_task 'shell', 'Creating self signed ssl certificates'
24
+ log_task 'Add self signed ssl certificates'
25
25
  run create_rsa_certificate(secrets_path, 'sslkey.key', 'sslcert.crt')
26
26
 
27
- log_thor_task 'shell', 'Creating monit pem file'
27
+ log_task 'Add monit pem file'
28
28
  run "#{create_rsa_certificate(secrets_path,
29
29
  'monit.pem', 'monit.pem')} && openssl gendh 512 >> #{secrets_path}/monit.pem"
30
30
 
@@ -34,7 +34,7 @@ module Orats
34
34
  private
35
35
 
36
36
  def create_inventory
37
- log_thor_task 'shell', 'Creating ansible inventory'
37
+ log_task 'Add ansible inventory'
38
38
  run "mkdir -p #{@target_path}/inventory/group_vars"
39
39
 
40
40
  local_to_user Commands::Common::RELATIVE_PATHS[:hosts]
@@ -44,12 +44,12 @@ module Orats
44
44
  def local_to_user(file)
45
45
  fixed_file = fix_path_for_user(file)
46
46
 
47
- log_thor_task 'shell', "Creating #{fixed_file}"
47
+ log_task "Add #{fixed_file}"
48
48
  run "cp #{base_path}/#{file} #{@target_path}/#{fixed_file}"
49
49
  end
50
50
 
51
51
  def create_secrets(secrets_path)
52
- log_thor_task 'shell', 'Creating ansible secrets'
52
+ log_task 'Add ansible secrets'
53
53
  run "mkdir #{secrets_path}"
54
54
 
55
55
  save_secret_string "#{secrets_path}/postgres_password"
@@ -69,7 +69,7 @@ module Orats
69
69
  end
70
70
 
71
71
  def install_role_dependencies
72
- log_thor_task 'shell', 'Updating ansible roles from the galaxy'
72
+ log_task 'Update ansible roles from the galaxy'
73
73
 
74
74
  galaxy_install =
75
75
  "ansible-galaxy install -r #{base_path}/#{Commands::Common::RELATIVE_PATHS[:galaxyfile]} --force"
@@ -18,6 +18,8 @@ module Orats
18
18
  end
19
19
 
20
20
  def init
21
+ check_exit_conditions
22
+
21
23
  rails_template 'base' do
22
24
  gsub_postgres_info
23
25
  gsub_redis_info unless @options[:redis_password].empty?
@@ -28,6 +30,7 @@ module Orats
28
30
  spring_binstub
29
31
 
30
32
  create_and_migrate_database
33
+ generate_home_page
31
34
  run_rake 'orats:favicons'
32
35
  end
33
36
 
@@ -2,10 +2,13 @@ module Orats
2
2
  module Commands
3
3
  module New
4
4
  module Rails
5
- def rails_template(command, flags = '')
6
- exit_if_cannot_rails
7
- exit_if_exists unless flags.index(/--skip/)
5
+ def check_exit_conditions
6
+ exit_if_process :not_found, 'rails', 'git'
7
+ exit_if_process :not_running, 'postgres', 'redis'
8
+ exit_if_path_exists
9
+ end
8
10
 
11
+ def rails_template(command, flags = '')
9
12
  orats_template = "--template #{base_path}/templates/#{command}.rb"
10
13
 
11
14
  run "rails new #{@active_path} #{flags} --skip-bundle #{orats_template unless command.empty?}"
@@ -13,7 +16,7 @@ module Orats
13
16
  end
14
17
 
15
18
  def custom_rails_template
16
- log_thor_task 'shell', 'Running custom rails template'
19
+ log_task 'Run custom rails template'
17
20
 
18
21
  @options[:template].include?('://') ? url_to_string(@options[:template])
19
22
  : file_to_string(@options[:template])
@@ -22,82 +25,149 @@ module Orats
22
25
  end
23
26
 
24
27
  def gsub_postgres_info
25
- log_thor_task 'root', 'Changing the postgres information'
28
+ log_task 'Update the postgres connection details'
26
29
  gsub_file "#{@active_path}/.env", 'DATABASE_HOST: localhost', "DATABASE_HOST: #{@options[:pg_location]}"
27
30
  gsub_file "#{@active_path}/.env", ': postgres', ": #{@options[:pg_username]}"
28
31
  gsub_file "#{@active_path}/.env", ': supersecrets', ": #{@options[:pg_password]}"
29
32
 
30
- git_commit 'Change the postgres information'
33
+ git_commit 'Update the postgres connection details'
31
34
  end
32
35
 
33
36
  def gsub_redis_info
34
- log_thor_task 'root', 'Changing the redis password'
37
+ log_task 'Update the redis connection details'
35
38
  gsub_file "#{@active_path}/.env", 'HE_PASSWORD: ""', "HE_PASSWORD: #{@options[:redis_password]}"
36
39
  gsub_file "#{@active_path}/.env", 'CACHE_HOST: localhost', "CACHE_HOST: #{@options[:redis_location]}"
37
40
 
38
- git_commit 'Add the redis password'
41
+ git_commit 'Update the redis connection details'
39
42
  end
40
43
 
41
44
  def gsub_project_path
42
- log_thor_task 'root', 'Changing the project path'
45
+ log_task 'Update the project path'
43
46
  gsub_file "#{@active_path}/.env", ': /full/path/to/your/project', ": #{File.expand_path(@active_path)}"
44
47
 
45
- git_commit 'Add the development project path'
48
+ git_commit 'Update the project path'
46
49
  end
47
50
 
48
51
  def bundle_install
49
- log_thor_task 'shell', 'Running bundle install, this may take a while'
52
+ log_task 'Run bundle install, this may take a while'
50
53
  run_from @active_path, 'bundle install'
51
54
 
52
- git_commit 'Add gem lock file'
55
+ git_commit 'Add Gemfile.lock'
53
56
  end
54
57
 
55
58
  def bundle_binstubs
56
- log_thor_task 'shell', 'Running bundle binstubs for a few gems'
59
+ log_task 'Run bundle binstubs for a few gems'
57
60
  run_from @active_path, 'bundle binstubs whenever puma sidekiq backup'
58
61
 
59
62
  git_commit 'Add binstubs for the important gems'
60
63
  end
61
64
 
62
65
  def spring_binstub
63
- log_thor_task 'shell', 'Running spring binstub'
66
+ log_task 'Run spring binstub'
64
67
  run_from @active_path, 'bundle exec spring binstub --all'
65
68
 
66
- git_commit 'Springify all of the bins'
69
+ git_commit 'Add spring binstubs for all of the bins'
67
70
  end
68
71
 
69
72
  def run_rake(command)
70
- log_thor_task 'shell', 'Running rake commands'
73
+ log_task 'Run rake command'
71
74
 
72
75
  run_from @active_path, "bundle exec rake #{command}"
73
76
  end
74
77
 
75
- def create_and_migrate_database
76
- run_rake 'db:create:all db:migrate'
77
- git_commit 'Add the database schema file'
78
- end
79
-
80
- private
81
-
82
- def exit_if_cannot_rails
83
- log_thor_task 'shell', 'Checking for rails'
78
+ def generate_home_page
79
+ log_task 'Add pages controller with static page'
80
+ run_from @active_path, 'bundle exec rails g controller Pages home'
84
81
 
85
- has_rails = run('which rails', capture: true)
86
-
87
- log_error 'error', 'Cannot access rails', 'question', 'Are you sure you have rails setup correctly?', true do
88
- log_status_bottom 'tip', 'You can install it by running `gem install rails`', :white
89
- end if has_rails.empty?
90
-
91
- exit 1 if has_rails.empty?
82
+ gsub_file "#{@active_path}/config/routes.rb", " # root 'welcome#index'" do <<-S
83
+ root 'pages#home'
84
+ S
85
+ end
86
+ gsub_file "#{@active_path}/config/routes.rb", " get 'pages/home'\n\n", ''
87
+
88
+ gsub_file "#{@active_path}/test/controllers/pages_controller_test.rb",
89
+ '"should get home"', "'expect home page'"
90
+ gsub_file "#{@active_path}/app/views/pages/home.html.erb", /.*\n/, ''
91
+ append_file "#{@active_path}/app/views/pages/home.html.erb" do <<-S
92
+ <%
93
+ title 'Welcome to Ruby on Rails'
94
+ meta_description '...'
95
+ heading 'Welcome to Ruby on Rails'
96
+ %>
97
+
98
+ <div class="row">
99
+ <div class="col-sm-9">
100
+ <p class="lead">
101
+ You have successfully generated a project with <%= link_to 'orats', 'https://github.com/nickjj/orats' %> v#{VERSION}.
102
+ </p>
103
+
104
+ <hr />
105
+
106
+ <p>
107
+ <%= image_tag 'https://badge.fury.io/rb/orats.png', alt: 'Gem badge' %> is the latest version of orats.
108
+ </p>
109
+
110
+ <hr />
111
+
112
+ <h3>Custom rake tasks</h3>
113
+ <pre>
114
+ <code>
115
+ # backup the database to S3 or any other location
116
+ bundle exec rake orats:backup
117
+
118
+ # generate a new set of favicons to the public directory
119
+ bundle exec rake orats:favicons
120
+ </code>
121
+ </pre>
122
+
123
+ <hr />
124
+
125
+ <h3>Trying to figure out what to do next?</h3>
126
+ <p>
127
+ Visit the wiki guide for <%= link_to 'what to look at after making a new project', 'https://github.com/nickjj/orats/wiki/What-to-look-at-after-making-a-new-project' %>.
128
+ </p>
129
+
130
+ <hr />
131
+
132
+ <h3>Looking to deploy your application?</h3>
133
+ <p>
134
+ Visit the wiki guide for <%= link_to 'get your application on a server ', 'https://github.com/nickjj/orats/wiki/Get-your-application-on-a-server' %>.
135
+ </p>
136
+
137
+ <hr />
138
+
139
+ <h3>Want to get rid of the pages controller?</h3>
140
+ <p>
141
+ No problem, just follow these steps:
142
+ <ul>
143
+ <li>
144
+ Run <code>bundle exec rails d controller Pages</code>
145
+ </li>
146
+ <li>
147
+ Remove the root route from <code>config/routes.rb</code>
148
+ </li>
149
+ <li>
150
+ Remove the link in the navigation partial at <code>app/views/layouts/_navigation_links.html.erb</code>
151
+ </li>
152
+ <li>
153
+ Restart the server
154
+ </li>
155
+ </ul>
156
+ </p>
157
+ </div>
158
+
159
+ <div class="col-sm-3">
160
+ <%= image_tag '/apple-touch-icon-228x228-precomposed.png', size: '228x228', alt: 'A ruby image I found on Google' %>
161
+ </div>
162
+ </div>
163
+ S
164
+ end
165
+ git_commit 'Add pages controller with home page'
92
166
  end
93
167
 
94
- def exit_if_exists
95
- log_thor_task 'shell', 'Checking if a file or directory already exists'
96
-
97
- if Dir.exist?(@active_path) || File.exist?(@active_path)
98
- log_error 'error', 'A file or directory already exists at this location', 'path', @active_path
99
- exit 1
100
- end
168
+ def create_and_migrate_database
169
+ run_rake 'db:create:all db:migrate'
170
+ git_commit 'Add the database schema file'
101
171
  end
102
172
  end
103
173
  end
@@ -51,7 +51,7 @@ module Orats
51
51
 
52
52
  def nuke_data
53
53
  valid_rails_directories.each do |directory|
54
- log_thor_task 'root', 'Removing postgres databases'
54
+ log_task 'Remove postgres databases'
55
55
  run_from directory, 'bundle exec rake db:drop:all'
56
56
 
57
57
  nuke_redis File.basename(directory)
@@ -59,7 +59,7 @@ module Orats
59
59
  end
60
60
 
61
61
  def nuke_redis(namespace)
62
- log_thor_task 'root', 'Removing redis keys'
62
+ log_task 'Remove redis keys'
63
63
 
64
64
  while not_able_to_nuke_redis?(@options[:redis_password], namespace)
65
65
  log_status_top 'error', "The redis password you supplied was incorrect\n", :red
@@ -78,7 +78,7 @@ module Orats
78
78
  end
79
79
 
80
80
  def nuke_directory
81
- log_thor_task 'root', 'Deleting directory'
81
+ log_task 'Delete directory'
82
82
  run "rm -rf #{@active_path}"
83
83
  end
84
84
  end
@@ -3,7 +3,7 @@ module Orats
3
3
  module Outdated
4
4
  module Compare
5
5
  def remote_to_local_gem_versions
6
- log_remote_info 'gem', 'Comparing this version of orats to the latest orats version',
6
+ log_remote_info 'gem', 'Compare this version of orats to the latest orats version',
7
7
  'version', "Latest: #{@remote_gem_version}, Yours: v#{VERSION}"
8
8
  end
9
9
 
@@ -13,7 +13,7 @@ module Orats
13
13
  local_galaxyfile_roles = @local_galaxyfile.size
14
14
  roles_diff_count = galaxyfile_diff.size
15
15
 
16
- log_status_top 'roles', "Comparing this version of orats' roles to the latest version:", :green
16
+ log_status_top 'roles', "Compare this version of orats' roles to the latest version:", :green
17
17
 
18
18
  if roles_diff_count == 0
19
19
  log_status_bottom 'message', "All #{local_galaxyfile_roles} roles are up to date", :yellow
@@ -41,7 +41,7 @@ module Orats
41
41
  item_diff = remote - local
42
42
  item_diff_count = item_diff.size
43
43
 
44
- log_remote_info label, "Comparing this version of orats' #{label} to the latest version",
44
+ log_remote_info label, "Compare this version of orats' #{label} to the latest version",
45
45
  'file', label == 'playbook' ? 'site.yml' : 'all.yml'
46
46
 
47
47
  item_diff.each do |line|
@@ -59,7 +59,7 @@ module Orats
59
59
  def local_to_user(label, keyword, flag_path, local)
60
60
  user = yield
61
61
 
62
- log_local_info label, "Comparing this version of orats' #{label} to #{File.basename(flag_path)}",
62
+ log_local_info label, "Compare this version of orats' #{label} to #{File.basename(flag_path)}",
63
63
  'path', flag_path
64
64
 
65
65
  missing_count = log_unmatched(local, user, 'missing', :red)
@@ -11,24 +11,11 @@ module Orats
11
11
  end
12
12
 
13
13
  def init
14
- return unless can_play?
14
+ exit_if_path_exists
15
+
15
16
  rails_template 'play'
16
17
  custom_rails_template unless @options[:template].empty?
17
18
  end
18
-
19
- private
20
-
21
- def can_play?
22
- log_thor_task 'shell', 'Checking for the ansible binary'
23
-
24
- has_ansible = run('which ansible', capture: true)
25
-
26
- log_error 'error', 'Cannot access ansible', 'question', 'Are you sure you have ansible setup correctly?', true do
27
- log_status_bottom 'tip', 'http://docs.ansible.com/intro_installation.html', :white
28
- end if has_ansible.empty?
29
-
30
- !has_ansible.empty?
31
- end
32
19
  end
33
20
  end
34
21
  end
@@ -3,9 +3,9 @@ module Orats
3
3
  module UI
4
4
  include Thor::Shell
5
5
 
6
- def log_thor_task(type, message)
6
+ def log_task(message)
7
7
  puts
8
- say_status type, "#{message}...", :yellow
8
+ say_status 'task', "#{message}:", :yellow
9
9
  puts '-'*80, ''; sleep 0.25
10
10
  end
11
11
 
@@ -1,16 +1,36 @@
1
- # =====================================================================================================
2
- # Template for generating authentication and authorization on top of the base template
3
- # =====================================================================================================
4
-
5
- # ----- Helper functions and variables ----------------------------------------------------------------
6
-
7
1
  require 'securerandom'
8
2
 
3
+ # =============================================================================
4
+ # template for generating an orats auth project for rails 4.1.x
5
+ # =============================================================================
6
+ # view the task list at the bottom of the file
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # private functions
11
+ # -----------------------------------------------------------------------------
9
12
  def generate_token
10
13
  SecureRandom.hex(64)
11
14
  end
12
15
 
13
- def create_migration(table_name, migration='')
16
+ def method_to_sentence(method)
17
+ method.tr!('_', ' ')
18
+ method[0] = method[0].upcase
19
+ method
20
+ end
21
+
22
+ def log_task(message)
23
+ puts
24
+ say_status 'task', "#{method_to_sentence(message.to_s)}:", :yellow
25
+ puts '-'*80, ''; sleep 0.25
26
+ end
27
+
28
+ def git_commit(message)
29
+ git add: '-A'
30
+ git commit: "-m '#{message}'"
31
+ end
32
+
33
+ def migrate(table_name, migration='')
14
34
  utc_now = Time.now.getutc.strftime("%Y%m%d%H%M%S")
15
35
  class_name = table_name.to_s.classify.pluralize
16
36
 
@@ -23,172 +43,197 @@ end
23
43
  }
24
44
  end
25
45
 
26
- # ----- Delete application.css ------------------------------------------------------------------------
46
+ # ---
27
47
 
28
- # This gets created by rails automatically when you make a new project
29
- run 'rm -f app/assets/stylesheets/application.css'
30
-
31
- # ----- Modify Gemfile --------------------------------------------------------------------------------
48
+ def delete_app_css
49
+ run 'rm -f app/assets/stylesheets/application.css'
50
+ end
32
51
 
33
- puts
34
- say_status 'root', 'Modifying Gemfile..', :yellow
35
- puts '-'*80, ''; sleep 0.25
52
+ def update_gemfile
53
+ log_task __method__
36
54
 
37
- inject_into_file 'Gemfile', before: "\ngem 'kaminari'" do <<-CODE
55
+ inject_into_file 'Gemfile', before: "\ngem 'kaminari'" do <<-S
38
56
 
39
57
  gem 'devise', '~> 3.2.4'
40
58
  gem 'devise-async', '~> 0.9.0'
41
59
  gem 'pundit', '~> 0.2.3'
42
- CODE
60
+ S
61
+ end
62
+ git_commit 'Add authentication related gems'
43
63
  end
44
64
 
45
- git add: '-A'
46
- git commit: "-m 'Add devise, devise-async and pundit gems'"
47
-
48
- # ----- Run bundle install ----------------------------------------------------------------------------
49
-
50
- puts
51
- say_status 'action', 'Running bundle install, it should not take too long', :yellow
52
- puts '-'*80, ''; sleep 0.25
65
+ def update_dotenv
66
+ log_task __method__
53
67
 
54
- run 'bundle install'
68
+ inject_into_file '.env', before: "\nSMTP_ADDRESS" do <<-CODE
69
+ TOKEN_DEVISE_SECRET: #{generate_token}
70
+ TOKEN_DEVISE_PEPPER: #{generate_token}
71
+ CODE
72
+ end
55
73
 
56
- # ----- Modify sidekiq config -------------------------------------------------------------------------
74
+ inject_into_file '.env', before: "\nDATABASE_NAME" do <<-CODE
75
+ ACTION_MAILER_DEVISE_DEFAULT_FROM: info@#{app_name}.com
76
+ CODE
77
+ end
78
+ git_commit 'Add devise tokens and default e-mail'
79
+ end
57
80
 
58
- puts
59
- say_status 'config', 'Modifying the sidekiq config', :yellow
60
- puts '-'*80, ''; sleep 0.25
81
+ def run_bundle_install
82
+ log_task __method__
61
83
 
62
- append_file 'config/sidekiq.yml' do <<-FILE
63
- - mailer
64
- FILE
84
+ run 'bundle install'
65
85
  end
66
86
 
67
- git add: '-A'
68
- git commit: "-m 'Add the devise mailer queue to the sidekiq config'"
87
+ def add_pundit
88
+ log_task __method__
69
89
 
70
- # ----- Create the account fixtures -------------------------------------------------------------------
90
+ generate 'pundit:install'
91
+ inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-S
92
+ include Pundit
71
93
 
72
- puts
73
- say_status 'test', 'Creating the account fixtures...', :yellow
74
- puts '-'*80, ''; sleep 0.25
94
+ S
95
+ end
75
96
 
76
- file 'test/fixtures/accounts.yml' do <<-'CODE'
77
- foo:
78
- id: 1
79
- email: foo@bar.com
80
- encrypted_password: passwordisnotreallyencrypted
81
- role: admin
82
- created_at: 2012-01-01 01:45:17
83
- current_sign_in_at: 2013-03-15 11:22:33
97
+ inject_into_file 'app/controllers/application_controller.rb', after: ":exception\n" do <<-S
84
98
 
85
- no_role:
86
- id: 2
87
- email: joey@almostcool.com
88
- encrypted_password: hackthegibson
89
- created_at: 1995-09-15 08:10:12
99
+ rescue_from Pundit::NotAuthorizedError, with: :account_not_authorized
100
+ S
101
+ end
90
102
 
91
- bad_role:
92
- id: 3
93
- email: hello@world.com
94
- encrypted_password: reallysecure
95
- role: ahhhh
96
- created_at: 2011-09-20 10:10:10
103
+ inject_into_file 'app/controllers/application_controller.rb', after: " #end\n" do <<-S
97
104
 
98
- beep:
99
- id: 4
100
- email: beep@beep.com
101
- encrypted_password: beepbeepbeep
102
- created_at: 2010-03-6 05:15:45
103
- CODE
105
+ def account_not_authorized
106
+ redirect_to request.headers['Referer'] || root_path, flash: { error: I18n.t('authorization.error') }
107
+ end
108
+ S
109
+ end
110
+ git_commit 'Add pundit policy and controller logic'
104
111
  end
105
112
 
106
- git add: '-A'
107
- git commit: "-m 'Add the account model'"
113
+ def add_devise_initializers
114
+ log_task __method__
108
115
 
109
- # ----- Modify the test helper ------------------------------------------------------------------------
116
+ file 'config/initializers/devise_async.rb', 'Devise::Async.backend = :sidekiq'
117
+ generate 'devise:install'
118
+ git_commit 'Add the devise and devise async initializers'
119
+ end
110
120
 
111
- puts
112
- say_status 'test', 'Modifying the test helper...', :yellow
113
- puts '-'*80, ''; sleep 0.25
121
+ def update_devise_initializer
122
+ log_task 'Update the devise initializer'
114
123
 
115
- inject_into_file 'test/test_helper.rb', after: "end\n" do <<-CODE
124
+ gsub_file 'config/initializers/devise.rb',
125
+ "'please-change-me-at-config-initializers-devise@example.com'", "ENV['ACTION_MAILER_DEVISE_DEFAULT_EMAIL']"
126
+ gsub_file 'config/initializers/devise.rb', /(?<=key = )'\w{128}'/, "ENV['TOKEN_DEVISE_SECRET']"
127
+ gsub_file 'config/initializers/devise.rb', /(?<=pepper = )'\w{128}'/, "ENV['TOKEN_DEVISE_PEPPER']"
128
+ gsub_file 'config/initializers/devise.rb', '# config.timeout_in = 30.minutes',
129
+ 'config.timeout_in = 2.hours'
116
130
 
117
- class ActionController::TestCase
118
- include Devise::TestHelpers
131
+ gsub_file 'config/initializers/devise.rb', '# config.expire_auth_token_on_timeout = false',
132
+ 'config.expire_auth_token_on_timeout = true'
133
+ gsub_file 'config/initializers/devise.rb', '# config.lock_strategy = :failed_attempts',
134
+ 'config.lock_strategy = :failed_attempts'
135
+ gsub_file 'config/initializers/devise.rb', '# config.unlock_strategy = :both',
136
+ 'config.unlock_strategy = :both'
137
+ gsub_file 'config/initializers/devise.rb', '# config.maximum_attempts = 20',
138
+ 'config.maximum_attempts = 7'
139
+ gsub_file 'config/initializers/devise.rb', '# config.unlock_in = 1.hour',
140
+ 'config.unlock_in = 2.hours'
141
+ gsub_file 'config/initializers/devise.rb', '# config.last_attempt_warning = false',
142
+ 'config.last_attempt_warning = true'
143
+ git_commit 'Update the devise defaults'
119
144
  end
120
- CODE
145
+
146
+ def update_sidekiq_config
147
+ log_task __method__
148
+
149
+ append_file 'config/sidekiq.yml' do <<-S
150
+ - mailer
151
+ S
152
+ end
153
+ git_commit 'Add the devise mailer queue to sidekiq'
121
154
  end
122
155
 
123
- git add: '-A'
124
- git commit: "-m 'Add the devise helpers to test helper'"
156
+ def update_routes
157
+ log_task __method__
125
158
 
126
- # ----- Create the account unit tests -----------------------------------------------------------------
159
+ gsub_file 'config/routes.rb', "mount Sidekiq::Web => '/sidekiq'\n", ''
160
+ inject_into_file 'config/routes.rb', after: "collection\n end\n" do <<-S
127
161
 
128
- puts
129
- say_status 'test', 'Creating the account unit tests...', :yellow
130
- puts '-'*80, ''; sleep 0.25
162
+ # disable users from being able to register by uncommenting the lines below
163
+ # get 'accounts/sign_up(.:format)', to: redirect('/')
164
+ # post 'accounts(.:format)', to: redirect('/')
131
165
 
132
- file 'test/models/account_test.rb' do <<-'CODE'
133
- require 'test_helper'
166
+ # disable users from deleting their own account by uncommenting the line below
167
+ # delete 'accounts(.:format)', to: redirect('/')
134
168
 
135
- class AccountTest < ActiveSupport::TestCase
136
- def setup
137
- @account = accounts(:foo)
138
- end
169
+ devise_for :accounts
139
170
 
140
- def teardown
141
- @account = nil
171
+ authenticate :account, lambda { |account| account.is?(:admin) } do
172
+ mount Sidekiq::Web => '/sidekiq'
142
173
  end
143
174
 
144
- test 'expect new account' do
145
- assert @account.valid?
146
- assert_not_nil @account.email
147
- assert_not_nil @account.encrypted_password
175
+ S
148
176
  end
177
+ git_commit 'Add the devise route and protect sidekiq with authentication'
178
+ end
149
179
 
150
- test 'expect guest to be default role' do
151
- no_role = accounts(:no_role)
152
- assert_equal 'guest', no_role.role
153
- end
180
+ def add_en_locale_for_authorization
181
+ log_task __method__
154
182
 
155
- test 'expect invalid role to not save' do
156
- bad_role = accounts(:bad_role)
157
- assert_not bad_role.valid?
183
+ gsub_file 'config/locales/en.yml', "hello: \"Hello world\"\n", ''
184
+ append_file 'config/locales/en.yml' do <<-S
185
+ authorization:
186
+ error: 'You are not authorized to perform this action.'
187
+ S
158
188
  end
189
+ git_commit 'Add en locale entry for authorization errors'
190
+ end
159
191
 
160
- test 'expect e-mail to be unique' do
161
- duplicate = Account.create(email: 'foo@bar.com')
192
+ def add_devise_migration
193
+ log_task __method__
162
194
 
163
- assert_not duplicate.valid?
164
- end
195
+ migrate :accounts, %{
196
+ create_table(:accounts) do |t|
197
+ ## Database authenticatable
198
+ t.string :email, :null => false, :default => ''
199
+ t.string :encrypted_password, :null => false, :default => ''
165
200
 
166
- test 'expect random password if password is empty' do
167
- @account.password = ''
168
- @account.encrypted_password = ''
169
- @account.save
201
+ ## Recoverable
202
+ t.string :reset_password_token
203
+ t.datetime :reset_password_sent_at
170
204
 
171
- random_password = Account.generate_password
172
- assert_equal 10, random_password.length
173
- end
205
+ ## Rememberable
206
+ t.datetime :remember_created_at
174
207
 
175
- test 'expect random password of 20 characters' do
176
- assert_equal 20, Account.generate_password(20).length
177
- end
178
- end
179
- CODE
180
- end
208
+ ## Trackable
209
+ t.integer :sign_in_count, :default => 0, :null => false
210
+ t.datetime :current_sign_in_at
211
+ t.datetime :last_sign_in_at
212
+ t.string :current_sign_in_ip
213
+ t.string :last_sign_in_ip
214
+
215
+ ## Lockable
216
+ t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
217
+ t.string :unlock_token # Only if unlock strategy is :email or :both
218
+ t.datetime :locked_at
219
+
220
+ ## Role
221
+ t.string :role, default: 'guest'
181
222
 
182
- git add: '-A'
183
- git commit: "-m 'Add the account unit tests'"
223
+ t.timestamps
224
+ end
184
225
 
185
- # ----- Create the account model ----------------------------------------------------------------------
226
+ add_index :accounts, :email, :unique => true
227
+ add_index :accounts, :reset_password_token, :unique => true
228
+ add_index :accounts, :unlock_token, :unique => true
229
+ }
230
+ git_commit 'Add devise model migration'
231
+ end
186
232
 
187
- puts
188
- say_status 'models', 'Creating the account model...', :yellow
189
- puts '-'*80, ''; sleep 0.25
233
+ def add_account_model
234
+ log_task __method__
190
235
 
191
- file 'app/models/account.rb' do <<-'CODE'
236
+ file 'app/models/account.rb' do <<-'S'
192
237
  class Account < ActiveRecord::Base
193
238
  ROLES = %w[admin guest]
194
239
 
@@ -229,105 +274,138 @@ class Account < ActiveRecord::Base
229
274
  Rails.cache.delete("account:#{id}")
230
275
  end
231
276
  end
232
- CODE
277
+ S
278
+ end
279
+ git_commit 'Add account model'
233
280
  end
234
281
 
235
- git add: '-A'
236
- git commit: "-m 'Add the account model'"
282
+ def add_seed_user
283
+ log_task __method__
237
284
 
238
- # ----- Create devise migration -----------------------------------------------------------------------
285
+ append_file 'db/seeds.rb', "\nAccount.create({ email: \"admin@#{app_name}.com\", password: \"password\",
286
+ role: \"admin\" })"
287
+ git_commit 'Add seed user'
288
+ end
239
289
 
240
- puts
241
- say_status 'db', 'Creating devise model migration...', :yellow
242
- puts '-'*80, ''; sleep 0.25
290
+ def update_test_helper
291
+ log_task __method__
292
+ inject_into_file 'test/test_helper.rb', after: "end\n" do <<-S
243
293
 
244
- create_migration :accounts, %{
245
- create_table(:accounts) do |t|
246
- ## Database authenticatable
247
- t.string :email, :null => false, :default => ''
248
- t.string :encrypted_password, :null => false, :default => ''
294
+ class ActionController::TestCase
295
+ include Devise::TestHelpers
296
+ end
297
+ S
298
+ end
299
+ git_commit 'Add devise test helper'
300
+ end
249
301
 
250
- ## Recoverable
251
- t.string :reset_password_token
252
- t.datetime :reset_password_sent_at
302
+ def add_account_fixtures
303
+ log_task __method__
304
+ file 'test/fixtures/accounts.yml' do <<-S
305
+ foo:
306
+ id: 1
307
+ email: foo@bar.com
308
+ encrypted_password: passwordisnotreallyencrypted
309
+ role: admin
310
+ created_at: 2012-01-01 01:45:17
311
+ current_sign_in_at: 2013-03-15 11:22:33
253
312
 
254
- ## Rememberable
255
- t.datetime :remember_created_at
313
+ no_role:
314
+ id: 2
315
+ email: joey@almostcool.com
316
+ encrypted_password: hackthegibson
317
+ created_at: 1995-09-15 08:10:12
256
318
 
257
- ## Trackable
258
- t.integer :sign_in_count, :default => 0, :null => false
259
- t.datetime :current_sign_in_at
260
- t.datetime :last_sign_in_at
261
- t.string :current_sign_in_ip
262
- t.string :last_sign_in_ip
319
+ bad_role:
320
+ id: 3
321
+ email: hello@world.com
322
+ encrypted_password: reallysecure
323
+ role: ahhhh
324
+ created_at: 2011-09-20 10:10:10
263
325
 
264
- ## Lockable
265
- t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
266
- t.string :unlock_token # Only if unlock strategy is :email or :both
267
- t.datetime :locked_at
326
+ beep:
327
+ id: 4
328
+ email: beep@beep.com
329
+ encrypted_password: beepbeepbeep
330
+ created_at: 2010-03-6 05:15:45
331
+ S
332
+ end
333
+ git_commit 'Add account fixtures'
334
+ end
268
335
 
269
- ## Role
270
- t.string :role, default: 'guest'
336
+ def add_account_unit_tests
337
+ log_task __method__
271
338
 
272
- t.timestamps
273
- end
339
+ file 'test/models/account_test.rb' do <<-S
340
+ require 'test_helper'
274
341
 
275
- add_index :accounts, :email, :unique => true
276
- add_index :accounts, :reset_password_token, :unique => true
277
- add_index :accounts, :unlock_token, :unique => true
278
- }
342
+ class AccountTest < ActiveSupport::TestCase
343
+ def setup
344
+ @account = accounts(:foo)
345
+ end
279
346
 
280
- git add: '-A'
281
- git commit: "-m 'Add devise model migration'"
347
+ def teardown
348
+ @account = nil
349
+ end
282
350
 
283
- # ----- Create a seed user ----------------------------------------------------------------------------
351
+ test 'expect new account' do
352
+ assert @account.valid?
353
+ assert_not_nil @account.email
354
+ assert_not_nil @account.encrypted_password
355
+ end
284
356
 
285
- puts
286
- say_status 'db', 'Creating a seed user...', :yellow
287
- puts '-'*80, ''; sleep 0.25
357
+ test 'expect guest to be default role' do
358
+ no_role = accounts(:no_role)
359
+ assert_equal 'guest', no_role.role
360
+ end
288
361
 
289
- append_file 'db/seeds.rb', "\nAccount.create({ email: \"admin@#{app_name}.com\", password: \"password\", role: \"admin\" })"
362
+ test 'expect invalid role to not save' do
363
+ bad_role = accounts(:bad_role)
364
+ assert_not bad_role.valid?
365
+ end
290
366
 
291
- git add: '-A'
292
- git commit: "-m 'Add a seed user'"
367
+ test 'expect e-mail to be unique' do
368
+ duplicate = Account.create(email: 'foo@bar.com')
293
369
 
294
- # ----- Create en i18n entries ------------------------------------------------------------------------
370
+ assert_not duplicate.valid?
371
+ end
295
372
 
296
- puts
297
- say_status 'db', 'Creating en i18n entries...', :yellow
298
- puts '-'*80, ''; sleep 0.25
373
+ test 'expect random password if password is empty' do
374
+ @account.password = ''
375
+ @account.encrypted_password = ''
376
+ @account.save
299
377
 
300
- gsub_file 'config/locales/en.yml', "hello: \"Hello world\"\n", ''
378
+ random_password = Account.generate_password
379
+ assert_equal 10, random_password.length
380
+ end
301
381
 
302
- append_file 'config/locales/en.yml' do <<-CODE
303
- authorization:
304
- error: 'You are not authorized to perform this action.'
305
- CODE
382
+ test 'expect random password of 20 characters' do
383
+ assert_equal 20, Account.generate_password(20).length
384
+ end
385
+ end
386
+ S
387
+ end
388
+ git_commit 'Add account unit tests'
306
389
  end
307
390
 
308
- git add: '-A'
309
- git commit: "-m 'Add en i18n entries'"
310
-
311
- # ----- Modify the application controller -------------------------------------------------------------
312
-
313
- puts
314
- say_status 'db', 'Modifying the application controller...', :yellow
315
- puts '-'*80, ''; sleep 0.25
391
+ def add_current_user_alias
392
+ log_task __method__
316
393
 
317
- inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-'CODE'
394
+ inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-S
318
395
  alias_method :current_user, :current_account
319
396
 
320
- CODE
397
+ S
398
+ end
399
+ git_commit 'Add current_user alias'
321
400
  end
322
401
 
323
- git add: '-A'
324
- git commit: "-m 'Alias current_user to current_account to play nice with other gems'"
325
-
326
- inject_into_file 'app/controllers/application_controller.rb', before: "end\n" do <<-'CODE'
402
+ def add_devise_controller_override
403
+ log_task __method__
404
+ inject_into_file 'app/controllers/application_controller.rb', before: "end\n" do <<-S
327
405
 
328
406
  private
329
407
 
330
- # Override devise to customize the after sign in path.
408
+ # override devise to customize the after sign in path
331
409
  #def after_sign_in_path_for(resource)
332
410
  # if resource.is? :admin
333
411
  # admin_path
@@ -335,19 +413,15 @@ inject_into_file 'app/controllers/application_controller.rb', before: "end\n" do
335
413
  # somewhere_path
336
414
  # end
337
415
  #end
338
- CODE
416
+ S
417
+ end
418
+ git_commit 'Add devise after_sign_in_path_for override'
339
419
  end
340
420
 
341
- git add: '-A'
342
- git commit: "-m 'Change the application controller to allow overriding the devise sign in path'"
343
-
344
- # ----- Create the devise views -----------------------------------------------------------------------
345
-
346
- puts
347
- say_status 'views', 'Creating the devise views...', :yellow
348
- puts '-'*80, ''; sleep 0.25
421
+ def add_devise_views
422
+ log_task __method__
349
423
 
350
- file 'app/views/devise/confirmations/new.html.erb' do <<-HTML
424
+ file 'app/views/devise/confirmations/new.html.erb' do <<-S
351
425
  <%
352
426
  title 'Confirm'
353
427
  meta_description '...'
@@ -374,19 +448,19 @@ file 'app/views/devise/confirmations/new.html.erb' do <<-HTML
374
448
  <%= render 'devise/shared/links' %>
375
449
  </div>
376
450
  </div>
377
- HTML
378
- end
451
+ S
452
+ end
379
453
 
380
- file 'app/views/devise/mailer/confirmation_instructions.html.erb' do <<-HTML
454
+ file 'app/views/devise/mailer/confirmation_instructions.html.erb' do <<-S
381
455
  <p>Welcome <%= @email %>!</p>
382
456
 
383
457
  <p>You can confirm your account email through the link below:</p>
384
458
 
385
459
  <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
386
- HTML
387
- end
460
+ S
461
+ end
388
462
 
389
- file 'app/views/devise/mailer/reset_password_instructions.html.erb' do <<-HTML
463
+ file 'app/views/devise/mailer/reset_password_instructions.html.erb' do <<-S
390
464
  <p>Hello <%= @resource.email %>!</p>
391
465
 
392
466
  <p>Someone has requested a link to change your password. You can do this through the link below.</p>
@@ -395,10 +469,10 @@ file 'app/views/devise/mailer/reset_password_instructions.html.erb' do <<-HTML
395
469
 
396
470
  <p>If you didn't request this, please ignore this email.</p>
397
471
  <p>Your password won't change until you access the link above and create a new one.</p>
398
- HTML
399
- end
472
+ S
473
+ end
400
474
 
401
- file 'app/views/devise/mailer/unlock_instructions.html.erb' do <<-HTML
475
+ file 'app/views/devise/mailer/unlock_instructions.html.erb' do <<-S
402
476
  <p>Hello <%= @resource.email %>!</p>
403
477
 
404
478
  <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
@@ -406,10 +480,10 @@ file 'app/views/devise/mailer/unlock_instructions.html.erb' do <<-HTML
406
480
  <p>Click the link below to unlock your account:</p>
407
481
 
408
482
  <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
409
- HTML
410
- end
483
+ S
484
+ end
411
485
 
412
- file 'app/views/devise/passwords/edit.html.erb' do <<-HTML
486
+ file 'app/views/devise/passwords/edit.html.erb' do <<-S
413
487
  <%
414
488
  title 'Change your password'
415
489
  meta_description '...'
@@ -438,10 +512,10 @@ file 'app/views/devise/passwords/edit.html.erb' do <<-HTML
438
512
  <%= render 'devise/shared/links' %>
439
513
  </div>
440
514
  </div>
441
- HTML
442
- end
515
+ S
516
+ end
443
517
 
444
- file 'app/views/devise/passwords/new.html.erb' do <<-HTML
518
+ file 'app/views/devise/passwords/new.html.erb' do <<-S
445
519
  <%
446
520
  title 'Forgot your password?'
447
521
  meta_description '...'
@@ -468,10 +542,10 @@ file 'app/views/devise/passwords/new.html.erb' do <<-HTML
468
542
  <%= render 'devise/shared/links' %>
469
543
  </div>
470
544
  </div>
471
- HTML
472
- end
545
+ S
546
+ end
473
547
 
474
- file 'app/views/devise/registrations/edit.html.erb' do <<-HTML
548
+ file 'app/views/devise/registrations/edit.html.erb' do <<-S
475
549
  <%
476
550
  title 'Edit your account'
477
551
  meta_description '...'
@@ -522,10 +596,10 @@ file 'app/views/devise/registrations/edit.html.erb' do <<-HTML
522
596
  </p>
523
597
  </div>
524
598
  </div>
525
- HTML
526
- end
599
+ S
600
+ end
527
601
 
528
- file 'app/views/devise/registrations/new.html.erb' do <<-HTML
602
+ file 'app/views/devise/registrations/new.html.erb' do <<-S
529
603
  <%
530
604
  title 'Register a new account'
531
605
  meta_description '...'
@@ -557,10 +631,10 @@ file 'app/views/devise/registrations/new.html.erb' do <<-HTML
557
631
  <%= render 'devise/shared/links' %>
558
632
  </div>
559
633
  </div>
560
- HTML
561
- end
634
+ S
635
+ end
562
636
 
563
- file 'app/views/devise/sessions/new.html.erb' do <<-HTML
637
+ file 'app/views/devise/sessions/new.html.erb' do <<-S
564
638
  <%
565
639
  title 'Sign in'
566
640
  meta_description '...'
@@ -600,10 +674,10 @@ file 'app/views/devise/sessions/new.html.erb' do <<-HTML
600
674
  <%= render 'devise/shared/links' %>
601
675
  </div>
602
676
  </div>
603
- HTML
604
- end
677
+ S
678
+ end
605
679
 
606
- file 'app/views/devise/unlocks/new.html.erb' do <<-HTML
680
+ file 'app/views/devise/unlocks/new.html.erb' do <<-S
607
681
  <%
608
682
  title 'Re-send unlock instructions'
609
683
  meta_description '...'
@@ -630,10 +704,10 @@ file 'app/views/devise/unlocks/new.html.erb' do <<-HTML
630
704
  <%= render 'devise/shared/links' %>
631
705
  </div>
632
706
  </div>
633
- HTML
634
- end
707
+ S
708
+ end
635
709
 
636
- file 'app/views/devise/shared/_links.html.erb' do <<-'HTML'
710
+ file 'app/views/devise/shared/_links.html.erb' do <<-'S'
637
711
  <%= content_tag(:h4, 'Or do something else') if controller_name != 'sessions' %>
638
712
  <ul>
639
713
  <%- if controller_name != 'sessions' %>
@@ -672,19 +746,15 @@ file 'app/views/devise/shared/_links.html.erb' do <<-'HTML'
672
746
  <% end -%>
673
747
  <% end -%>
674
748
  </ul>
675
- HTML
749
+ S
750
+ end
751
+ git_commit 'Add devise views'
676
752
  end
677
753
 
678
- git add: '-A'
679
- git commit: "-m 'Add the devise views'"
680
-
681
- # ----- Modify the layout files ------------------------------------------------------------------------
682
-
683
- puts
684
- say_status 'views', 'Modifying the layout files...', :yellow
685
- puts '-'*80, ''; sleep 0.25
754
+ def add_auth_links_to_the_navbar
755
+ log_task __method__
686
756
 
687
- file 'app/views/layouts/_navigation_auth.html.erb', <<-HTML
757
+ file 'app/views/layouts/_navigation_auth.html.erb', <<-S
688
758
  <% if current_account %>
689
759
  <li>
690
760
  <%= link_to 'Settings', edit_account_registration_path %>
@@ -700,152 +770,54 @@ file 'app/views/layouts/_navigation_auth.html.erb', <<-HTML
700
770
  <%= link_to 'Register', new_account_registration_path %>
701
771
  </li>
702
772
  <% end %>
703
- HTML
773
+ S
704
774
 
705
- inject_into_file 'app/views/layouts/_navigation.html.erb', after: "</ul>\n" do <<-CODE
775
+ inject_into_file 'app/views/layouts/_navigation.html.erb', after: "</ul>\n" do <<-S
706
776
  <ul class="nav navbar-nav nav-auth">
707
777
  <%= render 'layouts/navigation_auth' %>
708
778
  </ul>
709
- CODE
710
- end
779
+ S
780
+ end
711
781
 
712
- append_file 'app/assets/stylesheets/application.css.scss' do <<-CODE
782
+ append_file 'app/assets/stylesheets/application.css.scss' do <<-S
713
783
 
714
784
  @media (min-width: $screen-sm) {
715
785
  .nav-auth {
716
786
  float: right;
717
787
  }
718
788
  }
719
- CODE
720
- end
721
-
722
- git add: '-A'
723
- git commit: "-m 'Add account management links to the layout and add the necessary css selectors'"
724
-
725
- # ----- Modify the .env file --------------------------------------------------------------------------
726
-
727
- puts
728
- say_status 'root', 'Modifying the .env file...', :yellow
729
- puts '-'*80, ''; sleep 0.25
730
-
731
- inject_into_file '.env', before: "\nSMTP_ADDRESS" do <<-CODE
732
- TOKEN_DEVISE_SECRET: #{generate_token}
733
- TOKEN_DEVISE_PEPPER: #{generate_token}
734
- CODE
735
- end
736
-
737
- inject_into_file '.env', before: "\nDATABASE_NAME" do <<-CODE
738
- ACTION_MAILER_DEVISE_DEFAULT_FROM: info@#{app_name}.com
739
- CODE
740
- end
741
-
742
- git add: '-A'
743
- git commit: "-m 'Add the devise tokens and default email to the .env file'"
744
-
745
- # ----- Create the config files -----------------------------------------------------------------------
746
-
747
- puts
748
- say_status 'config', 'Creating the devise async initializer...', :yellow
749
- puts '-'*80, ''; sleep 0.25
750
-
751
- file 'config/initializers/devise_async.rb', 'Devise::Async.backend = :sidekiq'
752
- generate 'devise:install'
753
-
754
- git add: '-A'
755
- git commit: "-m 'Add the devise and devise async initializers'"
756
-
757
- # ----- Modify the config files -----------------------------------------------------------------------
758
-
759
- puts
760
- say_status 'config', 'Modifying the devise initializer...', :yellow
761
- puts '-'*80, ''; sleep 0.25
762
-
763
- gsub_file 'config/initializers/devise.rb',
764
- "'please-change-me-at-config-initializers-devise@example.com'", "ENV['ACTION_MAILER_DEVISE_DEFAULT_EMAIL']"
765
- gsub_file 'config/initializers/devise.rb', /(?<=key = )'\w{128}'/, "ENV['TOKEN_DEVISE_SECRET']"
766
- gsub_file 'config/initializers/devise.rb', /(?<=pepper = )'\w{128}'/, "ENV['TOKEN_DEVISE_PEPPER']"
767
-
768
- gsub_file 'config/initializers/devise.rb', '# config.timeout_in = 30.minutes',
769
- 'config.timeout_in = 2.hours'
770
-
771
- gsub_file 'config/initializers/devise.rb', '# config.expire_auth_token_on_timeout = false',
772
- 'config.expire_auth_token_on_timeout = true'
773
-
774
- gsub_file 'config/initializers/devise.rb', '# config.lock_strategy = :failed_attempts',
775
- 'config.lock_strategy = :failed_attempts'
776
-
777
- gsub_file 'config/initializers/devise.rb', '# config.unlock_strategy = :both',
778
- 'config.unlock_strategy = :both'
779
-
780
- gsub_file 'config/initializers/devise.rb', '# config.maximum_attempts = 20',
781
- 'config.maximum_attempts = 7'
782
-
783
- gsub_file 'config/initializers/devise.rb', '# config.unlock_in = 1.hour',
784
- 'config.unlock_in = 2.hours'
785
-
786
- gsub_file 'config/initializers/devise.rb', '# config.last_attempt_warning = false',
787
- 'config.last_attempt_warning = true'
788
-
789
- git add: '-A'
790
- git commit: "-m 'Change the devise initializer default values'"
791
-
792
- # ----- Modify the routes file ------------------------------------------------------------------------
793
-
794
- puts
795
- say_status 'config', 'Modifying the routes file...', :yellow
796
- puts '-'*80, ''; sleep 0.25
797
-
798
- inject_into_file 'config/routes.rb', after: "collection\n end\n" do <<-CODE
799
-
800
- # disable users from being able to register by uncommenting the lines below
801
- # get 'accounts/sign_up(.:format)', to: redirect('/')
802
- # post 'accounts(.:format)', to: redirect('/')
803
-
804
- # disable users from deleting their own account by uncommenting the line below
805
- # delete 'accounts(.:format)', to: redirect('/')
806
-
807
- devise_for :accounts
808
-
809
- authenticate :account, lambda { |account| account.is?(:admin) } do
810
- mount Sidekiq::Web => '/sidekiq'
789
+ S
811
790
  end
812
-
813
- CODE
814
- end
815
-
816
- git add: '-A'
817
- git commit: "-m 'Add devise to the routes file'"
818
-
819
- # ----- Add pundit support ----------------------------------------------------------------------------
820
-
821
- puts
822
- say_status 'root', 'Adding pundit support...', :yellow
823
- puts '-'*80, ''; sleep 0.25
824
-
825
- generate 'pundit:install'
826
-
827
- git add: '-A'
828
- git commit: "-m 'Add pundit application policy'"
829
-
830
- inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-'CODE'
831
- include Pundit
832
-
833
- CODE
834
- end
835
-
836
- inject_into_file 'app/controllers/application_controller.rb', after: ":exception\n" do <<-'CODE'
837
-
838
- rescue_from Pundit::NotAuthorizedError, with: :account_not_authorized
839
- CODE
840
- end
841
-
842
- inject_into_file 'app/controllers/application_controller.rb', after: " #end\n" do <<-'CODE'
843
-
844
- def account_not_authorized
845
- redirect_to request.headers['Referer'] || root_path, flash: { error: I18n.t('authorization.error') }
846
- end
847
- CODE
848
- end
849
-
850
- git add: '-A'
851
- git commit: "-m 'Add pundit logic to the application controller'"
791
+ git_commit 'Add authentication links to the layout'
792
+ end
793
+
794
+ def remove_unused_files_from_git
795
+ log_task __method__
796
+
797
+ git add: '-u'
798
+ git_commit 'Remove unused files'
799
+ end
800
+
801
+ # ---
802
+
803
+ delete_app_css
804
+ update_gemfile
805
+ update_dotenv
806
+ run_bundle_install
807
+ add_pundit
808
+ add_devise_initializers
809
+ update_devise_initializer
810
+ update_sidekiq_config
811
+ update_routes
812
+ add_en_locale_for_authorization
813
+ add_devise_migration
814
+ add_account_model
815
+ add_seed_user
816
+ update_test_helper
817
+ add_account_fixtures
818
+ add_account_unit_tests
819
+ add_current_user_alias
820
+ add_devise_controller_override
821
+ add_devise_views
822
+ add_auth_links_to_the_navbar
823
+ remove_unused_files_from_git