From 93d2cd6a5d4435ab972dd21abc74f1ba63864815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Sat, 4 Mar 2017 16:24:37 -0300 Subject: [PATCH 1/8] Improves --- app/assets/javascripts/orders.js.coffee | 4 +- test/integration/articles_test.rb | 6 -- .../private_customer_interactions_test.rb | 13 +-- test/test_helper.rb | 96 +++++++++---------- vagrant_script.sh | 8 ++ 5 files changed, 57 insertions(+), 70 deletions(-) diff --git a/app/assets/javascripts/orders.js.coffee b/app/assets/javascripts/orders.js.coffee index cb38dcf4..39a5dc08 100644 --- a/app/assets/javascripts/orders.js.coffee +++ b/app/assets/javascripts/orders.js.coffee @@ -127,7 +127,7 @@ new Rule State.fileUploaded = false $(this).preventDefault() - $(document).on 'click', '.skip-file-warning', @map.skipFileWarning + #$(document).on 'click', '.skip-file-warning', @map.skipFileWarning $(document).on 'ajax:success', 'a.details-link', @map.showDocumentDetails $(document).on 'item.removed', @map.removeItem $(document).on 'change keyup', '.price-modifier, .page-modifier, .file_line_item', @@ -135,7 +135,7 @@ new Rule $(document).on 'click', 'a[data-action="print"]', @map.print unload: -> - $(document).off 'click', '.skip-file-warning', @map.skipFileWarning + #$(document).off 'click', '.skip-file-warning', @map.skipFileWarning $(document).off 'ajax:success', 'a.details-link', @map.showDocumentDetails $(document).off 'item.removed', @map.removeItem $(document).off 'change keyup', '.price-modifier, .page-modifier, .file_line', diff --git a/test/integration/articles_test.rb b/test/integration/articles_test.rb index 01206baa..4aef627c 100644 --- a/test/integration/articles_test.rb +++ b/test/integration/articles_test.rb @@ -3,9 +3,6 @@ class ArticlesTest < ActionDispatch::IntegrationTest test 'should create an article' do login - - assert_page_has_no_errors! - assert_equal prints_path, current_path visit new_article_path assert_page_has_no_errors! @@ -28,9 +25,6 @@ class ArticlesTest < ActionDispatch::IntegrationTest test 'should delete an article' do login - - assert_page_has_no_errors! - assert_equal prints_path, current_path visit articles_path assert_page_has_no_errors! diff --git a/test/integration/private_customer_interactions_test.rb b/test/integration/private_customer_interactions_test.rb index e617f64c..cadcad96 100644 --- a/test/integration/private_customer_interactions_test.rb +++ b/test/integration/private_customer_interactions_test.rb @@ -210,15 +210,12 @@ class PrivateCustomerInteractionsTest < ActionDispatch::IntegrationTest assert page.has_no_css?('a.add_from_order') end - sleep 2 - within '.nav-collapse' do click_link I18n.t('view.catalog.new_order') - end - sleep 2 - assert_equal new_order_path, current_path - assert_page_has_no_errors! + assert_page_has_no_errors! + assert_equal new_order_path, current_path + end page.all 'div.order_line', count: tag.reload.documents_count end @@ -233,8 +230,6 @@ def customer_login(options = {}) visit new_customer_session_path - assert_page_has_no_errors! - customers(options[:customer_id]).tap do |customer| fill_in I18n.t('authlogic.attributes.customer_session.email'), with: customer.email @@ -246,7 +241,5 @@ def customer_login(options = {}) assert_page_has_no_errors! assert_equal options[:expected_path], current_path - - show_collapse_menu_if_needed end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 49c251b9..2d8b8a7e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,7 +7,7 @@ require 'database_cleaner' require 'minitest/reporters' require 'capybara-screenshot/minitest' -require 'capybara/poltergeist' +# require 'capybara/poltergeist' Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new @@ -104,33 +104,18 @@ class ActiveSupport::TestCase setup :activate_authlogic end -SELENIUM_SERVER = "192.168.33.10" -SELENIUM_APP_HOST = "192.168.33.1" -Capybara.javascript_driver = :selenium_remote_firefox +class JSException < Exception + attr_reader :msgs -# CapybaraDriverRegistrar is a helper class that enables you to easily register -# Capybara drivers -class CapybaraDriverRegistrar - - # register a Selenium driver for the given browser to run on the localhost - def self.register_selenium_local_driver(browser) - Capybara.register_driver "selenium_#{browser}".to_sym do |app| - Capybara::Selenium::Driver.new(app, browser: browser) - end + def initialize(msgs) + @msgs = msgs end - # register a Selenium driver for the given browser to run with a Selenium - # Server on another host - def self.register_selenium_remote_driver(browser) - Capybara.register_driver "selenium_remote_#{browser}".to_sym do |app| - Capybara::Selenium::Driver.new(app, browser: :remote, url: "http://#{SELENIUM_SERVER}:4444/wd/hub", desired_capabilities: browser) - end + def to_s + "Js issue: \n #{msgs.join("\n")}" end end -# Register various Selenium drivers -CapybaraDriverRegistrar.register_selenium_remote_driver(:firefox) - class ActionDispatch::IntegrationTest # Make the Capybara DSL available in all integration tests include Capybara::DSL @@ -143,41 +128,44 @@ class ActionDispatch::IntegrationTest # Stop ActiveRecord from wrapping tests in transactions self.use_transactional_fixtures = false - #Capybara.register_driver :chrome do |app| - # Capybara::Selenium::Driver.new(app, :browser => :chrome) - #end - #Capybara::Screenshot.webkit_options = { width: 1024, height: 768 } - #Capybara::Screenshot.class_eval do - # register_driver(:chrome) do |driver, path| - # driver.browser.save_screenshot(path) - # end - #end + # Vagrant config + SELENIUM_SERVER = "192.168.33.10" + SELENIUM_APP_HOST = "192.168.33.1" + + Capybara.register_driver :selenium_remote_firefox do |app| + Capybara::Selenium::Driver.new( + app, + browser: :remote, + url: "http://#{SELENIUM_SERVER}:4444/wd/hub", + desired_capabilities: :firefox + ) + end + + _running_local = ENV['local'] + Capybara.javascript_driver = _running_local ? :selenium : :selenium_remote_firefox #:selenium #: :chrome + Capybara.current_driver = Capybara.javascript_driver + Capybara.server_port = '54163' + Capybara.server_host = _running_local ? 'localhost' : '192.168.33.1' + Capybara.app_host = "http://#{SELENIUM_APP_HOST}:#{Capybara.server_port}" + Capybara.default_max_wait_time = 1 - #Capybara.register_driver :selenium_remote_firefox do |app| - # Capybara::Selenium::Driver.new( - # app, browser: :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: :firefox - # ) - #end + if _running_local + Selenium::WebDriver::Firefox::Binary.path = '/opt/firefox42/firefox' + end setup do - Capybara.javascript_driver = :selenium_remote_firefox #:selenium #: :chrome - Capybara.current_driver = Capybara.javascript_driver - #Capybara.run_server = false - Capybara.server_port = '54163' - Capybara.server_host = '192.168.33.1' - Capybara.app_host = "http://#{SELENIUM_APP_HOST}:#{Capybara.server_port}" Capybara.reset! # Forget the (simulated) browser state - Capybara.default_max_wait_time = 4 - #Capybara.page.current_window.resize_to(1200, 800) + Capybara.page.driver.browser.manage.window.maximize end teardown do - #errors = Capybara.page.driver.browser.manage.logs.get(:browser) - #if errors.present? - # message = errors.map(&:message).join("\n") - # puts message - #end + errors = Capybara.page.driver.browser.manage.logs.get(:browser) + + if errors + parsed_errors = errors.map { |e| e if e.level == 'SEVERE' && message.present? }.compact + raise JSException.new(parsed_errors) if parsed_errors.size > 0 + end DatabaseCleaner.clean # Truncate the database Capybara.reset! # Forget the (simulated) browser state @@ -206,8 +194,6 @@ def login(*args) visit new_user_session_path - assert_page_has_no_errors! - User.find(options[:user_id]).tap do |user| fill_in I18n.t('authlogic.attributes.user_session.username'), with: user.email @@ -219,7 +205,13 @@ def login(*args) assert_page_has_no_errors! assert_equal options[:expected_path], current_path + end + + def log_js_errors + errors = page.driver.browser.manage.logs.get(:browser) + return unless errors - show_collapse_menu_if_needed + parsed_errors = errors.map { |e| e if e.level == 'SEVERE' && message.present? }.compact + raise JSException.new(parsed_errors) if parsed_errors end end diff --git a/vagrant_script.sh b/vagrant_script.sh index f1fa1d2b..b16a41af 100755 --- a/vagrant_script.sh +++ b/vagrant_script.sh @@ -95,6 +95,14 @@ echo -n "Add host alias..." echo "192.168.33.1 host" >> /etc/hosts echo "ok" +#========================================================= +echo -n "Making rotsen & Cloning printHub" +#========================================================= +sudo mkdir -p /home/rotsen/rails/ +sudo chown vagrant -R /home/rotsen/ +cd /home/rotsen/rails +git clone --depth 1 https://github.com/Shelvak/print_hub + #========================================================= echo "Reboot the VM" #========================================================= From f09b1965cdbf885b668751eb53c7f39c8099238f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Sat, 4 Mar 2017 17:22:29 -0300 Subject: [PATCH 2/8] Devise part 1 --- Gemfile | 3 +- Gemfile.lock | 25 +- app/controllers/application_controller.rb | 16 - app/views/devise/confirmations/new.html.erb | 16 + .../mailer/confirmation_instructions.html.erb | 5 + .../devise/mailer/password_change.html.erb | 3 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + app/views/devise/passwords/edit.html.erb | 19 ++ app/views/devise/passwords/new.html.erb | 15 + app/views/devise/registrations/edit.html.erb | 27 ++ app/views/devise/registrations/new.html.erb | 17 ++ app/views/devise/sessions/new.html.erb | 15 + app/views/devise/shared/_links.html.erb | 25 ++ app/views/devise/unlocks/new.html.erb | 16 + config/initializers/devise.rb | 274 ++++++++++++++++++ config/locales/devise.en.yml | 62 ++++ ...0170304192533_authlogic_users_to_devise.rb | 48 +++ ...0304195401_authlogic_customer_to_devise.rb | 51 ++++ db/schema.rb | 52 ++-- 20 files changed, 657 insertions(+), 47 deletions(-) create mode 100644 app/views/devise/confirmations/new.html.erb create mode 100644 app/views/devise/mailer/confirmation_instructions.html.erb create mode 100644 app/views/devise/mailer/password_change.html.erb create mode 100644 app/views/devise/mailer/reset_password_instructions.html.erb create mode 100644 app/views/devise/mailer/unlock_instructions.html.erb create mode 100644 app/views/devise/passwords/edit.html.erb create mode 100644 app/views/devise/passwords/new.html.erb create mode 100644 app/views/devise/registrations/edit.html.erb create mode 100644 app/views/devise/registrations/new.html.erb create mode 100644 app/views/devise/sessions/new.html.erb create mode 100644 app/views/devise/shared/_links.html.erb create mode 100644 app/views/devise/unlocks/new.html.erb create mode 100644 config/initializers/devise.rb create mode 100644 config/locales/devise.en.yml create mode 100644 db/migrate/20170304192533_authlogic_users_to_devise.rb create mode 100644 db/migrate/20170304195401_authlogic_customer_to_devise.rb diff --git a/Gemfile b/Gemfile index dc863221..a90b026b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,8 @@ source 'https://rubygems.org' gem 'rails', '4.2.6' gem 'pg' -gem 'authlogic' +# gem 'authlogic' +gem 'devise' gem 'jc-validates_timeliness' gem 'awesome_nested_set' gem 'will_paginate' diff --git a/Gemfile.lock b/Gemfile.lock index c3b950a5..c5b5237f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,11 +46,6 @@ GEM archive-zip (0.7.0) io-like (~> 0.3.0) arel (6.0.3) - authlogic (3.4.6) - activerecord (>= 3.2) - activesupport (>= 3.2) - request_store (~> 1.0) - scrypt (>= 1.2, < 3.0) autoparse (0.3.3) addressable (>= 2.3.1) extlib (>= 0.9.15) @@ -59,6 +54,7 @@ GEM activerecord (>= 4.0.0, < 5.1) awesome_print (1.7.0) barby (0.6.4) + bcrypt (3.1.11) bugsnag (4.2.1) builder (3.2.2) byebug (9.0.5) @@ -114,6 +110,12 @@ GEM cups (0.1.10) daemons (1.2.3) database_cleaner (1.5.3) + devise (4.2.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) erubis (2.7.0) eventmachine (1.2.0.1) execjs (2.7.0) @@ -121,9 +123,6 @@ GEM faraday (0.9.2) multipart-post (>= 1.2, < 3) ffi (1.9.10) - ffi-compiler (0.1.3) - ffi (>= 1.0.0) - rake get_process_mem (0.2.1) globalid (0.3.6) activesupport (>= 4.1.0) @@ -213,6 +212,7 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) + orm_adapter (0.5.0) os (0.9.6) paper_trail (5.2.0) activerecord (>= 3.0, < 6.0) @@ -263,6 +263,8 @@ GEM rake (11.2.2) redis (3.3.0) request_store (1.3.1) + responders (2.3.0) + railties (>= 4.2.0, < 5.1) retriable (1.4.1) rghost (0.9.6) rqrcode (0.10.1) @@ -277,9 +279,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - scrypt (2.1.1) - ffi-compiler (>= 0.0.2) - rake selenium-webdriver (2.53.3) childprocess (~> 0.5) rubyzip (~> 1.0) @@ -335,6 +334,8 @@ GEM unicorn-worker-killer (0.4.4) get_process_mem (~> 0) unicorn (>= 4, < 6) + warden (1.2.7) + rack (>= 1.0) websocket (1.2.3) websocket-driver (0.6.4) websocket-extensions (>= 0.1.0) @@ -350,7 +351,6 @@ PLATFORMS DEPENDENCIES RedCloth - authlogic awesome_nested_set awesome_print barby @@ -368,6 +368,7 @@ DEPENDENCIES coffee-rails cups database_cleaner + devise google_drive (= 1.0.6) interactive_editor jc-validates_timeliness diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3aa00cb1..c1a7338b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,22 +47,6 @@ def add_user_info_to_bugsnag(notif) end end - def current_customer_session - @current_customer_session ||= CustomerSession.find - end - - def current_customer - @current_customer ||= current_customer_session && current_customer_session.record - end - - def current_user_session - @current_user_session ||= UserSession.find - end - - def current_user - @current_user ||= current_user_session && current_user_session.record - end - def user_for_paper_trail current_user.try(:id) end diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 00000000..949b1727 --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :confirmation_token %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 00000000..b41daf47 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 00000000..a938930b --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,19 @@ +

