Skip to content

Commit

Permalink
revert rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Feb 5, 2024
1 parent 3697320 commit 939828b
Show file tree
Hide file tree
Showing 56 changed files with 216 additions and 220 deletions.
3 changes: 1 addition & 2 deletions app/admin/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
form do |f|
f.inputs do
f.input :name
f.input :icon_name,
hint: "See all available <a href='https://getbootstrap.com/docs/3.3/components/#glyphicons' target='_blank'>icons here</a>".html_safe
f.input :icon_name, hint: "See all available <a href='https://getbootstrap.com/docs/3.3/components/#glyphicons' target='_blank'>icons here</a>".html_safe
end
f.actions
end
Expand Down
2 changes: 1 addition & 1 deletion app/admin/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def destroy
filter :updated_at

permit_params :name, :email, :web, :phone, :city, :neighborhood,
:address, :description, :public_opening_times, :logo
:address, :description, :public_opening_times, :logo
end
2 changes: 1 addition & 1 deletion app/admin/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end

permit_params :type, :tag_list, :title, :category_id, :user_id,
:description, :organization_id, :active, :is_group
:description, :organization_id, :active, :is_group

filter :type, as: :select, collection: -> { Post.subclasses }
filter :id
Expand Down
2 changes: 1 addition & 1 deletion app/admin/transfer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveAdmin.register Transfer do
includes :post, movements: { account: %i[accountable organization] }
includes :post, movements: { account: [:accountable, :organization] }

actions :index, :destroy

Expand Down
2 changes: 1 addition & 1 deletion app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@
end

permit_params :username, :email, :phone, :postcode, :gender, :locale,
members_attributes: %i[id organization_id active manager _destroy]
members_attributes: [:id, :organization_id, :active, :manager, :_destroy]
end
6 changes: 3 additions & 3 deletions app/assets/javascripts/libs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//= require jquery2
//= require jquery_ujs
//= require vendor/jquery.validate
//= require jquery.validate
//= require bootstrap
//= require ./vendor/highcharts
//= require ./vendor/highcharts-exporting
//= require highcharts
//= require highcharts-exporting
//= require select2
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ def set_locale

def user_not_authorized
flash[:error] = "You are not authorized to perform this action."
redirect_to(request.referer || root_path)
redirect_to(request.referrer || root_path)
end

def resource_not_found
render "errors/not_found", status: :not_found
render 'errors/not_found', status: 404
end

def member_should_exist_and_be_active
if !current_member
redirect_to organizations_path
elsif !current_member.active
flash[:error] = I18n.t("users.index.account_deactivated")
flash[:error] = I18n.t('users.index.account_deactivated')
redirect_to select_organization_path
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/concerns/with_transfer_params.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module WithTransferParams
def transfer_params
permitted_transfer_params = %i[
destination
amount
reason
post_id
permitted_transfer_params = [
:destination,
:amount,
:reason,
:post_id,
]

permitted_transfer_params.push(:source) if admin?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class ErrorsController < ApplicationController
def not_found
render status: :not_found
render status: 404
end

def internal_server_error
render status: :internal_server_error
render status: 500
end
end
15 changes: 8 additions & 7 deletions app/controllers/multi_transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class MultiTransfersController < ApplicationController
include WithTransferParams

STEPS = %w[
select_type
select_source
select_target
set_params
confirm
STEPS = [
'select_type',
'select_source',
'select_target',
'set_params',
'confirm'
]

def step
Expand Down Expand Up @@ -60,10 +60,11 @@ def prepare_template_vars
@target_accountable = Account.find(@to.first).accountable
end

@should_render_offer_selector =
@should_render_offer_selector = (
@type_of_transfer.to_sym == :many_to_one &&
@target_accountable &&
@target_accountable.offers.length > 0
)

@from_names = Account.find(@from).map(&:accountable).map(&:to_s)
@to_names = Account.find(@to).map(&:accountable).map(&:to_s)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class OrganizationsController < ApplicationController
before_action :load_resource, only: %i[show edit update set_current]
before_action :load_resource, only: [:show, :edit, :update, :set_current]
before_action :user_should_be_confirmed

def index
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class PagesController < ApplicationController
def show
render template: "pages/#{params[:page]}"
rescue ActionView::MissingTemplate
render "errors/not_found", status: :not_found
begin
render template: "pages/#{params[:page]}"
rescue ActionView::MissingTemplate
render "errors/not_found", status: 404
end
end
end
15 changes: 7 additions & 8 deletions app/controllers/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def create
OrganizationNotifier.new_petition(petition).deliver_now
OrganizationNotifier.petition_sent(petition).deliver_now

flash[:notice] = t("petitions.application_status", status: t("petitions.status.sent"))
flash[:notice] = t('petitions.application_status', status: t("petitions.status.sent"))
else
flash[:error] = t("errors.internal_server_error.description")
flash[:error] = t('errors.internal_server_error.description')
end

redirect_back fallback_location: organization_path(petition.organization)
Expand All @@ -22,19 +22,18 @@ def update
status = params[:status]

if petition.update(status: status)
petition.user.add_to_organization(petition.organization) if status == "accepted"
flash[:notice] = t("petitions.application_status", status: t("petitions.status.#{status}"))
petition.user.add_to_organization(petition.organization) if status == 'accepted'
flash[:notice] = t('petitions.application_status', status: t("petitions.status.#{status}"))
else
flash[:error] = t("errors.internal_server_error.description")
flash[:error] = t('errors.internal_server_error.description')
end

redirect_to manage_petitions_path
end

def manage
@status = params[:status] || "pending"
@users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id,
status: @status }).page(params[:page]).per(20)
@status = params[:status] || 'pending'
@users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id, status: @status }).page(params[:page]).per(20)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PostsController < ApplicationController
class PostsController < ApplicationController
has_scope :by_category, as: :cat
has_scope :tagged_with, as: :tag
has_scope :by_organization, as: :org
Expand Down Expand Up @@ -91,7 +91,7 @@ def set_user_id(p)

