Skip to content

Commit

Permalink
Re-enable rubocop and put it in travis
Browse files Browse the repository at this point in the history
Closes #92
  • Loading branch information
ChrisMacNaughton committed Sep 16, 2020
1 parent 5223155 commit 688cd80
Show file tree
Hide file tree
Showing 45 changed files with 211 additions and 218 deletions.
1 change: 0 additions & 1 deletion .rubocop
@@ -1,2 +1 @@
--rails
--extra-details
20 changes: 15 additions & 5 deletions .rubocop.yml
@@ -1,10 +1,11 @@
Rails:
Enabled: true
require:
- rubocop-rails

Metrics/LineLength:
Layout/LineLength:
Max: 120

AllCops:
NewCops: enable
Exclude:
- db/migrate/*
- db/schema.rb
Expand All @@ -14,6 +15,7 @@ AllCops:
- config/initializers/devise.rb
- app/models/setting.rb
- config/deploy.rb

Style/Documentation:
Enabled: false

Expand All @@ -33,16 +35,24 @@ Rails/InverseOf:
Metrics/BlockLength:
Exclude:
- config/environments/development.rb
- config/routes.rb
- Guardfile
- lib/tasks/auto_annotate_models.rake
- config/initializers/simple_form_bootstrap.rb
- config/initializers/doorkeeper_openid_connect.rb
- lib/tasks/*
- app/admin/*
- spec/models/*.rb
- spec/controllers/*.rb
- spec/controllers/admin/*.rb

Naming/AccessorMethodName:
Enabled: false

Layout/AlignHash:
Layout/HashAlignment:
Enabled: False

GlobalVars:
Style/GlobalVars:
AllowedVariables:
- $redis

Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -27,3 +27,4 @@ script:
- bundle exec rake db:create
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rspec
- bundle exec rubocop
2 changes: 1 addition & 1 deletion Capfile
Expand Up @@ -11,7 +11,7 @@ require 'capistrano/rvm'
require 'capistrano/puma'
install_plugin Capistrano::Puma

require "capistrano/scm/git"
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Expand Down
13 changes: 7 additions & 6 deletions Gemfile
Expand Up @@ -25,12 +25,12 @@ gem 'redis', '~> 4.0'

gem 'bootsnap', '>= 1.3.2', require: false

gem 'rails-i18n'
gem 'dotenv', '~> 2.5.0'
gem 'rails-i18n'

gem 'devise'
gem 'devise-i18n'
gem 'devise_fido_usf'
gem 'devise-i18n'
gem 'friendly_id'
# Do TOTP 2FA
gem 'devise-two-factor'
Expand All @@ -55,10 +55,10 @@ gem 'scout_apm'
# gem 'rails-settings-cached'

gem 'peek'
gem 'peek-pg'
gem 'peek-gc'
gem 'peek-performance_bar'
gem 'peek-pg'
gem 'tipsy-rails'
gem 'peek-gc'

# SAML the things!
gem 'saml_idp'
Expand Down Expand Up @@ -88,6 +88,7 @@ group :development do
gem 'brakeman', require: false
gem 'overcommit'
gem 'rubocop', require: false
gem 'rubocop-rails', require: false

gem 'guard'
gem 'guard-bundler', require: false
Expand All @@ -100,15 +101,15 @@ group :development do

gem 'bcrypt_pbkdf', require: false
gem 'capistrano', require: false
gem 'capistrano3-puma', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano3-puma', require: false
gem 'ed25519', require: false
end

group :test do
gem 'faker'
gem 'timecop'
gem 'shoulda'
gem 'timecop'
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -344,6 +344,10 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.4.0)
parser (>= 2.7.1.4)
rubocop-rails (2.7.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.87.0)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.10.1)
Expand Down Expand Up @@ -487,6 +491,7 @@ DEPENDENCIES
rqrcode
rspec-rails (~> 4)
rubocop
rubocop-rails
saml_idp
sass-rails (~> 6.0)
scout_apm
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/admin/groups_controller.rb
Expand Up @@ -17,9 +17,9 @@ def form_relations
parent: {
type: :select,
options: { prompt: 'No Parent' },
finder: -> {
helpers.options_from_collection_for_select(Group.all, :id, :name, @model.parent.try(:id))
}
finder: lambda {
helpers.options_from_collection_for_select(Group.all, :id, :name, @model.parent.try(:id))
}
},
permissions: {
type: :select,
Expand Down Expand Up @@ -51,7 +51,7 @@ def model_params
p
end

def sort_whitelist
['created_at', 'name']
def sort_whitelist
%w[created_at name]
end
end
22 changes: 6 additions & 16 deletions app/controllers/admin/settings_controller.rb
Expand Up @@ -10,25 +10,15 @@ def index; end
# PATCH/PUT /admin/settings/1.json
def update
opts = setting_params
if opts[:registration_enabled].nil?
opts[:registration_enabled] = false
else
opts[:registration_enabled] = true
end
opts[:registration_enabled] = if opts[:registration_enabled].nil?
false
else
true
end
opts.each do |setting, value|
Setting.send("#{setting}=", value)
puts "#{setting}: #{value}"
end
redirect_to admin_settings_url, notice: 'Settings were successfully updated.'
# respond_to do |format|
# if @setting.update(setting_params)
# format.html { redirect_to @setting, notice: 'Setting was successfully updated.' }
# format.json { render :show, status: :ok, location: @setting }
# else
# format.html { render :edit }
# format.json { render json: @setting.errors, status: :unprocessable_entity }
# end
# end
end

private
Expand All @@ -46,7 +36,7 @@ def setting_params
:oidc_signing_key,
:registration_enabled,
:logo, :logo_height, :logo_width,
:home_template, :registered_home_template,
:home_template, :registered_home_template
)
end
end
4 changes: 2 additions & 2 deletions app/controllers/admin/users_controller.rb
Expand Up @@ -42,11 +42,11 @@ def model_params
end

def sort_whitelist
['created_at', 'username', 'email']
%w[created_at username email]
end

def filter_whitelist
['username', 'email']
%w[username email]
end

def filter
Expand Down
26 changes: 11 additions & 15 deletions app/controllers/admin_controller.rb
@@ -1,19 +1,17 @@
# frozen_string_literal: true

class AdminController < ApplicationController
class AdminController < ApplicationController # rubocop:disable Metrics/ClassLength
# before_action :authenticate_user!
before_action :ensure_user_is_admin!
before_action :set_model, only: %i[show edit update destroy]
# GET /admin/#{model}
# GET /admin/#{model}.json
def index
@models = model
.page(params[:page] || 1)
.includes(includes)
.order(order)
if filter
@models = @models.where(filter)
end
.page(params[:page] || 1)
.includes(includes)
.order(order)
@models = @models.where(filter) if filter
end

# GET /admin/#{model}/1
Expand All @@ -30,7 +28,6 @@ def edit; end

# POST /admin/#{model}
# POST /admin/#{model}.json
# rubocop:disable Metrics/AbcSize
def create
@model = model.new(model_params)
respond_to do |format|
Expand All @@ -43,7 +40,6 @@ def create
end
end
end
# rubocop:enable Metrics/AbcSize

# PATCH/PUT /admin/#{model}/1
# PATCH/PUT /admin/#{model}/1.json
Expand Down Expand Up @@ -94,19 +90,19 @@ def includes

def filter
if filter_whitelist.include? params[:filter_by]
{params[:filter_by] => params[:filter]}
{ params[:filter_by] => params[:filter] }
else
{}
end
end

def order
def order # rubocop:disable Metrics/AbcSize
sort = {
sort_by: :created_at,
sort_dir: :asc,
sort_dir: :asc
}
sort[:sort_by] = params[:sort_by] if params[:sort_by] && sort_whitelist.include?(params[:sort_by])
sort[:sort_dir] = params[:sort_dir] if params[:sort_dir] && ['asc', 'desc'].include?(params[:sort_dir])
sort[:sort_dir] = params[:sort_dir] if params[:sort_dir] && %w[asc desc].include?(params[:sort_dir])
{ sort[:sort_by] => sort[:sort_dir] }
end

Expand Down Expand Up @@ -141,7 +137,7 @@ def set_model
end

def ensure_user_is_admin!
raise ActionController::RoutingError.new('Not Found') and return \
unless current_user && current_user.admin?
raise(ActionController::RoutingError, 'Not Found') and return \
unless current_user&.admin?
end
end
13 changes: 6 additions & 7 deletions app/controllers/application_controller.rb
Expand Up @@ -22,11 +22,11 @@ def default_url_options
end

def after_sign_in_path_for(resource)
request.env['omniauth.origin'] || params[:redirect_to] || stored_location_for(resource) || root_url
request.env['omniauth.origin'] || params[:redirect_to] || stored_location_for(resource) || root_url
end

def peek_enabled?
super || ( current_user && current_user.admin? )
super || current_user&.admin?
end

# U2F (universal 2nd factor) devices need a unique identifier for the application
Expand All @@ -36,13 +36,12 @@ def u2f_app_id
request.base_url
end


protected
protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in, keys: [:login, :otp_attempt])
devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :email])
devise_parameter_sanitizer.permit(:account_update, keys: [:username, :email, :name])
devise_parameter_sanitizer.permit(:sign_in, keys: %i[login otp_attempt])
devise_parameter_sanitizer.permit(:sign_up, keys: %i[username email])
devise_parameter_sanitizer.permit(:account_update, keys: %i[username email name])
end

private
Expand Down

0 comments on commit 688cd80

Please sign in to comment.