Skip to content

Commit

Permalink
Merge branch 'dev' for release 5.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gnepud committed Dec 5, 2022
2 parents 7140939 + 129e2cd commit a5c9a7d
Show file tree
Hide file tree
Showing 57 changed files with 557 additions and 232 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog Fab-manager

## v5.5.6 2022 December 05

- Updated FabAnalytics reports to include new features
- Fix a bug: setting somes decimal amounts (e.g. 4,85) result in another amount (e.g. 4,84)
- Fix a bug: unable to export statistics
- Fix a bug: soft destroyed machines and spaces are still reported in the OpenAPI

## v5.5.5 2022 November 22

- Soft destroy of spaces and machines
Expand Down
19 changes: 10 additions & 9 deletions app/controllers/api/coupons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# API Controller for resources of type Coupon
# Coupons are used in payments
class API::CouponsController < API::ApiController
include ApplicationHelper

before_action :authenticate_user!, except: %i[validate]
before_action :set_coupon, only: %i[show update destroy]

Expand Down Expand Up @@ -31,14 +33,13 @@ def validate
if @coupon.nil?
render json: { status: 'rejected' }, status: :not_found
else
_user_id = if current_user&.admin?
params[:user_id]
else
current_user&.id
end

amount = params[:amount].to_f * 100.0
status = @coupon.status(_user_id, amount)
user_id = if current_user&.admin?
params[:user_id]
else
current_user&.id
end

status = @coupon.status(user_id, to_centimes(params[:amount]))
if status == 'active'
render :validate, status: :ok, location: @coupon
else
Expand Down Expand Up @@ -89,7 +90,7 @@ def coupon_params
@parameters
else
@parameters = params
@parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_f * 100.0 if @parameters[:coupon][:amount_off]
@parameters[:coupon][:amount_off] = to_centimes(@parameters[:coupon][:amount_off]) if @parameters[:coupon][:amount_off]

@parameters = @parameters.require(:coupon).permit(:name, :code, :percent_off, :amount_off, :validity_per_user, :valid_until,
:max_usages, :active)
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/api/machines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ def update

def destroy
authorize @machine
if @machine.destroyable?
@machine.destroy
else
@machine.soft_destroy!
end
method = @machine.destroyable? ? :destroy : :soft_destroy!
@machine.send(method)
head :no_content
end

Expand Down
8 changes: 5 additions & 3 deletions app/controllers/api/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Plan are used to define subscription's characteristics.
# PartnerPlan is a special kind of plan which send notifications to an external user
class API::PlansController < API::ApiController
before_action :authenticate_user!, except: [:index, :durations]
include ApplicationHelper

before_action :authenticate_user!, except: %i[index durations]

def index
@plans = Plan.includes(:plan_file)
Expand Down Expand Up @@ -70,10 +72,10 @@ def plan_params
@parameters
else
@parameters = params
@parameters[:plan][:amount] = @parameters[:plan][:amount].to_f * 100.0 if @parameters[:plan][:amount]
@parameters[:plan][:amount] = to_centimes(@parameters[:plan][:amount]) if @parameters[:plan][:amount]
if @parameters[:plan][:prices_attributes]
@parameters[:plan][:prices_attributes] = @parameters[:plan][:prices_attributes].map do |price|
{ amount: price[:amount].to_f * 100.0, id: price[:id] }
{ amount: to_centimes(price[:amount]), id: price[:id] }
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/prepaid_packs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# API Controller for resources of type PrepaidPack
# PrepaidPacks are used to provide discounts to users that bought many hours at once
class API::PrepaidPacksController < API::ApiController
include ApplicationHelper

before_action :authenticate_user!, except: :index
before_action :set_pack, only: %i[show update destroy]

Expand Down Expand Up @@ -46,7 +48,7 @@ def set_pack

