1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-21 15:54:22 +01:00

Merge branch 'dev' for release 5.0.7

This commit is contained in:
Sylvain 2021-06-24 16:55:48 +02:00
commit 2492bb60e5
20 changed files with 142 additions and 111 deletions

View File

@ -1,5 +1,12 @@
# Changelog Fab-manager # Changelog Fab-manager
## v5.0.7 2021 June 24
- Fix a bug: unable to export members list if no subscriptions was taken
- Fix a bug: most OpenAPI endpoints were dysfunctional
- Fix a bug: unable to open some modals when the logo was undefined
- Fix a bug: stripe subscription generation fails if the user already has a subscription
## v5.0.6 2021 June 21 ## v5.0.6 2021 June 21
- Updated babel and its dependencies to 7.14.5 / 7.14.6 - Updated babel and its dependencies to 7.14.5 / 7.14.6

View File

@ -120,7 +120,7 @@ class API::MembersController < API::ApiController
Profile.where(user_id: User.members).maximum('updated_at'), Profile.where(user_id: User.members).maximum('updated_at'),
InvoicingProfile.where(user_id: User.members).maximum('updated_at'), InvoicingProfile.where(user_id: User.members).maximum('updated_at'),
StatisticProfile.where(user_id: User.members).maximum('updated_at'), StatisticProfile.where(user_id: User.members).maximum('updated_at'),
Subscription.maximum('updated_at') Subscription.maximum('updated_at') || DateTime.current
].max ].max
export = Export.where(category: 'users', export_type: 'members') export = Export.where(category: 'users', export_type: 'members')

View File

@ -1,5 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
# module definition
module OpenAPI::V1; end
# Parameters for OpenAPI endpoints # Parameters for OpenAPI endpoints
class OpenAPI::V1::BaseController < ActionController::Base class OpenAPI::V1::BaseController < ActionController::Base
protect_from_forgery with: :null_session protect_from_forgery with: :null_session

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# authorized 3rd party softwares can list the bookable machines through the OpenAPI
class OpenAPI::V1::BookableMachinesController < OpenAPI::V1::BaseController class OpenAPI::V1::BookableMachinesController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
expose_doc expose_doc
@ -22,19 +25,15 @@ class OpenAPI::V1::BookableMachinesController < OpenAPI::V1::BaseController
if user.subscription return unless user.subscription
plan_id = user.subscription.plan_id
@machines.each do |machine| plan_id = user.subscription.plan_id
credit = Credit.find_by(plan_id: plan_id, creditable: machine)
users_credit = user.users_credits.find_by(credit: credit) if credit
if credit @machines.each do |machine|
@hours_remaining[machine.id] = credit.hours - (users_credit.try(:hours_used) || 0) credit = Credit.find_by(plan_id: plan_id, creditable: machine)
else users_credit = user.users_credits.find_by(credit: credit) if credit
@hours_remaining[machine.id] = 0
end @hours_remaining[machine.id] = credit ? credit.hours - (users_credit.try(:hours_used) || 0) : 0
end
end end
end end
end end

View File

@ -1,32 +1,37 @@
# frozen_string_literal: true
# authorized 3rd party softwares can manage the events through the OpenAPI
class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc expose_doc
def index def index
@events = Event.includes(:event_image, :event_files, :availability, :category)
if upcoming @events = if upcoming
@events = Event.includes(:event_image, :event_files, :availability, :category) @events.references(:availabilities)
.where('availabilities.end_at >= ?', DateTime.current) .where('availabilities.end_at >= ?', DateTime.current)
.order('availabilities.start_at ASC').references(:availabilities) .order('availabilities.start_at ASC')
else else
@events = Event.includes(:event_image, :event_files, :availability, :category).order(created_at: :desc) @events.order(created_at: :desc)
end end
if params[:id].present?
@events = @events.where(id: params[:id])
end
if params[:page].present? @events = @events.where(id: params[:id]) if params[:id].present?
@events = @events.page(params[:page]).per(per_page)
paginate @events, per_page: per_page return unless params[:page].present?
end
@events = @events.page(params[:page]).per(per_page)
paginate @events, per_page: per_page
end end
private private
def per_page
params[:per_page] || 20 def per_page
end params[:per_page] || 20
def upcoming end
params[:upcoming] || false
end def upcoming
params[:upcoming] || false
end
end end