Change your password

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + + <%= f.input :reset_password_token, as: :hidden %> + <%= f.full_error :reset_password_token %> + +
+ <%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> + <%= f.input :password_confirmation, label: "Confirm your new password", required: true %> +
+ +
+ <%= f.button :submit, "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 00000000..d1503e76 --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,15 @@ +

Forgot your password?

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Send me reset password instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 00000000..5db350b5 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,27 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +

Currently waiting confirmation for: <%= resource.unconfirmed_email %>

+ <% end %> + + <%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %> + <%= f.input :password_confirmation, required: false %> + <%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %> +
+ +
+ <%= f.button :submit, "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 00000000..34b4279e --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,17 @@ +

Sign up

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> + <%= f.input :password_confirmation, required: true %> +
+ +
+ <%= f.button :submit, "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 00000000..31f8a4d4 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,15 @@ +

Log in

+ +<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.input :email, required: false, autofocus: true %> + <%= f.input :password, required: false %> + <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %> +
+ +
+ <%= f.button :submit, "Log in" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 00000000..e6a3e419 --- /dev/null +++ b/app/views/devise/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 00000000..788f62e9 --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :unlock_token %> + +
+ <%= f.input :email, required: true, autofocus: true %> +
+ +
+ <%= f.button :submit, "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 00000000..758233c5 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,274 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = 'bc2669e02c8d691af8d616988029515f9ece4ca647ea8831323466d13dc146368d6ea5cd60b9a5dc4116673c70bc0169406bf5c365125db76b7c813a33533aac' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 11 + + # Set up a pepper to generate the hashed password. + # config.pepper = '93b2d1e623477421887577755a5603c40159c1451bf25ddecd14cb5f31a934ff2a841617dc828fb44e84247be3cc12969d6d2834103c20553b9e01446b7e4e0c' + + # Send a notification email when the user's password is changed + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 00000000..bd4c3ebc --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,62 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/db/migrate/20170304192533_authlogic_users_to_devise.rb b/db/migrate/20170304192533_authlogic_users_to_devise.rb new file mode 100644 index 00000000..d3ff75dc --- /dev/null +++ b/db/migrate/20170304192533_authlogic_users_to_devise.rb @@ -0,0 +1,48 @@ +class AuthlogicUsersToDevise < ActiveRecord::Migration + def up + add_column :users, :confirmation_token, :string, limit: 255 + add_column :users, :confirmed_at, :timestamp + add_column :users, :confirmation_sent_at, :timestamp + add_column :users, :unconfirmed_email, :string + + execute "UPDATE users SET confirmed_at = created_at, confirmation_sent_at = created_at" + + add_column :users, :reset_password_token, :string, limit: 255 + add_column :users, :reset_password_sent_at, :timestamp + add_column :users, :remember_token, :string, limit: 255 + add_column :users, :remember_created_at, :timestamp + add_column :users, :unlock_token, :string, limit: 255 + add_column :users, :locked_at, :timestamp + add_column :users, :sign_in_count, :integer + + rename_column :users, :crypted_password, :encrypted_password + + remove_column :users, :persistence_token + + add_index :users, :confirmation_token, unique: true + add_index :users, :reset_password_token, unique: true + add_index :users, :unlock_token, unique: true + end + def down + remove_column :users, :confirmation_token + remove_column :users, :confirmed_at + remove_column :users, :confirmation_sent_at + remove_column :users, :unconfirmed_email + remove_column :users, :reset_password_token + remove_column :users, :reset_password_sent_at + remove_column :users, :remember_token + remove_column :users, :remember_created_at + remove_column :users, :unlock_token + remove_column :users, :locked_at + + rename_column :users, :encrypted_password, :crypted_password + rename_column :users, :sign_in_count, :login_count + + add_column :users, :persistence_token, :string + add_column :users, :single_access_token, :string + + remove_index :users, :confirmation_token + remove_index :users, :reset_password_token + remove_index :users, :unlock_token + end +end diff --git a/db/migrate/20170304195401_authlogic_customer_to_devise.rb b/db/migrate/20170304195401_authlogic_customer_to_devise.rb new file mode 100644 index 00000000..b85d949c --- /dev/null +++ b/db/migrate/20170304195401_authlogic_customer_to_devise.rb @@ -0,0 +1,51 @@ +class AuthlogicCustomerToDevise < ActiveRecord::Migration + def up + add_column :customers, :confirmation_token, :string, limit: 255 + add_column :customers, :confirmed_at, :timestamp + add_column :customers, :confirmation_sent_at, :timestamp + add_column :customers, :unconfirmed_email, :string + + execute "UPDATE customers SET confirmed_at = created_at, confirmation_sent_at = created_at" + + add_column :customers, :reset_password_token, :string, limit: 255 + add_column :customers, :reset_password_sent_at, :timestamp + add_column :customers, :remember_token, :string, limit: 255 + add_column :customers, :remember_created_at, :timestamp + add_column :customers, :unlock_token, :string, limit: 255 + add_column :customers, :locked_at, :timestamp + add_column :customers, :sign_in_count, :integer + + rename_column :customers, :crypted_password, :encrypted_password + + remove_column :customers, :persistence_token + remove_column :customers, :perishable_token + + add_index :customers, :confirmation_token, unique: true + add_index :customers, :reset_password_token, unique: true + add_index :customers, :unlock_token, unique: true + end + + def down + # remove_column :customers, :confirmation_token + remove_column :customers, :confirmed_at + remove_column :customers, :confirmation_sent_at + remove_column :customers, :unconfirmed_email + remove_column :customers, :reset_password_token + remove_column :customers, :reset_password_sent_at + remove_column :customers, :remember_token + remove_column :customers, :remember_created_at + remove_column :customers, :unlock_token + remove_column :customers, :locked_at + + rename_column :customers, :encrypted_password, :crypted_password + rename_column :customers, :sign_in_count, :login_count + + add_column :customers, :persistence_token, :string + add_column :customers, :perishable_token, :string + add_column :customers, :single_access_token, :string + + # remove_index :customers, :confirmation_token + # remove_index :customers, :reset_password_token + # remove_index :customers, :unlock_token + end +end diff --git a/db/schema.rb b/db/schema.rb index 20a39eeb..94d69bd6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160914003737) do +ActiveRecord::Schema.define(version: 20170304192533) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -70,17 +70,20 @@ t.string "email", limit: 255 t.string "crypted_password", limit: 255 t.string "password_salt", limit: 255 - t.string "persistence_token", limit: 255 - t.string "perishable_token", limit: 255 t.boolean "enable", default: true t.string "kind", limit: 1, default: "n", null: false t.integer "group_id" + t.string "confirmation_token", limit: 255 + t.integer "login_count" + t.string "persistence_token" + t.string "perishable_token" + t.string "single_access_token" end + add_index "customers", ["confirmation_token"], name: "index_customers_on_confirmation_token", unique: true, using: :btree add_index "customers", ["email"], name: "index_customers_on_email", unique: true, using: :btree add_index "customers", ["enable"], name: "index_customers_on_enable", using: :btree add_index "customers", ["identification"], name: "index_customers_on_identification", unique: true, using: :btree - add_index "customers", ["perishable_token"], name: "index_customers_on_perishable_token", using: :btree create_table "customers_groups", force: :cascade do |t| t.string "name", limit: 255, null: false @@ -321,29 +324,42 @@ add_index "tags", ["private"], name: "index_tags_on_private", using: :btree create_table "users", force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "last_name", limit: 255, null: false - t.string "language", limit: 255, null: false - t.string "email", limit: 255, null: false - t.string "username", limit: 255, null: false - t.string "crypted_password", limit: 255, null: false - t.string "password_salt", limit: 255, null: false - t.string "persistence_token", limit: 255, null: false - t.boolean "admin", default: false, null: false + t.string "name", limit: 255, null: false + t.string "last_name", limit: 255, null: false + t.string "language", limit: 255, null: false + t.string "email", limit: 255, null: false + t.string "username", limit: 255, null: false + t.string "encrypted_password", limit: 255, null: false + t.string "password_salt", limit: 255, null: false + t.boolean "admin", default: false, null: false t.boolean "enable" - t.integer "lock_version", default: 0 + t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" - t.string "default_printer", limit: 255 - t.string "avatar_file_name", limit: 255 - t.string "avatar_content_type", limit: 255 + t.string "default_printer", limit: 255 + t.string "avatar_file_name", limit: 255 + t.string "avatar_content_type", limit: 255 t.integer "avatar_file_size" t.datetime "avatar_updated_at" t.integer "lines_per_page" - t.boolean "not_shifted", default: false + t.boolean "not_shifted", default: false + t.string "confirmation_token", limit: 255 + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.string "reset_password_token", limit: 255 + t.datetime "reset_password_sent_at" + t.string "remember_token", limit: 255 + t.datetime "remember_created_at" + t.string "unlock_token", limit: 255 + t.datetime "locked_at" + t.integer "sign_in_count" end + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_index "users", ["unlock_token"], name: "index_users_on_unlock_token", unique: true, using: :btree add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree create_table "versions", force: :cascade do |t| From e2e4fb8806967eece12c600663d907f300cf5d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Wed, 12 Sep 2018 22:21:24 -0300 Subject: [PATCH 3/8] Update --- Gemfile | 4 +- Gemfile.lock | 283 +++++++++--------- .../initializers/carrierwave_backgrounder.rb | 5 - db/schema.rb | 211 ++++--------- 4 files changed, 210 insertions(+), 293 deletions(-) diff --git a/Gemfile b/Gemfile index 3efdfcd7..cbd6ca45 100644 --- a/Gemfile +++ b/Gemfile @@ -18,8 +18,8 @@ gem 'cups' gem 'simple_form' # Files Processors -gem 'carrierwave' -gem 'carrierwave_backgrounder' +gem 'carrierwave', '~> 0.11.2' +gem 'carrierwave_backgrounder', '~> 0.4.2' gem 'mini_magick', '3.8.1' gem 'rghost' #Could make it happen only with carrierwave gem 'pdf-reader' diff --git a/Gemfile.lock b/Gemfile.lock index cb1c5979..e6728327 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,47 +1,43 @@ GEM remote: https://rubygems.org/ specs: - Ascii85 (1.0.3) + Ascii85 (1.0.2) RedCloth (4.3.2) - actioncable (5.2.1) - actionpack (= 5.2.1) + actioncable (5.1.4) + actionpack (= 5.1.4) nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1) - actionview (= 5.2.1) - activesupport (= 5.2.1) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1) - activesupport (= 5.2.1) + actionview (5.1.4) + activesupport (= 5.1.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.1) - activesupport (= 5.2.1) + activejob (5.1.4) + activesupport (= 5.1.4) globalid (>= 0.3.6) - activemodel (5.2.1) - activesupport (= 5.2.1) - activerecord (5.2.1) - activemodel (= 5.2.1) - activesupport (= 5.2.1) - arel (>= 9.0) - activestorage (5.2.1) - actionpack (= 5.2.1) - activerecord (= 5.2.1) - marcel (~> 0.3.1) - activesupport (5.2.1) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) + i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.5.2) @@ -49,20 +45,19 @@ GEM afm (0.2.2) airbrussh (1.3.0) sshkit (>= 1.6.1, != 1.7.0) - archive-zip (0.11.0) + archive-zip (0.7.0) io-like (~> 0.3.0) - arel (9.0.0) - awesome_nested_set (3.1.4) - activerecord (>= 4.0.0, < 5.3) + arel (8.0.0) + awesome_nested_set (3.1.3) + activerecord (>= 4.0.0, < 5.2) awesome_print (1.8.0) - barby (0.6.6) + barby (0.6.5) bcrypt (3.1.12) bcrypt_pbkdf (1.0.0) - bugsnag (6.8.0) - concurrent-ruby (~> 1.0) + bugsnag (6.3.0) builder (3.2.3) - byebug (10.0.2) - capistrano (3.11.0) + byebug (9.1.0) + capistrano (3.10.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -73,31 +68,34 @@ GEM capistrano-chruby (0.1.2) capistrano (~> 3.0) sshkit (~> 1.3) - capistrano-rails (1.4.0) + capistrano-rails (1.3.1) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - capybara (3.7.2) + capybara (2.16.1) addressable mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - xpath (~> 3.1) - capybara-screenshot (1.0.21) - capybara (>= 1.0, < 4) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + capybara-screenshot (1.0.18) + capybara (>= 1.0, < 3) launchy - carrierwave (1.2.3) - activemodel (>= 4.0.0) - activesupport (>= 4.0.0) + carrierwave (0.11.2) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) mime-types (>= 1.16) - carrierwave_backgrounder (0.0.2) - childprocess (0.9.0) + mimemagic (>= 0.3.0) + carrierwave_backgrounder (0.4.2) + carrierwave (~> 0.5) + childprocess (0.8.0) ffi (~> 1.0, >= 1.0.11) - chromedriver-helper (1.2.0) - archive-zip (~> 0.10) - nokogiri (~> 1.8) + chromedriver-helper (1.1.0) + archive-zip (~> 0.7.0) + nokogiri (~> 1.6) chronic (0.10.2) - chunky_png (1.3.10) + chunky_png (1.3.8) cliver (0.3.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -107,11 +105,11 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.0.5) - connection_pool (2.2.2) - crass (1.0.4) + connection_pool (2.2.1) + crass (1.0.3) cups (0.1.10) - daemons (1.2.6) - database_cleaner (1.7.0) + daemons (1.2.5) + database_cleaner (1.6.2) declarative (0.0.10) declarative-option (0.1.0) devise (4.5.0) @@ -121,36 +119,37 @@ GEM responders warden (~> 1.2.3) ed25519 (1.2.4) - erubi (1.7.1) - eventmachine (1.2.7) + erubi (1.7.0) + eventmachine (1.2.5) execjs (2.7.0) - faraday (0.15.2) + faraday (0.13.1) multipart-post (>= 1.2, < 3) - ffi (1.9.25) - get_process_mem (0.2.2) + ffi (1.9.18) + get_process_mem (0.2.1) globalid (0.4.1) activesupport (>= 4.2.0) - google-api-client (0.21.2) + google-api-client (0.13.6) addressable (~> 2.5, >= 2.5.1) - googleauth (>= 0.5, < 0.7.0) + googleauth (~> 0.5) httpclient (>= 2.8.1, < 3.0) mime-types (~> 3.0) representable (~> 3.0) retriable (>= 2.0, < 4.0) - google_drive (2.1.12) - google-api-client (>= 0.11.0, < 0.22.0) + google_drive (2.1.7) + google-api-client (>= 0.11.0, < 0.14.0) googleauth (>= 0.5.0, < 1.0.0) nokogiri (>= 1.5.3, < 2.0.0) - googleauth (0.6.6) + googleauth (0.6.2) faraday (~> 0.12) jwt (>= 1.4, < 3.0) + logging (~> 2.0) memoist (~> 0.12) multi_json (~> 1.11) - os (>= 0.9, < 2.0) + os (~> 0.9) signet (~> 0.7) hashery (2.1.2) httpclient (2.8.3) - i18n (1.1.0) + i18n (0.9.1) concurrent-ruby (~> 1.0) interactive_editor (0.0.11) spoon (>= 0.0.1) @@ -161,85 +160,87 @@ GEM actionpack (>= 3.1) railties (>= 3.1) sass (>= 3.2) - jquery-rails (4.3.3) + jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) + json (2.1.0) jwt (2.1.0) - kgio (2.11.2) + kgio (2.11.1) launchy (2.4.3) addressable (~> 2.3) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.2.2) + little-plugger (1.1.4) + logging (2.2.2) + little-plugger (~> 1.1) + multi_json (~> 1.10) + loofah (2.1.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.0) mini_mime (>= 0.1.1) - marcel (0.3.2) - mimemagic (~> 0.3.2) memoist (0.16.0) method_source (0.9.0) - mime-types (3.2.2) + mime-types (3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2018.0812) + mime-types-data (3.2016.0521) mimemagic (0.3.2) mini_magick (3.8.1) subexec (~> 0.2.1) - mini_mime (1.0.1) + mini_mime (1.0.0) mini_portile2 (2.3.0) - minitest (5.11.3) - multi_json (1.13.1) + minitest (5.10.3) + multi_json (1.12.2) multipart-post (2.0.0) - mustermann (1.0.3) + mustermann (1.0.1) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (5.0.2) - newrelic_rpm (5.4.0.347) - nio4r (2.3.1) - nokogiri (1.8.4) + net-ssh (5.0.1) + newrelic_rpm (4.6.0.338) + nio4r (2.1.0) + nokogiri (1.8.1) mini_portile2 (~> 2.3.0) orm_adapter (0.5.0) - os (1.0.0) - paper_trail (10.0.1) - activerecord (>= 4.2, < 5.3) + os (0.9.6) + paper_trail (8.1.1) + activerecord (>= 4.2, < 5.2) request_store (~> 1.1) parallel (1.12.1) - parallel_tests (2.22.1) + parallel_tests (2.19.0) parallel - pdf-reader (2.1.0) + pdf-reader (2.0.0) Ascii85 (~> 1.0.0) afm (~> 0.2.1) hashery (~> 2.0) ruby-rc4 ttfunk - pg (1.1.3) - poltergeist (1.18.1) - capybara (>= 2.1, < 4) + pg (0.21.0) + poltergeist (1.17.0) + capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - public_suffix (3.0.3) - rack (2.0.5) - rack-protection (2.0.3) + public_suffix (3.0.1) + rack (2.0.3) + rack-protection (2.0.0) rack - rack-test (1.1.0) + rack-test (0.8.2) rack (>= 1.0, < 3) - rails (5.2.1) - actioncable (= 5.2.1) - actionmailer (= 5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) - activemodel (= 5.2.1) - activerecord (= 5.2.1) - activestorage (= 5.2.1) - activesupport (= 5.2.1) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) bundler (>= 1.3.0) - railties (= 5.2.1) + railties (= 5.1.4) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) @@ -248,39 +249,38 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.1) - actionpack (= 5.2.1) - activesupport (= 5.2.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.18.1, < 2.0) raindrops (0.19.0) - rake (12.3.1) - rb-fsevent (0.10.3) + rake (12.3.0) + rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - redis (4.0.2) + redis (4.0.1) redis-namespace (1.6.0) redis (>= 3.0.4) representable (3.0.4) declarative (< 0.1.0) declarative-option (< 0.2.0) uber (< 0.2.0) - request_store (1.4.1) - rack (>= 1.4) + request_store (1.3.2) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) - retriable (3.1.2) + retriable (3.1.1) rghost (0.9.6) rqrcode (0.10.1) chunky_png (~> 1.0) ruby-rc4 (0.1.5) ruby_dep (1.5.0) - rubyzip (1.2.2) - sass (3.5.7) + rubyzip (1.2.1) + sass (3.5.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -295,33 +295,34 @@ GEM childprocess (~> 0.5) rubyzip (~> 1.0) websocket (~> 1.0) - sidekiq (5.2.1) - connection_pool (~> 2.2, >= 2.2.2) + sidekiq (5.0.5) + concurrent-ruby (~> 1.0) + connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) - redis (>= 3.3.5, < 5) - signet (0.9.1) + redis (>= 3.3.4, < 5) + signet (0.8.1) addressable (~> 2.3) faraday (~> 0.9) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simple_form (4.0.1) - actionpack (>= 5.0) - activemodel (>= 5.0) - sinatra (2.0.3) + simple_form (3.5.0) + actionpack (> 4, < 5.2) + activemodel (> 4, < 5.2) + sinatra (2.0.0) mustermann (~> 1.0) rack (~> 2.0) - rack-protection (= 2.0.3) + rack-protection (= 2.0.0) tilt (~> 2.0) spoon (0.0.6) ffi - sprockets (3.7.2) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.17.0) + sshkit (1.15.1) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) subexec (0.2.3) @@ -334,13 +335,13 @@ GEM tilt (2.0.8) timeliness (0.3.8) ttfunk (1.5.1) - tzinfo (1.2.5) + tzinfo (1.2.4) thread_safe (~> 0.1) uber (0.1.0) - uglifier (4.1.19) + uglifier (4.0.2) execjs (>= 0.3.0, < 3) underscore-rails (1.8.3) - unicorn (5.4.1) + unicorn (5.3.1) kgio (~> 2.6) raindrops (~> 0.7) unicorn-worker-killer (0.4.4) @@ -348,15 +349,15 @@ GEM unicorn (>= 4, < 6) warden (1.2.7) rack (>= 1.0) - websocket (1.2.8) - websocket-driver (0.7.0) + websocket (1.2.5) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) whenever (0.10.0) chronic (>= 0.6.3) will_paginate (3.1.6) - xpath (3.1.0) - nokogiri (~> 1.8) + xpath (2.1.0) + nokogiri (~> 1.3) PLATFORMS ruby @@ -375,8 +376,8 @@ DEPENDENCIES capistrano-rails capybara capybara-screenshot - carrierwave - carrierwave_backgrounder + carrierwave (~> 0.11.2) + carrierwave_backgrounder (~> 0.4.2) chromedriver-helper chunky_png coffee-rails (~> 4.2) diff --git a/config/initializers/carrierwave_backgrounder.rb b/config/initializers/carrierwave_backgrounder.rb index 9da6264a..7244f05d 100644 --- a/config/initializers/carrierwave_backgrounder.rb +++ b/config/initializers/carrierwave_backgrounder.rb @@ -1,8 +1,3 @@ CarrierWave::Backgrounder.configure do |c| - # c.backend :resque, queue: :carrierwave c.backend :sidekiq, queue: :carrierwave - # c.backend :girl_friday, queue: :carrierwave - # c.backend :sucker_punch, queue: :carrierwave - # c.backend :qu, queue: :carrierwave - # c.backend :qc end diff --git a/db/schema.rb b/db/schema.rb index 4827629e..2e1169bd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(version: 20170304192533) do -======= -ActiveRecord::Schema.define(version: 20180828004548) do ->>>>>>> 607e4763e2f4f01c853275bc9056d6bb131e4861 +ActiveRecord::Schema.define(version: 2018_08_28_004548) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,13 +28,13 @@ end create_table "articles", id: :serial, force: :cascade do |t| - t.integer "code", null: false - t.string "name", null: false + t.string "name", limit: 255, null: false t.decimal "price", precision: 15, scale: 3, null: false t.text "description" t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" + t.integer "code", null: false t.integer "stock", default: 0 t.integer "notification_stock", default: 0 t.boolean "enabled", default: true @@ -46,57 +42,34 @@ t.index ["code"], name: "index_articles_on_code", unique: true end - create_table "credits", id: :serial, force: :cascade do |t| + create_table "credits", id: :integer, default: -> { "nextval('bonuses_id_seq'::regclass)" }, force: :cascade do |t| t.decimal "amount", precision: 15, scale: 3, null: false t.decimal "remaining", precision: 15, scale: 3, null: false t.date "valid_until" t.integer "customer_id" t.datetime "created_at" t.datetime "updated_at" - t.string "type", default: "Bonus", null: false - t.index ["created_at"], name: "index_credits_on_created_at" - t.index ["customer_id"], name: "index_credits_on_customer_id" + t.string "type", limit: 255, default: "Bonus", null: false + t.index ["created_at"], name: "index_bonuses_on_created_at" + t.index ["customer_id"], name: "index_bonuses_on_customer_id" t.index ["type"], name: "index_credits_on_type" - t.index ["valid_until"], name: "index_credits_on_valid_until" + t.index ["valid_until"], name: "index_bonuses_on_valid_until" end create_table "customers", id: :serial, force: :cascade do |t| - t.string "name", null: false - t.string "lastname" - t.string "identification", null: false + t.string "name", limit: 255, null: false + t.string "lastname", limit: 255 + t.string "identification", limit: 255, null: false t.decimal "free_monthly_bonus", precision: 15, scale: 3 t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" -<<<<<<< HEAD - t.boolean "bonus_without_expiration", default: false, null: false - t.string "email", limit: 255 - t.string "crypted_password", limit: 255 - t.string "password_salt", limit: 255 - t.boolean "enable", default: true - t.string "kind", limit: 1, default: "n", null: false - t.integer "group_id" - t.string "confirmation_token", limit: 255 - t.integer "login_count" - t.string "persistence_token" - t.string "perishable_token" - t.string "single_access_token" - end - - add_index "customers", ["confirmation_token"], name: "index_customers_on_confirmation_token", unique: true, using: :btree - add_index "customers", ["email"], name: "index_customers_on_email", unique: true, using: :btree - add_index "customers", ["enable"], name: "index_customers_on_enable", using: :btree - add_index "customers", ["identification"], name: "index_customers_on_identification", unique: true, using: :btree - - create_table "customers_groups", force: :cascade do |t| - t.string "name", limit: 255, null: false -======= t.boolean "bonus_without_expiration", default: false, null: false - t.string "email" - t.string "crypted_password" - t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" + t.string "email", limit: 255 + t.string "crypted_password", limit: 255 + t.string "password_salt", limit: 255 + t.string "persistence_token", limit: 255 + t.string "perishable_token", limit: 255 t.boolean "enable", default: true t.string "kind", limit: 1, default: "n", null: false t.integer "group_id" @@ -109,35 +82,34 @@ end create_table "customers_groups", id: :serial, force: :cascade do |t| - t.string "name", null: false ->>>>>>> 607e4763e2f4f01c853275bc9056d6bb131e4861 + t.string "name", limit: 255, null: false t.datetime "created_at" t.datetime "updated_at" t.index ["name"], name: "index_customers_groups_on_name", unique: true end - create_table "document_tag_relations", force: :cascade do |t| + create_table "document_tag_relations", id: :serial, force: :cascade do |t| t.integer "document_id", null: false t.integer "tag_id", null: false - t.index ["document_id", "tag_id"], name: "index_document_tag_relations_on_document_id_and_tag_id", unique: true + t.index ["document_id", "tag_id"], name: "index_documents_tags_on_document_id_and_tag_id", unique: true end create_table "documents", id: :serial, force: :cascade do |t| t.integer "code", null: false - t.string "name", null: false + t.string "name", limit: 255, null: false t.text "description" t.integer "pages", null: false t.integer "lock_version", default: 0 - t.string "file_file_name" - t.string "file_content_type" + t.string "file_file_name", limit: 255 + t.string "file_content_type", limit: 255 t.integer "file_file_size" t.datetime "file_updated_at" t.datetime "created_at" t.datetime "updated_at" t.text "tag_path" - t.string "media" + t.string "media", limit: 255 t.boolean "enable", default: true, null: false - t.string "file_fingerprint" + t.string "file_fingerprint", limit: 255 t.boolean "private", default: false t.integer "stock", default: 0, null: false t.string "original_file" @@ -150,7 +122,7 @@ end create_table "feedbacks", id: :serial, force: :cascade do |t| - t.string "item", null: false + t.string "item", limit: 255, null: false t.boolean "positive", default: false, null: false t.text "comments" t.datetime "created_at" @@ -162,13 +134,13 @@ end create_table "file_lines", id: :serial, force: :cascade do |t| - t.string "file", null: false + t.string "file", limit: 255, null: false t.integer "pages", null: false t.integer "copies", null: false t.decimal "price_per_copy", precision: 15, scale: 3, null: false t.integer "order_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "print_job_type_id", null: false t.integer "print_id" t.index ["order_id"], name: "index_file_lines_on_order_id" @@ -190,7 +162,7 @@ end create_table "orders", id: :serial, force: :cascade do |t| - t.datetime "scheduled_at", null: false + t.datetime "scheduled_at" t.string "status", limit: 1, null: false t.boolean "print_out", null: false t.text "notes" @@ -208,8 +180,8 @@ t.decimal "amount", precision: 15, scale: 3, null: false t.decimal "paid", precision: 15, scale: 3, null: false t.string "paid_with", limit: 1, null: false - t.string "payable_type" t.integer "payable_id" + t.string "payable_type", limit: 255 t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" @@ -221,23 +193,23 @@ end create_table "print_job_types", id: :serial, force: :cascade do |t| - t.string "name", null: false - t.string "price", null: false + t.string "name", limit: 255, null: false + t.string "price", limit: 255, null: false t.boolean "two_sided", default: false t.boolean "default", default: false t.integer "lock_version", default: 0 - t.datetime "created_at" - t.datetime "updated_at" - t.string "media" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "media", limit: 255 t.boolean "enabled", default: true t.index ["name"], name: "index_print_job_types_on_name", unique: true end create_table "print_jobs", id: :serial, force: :cascade do |t| - t.string "job_id" + t.string "job_id", limit: 255 t.integer "copies", null: false t.decimal "price_per_copy", precision: 15, scale: 3, null: false - t.string "range" + t.string "range", limit: 255 t.integer "document_id" t.integer "print_id" t.integer "lock_version", default: 0 @@ -256,7 +228,7 @@ end create_table "prints", id: :serial, force: :cascade do |t| - t.string "printer", null: false + t.string "printer", limit: 255, null: false t.integer "user_id" t.integer "customer_id" t.integer "lock_version", default: 0 @@ -278,7 +250,7 @@ end create_table "sessions", id: :serial, force: :cascade do |t| - t.string "session_id", null: false + t.string "session_id", limit: 255, null: false t.text "data" t.datetime "created_at" t.datetime "updated_at" @@ -309,8 +281,8 @@ t.text "description" t.integer "lock_version", default: 0, null: false t.integer "user_id", null: false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "paid", default: false t.boolean "as_admin" t.index ["created_at"], name: "index_shifts_on_created_at" @@ -320,7 +292,7 @@ end create_table "tags", id: :serial, force: :cascade do |t| - t.string "name", null: false + t.string "name", limit: 255, null: false t.integer "parent_id" t.integer "lock_version", default: 0 t.datetime "created_at" @@ -336,73 +308,23 @@ t.index ["private"], name: "index_tags_on_private" end -<<<<<<< HEAD - add_index "tags", ["parent_id"], name: "index_tags_on_parent_id", using: :btree - add_index "tags", ["private"], name: "index_tags_on_private", using: :btree - - create_table "users", force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "last_name", limit: 255, null: false - t.string "language", limit: 255, null: false - t.string "email", limit: 255, null: false - t.string "username", limit: 255, null: false - t.string "encrypted_password", limit: 255, null: false - t.string "password_salt", limit: 255, null: false - t.boolean "admin", default: false, null: false - t.boolean "enable" - t.integer "lock_version", default: 0 - t.datetime "created_at" - t.datetime "updated_at" - t.string "default_printer", limit: 255 - t.string "avatar_file_name", limit: 255 - t.string "avatar_content_type", limit: 255 - t.integer "avatar_file_size" - t.datetime "avatar_updated_at" - t.integer "lines_per_page" - t.boolean "not_shifted", default: false - t.string "confirmation_token", limit: 255 - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "reset_password_token", limit: 255 - t.datetime "reset_password_sent_at" - t.string "remember_token", limit: 255 - t.datetime "remember_created_at" - t.string "unlock_token", limit: 255 - t.datetime "locked_at" - t.integer "sign_in_count" - end - - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - add_index "users", ["unlock_token"], name: "index_users_on_unlock_token", unique: true, using: :btree - add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree - - create_table "versions", force: :cascade do |t| - t.string "item_type", limit: 255, null: false - t.integer "item_id", null: false - t.string "event", limit: 255, null: false - t.integer "whodunnit" - t.text "object" -======= create_table "users", id: :serial, force: :cascade do |t| - t.string "name", null: false - t.string "last_name", null: false - t.string "language", null: false - t.string "email", null: false - t.string "username", null: false - t.string "crypted_password", null: false - t.string "password_salt", null: false - t.string "persistence_token", null: false + t.string "name", limit: 255, null: false + t.string "last_name", limit: 255, null: false + t.string "language", limit: 255, null: false + t.string "email", limit: 255, null: false + t.string "username", limit: 255, null: false + t.string "crypted_password", limit: 255, null: false + t.string "password_salt", limit: 255, null: false + t.string "persistence_token", limit: 255, null: false t.boolean "admin", default: false, null: false t.boolean "enable" t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" - t.string "default_printer" - t.string "avatar_file_name" - t.string "avatar_content_type" + t.string "default_printer", limit: 255 + t.string "avatar_file_name", limit: 255 + t.string "avatar_content_type", limit: 255 t.integer "avatar_file_size" t.datetime "avatar_updated_at" t.integer "lines_per_page" @@ -412,12 +334,11 @@ end create_table "versions", id: :serial, force: :cascade do |t| - t.string "item_type", null: false + t.string "item_type", limit: 255, null: false t.integer "item_id", null: false - t.string "event", null: false + t.string "event", limit: 255, null: false t.integer "whodunnit" t.text "object" ->>>>>>> 607e4763e2f4f01c853275bc9056d6bb131e4861 t.datetime "created_at" t.string "correlation_id" t.json "object_changes", default: {} @@ -435,15 +356,15 @@ t.index ["user_id"], name: "index_withdraws_on_user_id" end - add_foreign_key "article_lines", "articles" - add_foreign_key "article_lines", "prints" - add_foreign_key "credits", "customers" - add_foreign_key "order_lines", "documents" - add_foreign_key "order_lines", "orders" - add_foreign_key "orders", "customers" - add_foreign_key "print_jobs", "documents" - add_foreign_key "print_jobs", "prints" - add_foreign_key "prints", "customers" - add_foreign_key "prints", "orders" - add_foreign_key "prints", "users" + add_foreign_key "article_lines", "articles", name: "article_lines_article_id_fk", on_delete: :restrict + add_foreign_key "article_lines", "prints", name: "article_lines_print_id_fk", on_delete: :restrict + add_foreign_key "credits", "customers", name: "credits_customer_id_fk", on_delete: :restrict + add_foreign_key "order_lines", "documents", name: "order_lines_document_id_fk", on_delete: :restrict + add_foreign_key "order_lines", "orders", name: "order_lines_order_id_fk", on_delete: :restrict + add_foreign_key "orders", "customers", name: "orders_customer_id_fk", on_delete: :restrict + add_foreign_key "print_jobs", "documents", name: "print_jobs_document_id_fk", on_delete: :restrict + add_foreign_key "print_jobs", "prints", name: "print_jobs_print_id_fk", on_delete: :restrict + add_foreign_key "prints", "customers", name: "prints_customer_id_fk", on_delete: :restrict + add_foreign_key "prints", "orders", name: "prints_order_id_fk", on_delete: :restrict + add_foreign_key "prints", "users", name: "prints_user_id_fk", on_delete: :restrict end From 03098f658c49e91d4ad8a5f954fa62669f7d10fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Wed, 12 Sep 2018 23:07:26 -0300 Subject: [PATCH 4/8] Paso 2 --- Gemfile | 1 + Gemfile.lock | 3 + app/controllers/user_sessions_controller.rb | 2 +- app/models/customer.rb | 16 +- app/models/customer_session.rb | 4 +- app/models/user.rb | 12 +- app/models/user_session.rb | 18 +- config/initializers/devise.rb | 6 +- ...0170304192533_authlogic_users_to_devise.rb | 5 +- ...0304195401_authlogic_customer_to_devise.rb | 2 +- db/schema.rb | 158 ++++++++++-------- lib/admin_constraint.rb | 4 +- test/fixtures/customers.yml | 21 +-- test/fixtures/users.yml | 5 +- test/test_helper.rb | 30 +++- 15 files changed, 162 insertions(+), 125 deletions(-) diff --git a/Gemfile b/Gemfile index cbd6ca45..162155eb 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'rails', '~> 5.1' gem 'pg' gem 'devise' +gem 'devise-encryptable' gem 'jc-validates_timeliness' gem 'awesome_nested_set' gem 'will_paginate' diff --git a/Gemfile.lock b/Gemfile.lock index e6728327..b723700e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,8 @@ GEM railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) + devise-encryptable (0.2.0) + devise (>= 2.1.0) ed25519 (1.2.4) erubi (1.7.0) eventmachine (1.2.5) @@ -384,6 +386,7 @@ DEPENDENCIES cups database_cleaner devise + devise-encryptable ed25519 google_drive interactive_editor diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 6b67e5a6..11606ca4 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -39,7 +39,7 @@ def destroy end record = current_user_session.record - record.reset_persistence_token # ensure the session is over + # record.reset_persistence_token # ensure the session is over current_user_session.destroy if Rails.env.test? diff --git a/app/models/customer.rb b/app/models/customer.rb index ba071fa6..1373ab6d 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,14 +1,14 @@ class Customer < ApplicationModel has_paper_trail ignore: [:perishable_token] - acts_as_authentic do |c| - c.maintain_sessions = false - c.validates_uniqueness_of_email_field_options = { case_sensitive: false } - c.validates_length_of_email_field_options = { maximum: 255 } - c.merge_validates_length_of_password_field_options({ minimum: 4 }) - - c.crypto_provider = Authlogic::CryptoProviders::Sha512 - end + # acts_as_authentic do |c| + # c.maintain_sessions = false + # c.validates_uniqueness_of_email_field_options = { case_sensitive: false } + # c.validates_length_of_email_field_options = { maximum: 255 } + # c.merge_validates_length_of_password_field_options({ minimum: 4 }) + + # c.crypto_provider = Authlogic::CryptoProviders::Sha512 + # end KINDS = { normal: 'n', diff --git a/app/models/customer_session.rb b/app/models/customer_session.rb index 3630deff..fdf9c209 100644 --- a/app/models/customer_session.rb +++ b/app/models/customer_session.rb @@ -1,3 +1,3 @@ -class CustomerSession < Authlogic::Session::Base - find_by_login_method :find_by_activated_email +class CustomerSession #< Authlogic::Session::Base + # find_by_login_method :find_by_activated_email end diff --git a/app/models/user.rb b/app/models/user.rb index f83e310c..40aa0bca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,12 @@ class User < ApplicationModel - has_paper_trail except: [:persistence_token, :updated_at, :lock_version] + has_paper_trail except: [:updated_at, :lock_version] mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name - acts_as_authentic do |c| - c.maintain_sessions = false - c.crypto_provider = Authlogic::CryptoProviders::Sha512 - c.merge_validates_length_of_password_field_options({ minimum: 4 }) - end + # acts_as_authentic do |c| + # c.maintain_sessions = false + # c.crypto_provider = Authlogic::CryptoProviders::Sha512 + # c.merge_validates_length_of_password_field_options({ minimum: 4 }) + # end # Scopes scope :actives, -> { where(enable: true) } diff --git a/app/models/user_session.rb b/app/models/user_session.rb index 73d039ea..106ef52f 100644 --- a/app/models/user_session.rb +++ b/app/models/user_session.rb @@ -1,13 +1,13 @@ -class UserSession < Authlogic::Session::Base - find_by_login_method :find_by_username_or_email +class UserSession #< Authlogic::Session::Base + # find_by_login_method :find_by_username_or_email - after_save :create_shift + # after_save :create_shift - def create_shift - record.start_shift! unless record.has_pending_shift? || record.not_shifted - end + # def create_shift + # record.start_shift! unless record.has_pending_shift? || record.not_shifted + # end - def close_shift! - fail 'Unclosed shifts!' unless record.close_pending_shifts! - end + # def close_shift! + # fail 'Unclosed shifts!' unless record.close_pending_shifts! + # end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 758233c5..68164f7c 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,5 +1,3 @@ -# Use this hook to configure devise mailer, warden hooks and so forth. -# Many of these configuration options can be set straight in your model. Devise.setup do |config| # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing @@ -105,7 +103,7 @@ # a value less than 10 in other environments. Note that, for bcrypt (the default # algorithm), the cost increases exponentially with the number of stretches (e.g. # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). - config.stretches = Rails.env.test? ? 1 : 11 + config.stretches = Rails.env.test? ? 1 : 20 # Set up a pepper to generate the hashed password. # config.pepper = '93b2d1e623477421887577755a5603c40159c1451bf25ddecd14cb5f31a934ff2a841617dc828fb44e84247be3cc12969d6d2834103c20553b9e01446b7e4e0c' @@ -214,7 +212,7 @@ # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). # # Require the `devise-encryptable` gem when using anything other than bcrypt - # config.encryptor = :sha512 + config.encryptor = :authlogic_sha512 # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for diff --git a/db/migrate/20170304192533_authlogic_users_to_devise.rb b/db/migrate/20170304192533_authlogic_users_to_devise.rb index d3ff75dc..f9df841e 100644 --- a/db/migrate/20170304192533_authlogic_users_to_devise.rb +++ b/db/migrate/20170304192533_authlogic_users_to_devise.rb @@ -1,4 +1,4 @@ -class AuthlogicUsersToDevise < ActiveRecord::Migration +class AuthlogicUsersToDevise < ActiveRecord::Migration[5.1] def up add_column :users, :confirmation_token, :string, limit: 255 add_column :users, :confirmed_at, :timestamp @@ -23,8 +23,9 @@ def up add_index :users, :reset_password_token, unique: true add_index :users, :unlock_token, unique: true end + def down - remove_column :users, :confirmation_token + remove_column :users, :confirmation_token remove_column :users, :confirmed_at remove_column :users, :confirmation_sent_at remove_column :users, :unconfirmed_email diff --git a/db/migrate/20170304195401_authlogic_customer_to_devise.rb b/db/migrate/20170304195401_authlogic_customer_to_devise.rb index b85d949c..0ede28e4 100644 --- a/db/migrate/20170304195401_authlogic_customer_to_devise.rb +++ b/db/migrate/20170304195401_authlogic_customer_to_devise.rb @@ -1,4 +1,4 @@ -class AuthlogicCustomerToDevise < ActiveRecord::Migration +class AuthlogicCustomerToDevise < ActiveRecord::Migration[5.1] def up add_column :customers, :confirmation_token, :string, limit: 255 add_column :customers, :confirmed_at, :timestamp diff --git a/db/schema.rb b/db/schema.rb index 2e1169bd..e21c332c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_28_004548) do +ActiveRecord::Schema.define(version: 20180828004548) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -28,13 +28,13 @@ end create_table "articles", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false + t.integer "code", null: false + t.string "name", null: false t.decimal "price", precision: 15, scale: 3, null: false t.text "description" t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" - t.integer "code", null: false t.integer "stock", default: 0 t.integer "notification_stock", default: 0 t.boolean "enabled", default: true @@ -42,74 +42,85 @@ t.index ["code"], name: "index_articles_on_code", unique: true end - create_table "credits", id: :integer, default: -> { "nextval('bonuses_id_seq'::regclass)" }, force: :cascade do |t| + create_table "credits", id: :serial, force: :cascade do |t| t.decimal "amount", precision: 15, scale: 3, null: false t.decimal "remaining", precision: 15, scale: 3, null: false t.date "valid_until" t.integer "customer_id" t.datetime "created_at" t.datetime "updated_at" - t.string "type", limit: 255, default: "Bonus", null: false - t.index ["created_at"], name: "index_bonuses_on_created_at" - t.index ["customer_id"], name: "index_bonuses_on_customer_id" + t.string "type", default: "Bonus", null: false + t.index ["created_at"], name: "index_credits_on_created_at" + t.index ["customer_id"], name: "index_credits_on_customer_id" t.index ["type"], name: "index_credits_on_type" - t.index ["valid_until"], name: "index_bonuses_on_valid_until" + t.index ["valid_until"], name: "index_credits_on_valid_until" end create_table "customers", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "lastname", limit: 255 - t.string "identification", limit: 255, null: false + t.string "name", null: false + t.string "lastname" + t.string "identification", null: false t.decimal "free_monthly_bonus", precision: 15, scale: 3 t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" t.boolean "bonus_without_expiration", default: false, null: false - t.string "email", limit: 255 - t.string "crypted_password", limit: 255 - t.string "password_salt", limit: 255 - t.string "persistence_token", limit: 255 - t.string "perishable_token", limit: 255 + t.string "email" + t.string "encrypted_password" + t.string "password_salt" t.boolean "enable", default: true t.string "kind", limit: 1, default: "n", null: false t.integer "group_id" + t.string "confirmation_token", limit: 255 + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.string "reset_password_token", limit: 255 + t.datetime "reset_password_sent_at" + t.string "remember_token", limit: 255 + t.datetime "remember_created_at" + t.string "unlock_token", limit: 255 + t.datetime "locked_at" + t.integer "sign_in_count" t.string "rfid" t.index "to_tsvector('spanish'::regconfig, (((((COALESCE(identification, ''::character varying))::text || ' '::text) || (COALESCE(name, ''::character varying))::text) || ' '::text) || (COALESCE(lastname, ''::character varying))::text))", name: "index_customers_on_identification_name_and_lastname_ts", using: :gin + t.index ["confirmation_token"], name: "index_customers_on_confirmation_token", unique: true t.index ["email"], name: "index_customers_on_email", unique: true t.index ["enable"], name: "index_customers_on_enable" t.index ["identification"], name: "index_customers_on_identification", unique: true - t.index ["perishable_token"], name: "index_customers_on_perishable_token" + t.index ["reset_password_token"], name: "index_customers_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_customers_on_unlock_token", unique: true end create_table "customers_groups", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false + t.string "name", null: false t.datetime "created_at" t.datetime "updated_at" t.index ["name"], name: "index_customers_groups_on_name", unique: true end - create_table "document_tag_relations", id: :serial, force: :cascade do |t| + create_table "document_tag_relations", force: :cascade do |t| t.integer "document_id", null: false t.integer "tag_id", null: false - t.index ["document_id", "tag_id"], name: "index_documents_tags_on_document_id_and_tag_id", unique: true + t.index ["document_id", "tag_id"], name: "index_document_tag_relations_on_document_id_and_tag_id", unique: true end create_table "documents", id: :serial, force: :cascade do |t| t.integer "code", null: false - t.string "name", limit: 255, null: false + t.string "name", null: false t.text "description" t.integer "pages", null: false t.integer "lock_version", default: 0 - t.string "file_file_name", limit: 255 - t.string "file_content_type", limit: 255 + t.string "file_file_name" + t.string "file_content_type" t.integer "file_file_size" t.datetime "file_updated_at" t.datetime "created_at" t.datetime "updated_at" t.text "tag_path" - t.string "media", limit: 255 + t.string "media" t.boolean "enable", default: true, null: false - t.string "file_fingerprint", limit: 255 + t.string "file_fingerprint" t.boolean "private", default: false t.integer "stock", default: 0, null: false t.string "original_file" @@ -122,7 +133,7 @@ end create_table "feedbacks", id: :serial, force: :cascade do |t| - t.string "item", limit: 255, null: false + t.string "item", null: false t.boolean "positive", default: false, null: false t.text "comments" t.datetime "created_at" @@ -134,13 +145,13 @@ end create_table "file_lines", id: :serial, force: :cascade do |t| - t.string "file", limit: 255, null: false + t.string "file", null: false t.integer "pages", null: false t.integer "copies", null: false t.decimal "price_per_copy", precision: 15, scale: 3, null: false t.integer "order_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.integer "print_job_type_id", null: false t.integer "print_id" t.index ["order_id"], name: "index_file_lines_on_order_id" @@ -162,7 +173,7 @@ end create_table "orders", id: :serial, force: :cascade do |t| - t.datetime "scheduled_at" + t.datetime "scheduled_at", null: false t.string "status", limit: 1, null: false t.boolean "print_out", null: false t.text "notes" @@ -180,8 +191,8 @@ t.decimal "amount", precision: 15, scale: 3, null: false t.decimal "paid", precision: 15, scale: 3, null: false t.string "paid_with", limit: 1, null: false + t.string "payable_type" t.integer "payable_id" - t.string "payable_type", limit: 255 t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" @@ -193,23 +204,23 @@ end create_table "print_job_types", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "price", limit: 255, null: false + t.string "name", null: false + t.string "price", null: false t.boolean "two_sided", default: false t.boolean "default", default: false t.integer "lock_version", default: 0 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "media", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + t.string "media" t.boolean "enabled", default: true t.index ["name"], name: "index_print_job_types_on_name", unique: true end create_table "print_jobs", id: :serial, force: :cascade do |t| - t.string "job_id", limit: 255 + t.string "job_id" t.integer "copies", null: false t.decimal "price_per_copy", precision: 15, scale: 3, null: false - t.string "range", limit: 255 + t.string "range" t.integer "document_id" t.integer "print_id" t.integer "lock_version", default: 0 @@ -228,7 +239,7 @@ end create_table "prints", id: :serial, force: :cascade do |t| - t.string "printer", limit: 255, null: false + t.string "printer", null: false t.integer "user_id" t.integer "customer_id" t.integer "lock_version", default: 0 @@ -250,7 +261,7 @@ end create_table "sessions", id: :serial, force: :cascade do |t| - t.string "session_id", limit: 255, null: false + t.string "session_id", null: false t.text "data" t.datetime "created_at" t.datetime "updated_at" @@ -281,8 +292,8 @@ t.text "description" t.integer "lock_version", default: 0, null: false t.integer "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "paid", default: false t.boolean "as_admin" t.index ["created_at"], name: "index_shifts_on_created_at" @@ -292,7 +303,7 @@ end create_table "tags", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false + t.string "name", null: false t.integer "parent_id" t.integer "lock_version", default: 0 t.datetime "created_at" @@ -309,34 +320,47 @@ end create_table "users", id: :serial, force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "last_name", limit: 255, null: false - t.string "language", limit: 255, null: false - t.string "email", limit: 255, null: false - t.string "username", limit: 255, null: false - t.string "crypted_password", limit: 255, null: false - t.string "password_salt", limit: 255, null: false - t.string "persistence_token", limit: 255, null: false + t.string "name", null: false + t.string "last_name", null: false + t.string "language", null: false + t.string "email", null: false + t.string "username", null: false + t.string "encrypted_password", null: false + t.string "password_salt", null: false t.boolean "admin", default: false, null: false t.boolean "enable" t.integer "lock_version", default: 0 t.datetime "created_at" t.datetime "updated_at" - t.string "default_printer", limit: 255 - t.string "avatar_file_name", limit: 255 - t.string "avatar_content_type", limit: 255 + t.string "default_printer" + t.string "avatar_file_name" + t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" t.integer "lines_per_page" t.boolean "not_shifted", default: false + t.string "confirmation_token", limit: 255 + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.string "reset_password_token", limit: 255 + t.datetime "reset_password_sent_at" + t.string "remember_token", limit: 255 + t.datetime "remember_created_at" + t.string "unlock_token", limit: 255 + t.datetime "locked_at" + t.integer "sign_in_count" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true t.index ["username"], name: "index_users_on_username", unique: true end create_table "versions", id: :serial, force: :cascade do |t| - t.string "item_type", limit: 255, null: false + t.string "item_type", null: false t.integer "item_id", null: false - t.string "event", limit: 255, null: false + t.string "event", null: false t.integer "whodunnit" t.text "object" t.datetime "created_at" @@ -356,15 +380,15 @@ t.index ["user_id"], name: "index_withdraws_on_user_id" end - add_foreign_key "article_lines", "articles", name: "article_lines_article_id_fk", on_delete: :restrict - add_foreign_key "article_lines", "prints", name: "article_lines_print_id_fk", on_delete: :restrict - add_foreign_key "credits", "customers", name: "credits_customer_id_fk", on_delete: :restrict - add_foreign_key "order_lines", "documents", name: "order_lines_document_id_fk", on_delete: :restrict - add_foreign_key "order_lines", "orders", name: "order_lines_order_id_fk", on_delete: :restrict - add_foreign_key "orders", "customers", name: "orders_customer_id_fk", on_delete: :restrict - add_foreign_key "print_jobs", "documents", name: "print_jobs_document_id_fk", on_delete: :restrict - add_foreign_key "print_jobs", "prints", name: "print_jobs_print_id_fk", on_delete: :restrict - add_foreign_key "prints", "customers", name: "prints_customer_id_fk", on_delete: :restrict - add_foreign_key "prints", "orders", name: "prints_order_id_fk", on_delete: :restrict - add_foreign_key "prints", "users", name: "prints_user_id_fk", on_delete: :restrict + add_foreign_key "article_lines", "articles" + add_foreign_key "article_lines", "prints" + add_foreign_key "credits", "customers" + add_foreign_key "order_lines", "documents" + add_foreign_key "order_lines", "orders" + add_foreign_key "orders", "customers" + add_foreign_key "print_jobs", "documents" + add_foreign_key "print_jobs", "prints" + add_foreign_key "prints", "customers" + add_foreign_key "prints", "orders" + add_foreign_key "prints", "users" end diff --git a/lib/admin_constraint.rb b/lib/admin_constraint.rb index 61d25036..443e3fcd 100644 --- a/lib/admin_constraint.rb +++ b/lib/admin_constraint.rb @@ -3,7 +3,7 @@ def matches?(request) credentials = request.cookie_jar['user_credentials'] Rails.logger.info("Someone wants to loggin #{credentials}") return false if credentials.blank? - user = User.find_by_persistence_token(credentials.split(':')[0]) - user && user.admin? && user.not_shifted + # user = User.find_by_persistence_token(credentials.split(':')[0]) + # user && user.admin? && user.not_shifted end end diff --git a/test/fixtures/customers.yml b/test/fixtures/customers.yml index 91d8409d..d8ce7e54 100644 --- a/test/fixtures/customers.yml +++ b/test/fixtures/customers.yml @@ -4,10 +4,9 @@ student: identification: 123 email: student@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('student123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + crypted_password: <%= encrypt('student123', salt) %> + perishable_token: <%= friendly_token %> free_monthly_bonus: 100.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:reliable] %> @@ -18,10 +17,9 @@ teacher: identification: 321 email: teacher@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('teacher123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + crypted_password: <%= encrypt('teacher123', salt) %> + perishable_token: <%= friendly_token %> free_monthly_bonus: 10.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> @@ -32,10 +30,9 @@ student_without_bonus: identification: 666 email: student_without_bonus@printhub.com enable: true - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('student_without_bonus123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 - perishable_token: <%= Authlogic::Random.friendly_token %> + password_salt: <%= salt = hex_token %> + crypted_password: <%= encrypt('student_without_bonus123', salt) %> + perishable_token: <%= friendly_token %> free_monthly_bonus: 0.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 7f40484a..1d9e27f6 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -6,9 +6,8 @@ operator: default_printer: <%= Cups.show_destinations.select {|p| p =~ /pdf/i}.first %> lines_per_page: 10 username: operator - password_salt: <%= salt = Authlogic::Random.hex_token %> - crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt('operator123' + salt) %> - persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 + password_salt: <%= salt = hex_token %> + crypted_password: <%= encrypt('operator123', salt) %> admin: true enable: true not_shifted: false diff --git a/test/test_helper.rb b/test/test_helper.rb index 5173eb45..aa7be324 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,7 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' -require 'authlogic/test_case' +# require 'authlogic/test_case' require 'sidekiq/testing' require 'database_cleaner' # require 'minitest/reporters' @@ -12,12 +12,32 @@ # Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new +module FixturesExAuthlogicHelpers + def hex_token + SecureRandom.hex(64) + end + + def friendly_token + SecureRandom.urlsafe_base64(15) + end + + def encrypt(text, salt) + Devise::Encryptable::Encryptors::AuthlogicSha512.digest( + text, Devise.stretches, salt, nil + ) + end +end + +ActiveRecord::FixtureSet.context_class.send :include, FixturesExAuthlogicHelpers + class ActiveSupport::TestCase ActiveRecord::Migration.maintain_test_schema! set_fixture_class versions: PaperTrail::Version # self.use_transactional_fixtures = true # Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new + # Fixtures Ex-Authlogic generators + fixtures :all # Add more helper methods to be used by all tests here... @@ -95,13 +115,7 @@ def drop_all_prints end class ActionController::TestCase - include Authlogic::TestCase - setup :activate_authlogic -end - -class ActiveSupport::TestCase - include Authlogic::TestCase - setup :activate_authlogic + include Devise::TestHelpers end class JSException < Exception From a8f5e6d4a86d81d97aaddc2927205ce90710c5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Wed, 12 Sep 2018 23:17:20 -0300 Subject: [PATCH 5/8] Paso 3 (columnas....) --- app/controllers/password_resets_controller.rb | 12 ++++++------ app/models/customer.rb | 2 +- test/fixtures/customers.yml | 9 +++------ test/fixtures/users.yml | 2 +- test/models/user_test.rb | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb index d9c2598b..02e302f2 100644 --- a/app/controllers/password_resets_controller.rb +++ b/app/controllers/password_resets_controller.rb @@ -24,17 +24,17 @@ def create # GET /password_resets/token/edit def edit @title = t('view.password_resets.edit_title') - @customer = Customer.find_using_perishable_token( - params[:token], TOKEN_VALIDITY - ) + # @customer = Customer.find_using_perishable_token( + # params[:token], TOKEN_VALIDITY + # ) end # PUT /password_resets/token def update @title = t('view.password_resets.edit_title') - @customer = Customer.find_using_perishable_token( - params[:token], TOKEN_VALIDITY - ) + # @customer = Customer.find_using_perishable_token( + # params[:token], TOKEN_VALIDITY + # ) respond_to do |format| if @customer.try(:update, customer_params) diff --git a/app/models/customer.rb b/app/models/customer.rb index 1373ab6d..9aad2df9 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,5 +1,5 @@ class Customer < ApplicationModel - has_paper_trail ignore: [:perishable_token] + has_paper_trail # acts_as_authentic do |c| # c.maintain_sessions = false diff --git a/test/fixtures/customers.yml b/test/fixtures/customers.yml index d8ce7e54..ce532a42 100644 --- a/test/fixtures/customers.yml +++ b/test/fixtures/customers.yml @@ -5,8 +5,7 @@ student: email: student@printhub.com enable: true password_salt: <%= salt = hex_token %> - crypted_password: <%= encrypt('student123', salt) %> - perishable_token: <%= friendly_token %> + encrypted_password: <%= encrypt('student123', salt) %> free_monthly_bonus: 100.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:reliable] %> @@ -18,8 +17,7 @@ teacher: email: teacher@printhub.com enable: true password_salt: <%= salt = hex_token %> - crypted_password: <%= encrypt('teacher123', salt) %> - perishable_token: <%= friendly_token %> + encrypted_password: <%= encrypt('teacher123', salt) %> free_monthly_bonus: 10.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> @@ -31,8 +29,7 @@ student_without_bonus: email: student_without_bonus@printhub.com enable: true password_salt: <%= salt = hex_token %> - crypted_password: <%= encrypt('student_without_bonus123', salt) %> - perishable_token: <%= friendly_token %> + encrypted_password: <%= encrypt('student_without_bonus123', salt) %> free_monthly_bonus: 0.00 bonus_without_expiration: false kind: <%= Customer::KINDS[:normal] %> diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 1d9e27f6..31fc679e 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -7,7 +7,7 @@ operator: lines_per_page: 10 username: operator password_salt: <%= salt = hex_token %> - crypted_password: <%= encrypt('operator123', salt) %> + encrypted_password: <%= encrypt('operator123', salt) %> admin: true enable: true not_shifted: false diff --git a/test/models/user_test.rb b/test/models/user_test.rb index ec4402ce..64509d65 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -17,7 +17,7 @@ def setup assert_equal users(:operator).default_printer, @operator.default_printer assert_equal users(:operator).lines_per_page, @operator.lines_per_page assert_equal users(:operator).username, @operator.username - assert_equal users(:operator).crypted_password, @operator.crypted_password + assert_equal users(:operator).encrypted_password, @operator.encrypted_password assert_equal users(:operator).admin, @operator.admin assert_equal users(:operator).enable, @operator.enable end From 3c07cdaa09e35898300174b4ac68ac7572c39a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Wed, 12 Sep 2018 23:30:57 -0300 Subject: [PATCH 6/8] Paso 4 --- app/models/customer.rb | 2 ++ app/models/customer_session.rb | 3 -- app/models/user.rb | 3 ++ .../application_controller_test.rb | 24 ++++++------- test/controllers/articles_controller_test.rb | 2 +- test/controllers/bonuses_controller_test.rb | 2 +- test/controllers/customers_controller_test.rb | 34 +++++++++---------- .../customers_groups_controller_test.rb | 2 +- test/controllers/documents_controller_test.rb | 2 +- test/controllers/files_controller_test.rb | 12 +++---- test/controllers/orders_controller_test.rb | 10 +++--- test/controllers/payments_controller_test.rb | 2 +- .../print_job_types_controller_test.rb | 2 +- test/controllers/prints_controller_test.rb | 2 +- .../shift_closures_controller_test.rb | 2 +- test/controllers/shifts_controller_test.rb | 2 +- test/controllers/stats_controller_test.rb | 2 +- test/controllers/tags_controller_test.rb | 2 +- .../user_sessions_controller_test.rb | 6 ++-- test/controllers/users_controller_test.rb | 2 +- test/models/print_test.rb | 11 +++--- test/models/user_test.rb | 1 + test/test_helper.rb | 4 +-- 23 files changed, 69 insertions(+), 65 deletions(-) delete mode 100644 app/models/customer_session.rb diff --git a/app/models/customer.rb b/app/models/customer.rb index 9aad2df9..b43fd8a8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,8 @@ class Customer < ApplicationModel has_paper_trail + devise :database_authenticatable, :recoverable, :trackable, :validatable, :encryptable + # acts_as_authentic do |c| # c.maintain_sessions = false # c.validates_uniqueness_of_email_field_options = { case_sensitive: false } diff --git a/app/models/customer_session.rb b/app/models/customer_session.rb deleted file mode 100644 index fdf9c209..00000000 --- a/app/models/customer_session.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CustomerSession #< Authlogic::Session::Base - # find_by_login_method :find_by_activated_email -end diff --git a/app/models/user.rb b/app/models/user.rb index 40aa0bca..8b66e790 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,9 @@ class User < ApplicationModel has_paper_trail except: [:updated_at, :lock_version] mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name + devise :database_authenticatable, :recoverable, :trackable, :validatable, :encryptable + + # acts_as_authentic do |c| # c.maintain_sessions = false # c.crypto_provider = Authlogic::CryptoProviders::Sha512 diff --git a/test/controllers/application_controller_test.rb b/test/controllers/application_controller_test.rb index cc92d00b..ecc83c7d 100644 --- a/test/controllers/application_controller_test.rb +++ b/test/controllers/application_controller_test.rb @@ -28,7 +28,7 @@ def setup test 'current user session' do assert_nil @controller.send(:current_user_session) - UserSession.create(@operator) + sign_in(@operator) assert_not_nil @controller.send(:current_user_session) end @@ -36,7 +36,7 @@ def setup test 'current user' do assert_nil @controller.send(:current_user) - UserSession.create(@operator) + sign_in(@operator) assert_not_nil @controller.send(:current_user) assert_equal @operator.id, @controller.send(:current_user).id @@ -74,7 +74,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_user) end @@ -82,7 +82,7 @@ def setup test 'require no user' do assert @controller.send(:require_no_user) - UserSession.create(@operator) + sign_in(@operator) assert !@controller.send(:require_no_user) assert_redirected_to prints_url @@ -96,7 +96,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_customer_or_user) end @@ -107,7 +107,7 @@ def setup assert_not_nil @controller.send(:check_logged_in) assert_redirected_to root_url - UserSession.create(@operator) + sign_in(@operator) assert_nil @controller.send(:check_logged_in) assert_not_nil @controller.send(:current_user) @@ -145,7 +145,7 @@ def setup assert_equal I18n.t('messages.must_be_logged_in'), @controller.send(:flash)[:notice] - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_no_customer_or_user) end @@ -163,14 +163,14 @@ def setup test 'require no customer or admin with user' do @operator.update(admin: false) - UserSession.create(@operator) + sign_in(@operator) assert @controller.send(:require_no_customer_or_user) assert_response :success end test 'require admin user with admin user' do - UserSession.create(@operator) + sign_in(@operator) assert_not_equal false, @controller.send(:require_admin_user) end @@ -178,7 +178,7 @@ def setup test 'require admin with a non admin user' do @operator.update(admin: false) - UserSession.create(@operator) + sign_in(@operator) assert_equal false, @controller.send(:require_admin_user) assert_redirected_to prints_url @@ -209,7 +209,7 @@ def setup @operator.update(admin: false, not_shifted: false) @operator.close_pending_shifts! - UserSession.create(@operator) + sign_in(@operator) @controller.send(:session)[:has_an_open_shift] = true @@ -230,7 +230,7 @@ def setup @operator.update(not_shifted: true) assert_no_difference 'Shift.count' do - UserSession.create(@operator) + sign_in(@operator) @controller.send(:session)[:has_an_open_shift] = true assert_nil @controller.send(:run_shift_tasks) diff --git a/test/controllers/articles_controller_test.rb b/test/controllers/articles_controller_test.rb index 1f48b295..14b323b2 100644 --- a/test/controllers/articles_controller_test.rb +++ b/test/controllers/articles_controller_test.rb @@ -5,7 +5,7 @@ class ArticlesControllerTest < ActionController::TestCase @article = articles(:binding) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) end test 'should get index' do diff --git a/test/controllers/bonuses_controller_test.rb b/test/controllers/bonuses_controller_test.rb index 4e330fe8..adacd567 100644 --- a/test/controllers/bonuses_controller_test.rb +++ b/test/controllers/bonuses_controller_test.rb @@ -2,7 +2,7 @@ class BonusesControllerTest < ActionController::TestCase def setup - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/customers_controller_test.rb b/test/controllers/customers_controller_test.rb index 6cf343f1..0d83bdfb 100644 --- a/test/controllers/customers_controller_test.rb +++ b/test/controllers/customers_controller_test.rb @@ -7,7 +7,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get index' do - UserSession.create(@operator) + sign_in(@operator) get :index assert_response :success @@ -17,7 +17,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get filtered index' do - UserSession.create(@operator) + sign_in(@operator) get :index, params: { q: 'Anakin|Darth' } assert_response :success @@ -30,7 +30,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get index with debt customers' do - UserSession.create(@operator) + sign_in(@operator) get :index, params: { status: 'with_debt' } assert_response :success @@ -42,7 +42,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get new' do - UserSession.create(@operator) + sign_in(@operator) get :new assert_response :success @@ -62,7 +62,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should create simple customer' do - UserSession.create(@operator) + sign_in(@operator) assert_difference ['Customer.unscoped.count'] do assert_difference 'PaperTrail::Version.count' do @@ -86,7 +86,7 @@ class CustomersControllerTest < ActionController::TestCase test 'should create customer' do User.where(id: @operator.id).update_all(not_shifted: true) - UserSession.create(@operator) + sign_in(@operator) assert_difference ['Customer.unscoped.count', 'Bonus.count'] do assert_difference 'PaperTrail::Version.count', 2 do @@ -169,7 +169,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should show customer' do - UserSession.create(@operator) + sign_in(@operator) get :show, params: { id: @customer.to_param } assert_response :success @@ -179,7 +179,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get edit' do - UserSession.create(@operator) + sign_in(@operator) get :edit, params: { id: @customer.to_param } assert_response :success @@ -190,7 +190,7 @@ class CustomersControllerTest < ActionController::TestCase test 'should update customer' do User.where(id: @operator.id).update_all(not_shifted: true) - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Customer.count' do assert_difference 'Bonus.count' do @@ -215,7 +215,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should update customer deposits' do - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Customer.count' do assert_difference 'Deposit.count' do @@ -238,7 +238,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should destroy customer' do - UserSession.create(@operator) + sign_in(@operator) assert_difference('Customer.count', -1) do delete :destroy, params: { id: Customer.find(customers(:teacher).id).to_param } @@ -248,7 +248,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should get credit detail' do - UserSession.create(@operator) + sign_in(@operator) get :credit_detail, params: { id: @customer.to_param }, xhr: true @@ -323,7 +323,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should pay off customer debt' do - UserSession.create(@operator) + sign_in(@operator) put :pay_off_debt, params: { id: @customer.to_param }, xhr: true @@ -334,7 +334,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should pay off a customer month debt' do - UserSession.create(@operator) + sign_in(@operator) month = @customer.months_to_pay.last @@ -347,7 +347,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should be able to use customer rfid' do - UserSession.create(@operator) + sign_in(@operator) @customer.update(rfid: '123123') put :use_rfid, params: { id: @customer.to_param, rfid: '123123' }, xhr: true @@ -359,7 +359,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should not be able to use customer rfid' do - UserSession.create(@operator) + sign_in(@operator) @customer.update(rfid: '123123') put :use_rfid, params: { id: @customer.to_param, rfid: '111111' }, xhr: true @@ -370,7 +370,7 @@ class CustomersControllerTest < ActionController::TestCase end test 'should assign customer rfid' do - UserSession.create(@operator) + sign_in(@operator) assert_nil @customer.rfid post :assign_rfid, params: { id: @customer.to_param, rfid: '123123' }, xhr: true diff --git a/test/controllers/customers_groups_controller_test.rb b/test/controllers/customers_groups_controller_test.rb index e2b8fcf1..7971a156 100644 --- a/test/controllers/customers_groups_controller_test.rb +++ b/test/controllers/customers_groups_controller_test.rb @@ -3,7 +3,7 @@ class CustomersGroupsControllerTest < ActionController::TestCase setup do @customers_group = customers_groups(:graduate) - UserSession.create users(:operator) + sign_in users(:operator) end test 'should get index' do diff --git a/test/controllers/documents_controller_test.rb b/test/controllers/documents_controller_test.rb index fac9340c..9a207b2c 100644 --- a/test/controllers/documents_controller_test.rb +++ b/test/controllers/documents_controller_test.rb @@ -5,7 +5,7 @@ class DocumentsControllerTest < ActionController::TestCase @document = documents(:math_book) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) prepare_document_files end diff --git a/test/controllers/files_controller_test.rb b/test/controllers/files_controller_test.rb index 3290c4e7..19f9be39 100644 --- a/test/controllers/files_controller_test.rb +++ b/test/controllers/files_controller_test.rb @@ -10,7 +10,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download avatar' do - UserSession.create(@operator) + sign_in(@operator) get :download, params: { path: drop_private_dir(@operator.avatar.path) } assert_response :success @@ -21,7 +21,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download document' do - UserSession.create(@operator) + sign_in(@operator) get :download, params: { path: drop_private_dir(@document.file.path) } assert_response :success @@ -32,7 +32,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should not download document' do - UserSession.create(@operator) + sign_in(@operator) file = @document.file.path @@ -45,7 +45,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download barcode' do - UserSession.create(@operator) + sign_in(@operator) get :download_barcode, params: { code: @document.code } assert_response :success @@ -54,7 +54,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should download barcode of new document' do - UserSession.create(@operator) + sign_in(@operator) get :download_barcode, params: { code: '159321' } assert_response :success @@ -84,7 +84,7 @@ class FilesControllerTest < ActionController::TestCase end test 'should not download avatar' do - UserSession.create(@operator) + sign_in(@operator) file = @operator.avatar.path diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index c46c2dd2..0915f759 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -10,7 +10,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'all' } assert_response :success @@ -25,7 +25,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user for print index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'print' } assert_response :success @@ -38,7 +38,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should get user filtered index' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :index, params: { type: 'all', q: 'darth' } assert_response :success @@ -114,7 +114,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should show user order' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) get :show, params: { type: 'all', id: @order.to_param } assert_response :success @@ -168,7 +168,7 @@ class OrdersControllerTest < ActionController::TestCase test 'should cancel order as user' do @request.host = 'localhost' - UserSession.create(@operator) + sign_in(@operator) assert_no_difference 'Order.count' do delete :destroy, params: { id: @order.to_param, type: 'all' } diff --git a/test/controllers/payments_controller_test.rb b/test/controllers/payments_controller_test.rb index ef711526..79bc3ede 100644 --- a/test/controllers/payments_controller_test.rb +++ b/test/controllers/payments_controller_test.rb @@ -2,7 +2,7 @@ class PaymentsControllerTest < ActionController::TestCase def setup - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/print_job_types_controller_test.rb b/test/controllers/print_job_types_controller_test.rb index 273cf744..ba3cca41 100644 --- a/test/controllers/print_job_types_controller_test.rb +++ b/test/controllers/print_job_types_controller_test.rb @@ -4,7 +4,7 @@ class PrintJobTypesControllerTest < ActionController::TestCase setup do @print_job_type = PrintJobType.find print_job_types(:a4).id - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/prints_controller_test.rb b/test/controllers/prints_controller_test.rb index a4fab44e..9fb84d48 100644 --- a/test/controllers/prints_controller_test.rb +++ b/test/controllers/prints_controller_test.rb @@ -6,7 +6,7 @@ class PrintsControllerTest < ActionController::TestCase @printer = ::CustomCups.pdf_printer @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) fail "Can't find a PDF printer to run tests with." unless @printer diff --git a/test/controllers/shift_closures_controller_test.rb b/test/controllers/shift_closures_controller_test.rb index d309f14f..c99615ad 100644 --- a/test/controllers/shift_closures_controller_test.rb +++ b/test/controllers/shift_closures_controller_test.rb @@ -5,7 +5,7 @@ class ShiftClosuresControllerTest < ActionController::TestCase @shift_closure = shift_closures(:first) @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) end test "should get index" do diff --git a/test/controllers/shifts_controller_test.rb b/test/controllers/shifts_controller_test.rb index 3a7841c5..319fc3ff 100644 --- a/test/controllers/shifts_controller_test.rb +++ b/test/controllers/shifts_controller_test.rb @@ -4,7 +4,7 @@ class ShiftsControllerTest < ActionController::TestCase setup do @shift = shifts(:current_shift) - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/stats_controller_test.rb b/test/controllers/stats_controller_test.rb index 0bb95d68..d1ea8b7f 100644 --- a/test/controllers/stats_controller_test.rb +++ b/test/controllers/stats_controller_test.rb @@ -3,7 +3,7 @@ class StatsControllerTest < ActionController::TestCase def setup @controller = StatsController.new - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get printers stats' do diff --git a/test/controllers/tags_controller_test.rb b/test/controllers/tags_controller_test.rb index 5e5d2157..28d6f3a1 100644 --- a/test/controllers/tags_controller_test.rb +++ b/test/controllers/tags_controller_test.rb @@ -3,7 +3,7 @@ class TagsControllerTest < ActionController::TestCase setup do @tag = tags(:books) - UserSession.create(users(:operator)) + sign_in(users(:operator)) end test 'should get index' do diff --git a/test/controllers/user_sessions_controller_test.rb b/test/controllers/user_sessions_controller_test.rb index 058e1c42..4ba98424 100644 --- a/test/controllers/user_sessions_controller_test.rb +++ b/test/controllers/user_sessions_controller_test.rb @@ -114,7 +114,7 @@ class UserSessionsControllerTest < ActionController::TestCase @operator.close_pending_shifts! assert_difference '@operator.shifts.count' do - UserSession.create(@operator) + sign_in(@operator) end assert_not_nil UserSession.find @@ -132,7 +132,7 @@ class UserSessionsControllerTest < ActionController::TestCase @operator.close_pending_shifts! assert_difference '@operator.shifts.count' do - UserSession.create(@operator) + sign_in(@operator) end assert_not_nil UserSession.find @@ -151,7 +151,7 @@ class UserSessionsControllerTest < ActionController::TestCase test 'should exit whitout close the shift' do @operator.close_pending_shifts! - UserSession.create(@operator) + sign_in(@operator) assert_equal 1, @operator.shifts.pending.size diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 27cc4523..cfd0de5b 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -4,7 +4,7 @@ class UsersControllerTest < ActionController::TestCase setup do @operator = users(:operator) - UserSession.create(@operator) + sign_in(@operator) prepare_avatar_files end diff --git a/test/models/print_test.rb b/test/models/print_test.rb index 457f6ba2..e534f640 100644 --- a/test/models/print_test.rb +++ b/test/models/print_test.rb @@ -2,6 +2,7 @@ # Clase para probar el modelo "Print" class PrintTest < ActiveSupport::TestCase + # Función para inicializar las variables utilizadas en las pruebas def setup @print = prints(:math_print) @@ -244,7 +245,7 @@ def teardown end test 'create with free credit and paying more in cash' do - UserSession.create(users(:operator)) + # sign_in(users(:operator)) @customer = customers(:student) Bonus.all.delete_all Deposit.all.delete_all @@ -314,7 +315,7 @@ def teardown end test 'create with free credit' do - UserSession.create(users(:operator)) + sign_in(users(:operator)) counts = ['Print.count', 'Payment.count', '::CustomCups.last_job_id(@printer)', 'ArticleLine.count'] @@ -718,7 +719,7 @@ def teardown end test 'revoke' do - UserSession.create(@operator) + sign_in(@operator) @article = articles(:binding) assert_difference '@article.reload.stock', 2 do @@ -733,7 +734,7 @@ def teardown test 'can not revoke if is not admin' do @operator.update(admin: false) - UserSession.create(users(:operator)) + sign_in(users(:operator)) assert_no_difference('Bonus.count') { assert_nil @print.revoke! } @@ -741,7 +742,7 @@ def teardown end test 'revoke a print paid with credit returns the value to the customer' do - UserSession.create(@operator) + sign_in(@operator) print = prints(:math_print_with_credit) initial_bonus = print.customer.bonuses.to_a.sum(&:remaining) payments_amount = print.payments.select(&:credit?).to_a.sum(&:paid) diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 64509d65..d2948216 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -2,6 +2,7 @@ # Clase para probar el modelo "User" class UserTest < ActiveSupport::TestCase + # Función para inicializar las variables utilizadas en las pruebas def setup @operator = users(:operator) diff --git a/test/test_helper.rb b/test/test_helper.rb index aa7be324..d4648598 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -115,7 +115,7 @@ def drop_all_prints end class ActionController::TestCase - include Devise::TestHelpers + include Devise::Test::ControllerHelpers end class JSException < Exception @@ -252,7 +252,7 @@ def login(*args) # options[:expected_path] ||= prints_path # user = options[:user_id].present? ? User.find(options[:user_id]) : users(:operator) - # # UserSession.create(user) + # # sign_in(user) # page.driver.set_cookie( # 'user_credentials', # "#{user.persistence_token}::#{user.id}" From f305f33e50287968efda64207aafbee8cce02c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Wed, 12 Sep 2018 23:44:43 -0300 Subject: [PATCH 7/8] Pseudo-CurrentAttributes --- app/controllers/application_controller.rb | 7 ++++++- app/models/print.rb | 5 +++-- config/initializers/devise.rb | 2 +- config/routes/customer/customer_session.rb | 7 ++++--- config/routes/user/user_session.rb | 7 ++++--- test/models/print_test.rb | 11 ++++++----- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bbc7e695..0e2280cc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :null_session, unless: :trusted_sites - before_action :set_js_format_in_iframe_request, :set_paper_trail_whodunnit + before_action :set_js_format_in_iframe_request, :set_paper_trail_whodunnit, :assign_currents before_bugsnag_notify :add_user_info_to_bugsnag after_action -> { expires_now if current_user || current_customer } @@ -215,4 +215,9 @@ def trusted_sites return true if request.headers[custom_header] == site end end + + def assign_currents + Current.user = current_user + Current.customer = current_customer + end end diff --git a/app/models/print.rb b/app/models/print.rb index 63209999..75c3b9c2 100644 --- a/app/models/print.rb +++ b/app/models/print.rb @@ -72,8 +72,9 @@ class Print < ApplicationModel def initialize(attributes = nil) super(attributes) - self.user = UserSession.find.try(:user) || user rescue user + self.user = Current.user || user rescue user self.status ||= STATUS[:pending_payment] + self.pay_later! if [1, '1', true].include?(pay_later) case @@ -144,7 +145,7 @@ def mark_order_as_completed end def revoke! - return unless UserSession.find.try(:record).try(:admin) + return unless Current.user.try(:admin) Print.transaction do begin diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 68164f7c..95979ccd 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -218,7 +218,7 @@ # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you # are using only default views. - # config.scoped_views = false + config.scoped_views = true # Configure the default scope given to Warden. By default it's the first # devise role declared in your routes (usually :user). diff --git a/config/routes/customer/customer_session.rb b/config/routes/customer/customer_session.rb index 69d1e8c0..9367caca 100644 --- a/config/routes/customer/customer_session.rb +++ b/config/routes/customer/customer_session.rb @@ -1,3 +1,4 @@ -resources :customer_sessions, only: [:new, :create] do - delete :destroy, on: :collection -end +# resources :customer_sessions, only: [:new, :create] do +# delete :destroy, on: :collection +# end +devise_for :customers, path: 'customers' diff --git a/config/routes/user/user_session.rb b/config/routes/user/user_session.rb index 010adbe8..a6984863 100644 --- a/config/routes/user/user_session.rb +++ b/config/routes/user/user_session.rb @@ -1,3 +1,4 @@ -resources :user_sessions, only: [:new, :create] do - delete :destroy, on: :collection -end +# resources :user_sessions, only: [:new, :create] do +# delete :destroy, on: :collection +# end +devise_for :users, path: 'users' diff --git a/test/models/print_test.rb b/test/models/print_test.rb index e534f640..a791dd6a 100644 --- a/test/models/print_test.rb +++ b/test/models/print_test.rb @@ -245,7 +245,7 @@ def teardown end test 'create with free credit and paying more in cash' do - # sign_in(users(:operator)) + Current.user = users(:operator) @customer = customers(:student) Bonus.all.delete_all Deposit.all.delete_all @@ -315,7 +315,7 @@ def teardown end test 'create with free credit' do - sign_in(users(:operator)) + Current.user = users(:operator) counts = ['Print.count', 'Payment.count', '::CustomCups.last_job_id(@printer)', 'ArticleLine.count'] @@ -719,7 +719,7 @@ def teardown end test 'revoke' do - sign_in(@operator) + Current.user = @operator @article = articles(:binding) assert_difference '@article.reload.stock', 2 do @@ -734,7 +734,7 @@ def teardown test 'can not revoke if is not admin' do @operator.update(admin: false) - sign_in(users(:operator)) + Current.user = users(:operator) assert_no_difference('Bonus.count') { assert_nil @print.revoke! } @@ -742,7 +742,8 @@ def teardown end test 'revoke a print paid with credit returns the value to the customer' do - sign_in(@operator) + Current.user = @operator + print = prints(:math_print_with_credit) initial_bonus = print.customer.bonuses.to_a.sum(&:remaining) payments_amount = print.payments.select(&:credit?).to_a.sum(&:paid) From 98da7fa0dc25c2bbc4557e8aac1e9b5d0451bf01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Coppi?= Date: Thu, 13 Sep 2018 00:07:29 -0300 Subject: [PATCH 8/8] Devise views/controllers V1 --- app/controllers/application_controller.rb | 33 +++++++++ .../customers/confirmations_controller.rb | 30 +++++++++ .../omniauth_callbacks_controller.rb | 30 +++++++++ .../customers/passwords_controller.rb | 34 ++++++++++ .../customers/registrations_controller.rb | 62 +++++++++++++++++ .../customers/sessions_controller.rb | 27 ++++++++ .../customers/unlocks_controller.rb | 30 +++++++++ app/controllers/user_sessions_controller.rb | 67 ------------------- app/controllers/users/sessions_controller.rb | 12 ++++ app/models/current.rb | 20 ++++++ .../customers/confirmations/new.html.erb | 20 ++++++ .../mailer/confirmation_instructions.html.erb | 5 ++ .../customers/mailer/email_changed.html.erb | 7 ++ .../customers/mailer/password_change.html.erb | 3 + .../reset_password_instructions.html.erb | 8 +++ .../mailer/unlock_instructions.html.erb | 7 ++ app/views/customers/passwords/edit.html.erb | 24 +++++++ app/views/customers/passwords/new.html.erb | 18 +++++ .../customers/registrations/edit.html.erb | 35 ++++++++++ .../customers/registrations/new.html.erb | 25 +++++++ app/views/customers/sessions/new.html.erb | 20 ++++++ app/views/customers/shared/_links.html.erb | 25 +++++++ app/views/customers/unlocks/new.html.erb | 19 ++++++ app/views/users/sessions/new.html.erb | 22 ++++++ config/routes/customer/customer_session.rb | 4 +- config/routes/user/user_session.rb | 2 +- test/test_helper.rb | 1 + 27 files changed, 521 insertions(+), 69 deletions(-) create mode 100644 app/controllers/customers/confirmations_controller.rb create mode 100644 app/controllers/customers/omniauth_callbacks_controller.rb create mode 100644 app/controllers/customers/passwords_controller.rb create mode 100644 app/controllers/customers/registrations_controller.rb create mode 100644 app/controllers/customers/sessions_controller.rb create mode 100644 app/controllers/customers/unlocks_controller.rb delete mode 100644 app/controllers/user_sessions_controller.rb create mode 100644 app/controllers/users/sessions_controller.rb create mode 100644 app/models/current.rb create mode 100644 app/views/customers/confirmations/new.html.erb create mode 100644 app/views/customers/mailer/confirmation_instructions.html.erb create mode 100644 app/views/customers/mailer/email_changed.html.erb create mode 100644 app/views/customers/mailer/password_change.html.erb create mode 100644 app/views/customers/mailer/reset_password_instructions.html.erb create mode 100644 app/views/customers/mailer/unlock_instructions.html.erb create mode 100644 app/views/customers/passwords/edit.html.erb create mode 100644 app/views/customers/passwords/new.html.erb create mode 100644 app/views/customers/registrations/edit.html.erb create mode 100644 app/views/customers/registrations/new.html.erb create mode 100644 app/views/customers/sessions/new.html.erb create mode 100644 app/views/customers/shared/_links.html.erb create mode 100644 app/views/customers/unlocks/new.html.erb create mode 100644 app/views/users/sessions/new.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0e2280cc..c75ea63d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -220,4 +220,37 @@ def assign_currents Current.user = current_user Current.customer = current_customer end + + # Devise SignIn callback + def after_sign_in_path_for(resource_or_scope) + session[:has_an_open_shift] = current_user.has_stale_shift? + current_user + if @user_session.record.has_stale_shift? + [ + edit_shift_url(@user_session.record.stale_shift), + notice: t('view.shifts.edit_stale') + ] + else + [prints_url, notice: t('view.user_sessions.correctly_created')] + end + + end + + # Devise SignOut callback + def after_sign_out_path_for(resource_or_scope) + if resource_or_scope == :user + new_user_session_path + elsif resource_or_scope == :admin + new_admin_session_path + else + root_path + end + if params[:close_shift] + if params[:as_operator] + current_user.last_open_shift_as_operator! + end + + current_user_session.close_shift! + end + end end diff --git a/app/controllers/customers/confirmations_controller.rb b/app/controllers/customers/confirmations_controller.rb new file mode 100644 index 00000000..ef7b210f --- /dev/null +++ b/app/controllers/customers/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/app/controllers/customers/omniauth_callbacks_controller.rb b/app/controllers/customers/omniauth_callbacks_controller.rb new file mode 100644 index 00000000..efc3aa4d --- /dev/null +++ b/app/controllers/customers/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + + # More info at: + # https://github.com/plataformatec/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when OmniAuth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end +end diff --git a/app/controllers/customers/passwords_controller.rb b/app/controllers/customers/passwords_controller.rb new file mode 100644 index 00000000..55b7a299 --- /dev/null +++ b/app/controllers/customers/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Customers::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/controllers/customers/registrations_controller.rb b/app/controllers/customers/registrations_controller.rb new file mode 100644 index 00000000..3ac9dd47 --- /dev/null +++ b/app/controllers/customers/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Customers::RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/customers/sessions_controller.rb b/app/controllers/customers/sessions_controller.rb new file mode 100644 index 00000000..ab0be3cb --- /dev/null +++ b/app/controllers/customers/sessions_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Customers::SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + # def destroy + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end +end diff --git a/app/controllers/customers/unlocks_controller.rb b/app/controllers/customers/unlocks_controller.rb new file mode 100644 index 00000000..35850ff2 --- /dev/null +++ b/app/controllers/customers/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Customers::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb deleted file mode 100644 index 11606ca4..00000000 --- a/app/controllers/user_sessions_controller.rb +++ /dev/null @@ -1,67 +0,0 @@ -class UserSessionsController < ApplicationController - before_action :require_no_user, only: [:new, :create] - before_action :require_user, only: :destroy - - - # GET /user_sessions/new - # GET /user_sessions/new.json - def new - @title = t 'view.user_sessions.new_title' - @user_session = UserSession.new - end - - def create - @title = t 'view.user_sessions.new_title' - @user_session = UserSession.new( - params.require(:user_session).permit(:username, :password) - ) - - respond_to do |format| - if @user_session.save - session[:has_an_open_shift] = current_user.has_stale_shift? - - format.html { redirect_back_or_default *initial_url_and_options } - format.json { render json: @user_session, status: :created, location: initial_url } - else - format.html { render action: 'new' } - format.json { render json: @user_session.errors, status: :unprocessable_entity } - end - end - end - - def destroy - if params[:close_shift] - if params[:as_operator] - current_user.last_open_shift_as_operator! - end - - current_user_session.close_shift! - end - - record = current_user_session.record - # record.reset_persistence_token # ensure the session is over - current_user_session.destroy - - if Rails.env.test? - (Capybara.page.driver.remove_cookie('user_credentials') rescue nil) - end - - respond_to do |format| - format.html { redirect_to(new_user_session_url, notice: t('view.user_sessions.correctly_destroyed')) } - format.json { head :ok } - end - end - - private - - def initial_url_and_options - if @user_session.record.has_stale_shift? - [ - edit_shift_url(@user_session.record.stale_shift), - notice: t('view.shifts.edit_stale') - ] - else - [prints_url, notice: t('view.user_sessions.correctly_created')] - end - end -end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb new file mode 100644 index 00000000..3d1e2e5a --- /dev/null +++ b/app/controllers/users/sessions_controller.rb @@ -0,0 +1,12 @@ +class Users::SessionsController < Devise::SessionsController + before_action :require_no_user, only: [:new, :create] + before_action :require_user, only: :destroy + + before_action :set_title + + private + + def set_title + @title = t("view.user_sessions.#{action_name}_title") + end +end diff --git a/app/models/current.rb b/app/models/current.rb new file mode 100644 index 00000000..fca8cee5 --- /dev/null +++ b/app/models/current.rb @@ -0,0 +1,20 @@ +class Current # < ActiveSupport::CurrentAttributes + # attribute :user, :customer + # Temporal CurrentAttributes + + def self.user + ::RequestStore.read('user') + end + + def self.user=(value) + ::RequestStore.write('user', value) + end + + def self.customer + ::RequestStore.read('customer') + end + + def self.customer=(value) + ::RequestStore.write('customer', value) + end +end diff --git a/app/views/customers/confirmations/new.html.erb b/app/views/customers/confirmations/new.html.erb new file mode 100644 index 00000000..496c56b2 --- /dev/null +++ b/app/views/customers/confirmations/new.html.erb @@ -0,0 +1,20 @@ +