def pack_params
pack_params = params
pack_params[:pack][:amount] = pack_params[:pack][:amount].to_f * 100.0 if pack_params[:pack][:amount]
pack_params[:pack][:amount] = to_centimes(pack_params[:pack][:amount]) if pack_params[:pack][:amount]
params.require(:pack).permit(:priceable_id, :priceable_type, :group_id, :amount, :minutes, :validity_count, :validity_interval,
:disabled)
end
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/api/prices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# API Controller for resources of type Price
# Prices are used in reservations (Machine, Space)
class API::PricesController < API::ApiController
include ApplicationHelper

before_action :authenticate_user!
before_action :set_price, only: %i[update destroy]

def create
@price = Price.new(price_create_params)
@price.amount *= 100
@price.amount = to_centimes(price_create_params[:amount])

authorize @price

Expand All @@ -26,7 +28,7 @@ def index
def update
authorize Price
price_parameters = price_params
price_parameters[:amount] = price_parameters[:amount] * 100
price_parameters[:amount] = to_centimes(price_parameters[:amount])
if @price.update(price_parameters)
render status: :ok
else
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/api/pricing_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# frozen_string_literal: true

# @deprecated
# <b>DEPRECATED:</b> Please use <tt>API::PriceController</tt> instead.
# API Controller for managing Plans prices
class API::PricingController < API::ApiController
before_action :authenticate_user!, except: %i[index show]
include ApplicationHelper

before_action :authenticate_user!, except: %i[index update]

def index
@group_pricing = Group.includes(:plans, :trainings_pricings)
Expand All @@ -19,10 +23,10 @@ def update
next unless group

training_pricing = group.trainings_pricings.find_or_initialize_by(training_id: training.id)
training_pricing.amount = amount * 100
training_pricing.amount = to_centimes(amount)
training_pricing.save
end
end
head 200
head :ok
end
end
12 changes: 4 additions & 8 deletions app/controllers/api/spaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# API Controller for resources of type Space
class API::SpacesController < API::ApiController
before_action :authenticate_user!, except: %i[index show]
before_action :set_space, only: %i[update destroy]
respond_to :json

def index
Expand All @@ -27,7 +28,6 @@ def create

def update
authorize Space
@space = get_space
if @space.update(space_params)
render :show, status: :ok, location: @space
else
Expand All @@ -36,19 +36,15 @@ def update
end

def destroy
@space = get_space
authorize @space
if @space.destroyable?
@space.destroy
else
@space.soft_destroy!
end
method = @space.destroyable? ? :destroy : :soft_destroy!
@space.send(method)
head :no_content
end

private

def get_space
def set_space
Space.friendly.find(params[:id])
end

Expand Down
8 changes: 6 additions & 2 deletions app/controllers/api/trainings_pricings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

# @deprecated
# <b>DEPRECATED:</b> Please use <tt>API::PriceController</tt> instead.
# API Controller for managing Training prices
class API::TrainingsPricingsController < API::ApiController
include ApplicationHelper

before_action :authenticate_user!

def index
Expand All @@ -12,14 +16,14 @@ def update
if current_user.admin?
@trainings_pricing = TrainingsPricing.find(params[:id])
trainings_pricing_parameters = trainings_pricing_params
trainings_pricing_parameters[:amount] = trainings_pricing_parameters[:amount] * 100
trainings_pricing_parameters[:amount] = to_centimes(trainings_pricing_parameters[:amount])
if @trainings_pricing.update(trainings_pricing_parameters)
render status: :ok
else
render status: :unprocessable_entity
end
else
head 403
head :forbidden
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/wallet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def by_user
def transactions
@wallet = Wallet.find(params[:id])
authorize @wallet
@wallet_transactions = @wallet.wallet_transactions.includes(:invoice, :invoicing_profile).order(created_at: :desc)
@wallet_transactions = @wallet.wallet_transactions.includes(:invoice, :invoicing_profile, :payment_schedule).order(created_at: :desc)
end

def credit
Expand All @@ -23,7 +23,7 @@ def credit
@wallet = Wallet.find(credit_params[:id])
authorize @wallet
service = WalletService.new(user: current_user, wallet: @wallet)
transaction = service.credit(credit_params[:amount].to_f)
transaction = service.credit(credit_params[:amount])
if transaction
service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir]
render :show
Expand Down
15 changes: 7 additions & 8 deletions app/controllers/open_api/v1/machines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OpenAPI::V1::MachinesController < OpenAPI::V1::BaseController
before_action :set_machine, only: %i[show update destroy]

