Run rubocop --fix-layout and remove encoding comments

This commit is contained in:
Patrick Gansterer 2021-03-01 15:27:26 +01:00
parent fa63e6e81d
commit ea2862fdef
283 changed files with 1164 additions and 1969 deletions

View file

@ -6,5 +6,4 @@ class Admin::BaseController < ApplicationController
@groups = Group.where(deleted_at: nil).order('created_on DESC').limit(10)
@users = User.order('created_on DESC').limit(10)
end
end

View file

@ -1,5 +1,4 @@
class Admin::ConfigsController < Admin::BaseController
before_action :get_tabs, only: [:show, :list]
def show
@ -11,7 +10,7 @@ class Admin::ConfigsController < Admin::BaseController
@current_tab = 'list'
@cfg = FoodsoftConfig
@dfl = FoodsoftConfig.config
@keys = FoodsoftConfig.keys.select {|k| FoodsoftConfig.allowed_key?(k)}.sort
@keys = FoodsoftConfig.keys.select { |k| FoodsoftConfig.allowed_key?(k) }.sort
end
def update
@ -56,10 +55,9 @@ class Admin::ConfigsController < Admin::BaseController
def convert_config_value(value)
if value.is_a? ActionController::Parameters
value.transform_values{ |v| convert_config_value(v) }.to_hash
value.transform_values { |v| convert_config_value(v) }.to_hash
else
value
end
end
end

View file

@ -15,5 +15,4 @@ class Admin::FinancesController < Admin::BaseController
@financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC')
render :layout => false
end
end

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class Admin::OrdergroupsController < Admin::BaseController
inherit_resources

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class Admin::WorkgroupsController < Admin::BaseController
inherit_resources

View file

@ -22,5 +22,4 @@ class Api::V1::ArticleCategoriesController < Api::V1::BaseController
def scope
ArticleCategory.all
end
end

View file

@ -51,26 +51,26 @@ class Api::V1::BaseController < ApplicationController
def not_found_handler(e)
# remove where-clauses from error message (not suitable for end-users)
msg = e.message.try {|m| m.sub(/\s*\[.*?\]\s*$/, '')} || 'Not found'
render status: 404, json: {error: 'not_found', error_description: msg}
msg = e.message.try { |m| m.sub(/\s*\[.*?\]\s*$/, '') } || 'Not found'
render status: 404, json: { error: 'not_found', error_description: msg }
end
def not_acceptable_handler(e)
msg = e.message || 'Data not acceptable'
render status: 422, json: {error: 'not_acceptable', error_description: msg}
render status: 422, json: { error: 'not_acceptable', error_description: msg }
end
def doorkeeper_unauthorized_render_options(error:)
{json: {error: error.name, error_description: error.description}}
{ json: { error: error.name, error_description: error.description } }
end
def doorkeeper_forbidden_render_options(error:)
{json: {error: error.name, error_description: error.description}}
{ json: { error: error.name, error_description: error.description } }
end
def permission_required_handler(e)
msg = e.message || 'Forbidden, user has no access'
render status: 403, json: {error: 'forbidden', error_description: msg}
render status: 403, json: { error: 'forbidden', error_description: msg }
end
# @todo something with ApplicationHelper#show_user

View file

@ -1,9 +1,7 @@
class Api::V1::ConfigsController < Api::V1::BaseController
before_action ->{ doorkeeper_authorize! 'config:user', 'config:read', 'config:write' }
before_action -> { doorkeeper_authorize! 'config:user', 'config:read', 'config:write' }
def show
render json: FoodsoftConfig, serializer: ConfigSerializer, root: 'config'
end
end

View file

@ -22,5 +22,4 @@ class Api::V1::FinancialTransactionClassesController < Api::V1::BaseController
def scope
FinancialTransactionClass.all
end
end

View file

@ -22,5 +22,4 @@ class Api::V1::FinancialTransactionTypesController < Api::V1::BaseController
def scope
FinancialTransactionType.includes(:bank_account, :financial_transaction_class)
end
end

View file

@ -1,7 +1,7 @@
class Api::V1::FinancialTransactionsController < Api::V1::BaseController
include Concerns::CollectionScope
before_action ->{ doorkeeper_authorize! 'finance:read', 'finance:write' }
before_action -> { doorkeeper_authorize! 'finance:read', 'finance:write' }
def index
render_collection search_scope
@ -20,5 +20,4 @@ class Api::V1::FinancialTransactionsController < Api::V1::BaseController
def ransack_auth_object
:finance
end
end

View file

@ -1,5 +1,4 @@
class Api::V1::NavigationsController < Api::V1::BaseController
def show
# we don't use active_model_serializers here, because source is a Hash
render json: { navigation: transform(navigation) }
@ -20,5 +19,4 @@ class Api::V1::NavigationsController < Api::V1::BaseController
r
end
end
end