Resend confirmation instructions

+ +<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :confirmation_token %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email), + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Resend confirmation instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/mailer/confirmation_instructions.html.erb b/app/views/customers/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/app/views/customers/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/customers/mailer/email_changed.html.erb b/app/views/customers/mailer/email_changed.html.erb new file mode 100644 index 00000000..32f4ba80 --- /dev/null +++ b/app/views/customers/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/customers/mailer/password_change.html.erb b/app/views/customers/mailer/password_change.html.erb new file mode 100644 index 00000000..b41daf47 --- /dev/null +++ b/app/views/customers/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/customers/mailer/reset_password_instructions.html.erb b/app/views/customers/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/app/views/customers/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/customers/mailer/unlock_instructions.html.erb b/app/views/customers/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/app/views/customers/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/customers/passwords/edit.html.erb b/app/views/customers/passwords/edit.html.erb new file mode 100644 index 00000000..2b551767 --- /dev/null +++ b/app/views/customers/passwords/edit.html.erb @@ -0,0 +1,24 @@ +

Change your password

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + + <%= f.input :reset_password_token, as: :hidden %> + <%= f.full_error :reset_password_token %> + +
+ <%= f.input :password, + label: "New password", + required: true, + autofocus: true, + hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, label: "Confirm your new password", required: true %> +
+ +
+ <%= f.button :submit, "Change my password" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/passwords/new.html.erb b/app/views/customers/passwords/new.html.erb new file mode 100644 index 00000000..f82ab54a --- /dev/null +++ b/app/views/customers/passwords/new.html.erb @@ -0,0 +1,18 @@ +

