diff --git a/.gitignore b/.gitignore index 07526820..131dabc0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ tmp/restart.txt tmp/**/* .sass-cache public/_test.html +public/assets +.idea diff --git a/Gemfile b/Gemfile index 46e22b9d..680a9330 100644 --- a/Gemfile +++ b/Gemfile @@ -1,28 +1,21 @@ source 'https://rubygems.org' -gem 'rails', '~> 4.2.11' +gem 'rails', '~> 6.0.3.3' # latest release -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - -gem 'schema_plus' -gem 'default_value_for' gem 'bluecloth' gem 'devise' gem 'jquery-rails' gem 'will_paginate' -gem 'cancan' +gem 'cancancan' gem 'rack' -gem 'nokogiri', "~> 1.8.5" +gem 'nokogiri' gem 'css3buttons' +gem 'rake' gem 'sass-rails' gem 'coffee-rails' gem 'uglifier' -# compatibility gems -gem 'protected_attributes' - # Deploy with Capistrano # gem 'capistrano' @@ -47,15 +40,15 @@ end group :development, :test do gem 'pry' gem 'rspec' - gem 'rspec-rails', '~> 3.0.0' - gem 'rspec-activemodel-mocks' # for compatibility - gem 'capybara', '~> 2.2.0', :require => false - gem 'capybara-webkit', :require => false - gem 'capybara-screenshot' - gem 'database_cleaner', :require => false - gem 'factory_girl_rails', :require => false - gem 'launchy', :require => false - gem 'spork', '0.9.0.rc9', :require => false + gem 'rspec-rails' + #gem 'rspec-activemodel-mocks' # for compatibility + #gem 'capybara', '~> 2.2.0', :require => false + #gem 'selenium-webdriver', :require => false + #gem 'capybara-screenshot' + #gem 'database_cleaner', :require => false + #gem 'factory_girl_rails', :require => false + #gem 'launchy', :require => false + #gem 'spork', '0.9.0.rc9', :require => false end group :mysql do diff --git a/Gemfile.lock b/Gemfile.lock index df5faf03..db9ae6cc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,95 +1,96 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) + actioncable (6.0.3.3) + actionpack (= 6.0.3.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.0.3.3) + actionpack (= 6.0.3.3) + activejob (= 6.0.3.3) + activerecord (= 6.0.3.3) + activestorage (= 6.0.3.3) + activesupport (= 6.0.3.3) + mail (>= 2.7.1) + actionmailer (6.0.3.3) + actionpack (= 6.0.3.3) + actionview (= 6.0.3.3) + activejob (= 6.0.3.3) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.1) - actionview (= 4.2.11.1) - activesupport (= 4.2.11.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.1) - activesupport (= 4.2.11.1) + rails-dom-testing (~> 2.0) + actionpack (6.0.3.3) + actionview (= 6.0.3.3) + activesupport (= 6.0.3.3) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.3.3) + actionpack (= 6.0.3.3) + activerecord (= 6.0.3.3) + activestorage (= 6.0.3.3) + activesupport (= 6.0.3.3) + nokogiri (>= 1.8.5) + actionview (6.0.3.3) + activesupport (= 6.0.3.3) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.1) - activesupport (= 4.2.11.1) - globalid (>= 0.3.0) - activemodel (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - activerecord (4.2.11.1) - activemodel (= 4.2.11.1) - activesupport (= 4.2.11.1) - arel (~> 6.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.3.3) + activesupport (= 6.0.3.3) + globalid (>= 0.3.6) + activemodel (6.0.3.3) + activesupport (= 6.0.3.3) + activerecord (6.0.3.3) + activemodel (= 6.0.3.3) + activesupport (= 6.0.3.3) + activestorage (6.0.3.3) + actionpack (= 6.0.3.3) + activejob (= 6.0.3.3) + activerecord (= 6.0.3.3) + marcel (~> 0.3.1) + activesupport (6.0.3.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) - arel (6.0.4) - bcrypt (3.1.12) + zeitwerk (~> 2.2, >= 2.2.2) + bcrypt (3.1.16) + bindex (0.8.1) bluecloth (2.2.0) - builder (3.2.3) - cancan (1.6.10) - capybara (2.2.1) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (~> 2.0) - capybara-screenshot (1.0.22) - capybara (>= 1.0, < 4) - launchy - coderay (1.1.2) - coffee-rails (4.2.2) + builder (3.2.4) + cancancan (3.1.0) + coderay (1.1.3) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.5) - crass (1.0.4) + concurrent-ruby (1.1.7) + crass (1.0.6) css3buttons (1.0.1) actionpack (>= 3.0.0) - database_cleaner (1.7.0) - debug_inspector (0.0.3) - default_value_for (3.1.0) - activerecord (>= 3.2.0, < 6.0) - devise (4.6.1) + devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.3) + diff-lcs (1.4.4) em-websocket (0.5.1) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) - erubis (2.7.0) + erubi (1.9.0) eventmachine (1.2.7) execjs (2.7.0) - factory_girl (4.9.0) - activesupport (>= 3.0.0) - factory_girl_rails (4.9.0) - factory_girl (~> 4.9.0) - railties (>= 3.0.0) - ffi (1.10.0) + ffi (1.13.1) formatador (0.2.5) globalid (0.4.2) activesupport (>= 4.2.0) - guard (2.15.0) + guard (2.16.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) @@ -105,215 +106,138 @@ GEM guard-compat (~> 1.0) multi_json (~> 1.8) http_parser.rb (0.6.0) - i18n (0.9.5) + i18n (1.8.5) concurrent-ruby (~> 1.0) - its-it (1.3.0) - jquery-rails (4.3.3) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - key_struct (0.4.2) - 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.3) + listen (3.2.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + loofah (2.7.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - lumberjack (1.0.13) + lumberjack (1.2.8) mail (2.7.1) mini_mime (>= 0.1.1) - method_source (0.9.2) - mime-types (3.2.2) - mime-types-data (~> 3.2015) - mime-types-data (3.2018.0812) - mini_mime (1.0.1) - mini_portile2 (2.3.0) - minitest (5.11.3) - modware (0.1.3) - key_struct (~> 0.4) - multi_json (1.13.1) - mysql2 (0.5.2) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (1.0.0) + mimemagic (0.3.5) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.2) + multi_json (1.15.0) + mysql2 (0.5.3) nenv (0.3.0) - nokogiri (1.8.5) - mini_portile2 (~> 2.3.0) - notiffany (0.1.1) + nio4r (2.5.4) + nokogiri (1.10.10) + mini_portile2 (~> 2.4.0) + notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) orm_adapter (0.5.0) - pg (1.1.4) - protected_attributes (1.1.4) - activemodel (>= 4.0.1, < 5.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - public_suffix (3.0.3) - rack (1.6.11) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.11.1) - actionmailer (= 4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - activemodel (= 4.2.11.1) - activerecord (= 4.2.11.1) - activesupport (= 4.2.11.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (4.2.11.1) - actionpack (= 4.2.11.1) - activesupport (= 4.2.11.1) + pg (1.2.3) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (6.0.3.3) + actioncable (= 6.0.3.3) + actionmailbox (= 6.0.3.3) + actionmailer (= 6.0.3.3) + actionpack (= 6.0.3.3) + actiontext (= 6.0.3.3) + actionview (= 6.0.3.3) + activejob (= 6.0.3.3) + activemodel (= 6.0.3.3) + activerecord (= 6.0.3.3) + activestorage (= 6.0.3.3) + activesupport (= 6.0.3.3) + bundler (>= 1.3.0) + railties (= 6.0.3.3) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.0.3.3) + actionpack (= 6.0.3.3) + activesupport (= 6.0.3.3) + method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.2) - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + thor (>= 0.20.3, < 2.0) + rake (13.0.1) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) ffi (~> 1.0) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) - rspec (3.0.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-activemodel-mocks (1.1.0) - activemodel (>= 3.0) - activesupport (>= 3.0) - rspec-mocks (>= 2.99, < 4.0) - rspec-core (3.0.4) - rspec-support (~> 3.0.0) - rspec-expectations (3.0.4) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.2) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.0.0) - rspec-mocks (3.0.4) - rspec-support (~> 3.0.0) - rspec-rails (3.0.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-support (~> 3.0.0) - rspec-support (3.0.4) - ruby_dep (1.5.0) - sass (3.7.3) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - schema_auto_foreign_keys (0.1.3) - its-it (~> 1.2) - schema_plus_foreign_keys (~> 0.1) - schema_plus_indexes (~> 0.2) - schema_monkey (2.1.5) - activerecord (>= 4.2) - modware (~> 0.1) - schema_plus (2.0.1) - activerecord (~> 4.2) - schema_auto_foreign_keys (~> 0.1) - schema_monkey (~> 2.1) - schema_plus_columns (~> 0.1) - schema_plus_core (~> 1.0) - schema_plus_db_default (~> 0.1) - schema_plus_default_expr (~> 0.1) - schema_plus_enums (~> 0.1) - schema_plus_foreign_keys (~> 0.1) - schema_plus_indexes (~> 0.1, >= 0.1.3) - schema_plus_pg_indexes (~> 0.1, >= 0.1.3) - schema_plus_tables (~> 0.1) - schema_plus_views (~> 0.1) - schema_plus_columns (0.3.0) - activerecord (>= 4.2, < 5.3) - its-it (~> 1.2) - schema_plus_core - schema_plus_indexes (~> 0.2) - schema_plus_compatibility (0.4.0) - activerecord (>= 4.2, < 5.3) - schema_monkey (~> 2.1) - schema_plus_core (1.0.2) - activerecord (~> 4.2) - its-it (~> 1.2) - schema_monkey (~> 2.1) - schema_plus_db_default (0.1.1) - activerecord (~> 4.2) - schema_plus_core (~> 1.0) - schema_plus_default_expr (0.1.5) - activerecord (>= 4.2, < 6.0) - its-it (~> 1.2) - schema_plus_core - schema_plus_enums (0.1.8) - activerecord (>= 4.2, < 5.3) - its-it (~> 1.2) - schema_plus_core - schema_plus_foreign_keys (0.1.8) - activerecord (>= 4.2, < 5.3) - its-it (~> 1.2) - schema_plus_compatibility (~> 0.2) - schema_plus_core - valuable - schema_plus_indexes (0.3.1) - activerecord (>= 4.2, < 5.3) - its-it (~> 1.2) - schema_plus_core - schema_plus_pg_indexes (0.1.12) - activerecord (~> 4.2) - its-it (~> 1.2) - schema_plus_core (~> 1.0) - schema_plus_indexes (~> 0.1, >= 0.1.3) - schema_plus_tables (0.1.1) - activerecord (~> 4.2) - schema_plus_core (~> 1.0) - schema_plus_views (0.3.1) - activerecord (~> 4.2) - schema_plus_core (~> 1.0) - shellany (0.0.1) - spork (0.9.0.rc9) - spring (2.0.2) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-rails (4.0.1) + actionpack (>= 4.2) activesupport (>= 4.2) - sprockets (3.7.2) + railties (>= 4.2) + rspec-core (~> 3.9) + rspec-expectations (~> 3.9) + rspec-mocks (~> 3.9) + rspec-support (~> 3.9) + rspec-support (3.9.3) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + shellany (0.0.1) + spring (2.1.1) + sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.4.0) - thor (0.20.3) + sqlite3 (1.4.2) + thor (1.0.1) thread_safe (0.3.6) - tilt (2.0.9) - tzinfo (1.2.5) + tilt (2.0.10) + tzinfo (1.2.7) thread_safe (~> 0.1) - uglifier (4.1.20) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - valuable (0.9.14) - warden (1.2.7) - rack (>= 1.0) - web-console (3.3.0) - activemodel (>= 4.2) - debug_inspector - railties (>= 4.2) - will_paginate (3.1.6) - xpath (2.1.0) - nokogiri (~> 1.3) + warden (1.2.9) + rack (>= 2.0.9) + web-console (4.0.4) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + websocket-driver (0.7.3) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + will_paginate (3.3.0) + zeitwerk (2.4.0) PLATFORMS ruby @@ -321,31 +245,22 @@ PLATFORMS DEPENDENCIES bcrypt bluecloth - cancan - capybara (~> 2.2.0) - capybara-screenshot + cancancan coffee-rails css3buttons - database_cleaner - default_value_for devise - factory_girl_rails guard-livereload jquery-rails - launchy mysql2 - nokogiri (~> 1.8.5) + nokogiri pg - protected_attributes pry rack - rails (~> 4.2.11) + rails (~> 6.0.3.3) + rake rspec - rspec-activemodel-mocks - rspec-rails (~> 3.0.0) + rspec-rails sass-rails - schema_plus - spork (= 0.9.0.rc9) spring sqlite3 uglifier @@ -353,4 +268,4 @@ DEPENDENCIES will_paginate BUNDLED WITH - 1.16.1 + 1.17.3 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 00000000..d1997f3c --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,6 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css +//= require jquery-1.7.1.min.js +//= require jquery_ujs.js +//= require jquery.delayed-observer.js \ No newline at end of file diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 75d5074f..9aeb9d62 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -1,7 +1,3 @@ -// = require jquery-1.7.1.min.js -// = require jquery_ujs.js -// = require jquery.delayed-observer.js - reinstallBehavior = (context)-> $('form.comment:not(.installed)', context).each -> $(this).addClass('installed') diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index bb3a1aec..53d25dcd 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -1,17 +1,17 @@ class Admin::CommentsController < ApplicationController layout 'admin' - skip_authorization_check :only => [:preview, :new_import, :import] - before_filter :set_navigation_ids - before_filter :save_return_to_url, :only => [:new, :edit, :approve, :destroy] - before_filter :require_admin!, :only => [:new_import, :import] + skip_authorization_check only: %i[preview new_import import] + before_action :set_navigation_ids + before_action :save_return_to_url, only: %i[new edit approve destroy] + before_action :require_admin!, only: %i[new_import import] def index authorize! :read, Comment - @all_comments = Comment. - accessible_by(current_ability). - order('created_at DESC'). - includes(:topic) + @all_comments = Comment + .accessible_by(current_ability) + .order('created_at DESC') + .includes(:topic) @comments = @all_comments.page(params[:page]) end @@ -23,15 +23,15 @@ def edit def update @comment = Comment.find(params[:id]) authorize! :update, @comment - if @comment.update_attributes(params[:comment], :as => current_user.role) + if @comment.update_attributes(params[:comment], as: current_user.role) redirect_back(admin_comments_path) else - render :action => 'edit' + render action: 'edit' end end def preview - render :text => ApplicationHelper.render_markdown(params[:content]) + render text: ApplicationHelper.render_markdown(params[:content]) end def approve @@ -39,9 +39,7 @@ def approve authorize! :update, @comment @comment.transaction do @comment.moderation_status = :ok - if @comment.site.moderation_method == :akismet - @comment.report_ham - end + @comment.report_ham if @comment.site.moderation_method == :akismet @comment.save! end redirect_back(admin_comments_path) @@ -51,9 +49,7 @@ def destroy @comment = Comment.find(params[:id]) authorize! :destroy, @comment @comment.transaction do - if params[:spam] && @comment.site.moderation_method == :akismet - @comment.report_spam - end + @comment.report_spam if params[:spam] && @comment.site.moderation_method == :akismet @comment.destroy end redirect_back(admin_comments_path) @@ -61,12 +57,12 @@ def destroy def new_import @sites = Site.all - @migrators = Juvia::Migrators::PLATFORMS.map{ |p| p.titleize } + @migrators = Juvia::Migrators::PLATFORMS.map { |p| p.titleize } end def import - options = {:table_prefix => params[:table_prefix], - :wp_multisite_id => params[:wp_multisite_id]} + options = { table_prefix: params[:table_prefix], + wp_multisite_id: params[:wp_multisite_id] } if Juvia::Migrators.process( params[:site_id], params[:import_type], @@ -76,13 +72,14 @@ def import params[:database_host], options ) - flash[:notice] = "Imported!" + flash[:notice] = 'Imported!' redirect_to(admin_comments_path) end end -private + private + def set_navigation_ids - @navigation_ids = [:dashboard, :comments] + @navigation_ids = %i[dashboard comments] end end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 70a4a569..0753b091 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,17 +1,17 @@ class Admin::DashboardController < ApplicationController layout 'admin' - skip_before_filter :authenticate_user!, :only => [:index, :new_admin, :create_admin] + skip_before_action :authenticate_user!, only: %i[index new_admin create_admin] skip_authorization_check - before_filter :require_admin!, :except => [:index, :new_admin, :create_admin] - before_filter :require_no_admins_defined, :only => [:new_admin, :create_admin] - before_filter :set_navigation_ids + before_action :require_admin!, except: %i[index new_admin create_admin] + before_action :require_no_admins_defined, only: %i[new_admin create_admin] + before_action :set_navigation_ids def index - if User.where(:admin => true).count == 0 - redirect_to :action => 'new_admin' + if User.where(admin: true).count == 0 + redirect_to action: 'new_admin' elsif current_user && current_user.accessible_sites.count == 0 - redirect_to :action => 'new_site' + redirect_to action: 'new_site' else redirect_to admin_sites_path end @@ -28,7 +28,7 @@ def create_admin sign_in(@user) redirect_to dashboard_path else - render :action => 'new_admin' + render action: 'new_admin' end end @@ -42,15 +42,14 @@ def create_site if @site.save redirect_to created_admin_site_path(@site) else - render :action => 'new_site' + render action: 'new_site' end end -private + private + def require_no_admins_defined - if User.where(:admin => true).count > 0 - render :template => 'shared/forbidden' - end + render template: 'shared/forbidden' if User.where(admin: true).count > 0 end def set_navigation_ids diff --git a/app/controllers/admin/help_controller.rb b/app/controllers/admin/help_controller.rb index b2f54695..2087e38d 100644 --- a/app/controllers/admin/help_controller.rb +++ b/app/controllers/admin/help_controller.rb @@ -1,15 +1,16 @@ class Admin::HelpController < ApplicationController layout 'help' - - skip_before_filter :authenticate_user! + + skip_before_action :authenticate_user! skip_authorization_check - before_filter :set_navigation_ids + before_action :set_navigation_ids def index - redirect_to :action => 'embedding' + redirect_to action: 'embedding' end -private + private + def set_navigation_ids @navigation_ids = [:help] end diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index a58a6567..d1f0a2ab 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,8 +1,8 @@ class Admin::SitesController < ApplicationController layout 'admin' - - before_filter :set_navigation_ids - + + before_action :set_navigation_ids + # GET /admin/sites # GET /admin/sites.json def index @@ -11,7 +11,7 @@ def index respond_to do |format| format.html # index.html.erb - format.json { render :json => @sites } + format.json { render json: @sites } end end @@ -23,7 +23,7 @@ def show respond_to do |format| format.html # show.html.erb - format.json { render :json => @site } + format.json { render json: @site } end end @@ -35,7 +35,7 @@ def new respond_to do |format| format.html # new.html.erb - format.json { render :json => @site } + format.json { render json: @site } end end @@ -59,16 +59,16 @@ def test # POST /admin/sites.json def create authorize! :create, Site - @site = Site.new(params[:site], :as => current_user.role) + @site = Site.new(params[:site], as: current_user.role) @site.user = current_user respond_to do |format| if @site.save format.html { redirect_to [:admin, @site] } - format.json { render :json => @site, :status => :created, :location => @site } + format.json { render json: @site, status: :created, location: @site } else - format.html { render :action => "new" } - format.json { render :json => @site.errors, :status => :unprocessable_entity } + format.html { render action: 'new' } + format.json { render json: @site.errors, status: :unprocessable_entity } end end end @@ -80,12 +80,12 @@ def update authorize! :update, @site respond_to do |format| - if @site.update_attributes(params[:site], :as => current_user.role) - format.html { redirect_to [:admin, @site], :notice => 'Site was successfully updated.' } + if @site.update_attributes(params[:site], as: current_user.role) + format.html { redirect_to [:admin, @site], notice: 'Site was successfully updated.' } format.json { head :ok } else - format.html { render :action => "edit" } - format.json { render :json => @site.errors, :status => :unprocessable_entity } + format.html { render action: 'edit' } + format.json { render json: @site.errors, status: :unprocessable_entity } end end end @@ -103,8 +103,9 @@ def destroy end end -private + private + def set_navigation_ids - @navigation_ids = [:dashboard, :sites] + @navigation_ids = %i[dashboard sites] end end diff --git a/app/controllers/admin/topics_controller.rb b/app/controllers/admin/topics_controller.rb index 02ec8e00..ba5815b3 100644 --- a/app/controllers/admin/topics_controller.rb +++ b/app/controllers/admin/topics_controller.rb @@ -2,7 +2,7 @@ class Admin::TopicsController < ApplicationController layout 'admin' load_and_authorize_resource - before_filter :set_navigation_ids + before_action :set_navigation_ids def show show! do @@ -15,27 +15,28 @@ def destroy end def index - raise "Not allowed" + raise 'Not allowed' end def new - raise "Not allowed" + raise 'Not allowed' end def create - raise "Not allowed" + raise 'Not allowed' end def edit - raise "Not allowed" + raise 'Not allowed' end def update - raise "Not allowed" + raise 'Not allowed' end -private + private + def set_navigation_ids - @navigation_ids = [:dashboard, :sites] + @navigation_ids = %i[dashboard sites] end end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 690d8a62..c9982e7f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,96 +1,95 @@ module Admin + class UsersController < ApplicationController + layout 'admin' -class UsersController < ApplicationController - layout 'admin' - - skip_authorization_check :only => [:index, :edit] - before_filter :set_navigation_ids - - def index - if !can?(:list, User) - redirect_to dashboard_path - return + skip_authorization_check only: %i[index edit] + before_action :set_navigation_ids + + def index + unless can?(:list, User) + redirect_to dashboard_path + return + end + + @users = User.order('email').page(params[:page]) + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @users } + end end - @users = User.order('email').page(params[:page]) + def show + @user = User.find(params[:id]) + authorize! :read, @user + @sites = @user.sites + @topics = @user.topics - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @users } + respond_to do |format| + format.html + format.json { render json: @user } + end end - end - def show - @user = User.find(params[:id]) - authorize! :read, @user - @sites = @user.sites - @topics = @user.topics + def new + authorize! :create, User + @user = User.new - respond_to do |format| - format.html - format.json { render :json => @user } + respond_to do |format| + format.html # new.html.erb + format.json { render json: @user } + end end - end - - def new - authorize! :create, User - @user = User.new - - respond_to do |format| - format.html # new.html.erb - format.json { render :json => @user } + + def edit + redirect_to admin_user_path(params[:id]) end - end - def edit - redirect_to admin_user_path(params[:id]) - end + def create + authorize! :create, User + @user = User.new(params[:user], as: current_user.role) - def create - authorize! :create, User - @user = User.new(params[:user], :as => current_user.role) - - respond_to do |format| - if @user.save - format.html { redirect_to(admin_users_path, :notice => 'User was successfully created.') } - format.json { render :json => @user, :status => :created, :location => @user } - else - format.html { render :action => "new" } - format.json { render :json => @user.errors, :status => :unprocessable_entity } + respond_to do |format| + if @user.save + format.html { redirect_to(admin_users_path, notice: 'User was successfully created.') } + format.json { render json: @user, status: :created, location: @user } + else + format.html { render action: 'new' } + format.json { render json: @user.errors, status: :unprocessable_entity } + end end end - end - def update - @user = User.find(params[:id]) - authorize! :update, @user + def update + @user = User.find(params[:id]) + authorize! :update, @user - respond_to do |format| - if @user.update_attributes(params[:user], :as => current_user.role) - format.html { redirect_to(admin_users_path, :notice => 'User was successfully updated.') } - format.json { head :ok } - else - format.html { render :action => "edit" } - format.json { render :json => @user.errors, :status => :unprocessable_entity } + respond_to do |format| + if @user.update_attributes(params[:user], as: current_user.role) + format.html { redirect_to(admin_users_path, notice: 'User was successfully updated.') } + format.json { head :ok } + else + format.html { render action: 'edit' } + format.json { render json: @user.errors, status: :unprocessable_entity } + end end end - end - def destroy - @user = User.find(params[:id]) - authorize! :destroy, @user - @user.destroy + def destroy + @user = User.find(params[:id]) + authorize! :destroy, @user + @user.destroy - respond_to do |format| - format.html { redirect_to(admin_users_path) } - format.json { head :ok } + respond_to do |format| + format.html { redirect_to(admin_users_path) } + format.json { head :ok } + end end - end -private - def set_navigation_ids - @navigation_ids = [:dashboard, :users] - end -end + private + def set_navigation_ids + @navigation_ids = %i[dashboard users] + end + end end # module Admin diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 1a590a5b..1f6837c0 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -5,24 +5,24 @@ class ApiController < ApplicationController layout nil - - skip_before_filter :verify_authenticity_token - skip_before_filter :authenticate_user! - before_filter :handle_cors - before_filter :populate_variables + + skip_before_action :verify_authenticity_token + skip_before_action :authenticate_user! + before_action :handle_cors + before_action :populate_variables class MissingParameter < StandardError end class UnacceptableFormat < StandardError end - rescue_from MissingParameter do |exception| - render :partial => 'missing_parameter' + rescue_from MissingParameter do |_exception| + render partial: 'missing_parameter' end rescue_from UnacceptableFormat do |exception| # Do nothing, response already sent. end - + def show_topic @topic_title = params[:topic_title] @topic_url = params[:topic_url] @@ -31,87 +31,88 @@ def show_topic # Must come before error checking because the error # templates depend on @include_base/@include_css. - if params.has_key?('comment_order') - @comment_order = params[:comment_order] - else - @comment_order = 'latest-first' - end + @comment_order = if params.has_key?('comment_order') + params[:comment_order] + else + 'latest-first' + end prepare!( - [:site_key, :topic_key, :container, :topic_title, :topic_url], - [:html, :js] + %i[site_key topic_key container topic_title topic_url], + %i[html js] ) if @topic = Topic.lookup(@site_key, @topic_key) render else - render :partial => 'site_not_found' + render partial: 'site_not_found' end end def add_comment prepare!( - [:site_key, :topic_key, :topic_title, :topic_url, :content], - [:html, :js, :json] + %i[site_key topic_key topic_title topic_url content], + %i[html js json] ) begin @content = decompress(params[:content]) if @content.blank? - render :partial => 'content_may_not_be_blank' + render partial: 'content_may_not_be_blank' return end - + Topic.transaction do @topic = Topic.lookup_or_create( @site_key, @topic_key, params[:topic_title], - params[:topic_url]) + params[:topic_url] + ) if @topic @comment = @topic.comments.create!( - :author_name => params[:author_name], - :author_email => params[:author_email], - :author_ip => request.env['REMOTE_ADDR'], - :author_user_agent => request.env['HTTP_USER_AGENT'], - :referer => request.env['HTTP_REFERER'], - :content => @content) + author_name: params[:author_name], + author_email: params[:author_email], + author_ip: request.env['REMOTE_ADDR'], + author_user_agent: request.env['HTTP_USER_AGENT'], + referer: request.env['HTTP_REFERER'], + content: @content + ) render else - render :partial => 'site_not_found' + render partial: 'site_not_found' end end - rescue => e + rescue StandardError => e log_exception(e) - render :partial => 'internal_error' + render partial: 'internal_error' end end def preview_comment - prepare!([], [:html, :js, :json]) + prepare!([], %i[html js json]) @content = decompress(params[:content]) end def list_topics - prepare!([:site_key], [:json, :jsonp]) + prepare!([:site_key], %i[json jsonp]) @site = Site.find_by_key(@site_key) if @site render else - render :partial => 'site_not_found' + render partial: 'site_not_found' end end -private + private + def handle_cors - headers["Access-Control-Allow-Origin"] = "*" - headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS" - headers["Access-Control-Max-Age"] = (60 * 60 * 24).to_s - if request.method == "OPTIONS" - render :text => '', :content_type => 'text/plain' - end + headers['Access-Control-Allow-Origin'] = '*' + headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS' + headers['Access-Control-Max-Age'] = (60 * 60 * 24).to_s + render text: '', content_type: 'text/plain' if request.method == 'OPTIONS' end - + def populate_variables @container = params[:container] @site_key = params[:site_key] @@ -144,7 +145,7 @@ def prepare!(required_params, accepted_formats) end raise UnacceptableFormat if performed? end - + def get_boolean_param(name, default = false) if params[name].present? value = params[name].downcase @@ -153,9 +154,9 @@ def get_boolean_param(name, default = false) default end end - + def decompress(str) - result = Zlib::Inflate.inflate(str.unpack('m').first) + result = Zlib::Inflate.inflate(str.unpack1('m')) result.force_encoding('utf-8') if result.respond_to?(:force_encoding) result end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a3803d39..60de2bff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,31 +1,29 @@ class ApplicationController < ActionController::Base protect_from_forgery - - before_filter :authenticate_user! - check_authorization :if => :inside_admin_area? - rescue_from CanCan::AccessDenied do |exception| - render :template => 'shared/forbidden' + before_action :authenticate_user! + check_authorization if: :inside_admin_area? + + rescue_from CanCan::AccessDenied do |_exception| + render template: 'shared/forbidden' end -private + private + ### before filters - + def require_admin! - if !current_user.admin? - render :template => 'shared/admin_required' - end + render template: 'shared/admin_required' unless current_user.admin? end - + def save_return_to_url - if (path = params[:return_to]) && path =~ /\A\// + if (path = params[:return_to]) && path =~ %r{\A/} session[:return_to] = path end end - - + ### helpers - + def redirect_back(default_url = nil) redirect_to(session.delete(:return_to) || :back) rescue RedirectBackError diff --git a/app/models/ability.rb b/app/models/ability.rb index 6e9380a3..0b397fbe 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -26,19 +26,19 @@ def initialize(user) # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities # Non-logged in users cannot do anything. - return if !user + return unless user - crud = [:create, :read, :update, :destroy] + crud = %i[create read update destroy] if user.admin? can crud, :all can :list, :all can :make_admin, User else - can [:read, :update, :destroy], User, :id => user.id - can crud, Site, :user_id => user.id - can crud, Topic, :site => { :user_id => user.id } - can crud, Comment, :topic => { :site => { :user_id => user.id } } + can %i[read update destroy], User, id: user.id + can crud, Site, user_id: user.id + can crud, Topic, site: { user_id: user.id } + can crud, Comment, topic: { site: { user_id: user.id } } end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index ca5fd8ec..e557933a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,28 +1,22 @@ -require 'digest/md5' -require 'net/http' -require 'cgi' - class Comment < ActiveRecord::Base class AkismetError < StandardError end - attr_accessible :author_name, :author_email, :author_ip, :author_user_agent, :referer, :content + belongs_to :topic, inverse_of: :comments + + acts_as_enum :moderation_status, %i[ok unchecked spam] - belongs_to :topic, :inverse_of => :comments - - acts_as_enum :moderation_status, [:ok, :unchecked, :spam] - - scope :visible, -> { where(:moderation_status => moderation_status(:ok)) } + scope :visible, -> { where(moderation_status: moderation_status(:ok)) } scope :requiring_moderation, -> { where("moderation_status != #{moderation_status(:ok)}") } - + validates_presence_of :content validates_presence_of :author_ip - + before_validation :nullify_blank_fields before_create :set_moderation_status after_create :update_topic_timestamp after_create :notify_moderators - + def site topic.site end @@ -33,21 +27,17 @@ def author_email=(value) end def author_email_md5 - if author_email - Digest::MD5.hexdigest(author_email.downcase) - else - nil - end + Digest::MD5.hexdigest(author_email.downcase) if author_email end - + def spam? response = call_akismet('comment-check', akismet_params) if response.body == 'invalid' - if response['X-akismet-debug-help'] - message = "Akismet server error: " << response['X-akismet-debug-help'] - else - message = "Unknown Akismet server error, maybe your API key is wrong" - end + message = if response['X-akismet-debug-help'] + 'Akismet server error: ' << response['X-akismet-debug-help'] + else + 'Unknown Akismet server error, maybe your API key is wrong' + end raise AkismetError, message elsif response.body == 'true' true @@ -57,72 +47,73 @@ def spam? raise AkismetError, "Akismet server error: #{response.body}" end end - + def report_ham call_akismet('submit-ham', akismet_params) end - + def report_spam call_akismet('submit-spam', akismet_params) end -private + private + AKISMET_HEADERS = { 'User-Agent' => "Juvia | Rails/#{Rails.version}", 'Content-Type' => 'application/x-www-form-urlencoded' - } - + }.freeze + def nullify_blank_fields self.author_name = nil if author_name.blank? self.author_email = nil if author_email.blank? self.author_user_agent = nil if author_user_agent.blank? self.referer = nil if referer.blank? end - + def akismet_params - raise AkismetError, "Site URL required for Akismet check" if topic.site.url.blank? + raise AkismetError, 'Site URL required for Akismet check' if topic.site.url.blank? + params = { - :blog => topic.site.url, - :user_ip => author_ip, - :user_agent => author_user_agent, - :referrer => referer, - :comment_content => content, - :comment_type => 'comment' + blog: topic.site.url, + user_ip: author_ip, + user_agent: author_user_agent, + referrer: referer, + comment_content: content, + comment_type: 'comment' } params[:comment_author] = author_name if author_name.present? params[:comment_author_email] = author_email if author_email.present? params end - + def call_akismet(function_name, params) - raise AkismetError, "Akismet key required" if topic.site.akismet_key.blank? + raise AkismetError, 'Akismet key required' if topic.site.akismet_key.blank? + uri = URI.parse("http://#{topic.site.akismet_key}.rest.akismet.com/1.1/#{function_name}") post_data = params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') response = Net::HTTP.start(uri.host, uri.port) do |http| http.post(uri.path, post_data, AKISMET_HEADERS) end - if response.code != "200" + if response.code != '200' raise AkismetError, "Akismet internal error #{response.code}" else response end end - + def set_moderation_status - case topic.site.moderation_method - when :akismet - self.moderation_status = spam? ? :spam : :ok - when :manual - self.moderation_status = :unchecked - else - self.moderation_status = :ok - end + self.moderation_status = case topic.site.moderation_method + when :akismet + spam? ? :spam : :ok + when :manual + :unchecked + else + :ok + end end def update_topic_timestamp - if topic - topic.update_attribute(:last_posted_at, Time.now) - end + topic&.update_attribute(:last_posted_at, Time.now) end def notify_moderators diff --git a/app/models/site.rb b/app/models/site.rb index 14f16b92..c57750f1 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,52 +1,50 @@ class Site < ActiveRecord::Base - belongs_to :user, :inverse_of => :sites - has_many :topics, :inverse_of => :site - has_many :comments, :through => :topics - - acts_as_enum :moderation_method, [:none, :akismet, :manual] - + belongs_to :user, inverse_of: :sites + has_many :topics, inverse_of: :site + has_many :comments, through: :topics + + acts_as_enum :moderation_method, %i[none akismet manual] + validates_presence_of :name validates_presence_of :key validates_presence_of :moderation_method - validates_presence_of :url, :if => :moderation_method_is_akismet? - validates_presence_of :akismet_key, :if => :moderation_method_is_akismet? + validates_presence_of :url, if: :moderation_method_is_akismet? + validates_presence_of :akismet_key, if: :moderation_method_is_akismet? before_validation :nullify_blank_fields - - attr_accessible :name, :url, :moderation_method, :akismet_key - attr_accessible :user, :user_id, :name, :key, :url, - :moderation_method, :akismet_key, :as => :admin - - default_value_for(:key) { SecureRandom.hex(20).to_i(16).to_s(36) } + #default_value_for(:key) { SecureRandom.hex(20).to_i(16).to_s(36) } + + # TODO: refactor using Rails query syntax, no need in raw SQL def public_topics_info result = [] - sql = %q{ + sql = ' SELECT topics.*, COUNT(comments.id) AS comment_count FROM topics LEFT JOIN sites ON sites.id = topics.site_id LEFT JOIN comments ON comments.topic_id = topics.id WHERE sites.id = ? GROUP BY topics.id - } + ' topics = Topic.find_by_sql([sql, id]) topics.each do |topic| result << { - :id => topic.id, - :key => topic.key, - :title => topic.title, - :url => topic.url, - :last_posted_at => topic.last_posted_at, - :comment_count => topic['comment_count'] + id: topic.id, + key: topic.key, + title: topic.title, + url: topic.url, + last_posted_at: topic.last_posted_at, + comment_count: topic['comment_count'] } end result end def last_updated_topics - topics.order("last_posted_at DESC") + topics.order('last_posted_at DESC') end -private + private + def nullify_blank_fields self.url = nil if url.blank? self.akismet_key = nil if akismet_key.blank? diff --git a/app/models/topic.rb b/app/models/topic.rb index 4f2ee561..ac2a90fe 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,8 +1,6 @@ class Topic < ActiveRecord::Base - attr_accessible :key, :title, :url - - belongs_to :site, :inverse_of => :topics - has_many :comments, -> { order("created_at DESC") }, :inverse_of => :topic + belongs_to :site, inverse_of: :topics + has_many :comments, -> { order('created_at DESC') }, inverse_of: :topic validates_presence_of :key validates_presence_of :title @@ -15,11 +13,7 @@ def self.lookup(site_key, topic_key) topic else site = Site.find_by_key(site_key) - if site - Topic.new(:key => topic_key, :site => site) - else - nil - end + Topic.new(key: topic_key, site: site) if site end end @@ -29,32 +23,28 @@ def self.lookup_or_create(site_key, topic_key, topic_title, topic_url) topic else site = Site.find_by_key(site_key) - if site - site.topics.create!( - :key => topic_key, - :title => topic_title, - :url => topic_url) - else - nil - end + site&.topics&.create!( + key: topic_key, + title: topic_title, + url: topic_url + ) end end def self.alt_key(topic_key) - topic_key.match(/\/$/) ? topic_key.chop : "#{topic_key}/" + topic_key.match(%r{/$}) ? topic_key.chop : "#{topic_key}/" end -private def self.find_by_site_key_and_topic_key(site_key, topic_key) Topic. where('sites.key = ? AND topics.key = ?', site_key, topic_key). joins(:site). - select('topics.*'). - first || - Topic. - where('sites.key = ? AND topics.key = ?', site_key, alt_key(topic_key)). - joins(:site). - select('topics.*'). - first + select('topics.*') + .first || + Topic. + where('sites.key = ? AND topics.key = ?', site_key, alt_key(topic_key)). + joins(:site). + select('topics.*'). + first end end diff --git a/app/models/user.rb b/app/models/user.rb index 25eb87ed..99d1b67e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,27 +1,22 @@ -require 'digest/md5' - class User < ActiveRecord::Base - has_many :sites, -> { order('name') }, :inverse_of => :user - has_many :topics, :through => :sites - + has_many :sites, -> { order('name') }, inverse_of: :user + has_many :topics, through: :sites + # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :validatable, :timeoutable - attr_accessible :email, :password, :password_confirmation, :remember_me - attr_accessible :email, :password, :password_confirmation, :remember_me, :admin, :as => :admin - before_validation :nullify_blank_password_on_update - + def comments - Comment. - joins(:topic => { :site => :user }). - where(:users => { :id => id }). - order('comments.created_at DESC') + Comment + .joins(topic: { site: :user }) + .where(users: { id: id }) + .order('comments.created_at DESC') end - + def accessible_comments if admin? Comment.where(nil) @@ -29,7 +24,7 @@ def accessible_comments comments end end - + def accessible_sites if admin? Site.where(nil) @@ -37,26 +32,19 @@ def accessible_sites sites end end - + def email_md5 - if email - Digest::MD5.hexdigest(email.downcase) - else - nil - end + Digest::MD5.hexdigest(email.downcase) if email end def role - if admin? - :admin - else - nil - end + :admin if admin? end -private + private + def nullify_blank_password_on_update - if !new_record? + unless new_record? self.password = nil if password.blank? self.password_confirmation = nil if password_confirmation.blank? end diff --git a/app/views/admin/comments/_comment.html.erb b/app/views/admin/comments/_comment.html.erb index 5de5c49f..f5a0fb91 100644 --- a/app/views/admin/comments/_comment.html.erb +++ b/app/views/admin/comments/_comment.html.erb @@ -1,4 +1,4 @@ -<%= div_for(comment, 'data-comment-id' => comment.id, :class => "moderation_status_#{comment.moderation_status}") do %> +
" id="<%= comment.id %>" data-comment-id="<%= comment.id %>">
-<% end %> +
diff --git a/app/views/admin/sites/_site.html.erb b/app/views/admin/sites/_site.html.erb index 1e9e39a8..d1192e8c 100644 --- a/app/views/admin/sites/_site.html.erb +++ b/app/views/admin/sites/_site.html.erb @@ -1,4 +1,4 @@ -<%= div_for(site, :class => 'item container') do %> +
<%= small_identity_tag(:site, site.name, [:admin, site]) %> @@ -8,4 +8,4 @@ <%= site.comments.count %> comments
-<% end %> \ No newline at end of file +
diff --git a/app/views/admin/topics/_topic.html.erb b/app/views/admin/topics/_topic.html.erb index ef07c640..6edf94b5 100644 --- a/app/views/admin/topics/_topic.html.erb +++ b/app/views/admin/topics/_topic.html.erb @@ -1,4 +1,4 @@ -<%= div_for(topic, :class => 'item container') do %> +
<%= small_identity_tag :topic, topic.title, [:admin, topic] %> @@ -7,4 +7,4 @@ <%= topic_comments_count_and_last_comment_date(topic) %>
-<% end %> \ No newline at end of file +
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 8f7e6cca..c6aff6b5 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -7,13 +7,13 @@
<% @users.each do |user| %> - <%= div_for(user, :class => 'item') do %> +
<% if user.admin? %>
admin
<% end %> - <% end %> +
<% end %>
diff --git a/bin/rails b/bin/rails index 1c894d52..07396602 100755 --- a/bin/rails +++ b/bin/rails @@ -1,10 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 0fb4e07e..17240489 100755 --- a/bin/rake +++ b/bin/rake @@ -1,7 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -require 'bundler/setup' -load Gem.bin_path('rake', 'rake') +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..0e39e8cb --- /dev/null +++ b/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require 'fileutils' + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:prepare' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring deleted file mode 100755 index 7b45d374..00000000 --- a/bin/spring +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env ruby - -# This file loads spring without using Bundler, in order to be fast. -# It gets overwritten when you run the `spring binstub` command. - -unless defined?(Spring) - require "rubygems" - require "bundler" - - if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) - Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq } - gem "spring", match[1] - require "spring/binstub" - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 10d89e75..7dee006b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,6 @@ require 'capybara/rails' require 'capybara/rspec' require 'capybara-screenshot/rspec' - require 'capybara-webkit' require 'database_cleaner' require 'launchy' require 'rspec/rails' @@ -21,7 +20,7 @@ # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} - Capybara.javascript_driver = :webkit + Capybara.javascript_driver = :selenium_headless Capybara::Screenshot.autosave_on_failure = false DatabaseCleaner.logger = Rails.logger