View file

@ -1,7 +1,7 @@
class Api::V1::OrderArticlesController < Api::V1::BaseController
include Concerns::CollectionScope
before_action ->{ doorkeeper_authorize! 'orders:read', 'orders:write' }
before_action -> { doorkeeper_authorize! 'orders:read', 'orders:write' }
def index
render_collection search_scope

View file

@ -1,7 +1,7 @@
class Api::V1::OrdersController < Api::V1::BaseController
include Concerns::CollectionScope
before_action ->{ doorkeeper_authorize! 'orders:read', 'orders:write' }
before_action -> { doorkeeper_authorize! 'orders:read', 'orders:write' }
def index
render_collection search_scope

View file

@ -1,7 +1,7 @@
class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
include Concerns::CollectionScope
before_action ->{ doorkeeper_authorize! 'finance:user' }
before_action -> { doorkeeper_authorize! 'finance:user' }
before_action :require_ordergroup
before_action :require_minimum_balance, only: [:create]
before_action -> { require_config_enabled :use_self_service }, only: [:create]
@ -29,5 +29,4 @@ class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
def create_params
params.require(:financial_transaction).permit(:amount, :financial_transaction_type_id, :note)
end
end

View file

@ -1,7 +1,7 @@
class Api::V1::User::GroupOrderArticlesController < Api::V1::BaseController
include Concerns::CollectionScope
before_action ->{ doorkeeper_authorize! 'group_orders:user' }
before_action -> { doorkeeper_authorize! 'group_orders:user' }
before_action :require_ordergroup
before_action :require_minimum_balance, only: [:create, :update] # destroy is ok
@ -62,10 +62,10 @@ class Api::V1::User::GroupOrderArticlesController < Api::V1::BaseController
end
def scope
GroupOrderArticle.
joins(:group_order).
includes(order_article: :article, group_order: :order).
where(group_orders: { ordergroup_id: current_ordergroup.id })
GroupOrderArticle
.joins(:group_order)
.includes(order_article: :article, group_order: :order)
.where(group_orders: { ordergroup_id: current_ordergroup.id })
end
def scope_for_update

View file

@ -1,6 +1,5 @@
class Api::V1::User::OrdergroupController < Api::V1::BaseController
before_action ->{ doorkeeper_authorize! 'finance:user' }, only: [:financial_overview]
before_action -> { doorkeeper_authorize! 'finance:user' }, only: [:financial_overview]
def financial_overview
ordergroup = Ordergroup.include_transaction_class_sum.find(current_ordergroup.id)
@ -19,5 +18,4 @@ class Api::V1::User::OrdergroupController < Api::V1::BaseController
}
}
end
end

View file

@ -1,9 +1,7 @@
class Api::V1::User::UsersController < Api::V1::BaseController
before_action ->{ doorkeeper_authorize! 'user:read', 'user:write' }
before_action -> { doorkeeper_authorize! 'user:read', 'user:write' }
def show
render json: current_user
end
end

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class ApplicationController < ActionController::Base
include Concerns::FoodcoopScope
include Concerns::Auth
@ -8,11 +7,10 @@ class ApplicationController < ActionController::Base
helper_method :available_locales
protect_from_forgery
before_action :authenticate, :set_user_last_activity, :store_controller, :items_per_page
before_action :authenticate, :set_user_last_activity, :store_controller, :items_per_page
after_action :remove_controller
around_action :set_time_zone, :set_currency
# Returns the controller handling the current request.
def self.current
Thread.current[:application_controller]
@ -90,10 +88,9 @@ class ApplicationController < ActionController::Base
old_currency = ::I18n.t('number.currency.format.unit')
new_currency = FoodsoftConfig[:currency_unit] || ''
new_currency += "\u202f" if FoodsoftConfig[:currency_space]
::I18n.backend.store_translations(::I18n.locale, number: {currency: {format: {unit: new_currency}}})
::I18n.backend.store_translations(::I18n.locale, number: { currency: { format: { unit: new_currency } } })
yield
ensure
::I18n.backend.store_translations(::I18n.locale, number: {currency: {format: {unit: old_currency}}})
::I18n.backend.store_translations(::I18n.locale, number: { currency: { format: { unit: old_currency } } })
end
end

View file

@ -1,5 +1,4 @@
class ArticleCategoriesController < ApplicationController
inherit_resources # Build default REST Actions via plugin
before_action :authenticate_article_meta
@ -23,5 +22,4 @@ class ArticleCategoriesController < ApplicationController
def collection
@article_categories = ArticleCategory.order('name')
end
end