def post_params
permitted_fields = [:description, :end_on, :start_on, :title, :category_id,
:user_id, :is_group, :active, { tag_list: [] }]
:user_id, :is_group, :active, tag_list: []]

params.fetch(resource, {}).permit(*permitted_fields).tap do |p|
set_user_id(p)
Expand Down
28 changes: 14 additions & 14 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "zip"
require 'zip'

class ReportsController < ApplicationController
before_action :authenticate_user!
Expand All @@ -8,20 +8,20 @@ class ReportsController < ApplicationController
def user_list
@members = report_collection("Member")

report_responder("Member", current_organization, @members)
report_responder('Member', current_organization, @members)
end

def post_list
@post_type = (params[:type] || "offer").capitalize.constantize
@posts = report_collection(@post_type)

report_responder("Post", current_organization, @posts, @post_type)
report_responder('Post', current_organization, @posts, @post_type)
end

def transfer_list
@transfers = report_collection("Transfer")
@transfers = report_collection('Transfer')

report_responder("Transfer", current_organization, @transfers)
report_responder('Transfer', current_organization, @transfers)
end

def download_all
Expand All @@ -35,7 +35,7 @@ def download_all
end
end
zip_data = File.read(temp_file.path)
send_data(zip_data, type: "application/zip", disposition: "attachment", filename: filename)
send_data(zip_data, type: 'application/zip', disposition: 'attachment', filename: filename)
rescue Errno::ENOENT
redirect_to download_all_report_path
ensure
Expand Down Expand Up @@ -65,11 +65,11 @@ def get_report(report_class, *args)

def report_collection(report_class)
case report_class.to_s
when "Member"
current_organization.members.active.includes(:user).order("members.member_uid")
when "Transfer"
when 'Member'
current_organization.members.active.includes(:user).order('members.member_uid')
when 'Transfer'
current_organization.all_transfers_with_accounts
when "Inquiry", "Offer"
when 'Inquiry', 'Offer'
report_class = report_class.constantize if report_class.is_a?(String)

current_organization.posts.of_active_members.active.
Expand All @@ -84,10 +84,10 @@ def add_csv_to_zip(report_class, zip)
collection = report_collection(report_class)

report = if report_class.in? %w(Inquiry Offer)
get_report("Csv::Post", current_organization, collection, report_class.constantize)
else
get_report("Csv::#{report_class}", current_organization, collection)
end
get_report("Csv::Post", current_organization, collection, report_class.constantize)
else
get_report("Csv::#{report_class}", current_organization, collection)
end

file = Tempfile.new
file.write(report.run)
Expand Down
34 changes: 17 additions & 17 deletions app/controllers/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def global_activity
@total_hours = num_movements = 0
members.each do |m|
num_movements += m.account.movements.count
@total_hours += m.account.movements.map do |a|
a.amount > 0 ? a.amount : 0
@total_hours += m.account.movements.map do
|a| (a.amount > 0) ? a.amount : 0
end.inject(0, :+)
end
@total_hours += current_organization.account.movements.
map { |a| a.amount > 0 ? a.amount : 0 }.inject(0, :+)
map { |a| (a.amount > 0) ? a.amount : 0 }.inject(0, :+)

@num_swaps = (num_movements + current_organization.account.movements.count) / 2

from = params[:from].presence.try(:to_date) || DateTime.now.to_date - 5.months
from = params[:from].presence.try(:to_date) || DateTime.now.to_date - 5.month
to = params[:to].presence.try(:to_date) || DateTime.now.to_date
num_months = (to.year * 12 + to.month) - (from.year * 12 + from.month) + 1
date = from
Expand All @@ -38,10 +38,10 @@ def global_activity

sum_hours = 0
swaps_members.flatten.each do |s|
sum_hours += s.amount > 0 ? s.amount : 0
sum_hours += (s.amount > 0) ? s.amount : 0
end
sum_hours += swaps_organization.map do |a|
a.amount > 0 ? a.amount : 0
sum_hours += swaps_organization.map do
|a| (a.amount > 0) ? a.amount : 0
end.inject(0, :+)
sum_hours = sum_hours / 3600.0 if sum_hours > 0
@hours_swaps_months << sum_hours
Expand Down Expand Up @@ -147,12 +147,12 @@ def compute_age(date_of_birth)

def age_group_labels
{
0..17 => "-17",
18..24 => "18-24",
25..34 => "25-34",
35..44 => "35-44",
45..54 => "45-54",
55..64 => "55-64",
0..17 => "-17",
18..24 => "18-24",
25..34 => "25-34",
35..44 => "35-44",
45..54 => "45-54",
55..64 => "55-64",
65..100 => "65+",
}
end
Expand All @@ -161,10 +161,10 @@ def gender_counts(members)
members.each_with_object(Hash.new(0)) do |member, counts|
gender = member.user_gender
gender_label = if gender.present?
t("simple_form.options.user.gender.#{gender}")
else
t("statistics.demographics.unknown")
end
t("simple_form.options.user.gender.#{gender}")
else
t("statistics.demographics.unknown")
end
counts[gender_label] += 1
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def create
if persister.save
redirect_to redirect_target
else
redirect_back fallback_location: redirect_target,
alert: transfer.errors.full_messages.to_sentence
redirect_back fallback_location: redirect_target, alert: transfer.errors.full_messages.to_sentence
end
end

Expand Down
Loading

0 comments on commit 939828b

Please sign in to comment.