Commit d3266d76 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei

Format code and add script to automate it

Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent 8954b2fd
Pipeline #7906 passed with stage
in 2 minutes and 46 seconds
......@@ -103,7 +103,7 @@ module Api::V1
end
end
protected
protected
# Overrides DeviseTokenAuth's RegistrationsController's
# render_create_success method in order to render account
......
......@@ -16,15 +16,13 @@ module Api::V1
# finds account which citizens' cpf correspond to the request's
@resource = resource_class.where(citizens: {cpf: q_value})
.includes(:citizen)
.where(provider: 'cpf').first
.includes(:citizen)
.where(provider: 'cpf').first
end
# create token and sign in
if @resource and valid_params?(field, q_value) and
@resource.valid_password?(resource_params[:password]) and
(!@resource.respond_to?(:active_for_authentication?) or
@resource.active_for_authentication?)
if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and
(!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
# create client id
@client_id = SecureRandom.urlsafe_base64(nil, false)
@token = SecureRandom.urlsafe_base64(nil, false)
......
......@@ -47,7 +47,7 @@ module Api::V1
end
end
private
private
# Only allow a trusted parameter "white list" through.
def cep_params
......
......@@ -67,7 +67,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_citizen
......
......@@ -60,7 +60,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_city_hall
......
......@@ -61,7 +61,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_dependant
......
module Api::V1
class OccupationsController < ApplicationController
include Authenticable
before_action :set_occupation, only: [:show, :update, :destroy]
# GET /occupations
......@@ -61,7 +61,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_occupation
begin
......
......@@ -60,7 +60,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_professional
......
......@@ -60,7 +60,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_schedule
......
......@@ -62,28 +62,28 @@ module Api::V1
private
# Use callbacks to share common setup or constraints between actions.
def set_sector
begin
@sector = Sector.find(params[:id])
rescue
@sector = nil
end
# Use callbacks to share common setup or constraints between actions.
def set_sector
begin
@sector = Sector.find(params[:id])
rescue
@sector = nil
end
end
# Only allow a trusted parameter "white list" through.
def sector_params
params.require(:sector).permit(
:id,
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:city_hall_id,
:description,
:name,
:schedules_by_sector
);
end
# Only allow a trusted parameter "white list" through.
def sector_params
params.require(:sector).permit(
:id,
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:city_hall_id,
:description,
:name,
:schedules_by_sector
);
end
end
end
......@@ -60,7 +60,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_service_place
......
......@@ -62,7 +62,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_service_type
......
......@@ -88,7 +88,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_shift
......
......@@ -59,7 +59,7 @@ module Api::V1
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_solicitation
......
......@@ -7,7 +7,7 @@ class ApplicationController < ActionController::API
protect_from_forgery
before_action :configure_permitted_parameters, if: :devise_controller?
protected
protected
# permit parameters for devise functions
def configure_permitted_parameters
......
......@@ -14,12 +14,12 @@ class Account < ApplicationRecord
# :token_authenticable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :trackable, :validatable
# DeviseTokenAuth #
# Include default DeviseTokenAuth methods.
include DeviseTokenAuth::Concerns::User
# @return [String] citizen's cpf
def cpf
self.citizen.cpf
......
......@@ -7,7 +7,7 @@ class Address < ApplicationRecord
def self.get_address(zipcode)
zipcode = zipcode.gsub(/\D/, '')
address = Address.find_by(zipcode: zipcode)
# if not registered in database or registered but too old (180 days)
if address.nil? or (Date.today - Date.parse(address.updated_at.to_s) > 180)
result = CepValidator.get_address(zipcode)
......@@ -81,7 +81,7 @@ class Address < ApplicationRecord
if state.nil?
return nil
end
return state.id
end
end
class Block < ApplicationRecord
# Associations #
belongs_to :account
belongs_to :sector
......
......@@ -6,7 +6,7 @@ class Citizen < ApplicationRecord
has_one :dependant
belongs_to :citizen, optional: true, :foreign_key => :responsible_id,
:class_name => "Citizen"
:class_name => "Citizen"
# Validations #
validates :cpf, cpf: true
......@@ -24,14 +24,14 @@ class Citizen < ApplicationRecord
validates_length_of :name, maximum: 255
validates_length_of :rg, maximum: 13
validates_length_of :address_number, within: 0..10,
allow_blank: true
allow_blank: true
validates_numericality_of :address_number,
only_integer: true,
allow_blank: true
only_integer: true,
allow_blank: true
validates_format_of :name,
with: /\A[^0-9`!@#\$%\^&*+_=]+\z/
with: /\A[^0-9`!@#\$%\^&*+_=]+\z/
validates_inclusion_of :active, in: [true, false]
......
......@@ -6,40 +6,40 @@ class CityHall < ApplicationRecord
# Validations #
validates_presence_of :name,
:cep,
:neighborhood,
:address_street,
:address_number,
:city_id,
:phone1,
:schedule_period,
:previous_notice
:cep,
:neighborhood,
:address_street,
:address_number,
:city_id,
:phone1,
:schedule_period,
:previous_notice
validates_presence_of :block_text, if: :citizen_access_blocked?
validates_uniqueness_of :city_id
validates_inclusion_of :active, in: [true, false]
validates_inclusion_of :citizen_access,
:citizen_register, in: [true, false]
:citizen_register, in: [true, false]
validates_numericality_of :schedule_period,
:previous_notice, greater_than: 0,
less_than_or_equal_to: 2000000000
:previous_notice, greater_than: 0,
less_than_or_equal_to: 2000000000
validates_length_of :phone1,
:phone2, maximum: 14
:phone2, maximum: 14
validates_length_of :name,
:neighborhood,
:address_street,
:address_complement, maximum: 255
:neighborhood,
:address_street,
:address_complement, maximum: 255
validates_length_of :address_number, maximum: 10, allow_blank: true
def self.all_active
CityHall.where(active: true)
end
private
private
# @return [boolean] check if citizen can access city hall
def citizen_access_blocked?
......
......@@ -6,5 +6,5 @@ class ProfessionalsServicePlace < ApplicationRecord
# Validations #
validates_presence_of :active,
:role
:role
end
......@@ -8,8 +8,8 @@ class Schedule < ApplicationRecord
# Validations #
validates_presence_of :citizen_ajax_read
:professional_ajax_read
:reminder_read
:service_start_time
:service_end_time
:professional_ajax_read
:reminder_read
:service_start_time
:service_end_time
end
......@@ -6,11 +6,11 @@ class Sector < ApplicationRecord
# Validations #
validates_presence_of :absence_max
:blocking_days
:cancel_limit
:description
:name
:schedules_by_sector
:blocking_days
:cancel_limit
:description
:name
:schedules_by_sector
validates_inclusion_of :active, in: [true, false]
......
......@@ -15,11 +15,11 @@ class ServicePlace < ApplicationRecord
validates_length_of :name, maximum: 255
validates_length_of :address_number, within: 0..10,
allow_blank: true
allow_blank: true
validates_numericality_of :address_number,
only_integer: true,
allow_blank: true
only_integer: true,
allow_blank: true
# @return all active service places
def self.all_active
......
......@@ -5,20 +5,20 @@ class Shift < ApplicationRecord
belongs_to :service_type
belongs_to :shift, optional: true
has_one :shift,
foreign_key: :next_shift_id,
class_name: "Shift"
foreign_key: :next_shift_id,
class_name: "Shift"
belongs_to :professional,
optional: true,
foreign_key: :professional_responsible_id,
class_name: "Professional"
optional: true,
foreign_key: :professional_responsible_id,
class_name: "Professional"
belongs_to :professional_2,
optional: true,
foreign_key: :professional_performer_id,
class_name: "Professional"
optional: true,
foreign_key: :professional_performer_id,
class_name: "Professional"
has_many :schedules
# Validations #
validates_presence_of :execution_start_time
:execution_end_time
:service_amount
:execution_end_time
:service_amount
end
class Situation < ApplicationRecord
# Associations #
has_many :schedules
......
class CitizenSerializer < ActiveModel::Serializer
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:birth_date,
:cep,
:city_id,
:cpf,
:email,
:name,
:neighborhood,
:note,
:pcd,
:phone1,
:phone2,
:photo_content_type,
:photo_file_name,
:photo_file_size,
:photo_update_at,
:rg
:active,
:address_complement,
:address_number,
:address_street,
:birth_date,
:cep,
:city_id,
:cpf,
:email,
:name,
:neighborhood,
:note,
:pcd,
:phone1,
:phone2,
:photo_content_type,
:photo_file_name,
:photo_file_size,
:photo_update_at,
:rg
belongs_to :account
end
class CityHallSerializer < ActiveModel::Serializer
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:block_text,
:citizen_access,
:citizen_register,
:cep,
:description,
:email,
:logo_content_type,
:logo_file_name,
:logo_file_size,
:logo_updated_at,
:name,
:neighborhood,
:previous_notice,
:phone1,
:phone2,
:schedule_period,
:show_professional,
:support_email,
:url
:active,
:address_complement,
:address_number,
:address_street,
:block_text,
:citizen_access,
:citizen_register,
:cep,
:description,
:email,
:logo_content_type,
:logo_file_name,
:logo_file_size,
:logo_updated_at,
:name,
:neighborhood,
:previous_notice,
:phone1,
:phone2,
:schedule_period,
:show_professional,
:support_email,
:url
belongs_to :city
end
class DependantSerializer < ActiveModel::Serializer
attributes :id,
:active,
:deactivated
:active,
:deactivated
belongs_to :citizen
end
class OccupationSerializer < ActiveModel::Serializer
attributes :id,
:active,
:description,
:name
:active,
:description,
:name
has_one :city_hall
end
class ProfessionalSerializer < ActiveModel::Serializer
ActiveModelSerializers.config.default_includes = '**'
attributes :id,
:active,
:registration
:active,
:registration
has_one :citizen, through: :account
has_one :occupation
......
class ScheduleSerializer < ActiveModel::Serializer
attributes :id,
:account_id,
:citizen_ajax_read,
:note,
:professional_ajax_read,
:reminder_email_sent,
:reminder_read,
:remainder_time,
:service_start_time,
:service_end_time
:account_id,
:citizen_ajax_read,
:note,
:professional_ajax_read,
:reminder_email_sent,
:reminder_read,
:remainder_time,
:service_start_time,
:service_end_time
belongs_to :service_place
belongs_to :shift
......
class SectorSerializer < ActiveModel::Serializer
attributes :id,
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:description,
:name,
:schedules_by_sector
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:description,
:name,
:schedules_by_sector
belongs_to :city_hall
end
class ServicePlaceSerializer < ActiveModel::Serializer
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:cep,
:email,
:name,
:neighborhood,
:phone1,
:phone2,
:url
:active,
:address_complement,
:address_number,
:address_street,
:cep,
:email,
:name,
:neighborhood,
:phone1,
:phone2,
:url
belongs_to :city_hall
end
class ServiceTypeSerializer < ActiveModel::Serializer
attributes :id,
:active,
:description
:active,
:description
belongs_to :sector
end
class ShiftSerializer < ActiveModel::Serializer
attributes :id,
:execution_start_time,
:execution_end_time,
:notes,
:service_amount
:execution_start_time,
:execution_end_time,
:notes,
:service_amount
belongs_to :service_place
belongs_to :service_type
has_one :shift, :foreign_key => :next_shift_id, :class_name => "Shift"
belongs_to :professional, :foreign_key => :professional_responsible_id,
:class_name => "Professional"
:class_name => "Professional"
belongs_to :professional_2, :foreign_key => :professional_performer_id,
:class_name => "Professional"
:class_name => "Professional"
end
class SolicitationSerializer < ActiveModel::Serializer
attributes :id,
:cep,
:cpf,
:email,
:name,
:phone,
:sent
:cep,
:cpf,
:email,
:name,
:phone,
:sent
has_one :city
end
class CepValidator < ActiveModel::EachValidator
# regular expression to describe a valid cep
CEP_REGEX = /^[0-9]{8}$/
......
......@@ -38,7 +38,7 @@ class CpfValidator < ActiveModel::EachValidator
return (check(10, arr) and check(11, arr))
end
private
private
# @return [boolean] true if last two digits are valid
# @param aux [Fixnum] the auh-th number to be validated (10 or 11)
......
class EmailValidator < ActiveModel::EachValidator
# regular expression to describe a valid email
EMAIL_REGEX = /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/
......
set term=xterm
set history=700
set t_Co=256
filetype plugin on
filetype indent on
set autoread
set nuw=5
let mapleader = ","
let g:mapleader = ","
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7