View file

@ -1,21 +1,20 @@
# encoding: utf-8
class ArticlesController < ApplicationController
before_action :authenticate_article_meta, :find_supplier
def index
if params['sort']
sort = case params['sort']
when "name" then "articles.name"
when "unit" then "articles.unit"
when "article_category" then "article_categories.name"
when "note" then "articles.note"
when "availability" then "articles.availability"
when "name_reverse" then "articles.name DESC"
when "unit_reverse" then "articles.unit DESC"
when "article_category_reverse" then "article_categories.name DESC"
when "note_reverse" then "articles.note DESC"
when "availability_reverse" then "articles.availability DESC"
end
when "name" then "articles.name"
when "unit" then "articles.unit"
when "article_category" then "article_categories.name"
when "note" then "articles.note"
when "availability" then "articles.availability"
when "name_reverse" then "articles.name DESC"
when "unit_reverse" then "articles.unit DESC"
when "article_category_reverse" then "article_categories.name DESC"
when "note_reverse" then "articles.note DESC"
when "availability_reverse" then "articles.availability DESC"
end
else
sort = "article_categories.name, articles.name"
end
@ -99,7 +98,7 @@ class ArticlesController < ApplicationController
end
end
raise ActiveRecord::Rollback if invalid_articles # Rollback all changes
raise ActiveRecord::Rollback if invalid_articles # Rollback all changes
end
end
end
@ -117,25 +116,25 @@ class ArticlesController < ApplicationController
# makes different actions on selected articles
def update_selected
raise I18n.t('articles.controller.error_nosel') if params[:selected_articles].nil?
articles = Article.find(params[:selected_articles])
Article.transaction do
case params[:selected_action]
when 'destroy'
articles.each(&:mark_as_deleted)
flash[:notice] = I18n.t('articles.controller.update_sel.notice_destroy')
when 'setNotAvailable'
articles.each {|a| a.update_attribute(:availability, false) }
flash[:notice] = I18n.t('articles.controller.update_sel.notice_unavail')
when 'setAvailable'
articles.each {|a| a.update_attribute(:availability, true) }
flash[:notice] = I18n.t('articles.controller.update_sel.notice_avail')
else
flash[:alert] = I18n.t('articles.controller.update_sel.notice_noaction')
when 'destroy'
articles.each(&:mark_as_deleted)
flash[:notice] = I18n.t('articles.controller.update_sel.notice_destroy')
when 'setNotAvailable'
articles.each { |a| a.update_attribute(:availability, false) }
flash[:notice] = I18n.t('articles.controller.update_sel.notice_unavail')
when 'setAvailable'
articles.each { |a| a.update_attribute(:availability, true) }
flash[:notice] = I18n.t('articles.controller.update_sel.notice_avail')
else
flash[:alert] = I18n.t('articles.controller.update_sel.notice_noaction')
end
end
# action succeded
redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page])
rescue => error
redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]),
:alert => I18n.t('errors.general_msg', :msg => error)
@ -149,7 +148,7 @@ class ArticlesController < ApplicationController
# Update articles from a spreadsheet
def parse_upload
uploaded_file = params[:articles]['file'] or raise I18n.t('articles.controller.parse_upload.no_file')
options = {filename: uploaded_file.original_filename}
options = { filename: uploaded_file.original_filename }
options[:outlist_absent] = (params[:articles]['outlist_absent'] == '1')
options[:convert_units] = (params[:articles]['convert_units'] == '1')
@updated_article_pairs, @outlisted_articles, @new_articles = @supplier.sync_from_file uploaded_file.tempfile, options
@ -177,10 +176,10 @@ class ArticlesController < ApplicationController
# Updates, deletes articles when upload or sync form is submitted
def update_synchronized
@outlisted_articles = Article.find(params[:outlisted_articles].try(:keys)||[])
@updated_articles = Article.find(params[:articles].try(:keys)||[])
@updated_articles.map{|a| a.assign_attributes(params[:articles][a.id.to_s]) }
@new_articles = (params[:new_articles]||[]).map{|a| @supplier.articles.build(a) }
@outlisted_articles = Article.find(params[:outlisted_articles].try(:keys) || [])
@updated_articles = Article.find(params[:articles].try(:keys) || [])
@updated_articles.map { |a| a.assign_attributes(params[:articles][a.id.to_s]) }
@new_articles = (params[:new_articles] || []).map { |a| @supplier.articles.build(a) }
has_error = false
Article.transaction do
@ -192,9 +191,9 @@ class ArticlesController < ApplicationController
has_error = true
end
# Update articles
@updated_articles.each {|a| a.save or has_error=true }
@updated_articles.each { |a| a.save or has_error = true }
# Add new articles
@new_articles.each {|a| a.save or has_error=true }
@new_articles.each { |a| a.save or has_error = true }
raise ActiveRecord::Rollback if has_error
end

