chore(rubocop): giganto rubocop commit.

muahahahah
This commit is contained in:
Joseph Mastey
2017-12-05 18:46:21 -06:00
parent 284cd8811c
commit 9902345291
120 changed files with 743 additions and 635 deletions
+5 -4
View File
@@ -1,5 +1,6 @@
# frozen_string_literal: true
class AdminController < ApplicationController
before_action :administrative, :if => :admin_param, :except => [:get_user]
before_action :administrative, if: :admin_param, except: [:get_user]
skip_before_action :has_info
def dashboard
@@ -41,7 +42,7 @@ class AdminController < ApplicationController
message = true
end
respond_to do |format|
format.json { render :json => { :msg => message ? "success" : "failure"} }
format.json { render json: { msg: message ? "success" : "failure"} }
end
end
@@ -54,7 +55,7 @@ class AdminController < ApplicationController
message = true
end
respond_to do |format|
format.json { render :json => { :msg => message ? "success" : "failure"} }
format.json { render json: { msg: message ? "success" : "failure"} }
end
end
@@ -66,6 +67,6 @@ class AdminController < ApplicationController
helper_method :custom_fields
def admin_param
params[:admin_id] != '1'
params[:admin_id] != "1"
end
end
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Api::V1::MobileController < ApplicationController
skip_before_action :authenticated
before_action :mobile_request?
+3 -2
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Api::V1::UsersController < ApplicationController
skip_before_action :authenticated
before_action :valid_api_token
@@ -24,7 +25,7 @@ class Api::V1::UsersController < ApplicationController
end
end
def identify_user(token="")
def identify_user(token = "")
# We've had issues with URL encoding, etc. causing issues so just to be safe
# we will go ahead and unescape the user's token
unescape_token(token)
@@ -42,7 +43,7 @@ class Api::V1::UsersController < ApplicationController
# We had some issues with the token and url encoding...
# this is an attempt to normalize the data.
def unescape_token(token="")
def unescape_token(token = "")
@clean_token = CGI::unescape(token)
end
+5 -4
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
before_action :authenticated, :has_info, :create_analytic, :mailer_options
helper_method :current_user, :is_admin?, :sanitize_font
@@ -22,8 +23,8 @@ class ApplicationController < ActionController::Base
end
def authenticated
path = request.fullpath.present? ? root_url(:url => request.fullpath) : root_url
redirect_to path and reset_session if not current_user
path = request.fullpath.present? ? root_url(url: request.fullpath) : root_url
redirect_to path and reset_session if !current_user
end
def is_admin?
@@ -31,7 +32,7 @@ class ApplicationController < ActionController::Base
end
def administrative
if not is_admin?
if !is_admin?
redirect_to root_url
end
end
@@ -51,7 +52,7 @@ class ApplicationController < ActionController::Base
end
def create_analytic
Analytics.create({ :ip_address => request.remote_ip, :referrer => request.referrer, :user_agent => request.user_agent})
Analytics.create({ ip_address: request.remote_ip, referrer: request.referrer, user_agent: request.user_agent})
end
def sanitize_font(css)
+4 -3
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class BenefitFormsController < ApplicationController
def index
@@ -8,9 +9,9 @@ class BenefitFormsController < ApplicationController
begin
path = params[:name]
file = params[:type].constantize.new(path)
send_file file, :disposition => 'attachment'
send_file file, disposition: "attachment"
rescue
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)
redirect_to user_benefit_forms_path(user_id: current_user.user_id)
end
end
@@ -22,7 +23,7 @@ class BenefitFormsController < ApplicationController
else
flash[:error] = "Something went wrong"
end
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)
redirect_to user_benefit_forms_path(user_id: current_user.user_id)
end
end
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class DashboardController < ApplicationController
skip_before_action :has_info
+7 -6
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class MessagesController < ApplicationController
def index
@@ -7,15 +8,15 @@ class MessagesController < ApplicationController
end
def show
@message = Message.where(:id => params[:id]).first
@message = Message.where(id: params[:id]).first
end
def destroy
message = Message.where(:id => params[:id]).first
message = Message.where(id: params[:id]).first
if message.destroy
flash[:success] = "Your message has been deleted."
redirect_to user_messages_path(:user_id => current_user.user_id)
redirect_to user_messages_path(user_id: current_user.user_id)
else
flash[:error] = "Could not delete message."
end
@@ -24,13 +25,13 @@ class MessagesController < ApplicationController
def create
if Message.create(message_params)
respond_to do |format|
format.html { redirect_to user_messages_path(:user_id => current_user.user_id) }
format.json { render :json => {:msg => "success"} }
format.html { redirect_to user_messages_path(user_id: current_user.user_id) }
format.json { render json: {msg: "success"} }
end
else
respond_to do |format|
format.html { redirect_to user_messages_path }
format.json { render :json => {:msg => "failure"} }
format.json { render json: {msg: "failure"} }
end
end
end
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class PaidTimeOffController < ApplicationController
def index
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class PasswordResetsController < ApplicationController
skip_before_action :authenticated
@@ -18,7 +19,7 @@ class PasswordResetsController < ApplicationController
def confirm_token
if !params[:token].nil? && is_valid?(params[:token])
flash[:success] = "Password reset token confirmed! Please create a new password."
render :reset_password
render "reset_password"
else
flash[:error] = "Invalid password reset token. Please try again."
redirect_to :login
+7 -6
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class PayController < ApplicationController
def index
@@ -6,20 +7,20 @@ class PayController < ApplicationController
def update_dd_info
msg = false
pay = Pay.new(
:bank_account_num => params[:bank_account_num],
:bank_routing_num => params[:bank_routing_num],
:percent_of_deposit => params[:dd_percent]
bank_account_num: params[:bank_account_num],
bank_routing_num: params[:bank_routing_num],
percent_of_deposit: params[:dd_percent]
)
pay.user_id = current_user.user_id
msg = true if pay.save!
respond_to do |format|
format.json {render :json => {:msg => msg } }
format.json {render json: {msg: msg } }
end
end
def show
respond_to do |format|
format.json { render :json => {:user => current_user.pay.as_json} }
format.json { render json: {user: current_user.pay.as_json} }
end
end
@@ -36,7 +37,7 @@ class PayController < ApplicationController
def decrypted_bank_acct_num
decrypted = Encryption.decrypt_sensitive_value(params[:value_to_decrypt])
respond_to do |format|
format.json {render :json => {:account_num => decrypted || "No Data" }}
format.json {render json: {account_num: decrypted || "No Data" }}
end
end
end
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class PerformanceController < ApplicationController
def index
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class RetirementController < ApplicationController
def index
+7 -8
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class ScheduleController < ApplicationController
def create
@@ -14,7 +15,7 @@ class ScheduleController < ApplicationController
end
respond_to do |format|
format.json {render :json => {:msg => message ? "success" : "failure" }}
format.json {render json: {msg: message ? "success" : "failure" }}
end
end
@@ -33,11 +34,9 @@ class ScheduleController < ApplicationController
rescue
end
respond_to do |format|
format.json do
render :json => jfs.to_json
end
end
end
format.json { render json: jfs.to_json }
end
end
private
@@ -47,8 +46,8 @@ class ScheduleController < ApplicationController
begin
vals = []
return vals if date_array.empty?
date_array.split('-').each do |s|
date = Date.strptime(s.strip, '%m/%d/%Y')
date_array.split("-").each do |s|
date = Date.strptime(s.strip, "%m/%d/%Y")
vals <<(date)
end
rescue ArgumentError
+4 -3
View File
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class SessionsController < ApplicationController
skip_before_action :has_info
skip_before_action :authenticated, :only => [:new, :create]
skip_before_action :authenticated, only: [:new, :create]
def new
@url = params[:url]
@@ -17,9 +18,9 @@ class SessionsController < ApplicationController
if user
if params[:remember_me]
cookies.permanent[:auth_token] = user.auth_token if User.where(:user_id => user.user_id).exists?
cookies.permanent[:auth_token] = user.auth_token if User.where(user_id: user.user_id).exists?
else
session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists?
session[:user_id] = user.user_id if User.where(user_id: user.user_id).exists?
end
redirect_to path
else
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class TutorialsController < ApplicationController
skip_before_action :has_info
skip_before_action :authenticated
+5 -4
View File
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class UsersController < ApplicationController
skip_before_action :has_info
skip_before_action :authenticated, :only => [:new, :create]
skip_before_action :authenticated, only: [:new, :create]
def new
@user = User.new
@@ -35,12 +36,12 @@ class UsersController < ApplicationController
end
message = true if user.save!
respond_to do |format|
format.html { redirect_to user_account_settings_path(:user_id => current_user.user_id) }
format.json { render :json => {:msg => message ? "success" : "false "} }
format.html { redirect_to user_account_settings_path(user_id: current_user.user_id) }
format.json { render json: {msg: message ? "success" : "false "} }
end
else
flash[:error] = "Could not update user!"
redirect_to user_account_settings_path(:user_id => current_user.user_id)
redirect_to user_account_settings_path(user_id: current_user.user_id)
end
end
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class WorkInfoController < ApplicationController
def index
@user = User.find_by_user_id(params[:user_id])
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module AdminHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module Api::V1::UsersHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module ApplicationHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module BenefitFormsHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module DashboardHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module MessagesHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module PaidTimeOffHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module PasswordResetsHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module PayHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module PerformanceHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module RetirementHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module ScheduleHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module SessionsHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module TutorialsHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module UsersHelper
end
+1
View File
@@ -1,2 +1,3 @@
# frozen_string_literal: true
module WorkInfoHelper
end
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class UserMailer < ActionMailer::Base
default from: "noreply@railsgoat.dev"
+2 -1
View File
@@ -1,5 +1,6 @@
# frozen_string_literal: true
class Analytics < ApplicationRecord
scope :hits_by_ip, ->(ip,col="*") { select("#{col}").where(:ip_address => ip).order("id DESC")}
scope :hits_by_ip, ->(ip, col = "*") { select("#{col}").where(ip_address: ip).order("id DESC")}
def self.count_by_col(col)
calculate(:count, col)
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
+4 -3
View File
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class Benefits < ApplicationRecord
def self.save(file, backup=false)
def self.save(file, backup = false)
data_path = Rails.root.join("public", "data")
full_file_name = "#{data_path}/#{file.original_filename}"
f = File.open(full_file_name, "wb+")
@@ -10,7 +11,7 @@ class Benefits < ApplicationRecord
end
def self.make_backup(file, data_path, full_file_name)
if File.exists?(full_file_name)
if File.exist?(full_file_name)
silence_streams(STDERR) { system("cp #{full_file_name} #{data_path}/bak#{Time.zone.now.to_i}_#{file.original_filename}") }
end
end
@@ -18,7 +19,7 @@ class Benefits < ApplicationRecord
def self.silence_streams(*streams)
on_hold = streams.collect { |stream| stream.dup }
streams.each do |stream|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? "NUL:" : "/dev/null")
stream.sync = true
end
yield
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class KeyManagement < ApplicationRecord
belongs_to :work_info
belongs_to :user
+2 -1
View File
@@ -1,9 +1,10 @@
# frozen_string_literal: true
class Message < ApplicationRecord
belongs_to :user
validates_presence_of :creator_id, :receiver_id, :message
def creator_name
if creator = User.where(:user_id => self.creator_id).first
if creator = User.where(user_id: self.creator_id).first
creator.full_name
else
"<b>Name unavailable</b>".html_safe
+2 -1
View File
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class PaidTimeOff < ApplicationRecord
belongs_to :user
has_many :schedule, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_many :schedule, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
def sick_days_remaining
self.sick_days_earned - self.sick_days_taken
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Pay < ApplicationRecord
# Associations
belongs_to :user
+2 -1
View File
@@ -1,8 +1,9 @@
# frozen_string_literal: true
class Performance < ApplicationRecord
belongs_to :user
def reviewer_name
u = User.find_by_id(self.reviewer)
u.full_name if u.respond_to?('fullname')
u.full_name if u.respond_to?("fullname")
end
end
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Retirement < ApplicationRecord
belongs_to :user
end
+1
View File
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Schedule < ApplicationRecord
belongs_to :paid_time_off
+24 -25
View File
@@ -1,46 +1,45 @@
require 'encryption'
# frozen_string_literal: true
require "encryption"
class User < ApplicationRecord
validates :password, :presence => true,
:confirmation => true,
:length => {:within => 6..40},
:on => :create,
:if => :password
validates :password, presence: true,
confirmation: true,
length: {within: 6..40},
on: :create,
if: :password
validates_presence_of :email
validates_uniqueness_of :email
validates_format_of :email, :with => /.+@.+\..+/i
validates_format_of :email, with: /.+@.+\..+/i
attr_accessor :skip_user_id_assign
before_save :assign_user_id, :on => :create
before_save :assign_user_id, on: :create
before_save :hash_password
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_one :paid_time_off, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_one :work_info, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_many :performance, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_many :messages, :foreign_key => :receiver_id, :primary_key => :user_id, :dependent => :destroy
has_many :pay, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_one :retirement, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
has_one :paid_time_off, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
has_one :work_info, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
has_many :performance, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
has_many :messages, foreign_key: :receiver_id, primary_key: :user_id, dependent: :destroy
has_many :pay, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
before_create { generate_token(:auth_token) }
before_create :build_benefits_data
def build_benefits_data
build_retirement(POPULATE_RETIREMENTS.shuffle.first)
build_paid_time_off(POPULATE_PAID_TIME_OFF.shuffle.first).schedule.build(POPULATE_SCHEDULE.shuffle.first)
build_work_info(POPULATE_WORK_INFO.shuffle.first)
build_retirement(POPULATE_RETIREMENTS.sample)
build_paid_time_off(POPULATE_PAID_TIME_OFF.sample).schedule.build(POPULATE_SCHEDULE.sample)
build_work_info(POPULATE_WORK_INFO.sample)
# Uncomment below line to use encrypted SSN(s)
#work_info.build_key_management(:iv => SecureRandom.hex(32))
performance.build(POPULATE_PERFORMANCE.shuffle.first)
performance.build(POPULATE_PERFORMANCE.sample)
end
def full_name
"#{self.first_name} #{self.last_name}"
end
=begin
# Instead of the entire user object being returned, we can use this to filter.
def as_json
super(only: [:user_id, :email, :first_name, :last_name])
end
=end
# # Instead of the entire user object being returned, we can use this to filter.
# def as_json
# super(only: [:user_id, :email, :first_name, :last_name])
# end
private
@@ -59,7 +58,7 @@ class User < ApplicationRecord
def assign_user_id
unless @skip_user_id_assign.present? || self.user_id.present?
user = User.order("user_id").last
uid = if user && user.user_id && !(User.exists?(:user_id => "#{user.user_id.to_i + 1}"))
uid = if user && user.user_id && !(User.exists?(user_id: "#{user.user_id.to_i + 1}"))
user.user_id.to_i + 1
else
1
+4 -3
View File
@@ -1,11 +1,12 @@
# frozen_string_literal: true
class WorkInfo < ApplicationRecord
belongs_to :user
has_one :key_management, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
has_one :key_management, foreign_key: :user_id, primary_key: :user_id, dependent: :destroy
#before_save :encrypt_ssn
# We should probably use this
def last_four
"***-**-" << self.decrypt_ssn[-4,4]
"***-**-" << self.decrypt_ssn[-4, 4]
end
def encrypt_ssn
@@ -36,6 +37,6 @@ class WorkInfo < ApplicationRecord
end
def cipher_type
'aes-256-cbc'
"aes-256-cbc"
end
end