def index
@machines = Machine.order(:created_at)
@machines = Machine.order(:created_at).where(deleted_at: nil)
end

def create
Expand All @@ -28,15 +28,14 @@ def update
end
end

def show; end
def show
head :not_found if @machine.deleted_at
end

def destroy
if @machine.destroyable?
@machine.destroy
head :no_content
else
render json: { error: 'has existing reservations' }, status: :unprocessable_entity
end
method = @machine.destroyable? ? :destroy : :soft_destroy!
@machine.send(method)
head :no_content
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/open_api/v1/spaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OpenAPI::V1::SpacesController < OpenAPI::V1::BaseController
before_action :set_space, only: %i[show]

def index
@spaces = Space.order(:created_at)
@spaces = Space.order(:created_at).where(deleted_at: nil)
end

def show; end
Expand Down
9 changes: 9 additions & 0 deletions app/frontend/templates/admin/settings/analyticsModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ <h3 class="text-center red" translate>{{ 'app.admin.settings.fab_analytics' }}</
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.version' }}</td><td>{{ data.version }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.members' }}</td><td>{{ data.members }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.admins' }}</td><td>{{ data.admins }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.managers' }}</td><td>{{ data.managers }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.availabilities' }}</td><td>{{ data.availabilities }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.reservations' }}</td><td>{{ data.reservations }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.orders' }}</td><td>{{ data.orders }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.plans' }}</td><td>{{ data.plans }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.spaces' }}</td><td>{{ data.spaces }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.online_payment' }}</td><td>{{ data.online_payment }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.gateway' }}</td><td>{{ data.gateway }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.wallet' }}</td><td>{{ data.wallet }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.statistics' }}</td><td>{{ data.statistics }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.trainings' }}</td><td>{{ data.trainings }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.public_agenda' }}</td><td>{{ data.public_agenda }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.machines' }}</td><td>{{ data.machines }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.store' }}</td><td>{{ data.store }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.invoices' }}</td><td>{{ data.invoices }}</td></tr>
<tr><td translate>{{ 'app.admin.settings.privacy.analytics.openlab' }}</td><td>{{ data.openlab }}</td></tr>
</tbody>
Expand Down
26 changes: 8 additions & 18 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _t(key, interpolations)
message = MessageFormat.new(I18n.t(scope_key_by_partial(key)), I18n.locale.to_s)
text = message.format(interpolations)
if html_safe_translation_key?(key)
text.html_safe
text.html_safe # rubocop:disable Rails/OutputSafety
else
text
end
Expand All @@ -65,23 +65,6 @@ def amount_to_f(amount)
amount / 100.00
end

##
# Retrieve an item in the given array of items
# by default, the "id" is expected to match the given parameter but
# this can be overridden by passing a third parameter to specify the
# property to match
##
def get_item(array, id, key = nil)
array.each do |i|
if key.nil?
return i if i.id == id
elsif i[key] == id
return i
end
end
nil
end

##
# Apply a correction for a future DateTime due to change in Daylight Saving Time (DST) period
# @param reference {ActiveSupport::TimeWithZone}
Expand All @@ -95,9 +78,15 @@ def dst_correction(reference, datetime)
res
end

# Return the given amount in centimes, without floating-point imprecision errors
def to_centimes(amount)
(BigDecimal(amount.to_s) * 100.0).to_f
end

private

## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb
# rubocop:disable Rails/HelperInstanceVariable
def scope_key_by_partial(key)
if key.to_s.first == '.'
raise "Cannot use t(#{key.inspect}) shortcut because path is not available" unless @virtual_path
Expand All @@ -107,6 +96,7 @@ def scope_key_by_partial(key)
key
end
end
# rubocop:enable Rails/HelperInstanceVariable

def html_safe_translation_key?(key)
key.to_s =~ /(\b|_|\.)html$/
Expand Down
Loading

0 comments on commit a5c9a7d

Please sign in to comment.