View file

@ -24,7 +24,7 @@ module Concerns::Auth
def login(user)
session[:user_id] = user.id
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
session[:locale] = user.locale
end
@ -56,18 +56,18 @@ module Concerns::Auth
# We have an authenticated user, now check role...
# Roles gets the user through his memberships.
hasRole = case role
when 'admin' then current_user.role_admin?
when 'finance' then current_user.role_finance?
when 'article_meta' then current_user.role_article_meta?
when 'pickups' then current_user.role_pickups?
when 'suppliers' then current_user.role_suppliers?
when 'orders' then current_user.role_orders?
when 'finance_or_invoices' then (current_user.role_finance? || current_user.role_invoices?)
when 'finance_or_orders' then (current_user.role_finance? || current_user.role_orders?)
when 'pickups_or_orders' then (current_user.role_pickups? || current_user.role_orders?)
when 'any' then true # no role required
else false # any unknown role will always fail
end
when 'admin' then current_user.role_admin?
when 'finance' then current_user.role_finance?
when 'article_meta' then current_user.role_article_meta?
when 'pickups' then current_user.role_pickups?
when 'suppliers' then current_user.role_suppliers?
when 'orders' then current_user.role_orders?
when 'finance_or_invoices' then (current_user.role_finance? || current_user.role_invoices?)
when 'finance_or_orders' then (current_user.role_finance? || current_user.role_orders?)
when 'pickups_or_orders' then (current_user.role_pickups? || current_user.role_orders?)
when 'any' then true # no role required
else false # any unknown role will always fail
end
if hasRole
current_user
else
@ -137,6 +137,7 @@ module Concerns::Auth
# @see https://github.com/doorkeeper-gem/doorkeeper/issues/71#issuecomment-5471317
def expire_access_tokens
return unless @current_user
Doorkeeper::AccessToken.transaction do
token_scope = Doorkeeper::AccessToken.where(revoked_at: nil, resource_owner_id: @current_user.id)
token_scope.each do |token|
@ -146,8 +147,7 @@ module Concerns::Auth
end
# Redirect to the login page, used in authenticate, plugins can override this.
def redirect_to_login(options={})
def redirect_to_login(options = {})
redirect_to login_url, options
end
end

View file

@ -36,7 +36,7 @@ module Concerns::AuthApi
# Make sure that at least one the given OAuth scopes is valid for the current user's permissions.
# @raise Api::Errors::PermissionsRequired
def doorkeeper_authorize_roles!(*scopes)
unless scopes.any? {|scope| doorkeeper_scope_permitted?(scope) }
unless scopes.any? { |scope| doorkeeper_scope_permitted?(scope) }
raise Api::Errors::PermissionRequired.new('Forbidden, no permission')
end
end
@ -60,7 +60,7 @@ module Concerns::AuthApi
when 'suppliers' then return current_user.role_suppliers?
when 'group_orders' then return current_user.role_orders?
when 'finance' then return current_user.role_finance?
# please note that offline_access does not belong here, since it is not used for permission checking
# please note that offline_access does not belong here, since it is not used for permission checking
end
case scope

View file

@ -54,5 +54,4 @@ module Concerns::CollectionScope
def ransack_auth_object
nil
end
end

View file

@ -30,7 +30,6 @@ module Concerns::FoodcoopScope
# Always stay in foodcoop url scope
def default_url_options(options = {})
super().merge({foodcoop: FoodsoftConfig.scope})
super().merge({ foodcoop: FoodsoftConfig.scope })
end
end

View file

@ -47,5 +47,4 @@ module Concerns::Locale
locale = session[:locale] = ::I18n.locale
logger.info("Set locale to #{locale}")
end
end

View file

@ -9,9 +9,8 @@ module Concerns::SendOrderPdf
when 'articles' then OrderByArticles
when 'fax' then OrderFax
when 'matrix' then OrderMatrix
end
end
pdf = klass.new order
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
end
end

View file

@ -1,6 +1,4 @@
# encoding: utf-8
class DeliveriesController < ApplicationController
before_action :find_supplier, :exclude => :fill_new_stock_article_form
def index
@ -14,7 +12,7 @@ class DeliveriesController < ApplicationController
def new
@delivery = @supplier.deliveries.build
@delivery.date = Date.today #TODO: move to model/database
@delivery.date = Date.today # TODO: move to model/database
end
def create
@ -37,7 +35,7 @@ class DeliveriesController < ApplicationController
if @delivery.update_attributes(params[:delivery])
flash[:notice] = I18n.t('deliveries.update.notice')
redirect_to [@supplier,@delivery]
redirect_to [@supplier, @delivery]
else
render :action => "edit"
end
@ -68,5 +66,4 @@ class DeliveriesController < ApplicationController
render :layout => false
end
end