View File

@ -1,12 +1,16 @@
# frozen_string_literal: true
# OpenAPI controller for the invoices # OpenAPI controller for the invoices
class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc expose_doc
def index def index
@invoices = Invoice.order(created_at: :desc) @invoices = Invoice.order(created_at: :desc)
.references(:invoicing_profiles)
@invoices = @invoices.where(user_id: params[:user_id]) if params[:user_id].present? @invoices = @invoices.where('invoicing_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
return unless params[:page].present? return unless params[:page].present?

View File

@ -1,36 +1,33 @@
# frozen_string_literal: true
# public API controller for resources of type Reservation
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc expose_doc
def index def index
@reservations = Reservation.order(created_at: :desc) @reservations = Reservation.order(created_at: :desc)
.includes(statistic_profile: :user)
.references(:statistic_profiles)
if params[:user_id].present? @reservations = @reservations.where('statistic_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
@reservations = @reservations.where(user_id: params[:user_id]) @reservations = @reservations.where(reservable_type: format_type(params[:reservable_type])) if params[:reservable_type].present?
else @reservations = @reservations.where(reservable_id: params[:reservable_id]) if params[:reservable_id].present?
@reservations = @reservations.includes(user: :profile)
end
if params[:reservable_type].present? return unless params[:page].present?
@reservations = @reservations.where(reservable_type: format_type(params[:reservable_type]))
end
if params[:reservable_id].present? @reservations = @reservations.page(params[:page]).per(per_page)
@reservations = @reservations.where(reservable_id: params[:reservable_id]) paginate @reservations, per_page: per_page
end
if params[:page].present?
@reservations = @reservations.page(params[:page]).per(per_page)
paginate @reservations, per_page: per_page
end
end end
private private
def format_type(type)
type.singularize.classify
end
def per_page def format_type(type)
params[:per_page] || 20 type.singularize.classify
end end
def per_page
params[:per_page] || 20
end
end end

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# public API controller for resources of type Training
class OpenAPI::V1::TrainingsController < OpenAPI::V1::BaseController class OpenAPI::V1::TrainingsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
expose_doc expose_doc

View File

@ -1,30 +1,30 @@
# frozen_string_literal: true
# public API controller for user's trainings
class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc expose_doc
def index def index
@user_trainings = UserTraining.order(created_at: :desc) @user_trainings = StatisticProfileTraining.includes(statistic_profile: :user)
.includes(:training)
.references(:statistic_profiles)
.order(created_at: :desc)
if params[:user_id].present?
@user_trainings = @user_trainings.where(user_id: params[:user_id])
else
@user_trainings = @user_trainings.includes(user: :profile)
end
if params[:training_id].present? @user_trainings = @user_trainings.where('statistic_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
@user_trainings = @user_trainings.where(training_id: params[:training_id]) @user_trainings = @user_trainings.where(training_id: params[:training_id]) if params[:training_id].present?
else
@user_trainings = @user_trainings.includes(:training)
end
if params[:page].present? return unless params[:page].present?
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
paginate @user_trainings, per_page: per_page @user_trainings = @user_trainings.page(params[:page]).per(per_page)
end paginate @user_trainings, per_page: per_page
end end
private private
def per_page
params[:per_page] || 20 def per_page
end params[:per_page] || 20
end
end end

View File

@ -1,5 +1,9 @@
# frozen_string_literal: true
# public API controller for users
class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc expose_doc
def index def index
@ -9,19 +13,17 @@ class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController
email_param = params[:email].is_a?(String) ? params[:email].downcase : params[:email].map(&:downcase) email_param = params[:email].is_a?(String) ? params[:email].downcase : params[:email].map(&:downcase)
@users = @users.where(email: email_param) @users = @users.where(email: email_param)
end end
@users = @users.where(id: params[:user_id]) if params[:user_id].present?
if params[:user_id].present? return unless params[:page].present?
@users = @users.where(id: params[:user_id])
end
if params[:page].present? @users = @users.page(params[:page]).per(per_page)
@users = @users.page(params[:page]).per(per_page) paginate @users, per_page: per_page
paginate @users, per_page: per_page
end
end end
private private
def per_page
params[:per_page] || 20 def per_page
end params[:per_page] || 20
end
end end

View File

@ -74,8 +74,8 @@ export const FabModal: React.FC<FabModalProps> = ({ title, isOpen, toggleModal,
onRequestClose={toggleModal}> onRequestClose={toggleModal}>
<div className="fab-modal-header"> <div className="fab-modal-header">
<Loader> <Loader>
<img src={blackLogo.custom_asset_file_attributes.attachment_url} <img src={blackLogo?.custom_asset_file_attributes?.attachment_url}
alt={blackLogo.custom_asset_file_attributes.attachment} alt={blackLogo?.custom_asset_file_attributes?.attachment}
className="modal-logo" /> className="modal-logo" />
</Loader> </Loader>
<h1>{ title }</h1> <h1>{ title }</h1>

View File

@ -63,7 +63,7 @@ class PDF::PaymentSchedule < Prawn::Document
align: :right, align: :right,
inline_format: true inline_format: true
name = full_name name = full_name
subscription = payment_schedule.payment_schedule_objects.find(&:subscription).subscription subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.subscription
# object # object
move_down 25 move_down 25

View File

@ -38,7 +38,7 @@ class CartService
def from_payment_schedule(payment_schedule) def from_payment_schedule(payment_schedule)
@customer = payment_schedule.user @customer = payment_schedule.user
plan = payment_schedule.payment_schedule_objects.find(&:subscription)&.subscription&.plan plan = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }&.subscription&.plan
coupon = CartItem::Coupon.new(@customer, @operator, payment_schedule.coupon&.code) coupon = CartItem::Coupon.new(@customer, @operator, payment_schedule.coupon&.code)
schedule = CartItem::PaymentSchedule.new(plan, coupon, true) schedule = CartItem::PaymentSchedule.new(plan, coupon, true)

View File

@ -162,7 +162,7 @@ class PaymentScheduleService
item.update_attributes(state: 'canceled') item.update_attributes(state: 'canceled')
end end
# cancel subscription # cancel subscription
subscription = payment_schedule.payment_schedule_objects.find(&:subscription).subscription subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.subscription
subscription.expire(DateTime.current) subscription.expire(DateTime.current)
subscription.canceled_at subscription.canceled_at
@ -181,7 +181,7 @@ class PaymentScheduleService
} }
# the subscription and reservation items # the subscription and reservation items
subscription = payment_schedule_item.payment_schedule.payment_schedule_objects.find(&:subscription).subscription subscription = payment_schedule_item.payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.subscription
if payment_schedule_item.payment_schedule.main_object.object_type == Reservation.name if payment_schedule_item.payment_schedule.main_object.object_type == Reservation.name
details[:reservation] = payment_schedule_item.details['other_items'] details[:reservation] = payment_schedule_item.details['other_items']
reservation = payment_schedule_item.payment_schedule.main_object.reservation reservation = payment_schedule_item.payment_schedule.main_object.reservation
@ -200,7 +200,7 @@ class PaymentScheduleService
## ##
def complete_next_invoice(payment_schedule_item, invoice) def complete_next_invoice(payment_schedule_item, invoice)
# the subscription item # the subscription item
subscription = payment_schedule_item.payment_schedule.payment_schedule_objects.find(&:subscription).subscription subscription = payment_schedule_item.payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.subscription
# sub-price for the subscription # sub-price for the subscription
details = { subscription: payment_schedule_item.details['recurring'] } details = { subscription: payment_schedule_item.details['recurring'] }

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
json.invoices @invoices do |invoice| json.invoices @invoices do |invoice|
json.extract! invoice, :id, :user_id, :reference, :total, :type, :description json.extract! invoice, :id, :reference, :total, :type, :description
json.user_id invoice.statistic_profile.user_id
if invoice.payment_gateway_object if invoice.payment_gateway_object
json.payment_gateway_object do json.payment_gateway_object do
json.id invoice.payment_gateway_object.gateway_object_id json.id invoice.payment_gateway_object.gateway_object_id

View File

@ -1,18 +1,23 @@
json.reservations @reservations do |reservation| # frozen_string_literal: true
json.extract! reservation, :id, :user_id, :reservable_id, :reservable_type, :updated_at, :created_at
if reservation.association(:user).loaded? json.reservations @reservations do |reservation|
json.user do json.extract! reservation, :id, :reservable_id, :reservable_type, :updated_at, :created_at
json.partial! 'open_api/v1/users/user', user: reservation.user
if reservation.association(:statistic_profile).loaded?
json.user_id reservation.statistic_profile.user_id
unless reservation.statistic_profile.user.nil?
json.user do
json.partial! 'open_api/v1/users/user', user: reservation.statistic_profile.user
end
end end
end end
json.reservable do json.reservable do
if reservation.reservable_type == "Training" if reservation.reservable_type == 'Training'
json.partial! 'open_api/v1/trainings/training', training: reservation.reservable json.partial! 'open_api/v1/trainings/training', training: reservation.reservable
elsif reservation.reservable_type == "Machine" elsif reservation.reservable_type == 'Machine'
json.partial! 'open_api/v1/machines/machine', machine: reservation.reservable json.partial! 'open_api/v1/machines/machine', machine: reservation.reservable
elsif reservation.reservable_type == "Event" elsif reservation.reservable_type == 'Event'
json.partial! 'open_api/v1/events/event', event: reservation.reservable json.partial! 'open_api/v1/events/event', event: reservation.reservable
end end
end end

View File

@ -1,9 +1,14 @@
json.user_trainings @user_trainings do |user_training| # frozen_string_literal: true
json.extract! user_training, :id, :user_id, :training_id, :updated_at, :created_at
if user_training.association(:user).loaded? json.user_trainings @user_trainings do |user_training|
json.user do json.extract! user_training, :id, :training_id, :updated_at, :created_at
json.partial! 'open_api/v1/users/user', user: user_training.user
if user_training.association(:statistic_profile).loaded?
json.user_id user_training.statistic_profile.user_id
unless user_training.statistic_profile.user.nil?
json.user do
json.partial! 'open_api/v1/users/user', user: user_training.statistic_profile.user
end
end end
end end

View File

@ -14,7 +14,7 @@ class Stripe::Service < Payment::Service
case payment_schedule.main_object.object_type case payment_schedule.main_object.object_type
when Reservation.name when Reservation.name
subscription = payment_schedule.payment_schedule_objects.find(&:subscription).object subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.object
reservable_stp_id = payment_schedule.main_object.object.reservable&.payment_gateway_object&.gateway_object_id reservable_stp_id = payment_schedule.main_object.object.reservable&.payment_gateway_object&.gateway_object_id
when Subscription.name when Subscription.name
subscription = payment_schedule.main_object.object subscription = payment_schedule.main_object.object

View File

@ -1,6 +1,6 @@
{ {
"name": "fab-manager", "name": "fab-manager",
"version": "5.0.6", "version": "5.0.7",
"description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.", "description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.",
"keywords": [ "keywords": [
"fablab", "fablab",

View File

@ -787,7 +787,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
# Check the answer # Check the answer
result = json_response(response.body) result = json_response(response.body)
assert_equal payment_schedule.id, result[:id], 'payment schedule id does not match' assert_equal payment_schedule.id, result[:id], 'payment schedule id does not match'
subscription = payment_schedule.payment_schedule_objects.find(&:subscription).object subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.object
assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match' assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match'
end end
@ -909,7 +909,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
# Check the answer # Check the answer
result = json_response(response.body) result = json_response(response.body)
assert_equal payment_schedule.id, result[:id], 'payment schedule id does not match' assert_equal payment_schedule.id, result[:id], 'payment schedule id does not match'
subscription = payment_schedule.payment_schedule_objects.find(&:subscription).object subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.object
assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match' assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match'
end end
end end