mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
Merge branch 'dev' for release 5.0.7
This commit is contained in:
commit
2492bb60e5
@ -1,5 +1,12 @@
|
||||
# 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
|
||||
|
||||
- Updated babel and its dependencies to 7.14.5 / 7.14.6
|
||||
|
@ -120,7 +120,7 @@ class API::MembersController < API::ApiController
|
||||
Profile.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'),
|
||||
Subscription.maximum('updated_at')
|
||||
Subscription.maximum('updated_at') || DateTime.current
|
||||
].max
|
||||
|
||||
export = Export.where(category: 'users', export_type: 'members')
|
||||
|
@ -1,5 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# module definition
|
||||
module OpenAPI::V1; end
|
||||
|
||||
# Parameters for OpenAPI endpoints
|
||||
class OpenAPI::V1::BaseController < ActionController::Base
|
||||
protect_from_forgery with: :null_session
|
||||
|
@ -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
|
||||
extend OpenAPI::ApiDoc
|
||||
expose_doc
|
||||
@ -22,19 +25,15 @@ class OpenAPI::V1::BookableMachinesController < OpenAPI::V1::BaseController
|
||||
|
||||
|
||||
|
||||
if user.subscription
|
||||
plan_id = user.subscription.plan_id
|
||||
return unless user.subscription
|
||||
|
||||
@machines.each do |machine|
|
||||
credit = Credit.find_by(plan_id: plan_id, creditable: machine)
|
||||
users_credit = user.users_credits.find_by(credit: credit) if credit
|
||||
plan_id = user.subscription.plan_id
|
||||
|
||||
if credit
|
||||
@hours_remaining[machine.id] = credit.hours - (users_credit.try(:hours_used) || 0)
|
||||
else
|
||||
@hours_remaining[machine.id] = 0
|
||||
end
|
||||
end
|
||||
@machines.each do |machine|
|
||||
credit = Credit.find_by(plan_id: plan_id, creditable: machine)
|
||||
users_credit = user.users_credits.find_by(credit: credit) if credit
|
||||
|
||||
@hours_remaining[machine.id] = credit ? credit.hours - (users_credit.try(:hours_used) || 0) : 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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
|
||||
extend OpenAPI::ApiDoc
|
||||
include Rails::Pagination
|
||||
expose_doc
|
||||
|
||||
|
||||
def index
|
||||
|
||||
if upcoming
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('availabilities.end_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC').references(:availabilities)
|
||||
else
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category).order(created_at: :desc)
|
||||
end
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
@events = if upcoming
|
||||
@events.references(:availabilities)
|
||||
.where('availabilities.end_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC')
|
||||
else
|
||||
@events.order(created_at: :desc)
|
||||
end
|
||||
|
||||
if params[:id].present?
|
||||
@events = @events.where(id: params[:id])
|
||||
end
|
||||
|
||||
if params[:page].present?
|
||||
@events = @events.page(params[:page]).per(per_page)
|
||||
paginate @events, per_page: per_page
|
||||
end
|
||||
@events = @events.where(id: params[:id]) if params[:id].present?
|
||||
|
||||
return unless params[:page].present?
|
||||
|
||||
@events = @events.page(params[:page]).per(per_page)
|
||||
paginate @events, per_page: per_page
|
||||
end
|
||||
|
||||
private
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
def upcoming
|
||||
params[:upcoming] || false
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
|
||||
def upcoming
|
||||
params[:upcoming] || false
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# OpenAPI controller for the invoices
|
||||
class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
include Rails::Pagination
|
||||
expose_doc
|
||||
|
||||
def index
|
||||
@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?
|
||||
|
||||
|
@ -1,36 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# public API controller for resources of type Reservation
|
||||
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
include Rails::Pagination
|
||||
expose_doc
|
||||
|
||||
def index
|
||||
@reservations = Reservation.order(created_at: :desc)
|
||||
.includes(statistic_profile: :user)
|
||||
.references(:statistic_profiles)
|
||||
|
||||
if params[:user_id].present?
|
||||
@reservations = @reservations.where(user_id: params[:user_id])
|
||||
else
|
||||
@reservations = @reservations.includes(user: :profile)
|
||||
end
|
||||
@reservations = @reservations.where('statistic_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
|
||||
@reservations = @reservations.where(reservable_type: format_type(params[:reservable_type])) if params[:reservable_type].present?
|
||||
@reservations = @reservations.where(reservable_id: params[:reservable_id]) if params[:reservable_id].present?
|
||||
|
||||
if params[:reservable_type].present?
|
||||
@reservations = @reservations.where(reservable_type: format_type(params[:reservable_type]))
|
||||
end
|
||||
return unless params[:page].present?
|
||||
|
||||
if params[:reservable_id].present?
|
||||
@reservations = @reservations.where(reservable_id: params[:reservable_id])
|
||||
end
|
||||
|
||||
if params[:page].present?
|
||||
@reservations = @reservations.page(params[:page]).per(per_page)
|
||||
paginate @reservations, per_page: per_page
|
||||
end
|
||||
@reservations = @reservations.page(params[:page]).per(per_page)
|
||||
paginate @reservations, per_page: per_page
|
||||
end
|
||||
|
||||
private
|
||||
def format_type(type)
|
||||
type.singularize.classify
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
def format_type(type)
|
||||
type.singularize.classify
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# public API controller for resources of type Training
|
||||
class OpenAPI::V1::TrainingsController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
expose_doc
|
||||
|
@ -1,30 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# public API controller for user's trainings
|
||||
class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
include Rails::Pagination
|
||||
expose_doc
|
||||
|
||||
|
||||
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(training_id: params[:training_id])
|
||||
else
|
||||
@user_trainings = @user_trainings.includes(:training)
|
||||
end
|
||||
@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]) if params[:training_id].present?
|
||||
|
||||
if params[:page].present?
|
||||
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
|
||||
paginate @user_trainings, per_page: per_page
|
||||
end
|
||||
return unless params[:page].present?
|
||||
|
||||
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
|
||||
paginate @user_trainings, per_page: per_page
|
||||
end
|
||||
|
||||
private
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# public API controller for users
|
||||
class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
include Rails::Pagination
|
||||
expose_doc
|
||||
|
||||
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)
|
||||
@users = @users.where(email: email_param)
|
||||
end
|
||||
@users = @users.where(id: params[:user_id]) if params[:user_id].present?
|
||||
|
||||
if params[:user_id].present?
|
||||
@users = @users.where(id: params[:user_id])
|
||||
end
|
||||
return unless params[:page].present?
|
||||
|
||||
if params[:page].present?
|
||||
@users = @users.page(params[:page]).per(per_page)
|
||||
paginate @users, per_page: per_page
|
||||
end
|
||||
@users = @users.page(params[:page]).per(per_page)
|
||||
paginate @users, per_page: per_page
|
||||
end
|
||||
|
||||
private
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:per_page] || 20
|
||||
end
|
||||
end
|
||||
|
@ -74,8 +74,8 @@ export const FabModal: React.FC<FabModalProps> = ({ title, isOpen, toggleModal,
|
||||
onRequestClose={toggleModal}>
|
||||
<div className="fab-modal-header">
|
||||
<Loader>
|
||||
<img src={blackLogo.custom_asset_file_attributes.attachment_url}
|
||||
alt={blackLogo.custom_asset_file_attributes.attachment}
|
||||
<img src={blackLogo?.custom_asset_file_attributes?.attachment_url}
|
||||
alt={blackLogo?.custom_asset_file_attributes?.attachment}
|
||||
className="modal-logo" />
|
||||
</Loader>
|
||||
<h1>{ title }</h1>
|
||||
|
@ -63,7 +63,7 @@ class PDF::PaymentSchedule < Prawn::Document
|
||||
align: :right,
|
||||
inline_format: true
|
||||
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
|
||||
move_down 25
|
||||
|
@ -38,7 +38,7 @@ class CartService
|
||||
|
||||
def from_payment_schedule(payment_schedule)
|
||||
@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)
|
||||
schedule = CartItem::PaymentSchedule.new(plan, coupon, true)
|
||||
|
@ -162,7 +162,7 @@ class PaymentScheduleService
|
||||
item.update_attributes(state: 'canceled')
|
||||
end
|
||||
# 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.canceled_at
|
||||
@ -181,7 +181,7 @@ class PaymentScheduleService
|
||||
}
|
||||
|
||||
# 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
|
||||
details[:reservation] = payment_schedule_item.details['other_items']
|
||||
reservation = payment_schedule_item.payment_schedule.main_object.reservation
|
||||
@ -200,7 +200,7 @@ class PaymentScheduleService
|
||||
##
|
||||
def complete_next_invoice(payment_schedule_item, invoice)
|
||||
# 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
|
||||
details = { subscription: payment_schedule_item.details['recurring'] }
|
||||
|
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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
|
||||
json.payment_gateway_object do
|
||||
json.id invoice.payment_gateway_object.gateway_object_id
|
||||
|
@ -1,18 +1,23 @@
|
||||
json.reservations @reservations do |reservation|
|
||||
json.extract! reservation, :id, :user_id, :reservable_id, :reservable_type, :updated_at, :created_at
|
||||
# frozen_string_literal: true
|
||||
|
||||
if reservation.association(:user).loaded?
|
||||
json.user do
|
||||
json.partial! 'open_api/v1/users/user', user: reservation.user
|
||||
json.reservations @reservations do |reservation|
|
||||
json.extract! reservation, :id, :reservable_id, :reservable_type, :updated_at, :created_at
|
||||
|
||||
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
|
||||
|
||||
json.reservable do
|
||||
if reservation.reservable_type == "Training"
|
||||
if reservation.reservable_type == 'Training'
|
||||
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
|
||||
elsif reservation.reservable_type == "Event"
|
||||
elsif reservation.reservable_type == 'Event'
|
||||
json.partial! 'open_api/v1/events/event', event: reservation.reservable
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,14 @@
|
||||
json.user_trainings @user_trainings do |user_training|
|
||||
json.extract! user_training, :id, :user_id, :training_id, :updated_at, :created_at
|
||||
# frozen_string_literal: true
|
||||
|
||||
if user_training.association(:user).loaded?
|
||||
json.user do
|
||||
json.partial! 'open_api/v1/users/user', user: user_training.user
|
||||
json.user_trainings @user_trainings do |user_training|
|
||||
json.extract! user_training, :id, :training_id, :updated_at, :created_at
|
||||
|
||||
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
|
||||
|
||||
|
@ -14,7 +14,7 @@ class Stripe::Service < Payment::Service
|
||||
|
||||
case payment_schedule.main_object.object_type
|
||||
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
|
||||
when Subscription.name
|
||||
subscription = payment_schedule.main_object.object
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"keywords": [
|
||||
"fablab",
|
||||
|
@ -787,7 +787,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
|
||||
# Check the answer
|
||||
result = json_response(response.body)
|
||||
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'
|
||||
end
|
||||
|
||||
@ -909,7 +909,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
|
||||
# Check the answer
|
||||
result = json_response(response.body)
|
||||
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'
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user