View file

@ -1,5 +1,4 @@
class FeedbackController < ApplicationController
def new
end
@ -11,5 +10,4 @@ class FeedbackController < ApplicationController
render :action => 'new'
end
end
end

View file

@ -1,6 +1,4 @@
# encoding: utf-8
class Finance::BalancingController < Finance::BaseController
def index
@orders = Order.finished.page(params[:page]).per(@per_page).order('ends DESC')
end
@ -11,20 +9,20 @@ class Finance::BalancingController < Finance::BaseController
@comments = @order.comments
@articles = @order.order_articles.ordered_or_member.includes(:article, :article_price,
group_order_articles: {group_order: :ordergroup})
group_order_articles: { group_order: :ordergroup })
sort_param = params['sort'] || 'name'
@articles = case sort_param
when 'name' then
@articles.order('articles.name ASC')
when 'name_reverse' then
@articles.order('articles.name DESC')
when 'order_number' then
@articles.order('articles.order_number ASC')
when 'order_number_reverse' then
@articles.order('articles.order_number DESC')
else
@articles
when 'name' then
@articles.order('articles.name ASC')
when 'name_reverse' then
@articles.order('articles.name DESC')
when 'order_number' then
@articles.order('articles.order_number ASC')
when 'order_number_reverse' then
@articles.order('articles.order_number DESC')
else
@articles
end
render layout: false if request.xhr?
@ -84,7 +82,6 @@ class Finance::BalancingController < Finance::BaseController
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
@order.close!(@current_user, @type)
redirect_to finance_order_index_url, notice: t('finance.balancing.close.notice')
rescue => error
redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: error.message)
end
@ -110,5 +107,4 @@ class Finance::BalancingController < Finance::BaseController
rescue => error
redirect_to finance_order_index_url, alert: t('errors.general_msg', msg: error.message)
end
end

View file

@ -1,5 +1,4 @@
class Finance::BankAccountsController < Finance::BaseController
def index
@bank_accounts = BankAccount.order('name')
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
@ -26,7 +25,7 @@ class Finance::BankAccountsController < Finance::BaseController
flash.notice = t('.notice', count: importer.count) if ok
@auto_submit = importer.auto_submit
@controls = importer.controls
#TODO: encrypt state
# TODO: encrypt state
@state = YAML.dump importer.dump
else
ok = true
@ -39,6 +38,7 @@ class Finance::BankAccountsController < Finance::BaseController
needs_redirect = true
ensure
return unless needs_redirect
redirect_path = finance_bank_account_transactions_url(@bank_account)
if request.post?
@js_redirect = redirect_path
@ -46,5 +46,4 @@ class Finance::BankAccountsController < Finance::BaseController
redirect_to redirect_path
end
end
end

View file

@ -5,12 +5,12 @@ class Finance::BankTransactionsController < ApplicationController
def index
if params["sort"]
sort = case params["sort"]
when "date" then "date"
when "amount" then "amount"
when "financial_link" then "financial_link_id"
when "date_reverse" then "date DESC"
when "amount_reverse" then "amount DESC"
when "financial_link_reverse" then "financial_link_id DESC"
when "date" then "date"
when "amount" then "amount"
when "financial_link" then "financial_link_id"
when "date_reverse" then "date DESC"
when "amount_reverse" then "amount DESC"
when "financial_link_reverse" then "financial_link_id DESC"
end
else
sort = "date DESC"

View file

@ -110,13 +110,13 @@ class Finance::FinancialLinksController < Finance::BaseController
redirect_to finance_link_url(@financial_link), notice: t('.notice')
end
protected
protected
def find_financial_link
@financial_link = FinancialLink.find(params[:id])
end
private
private
def financial_transaction_params
params.require(:financial_transaction).permit(:financial_transaction_type_id, :ordergroup_id, :amount, :note)
@ -128,5 +128,4 @@ private
JOIN bank_transactions b ON a.iban = b.iban AND b.financial_link_id = #{financial_link_id.to_i}
SQL
end
end

View file