Forgot your password?

+ +<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Send me reset password instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/registrations/edit.html.erb b/app/views/customers/registrations/edit.html.erb new file mode 100644 index 00000000..54fbc6c3 --- /dev/null +++ b/app/views/customers/registrations/edit.html.erb @@ -0,0 +1,35 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, required: true, autofocus: true %> + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +

Currently waiting confirmation for: <%= resource.unconfirmed_email %>

+ <% end %> + + <%= f.input :password, + hint: "leave it blank if you don't want to change it", + required: false + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, + required: false, + input_html: { autocomplete: "new-password" } %> + <%= f.input :current_password, + hint: "we need your current password to confirm your changes", + required: true, + input_html: { autocomplete: "current-password" } %> +
+ +
+ <%= f.button :submit, "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/customers/registrations/new.html.erb b/app/views/customers/registrations/new.html.erb new file mode 100644 index 00000000..9737652a --- /dev/null +++ b/app/views/customers/registrations/new.html.erb @@ -0,0 +1,25 @@ +

Sign up

+ +<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, + required: true, + autofocus: true , + input_html: { autocomplete: "email" }%> + <%= f.input :password, + required: true, + hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), + input_html: { autocomplete: "new-password" } %> + <%= f.input :password_confirmation, + required: true, + input_html: { autocomplete: "new-password" } %> +
+ +
+ <%= f.button :submit, "Sign up" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/sessions/new.html.erb b/app/views/customers/sessions/new.html.erb new file mode 100644 index 00000000..4f9eb995 --- /dev/null +++ b/app/views/customers/sessions/new.html.erb @@ -0,0 +1,20 @@ +

