chore(rubocop): giganto rubocop commit.
muahahahah
This commit is contained in:
@@ -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,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
||||
|
||||
@@ -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,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
class KeyManagement < ApplicationRecord
|
||||
belongs_to :work_info
|
||||
belongs_to :user
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
class Pay < ApplicationRecord
|
||||
# Associations
|
||||
belongs_to :user
|
||||
|
||||
@@ -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,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
class Retirement < ApplicationRecord
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
class Schedule < ApplicationRecord
|
||||
belongs_to :paid_time_off
|
||||
|
||||
|
||||
+24
-25
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user