@ -1,20 +1,19 @@
# encoding: utf-8
class Finance::FinancialTransactionsController < ApplicationController
before_action :authenticate_finance
before_action :find_ordergroup, :except => [:new_collection, :create_collection, :index_collection]
inherit_resources
# belongs_to :ordergroup
# belongs_to :ordergroup
def index
if params['sort']
sort = case params['sort']
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
else
sort = "created_on DESC"
end
@ -79,6 +78,7 @@ class Finance::FinancialTransactionsController < ApplicationController
def create_collection
raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
type = FinancialTransactionType.find_by_id(params[:type_id])
financial_link = nil
@ -103,12 +103,12 @@ class Finance::FinancialTransactionsController < ApplicationController
if params[:create_foodcoop_transaction]
ft = FinancialTransaction.new({
financial_transaction_type: type,
user: @current_user,
amount: foodcoop_amount,
note: params[:note],
financial_link: financial_link,
})
financial_transaction_type: type,
user: @current_user,
amount: foodcoop_amount,
note: params[:note],
financial_link: financial_link,
})
ft.save!
end
@ -131,5 +131,4 @@ class Finance::FinancialTransactionsController < ApplicationController
@foodcoop = true
end
end
end

View file

@ -1,5 +1,4 @@
class Finance::OrdergroupsController < Finance::BaseController
def index
m = /^(?<col>name|sum_of_class_\d+)(?<reverse>_reverse)?$/.match params["sort"]
if m

View file

@ -1,5 +1,4 @@
class Foodcoop::OrdergroupsController < ApplicationController
def index
@ordergroups = Ordergroup.undeleted.order('name')

View file

@ -1,5 +1,4 @@
class Foodcoop::UsersController < ApplicationController
def index
@users = User.undeleted.natural_order
@ -17,5 +16,4 @@ class Foodcoop::UsersController < ApplicationController
format.js { render :layout => false } # index.js.erb
end
end
end

View file

@ -1,16 +1,15 @@
class Foodcoop::WorkgroupsController < ApplicationController
before_action :authenticate_membership_or_admin,
:except => [:index]
:except => [:index]
def index
@workgroups = Workgroup.order("name")
end
def edit
@workgroup = Workgroup.find(params[:id])
end
def update
@workgroup = Workgroup.find(params[:id])
if @workgroup.update_attributes(params[:workgroup])

View file

@ -1,5 +1,4 @@
class GroupOrderArticlesController < ApplicationController
before_action :authenticate_finance
before_action :find_group_order_article, except: [:new, :create]
@ -30,7 +29,7 @@ class GroupOrderArticlesController < ApplicationController
update_summaries(@group_order_article)
render :create
else # Validation failed, show form
else # Validation failed, show form
render :new
end
end
@ -50,7 +49,7 @@ class GroupOrderArticlesController < ApplicationController
def destroy
# only destroy if quantity and tolerance was zero already, so that we don't
# lose what the user ordered, if any
if @group_order_article.quantity > 0 || @group_order_article.tolerance >0
if @group_order_article.quantity > 0 || @group_order_article.tolerance > 0
@group_order_article.update_attribute(:result, 0)
else
@group_order_article.destroy

View file

@ -33,7 +33,7 @@ class GroupOrdersController < ApplicationController
end
def show
@order= @group_order.order
@order = @group_order.order
end
def edit
@ -100,12 +100,11 @@ class GroupOrdersController < ApplicationController
if @ordergroup.not_enough_apples?
redirect_to group_orders_url,
alert: t('not_enough_apples', scope: 'group_orders.messages', apples: @ordergroup.apples,
stop_ordering_under: FoodsoftConfig[:stop_ordering_under])
stop_ordering_under: FoodsoftConfig[:stop_ordering_under])
end
end
def order_id_param
params[:order_id] || (params[:group_order] && params[:group_order][:order_id])
end
end

View file

@ -1,6 +1,4 @@
# encoding: utf-8
class HomeController < ApplicationController
def index
# unaccepted tasks
@unaccepted_tasks = Task.order(:due_date).unaccepted_tasks_for(current_user)
@ -44,13 +42,13 @@ class HomeController < ApplicationController
if params['sort']
sort = case params['sort']
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
else
sort = "created_on DESC"
end
@ -88,5 +86,4 @@ class HomeController < ApplicationController
params.require(:user).require(:ordergroup).permit(:contact_address)
end
end
end

View file

@ -1,12 +1,11 @@
class InvitesController < ApplicationController
before_action :authenticate_membership_or_admin_for_invites
before_action -> { require_config_disabled :disable_invite }
def new
@invite = Invite.new(:user => @current_user, :group => @group)
end
def create
authenticate_membership_or_admin params[:invite][:group_id]
@invite = Invite.new(params[:invite])

View file