Log in

+ +<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.input :email, + required: false, + autofocus: true, + input_html: { autocomplete: "email" } %> + <%= f.input :password, + required: false, + input_html: { autocomplete: "current-password" } %> + <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %> +
+ +
+ <%= f.button :submit, "Log in" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/customers/shared/_links.html.erb b/app/views/customers/shared/_links.html.erb new file mode 100644 index 00000000..e6a3e419 --- /dev/null +++ b/app/views/customers/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/app/views/customers/unlocks/new.html.erb b/app/views/customers/unlocks/new.html.erb new file mode 100644 index 00000000..37f63986 --- /dev/null +++ b/app/views/customers/unlocks/new.html.erb @@ -0,0 +1,19 @@ +

Resend unlock instructions

+ +<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + <%= f.full_error :unlock_token %> + +
+ <%= f.input :email, + required: true, + autofocus: true, + input_html: { autocomplete: "email" } %> +
+ +
+ <%= f.button :submit, "Resend unlock instructions" %> +
+<% end %> + +<%= render "customers/shared/links" %> diff --git a/app/views/users/sessions/new.html.erb b/app/views/users/sessions/new.html.erb new file mode 100644 index 00000000..76a5dcd0 --- /dev/null +++ b/app/views/users/sessions/new.html.erb @@ -0,0 +1,22 @@ +
+
+
+ <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), defaults: { required: false }) do |f| %> +
+ <%= f.input :username, input_html: { autocomplete: 'off', autofocus: true, class: 'span3' } %> + <%= f.input :password, input_html: { class: 'span3' } %> +
+
+ <%= f.button :submit, t('view.user_sessions.login'), class: 'btn btn-primary' %> +
+ <% end %> +
+
+
+ +<% if resource.errors.any? %> + +<% end %> diff --git a/config/routes/customer/customer_session.rb b/config/routes/customer/customer_session.rb index 9367caca..0a17a742 100644 --- a/config/routes/customer/customer_session.rb +++ b/config/routes/customer/customer_session.rb @@ -1,4 +1,6 @@ # resources :customer_sessions, only: [:new, :create] do # delete :destroy, on: :collection # end -devise_for :customers, path: 'customers' +devise_for :customers, path: 'customers', controllers: { + sessions: 'customers/sessions' # poner todos los demas +} diff --git a/config/routes/user/user_session.rb b/config/routes/user/user_session.rb index a6984863..97fd0982 100644 --- a/config/routes/user/user_session.rb +++ b/config/routes/user/user_session.rb @@ -1,4 +1,4 @@ # resources :user_sessions, only: [:new, :create] do # delete :destroy, on: :collection # end -devise_for :users, path: 'users' +devise_for :users, path: 'users', controllers: { sessions: 'users/sessions' } diff --git a/test/test_helper.rb b/test/test_helper.rb index d4648598..7d550996 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -164,6 +164,7 @@ def self._running_local ) end + # (Capybara.page.driver.remove_cookie('user_credentials') rescue nil) Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, { # debug: true,