@ -1,13 +1,12 @@
# encoding: utf-8
class LoginController < ApplicationController
skip_before_action :authenticate # no authentication since this is the login page
skip_before_action :authenticate # no authentication since this is the login page
before_action :validate_token, :only => [:new_password, :update_password]
# Display the form to enter an email address requesting a token to set a new password.
def forgot_password
@user = User.new
end
# Sends an email to a user with the token that allows setting a new password through action "password".
def reset_password
if request.get? || params[:user].nil? # Catch for get request and give better error message.
@ -19,12 +18,12 @@ class LoginController < ApplicationController
end
redirect_to login_url, :notice => I18n.t('login.controller.reset_password.notice')
end
# Set a new password with a token from the password reminder email.
# Called with params :id => User.id and :token => User.reset_password_token to specify a new password.
def new_password
end
# Sets a new password.
# Called with params :id => User.id and :token => User.reset_password_token to specify a new password.
def update_password

View file

@ -1,5 +1,4 @@
class OrderCommentsController < ApplicationController
def new
@order = Order.find(params[:order_id])
@order_comment = @order.comments.build(:user => current_user)

View file

@ -1,4 +1,3 @@
# encoding: utf-8
#
# Controller for managing orders, i.e. all actions that require the "orders" role.
# Normal ordering actions of members of order groups is handled by the OrderingController.
@ -16,12 +15,12 @@ class OrdersController < ApplicationController
@per_page = 15
if params['sort']
sort = case params['sort']
when "supplier" then "suppliers.name, ends DESC"
when "pickup" then "pickup DESC"
when "ends" then "ends DESC"
when "supplier_reverse" then "suppliers.name DESC"
when "ends_reverse" then "ends"
end
when "supplier" then "suppliers.name, ends DESC"
when "pickup" then "pickup DESC"
when "ends" then "ends DESC"
when "supplier_reverse" then "suppliers.name DESC"
when "ends_reverse" then "ends"
end
else
sort = "ends DESC"
end
@ -32,13 +31,13 @@ class OrdersController < ApplicationController
# Gives a view for the results to a specific order
# Renders also the pdf
def show
@order= Order.find(params[:id])
@order = Order.find(params[:id])
@view = (params[:view] || 'default').gsub(/[^-_a-zA-Z0-9]/, '')
@partial = case @view
when 'default' then 'articles'
when 'groups' then 'shared/articles_by/groups'
when 'articles' then 'shared/articles_by/articles'
else 'articles'
when 'default' then 'articles'
when 'groups' then 'shared/articles_by/groups'
when 'articles' then 'shared/articles_by/articles'
else 'articles'
end
respond_to do |format|
@ -50,10 +49,10 @@ class OrdersController < ApplicationController
send_order_pdf @order, params[:document]
end
format.csv do
send_data OrderCsv.new(@order).to_csv, filename: @order.name+'.csv', type: 'text/csv'
send_data OrderCsv.new(@order).to_csv, filename: @order.name + '.csv', type: 'text/csv'
end
format.text do
send_data OrderTxt.new(@order).to_txt, filename: @order.name+'.txt', type: 'text/plain'
send_data OrderTxt.new(@order).to_txt, filename: @order.name + '.txt', type: 'text/plain'
end
end
end
@ -163,6 +162,7 @@ class OrdersController < ApplicationController
def update_order_amounts
return if not params[:order_articles]
# where to leave remainder during redistribution
rest_to = []
rest_to << :tolerance if params[:rest_to_tolerance]
@ -186,18 +186,19 @@ class OrdersController < ApplicationController
unless oa.units_received.blank?
cunits[0] += oa.units_received * oa.article.unit_quantity
oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to
oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 }
oacounts.each_with_index { |c, i| cunits[i + 1] += c; counts[i + 1] += 1 if c > 0 }
end
end
oa.save!
end
end
return nil if counts[0] == 0
notice = []
notice << I18n.t('orders.update_order_amounts.msg1', count: counts[0], units: cunits[0])
notice << I18n.t('orders.update_order_amounts.msg2', count: counts[1], units: cunits[1]) if params[:rest_to_tolerance]
notice << I18n.t('orders.update_order_amounts.msg3', count: counts[2], units: cunits[2]) if params[:rest_to_stock]
if counts[3]>0 || cunits[3]>0
if counts[3] > 0 || cunits[3] > 0
notice << I18n.t('orders.update_order_amounts.msg4', count: counts[3], units: cunits[3])
end
notice.join(', ')
@ -206,5 +207,4 @@ class OrdersController < ApplicationController
def remove_empty_article
params[:order][:article_ids].reject!(&:blank?) if params[:order] && params[:order][:article_ids]
end
end

View file

@ -1,5 +1,4 @@
class PickupsController < ApplicationController
before_action :authenticate_pickups
def index

View file

@ -1,5 +1,4 @@
class SessionsController < ApplicationController
skip_before_action :authenticate
layout 'login'
@ -30,5 +29,4 @@ class SessionsController < ApplicationController
def redirect_to_foodcoop
redirect_to root_path
end
end

View file

@ -1,8 +1,7 @@
class StockitController < ApplicationController
def index
@stock_articles = StockArticle.undeleted.includes(:supplier, :article_category).
order('suppliers.name, article_categories.name, articles.name')
@stock_articles = StockArticle.undeleted.includes(:supplier, :article_category)
.order('suppliers.name, article_categories.name, articles.name')
end
def index_on_stock_article_create # See publish/subscribe design pattern in /doc.
@ -40,7 +39,7 @@ class StockitController < ApplicationController
end
def create
@stock_article = StockArticle.new({quantity: 0}.merge(params[:stock_article]))
@stock_article = StockArticle.new({ quantity: 0 }.merge(params[:stock_article]))
@stock_article.save!
render :layout => false
rescue ActiveRecord::RecordInvalid
@ -78,10 +77,10 @@ class StockitController < ApplicationController
render :layout => false
rescue => error
render :partial => "destroy_fail", :layout => false,
:locals => { :fail_msg => I18n.t('errors.general_msg', :msg => error.message) }
:locals => { :fail_msg => I18n.t('errors.general_msg', :msg => error.message) }
end
#TODO: Fix this!!
# TODO: Fix this!!
def articles_search
@articles = Article.not_in_stock.limit(8).where('name LIKE ?', "%#{params[:term]}%")
render :json => @articles.map(&:name)

View file

@ -11,7 +11,7 @@ class StylesController < ApplicationController
if css.blank?
render body: nil, content_type: 'text/css', status: 404
else
expires_in 1.week, public:true if params[:md5].present?
expires_in 1.week, public: true if params[:md5].present?
render body: css, content_type: 'text/css'
end
end

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class SuppliersController < ApplicationController
before_action :authenticate_suppliers, :except => [:index, :list]
helper :deliveries
@ -18,7 +17,7 @@ class SuppliersController < ApplicationController
# if shared_supplier_id is given, the new supplier will filled whith its attributes
def new
if params[:shared_supplier_id]
shared_supplier = SharedSupplier.find(params[:shared_supplier_id])
shared_supplier = SharedSupplier.find(params[:shared_supplier_id])
@supplier = shared_supplier.suppliers.new(shared_supplier.autofill_attributes)
else
@supplier = Supplier.new
@ -55,9 +54,9 @@ class SuppliersController < ApplicationController
@supplier.mark_as_deleted
flash[:notice] = I18n.t('suppliers.destroy.notice')
redirect_to suppliers_path
rescue => e
flash[:error] = I18n.t('errors.general_msg', :msg => e.message)
redirect_to @supplier
rescue => e
flash[:error] = I18n.t('errors.general_msg', :msg => e.message)
redirect_to @supplier
end
# gives a list with all available shared_suppliers
@ -74,5 +73,4 @@ class SuppliersController < ApplicationController
:iban, :custom_fields, :delivery_days, :order_howto, :note, :supplier_category_id,
:shared_supplier_id, :min_order_quantity, :shared_sync_method)
end
end

View file

@ -1,10 +1,9 @@
# encoding: utf-8
class TasksController < ApplicationController
#auto_complete_for :user, :nick
# auto_complete_for :user, :nick
def index
@non_group_tasks = Task.non_group.order('due_date', 'name').includes(assignments: :user)
@groups = Workgroup.order(:name).includes(open_tasks: {assignments: :user})
@groups = Workgroup.order(:name).includes(open_tasks: { assignments: :user })
end
def user
@ -19,7 +18,7 @@ class TasksController < ApplicationController
def create
@task = Task.new(current_user_id: current_user.id)
@task.created_by = current_user
@task.attributes=(task_params)
@task.attributes = (task_params)
if params[:periodic]
@task.periodic_task_group = PeriodicTaskGroup.new
end
@ -47,7 +46,7 @@ class TasksController < ApplicationController
was_periodic = @task.periodic?
prev_due_date = @task.due_date
@task.current_user_id = current_user.id
@task.attributes=(task_params)
@task.attributes = (task_params)
if @task.errors.empty? && @task.save
task_group.update_tasks_including(@task, prev_due_date) if params[:periodic]
flash[:notice] = I18n.t('tasks.update.notice')
@ -122,5 +121,4 @@ class TasksController < ApplicationController
.require(:task)
.permit(:name, :description, :duration, :user_list, :required_users, :workgroup_id, :due_date, :done)
end
end

View file

@ -1,5 +1,4 @@
class UsersController < ApplicationController
# Currently used to display users nick and ids for autocomplete
def index
@users = User.undeleted.natural_search(params[:q])
@ -7,5 +6,4 @@ class UsersController < ApplicationController
format.json { render :json => @users.map(&:token_attributes).to_json }
end
end
end