mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
[bug] create transverse plan: do not create one for the admins group
This commit is contained in:
parent
2efd7644d2
commit
56a56565ae
@ -1,2 +1,6 @@
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
Metrics/MethodLength:
|
||||
Max: 16
|
||||
Style/BracesAroundHashParameters:
|
||||
EnforcedStyle: context_dependent
|
||||
|
@ -5,6 +5,7 @@
|
||||
- Migrated front-end application from CoffeeScript to ECMAScript 6 (JS)
|
||||
- Integration of Eslint and Rubocop coding rules
|
||||
- Fix a bug: on small screens, display of button "change group" overflows
|
||||
- Fix a bug: creating a transverse plan, create one for the hidden admins group
|
||||
- Fix a security issue: dependency rack has a vulnerability as described in [CVE-2018-16471](https://nvd.nist.gov/vuln/detail/CVE-2018-16471)
|
||||
- Fix a security issue: dependency loofah has a vulnerability as described in [CVE-2018-16468](https://github.com/flavorjones/loofah/issues/154)
|
||||
- Updated documentation
|
||||
|
@ -5,6 +5,8 @@ class Group < ActiveRecord::Base
|
||||
has_many :machines_prices, ->{ where(priceable_type: 'Machine') }, class_name: 'Price', dependent: :destroy
|
||||
has_many :spaces_prices, ->{ where(priceable_type: 'Space') }, class_name: 'Price', dependent: :destroy
|
||||
|
||||
scope :all_except_admins, -> { where.not(slug: 'admins') }
|
||||
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
@ -19,23 +21,24 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
private
|
||||
def create_prices
|
||||
create_trainings_pricings
|
||||
create_machines_prices
|
||||
create_spaces_prices
|
||||
end
|
||||
|
||||
def create_trainings_pricings
|
||||
Training.all.each do |training|
|
||||
TrainingsPricing.create(group: self, training: training, amount: 0)
|
||||
end
|
||||
end
|
||||
def create_prices
|
||||
create_trainings_pricings
|
||||
create_machines_prices
|
||||
create_spaces_prices
|
||||
end
|
||||
|
||||
def create_machines_prices
|
||||
Machine.all.each do |machine|
|
||||
Price.create(priceable: machine, group: self, amount: 0)
|
||||
end
|
||||
def create_trainings_pricings
|
||||
Training.all.each do |training|
|
||||
TrainingsPricing.create(group: self, training: training, amount: 0)
|
||||
end
|
||||
end
|
||||
|
||||
def create_machines_prices
|
||||
Machine.all.each do |machine|
|
||||
Price.create(priceable: machine, group: self, amount: 0)
|
||||
end
|
||||
end
|
||||
|
||||
def create_spaces_prices
|
||||
Space.all.each do |space|
|
||||
@ -45,13 +48,15 @@ class Group < ActiveRecord::Base
|
||||
|
||||
def create_statistic_subtype
|
||||
user_index = StatisticIndex.find_by(es_type_key: 'user')
|
||||
StatisticSubType.create!({statistic_types: user_index.statistic_types, key: self.slug, label: self.name})
|
||||
StatisticSubType.create!( statistic_types: user_index.statistic_types, key: slug, label: name)
|
||||
end
|
||||
|
||||
def update_statistic_subtype
|
||||
user_index = StatisticIndex.find_by(es_type_key: 'user')
|
||||
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type).where(key: self.slug, statistic_types: { statistic_index_id: user_index.id }).first
|
||||
subtype.label = self.name
|
||||
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type)
|
||||
.where(key: slug, statistic_types: { statistic_index_id: user_index.id })
|
||||
.first
|
||||
subtype.label = name
|
||||
subtype.save!
|
||||
end
|
||||
end
|
||||
|
@ -27,19 +27,19 @@ class Plan < ActiveRecord::Base
|
||||
|
||||
validates :amount, :group, :base_name, presence: true
|
||||
validates :interval_count, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
|
||||
validates :interval_count, numericality: { less_than: 12 }, if: Proc.new {|plan| plan.interval == 'month'}
|
||||
validates :interval_count, numericality: { less_than: 52 }, if: Proc.new {|plan| plan.interval == 'week'}
|
||||
validates :interval, inclusion: { in: %w(year month week) }
|
||||
validates :interval_count, numericality: { less_than: 12 }, if: proc { |plan| plan.interval == 'month' }
|
||||
validates :interval_count, numericality: { less_than: 52 }, if: proc { |plan| plan.interval == 'week' }
|
||||
validates :interval, inclusion: { in: %w[year month week] }
|
||||
validates :base_name, :slug, presence: true
|
||||
|
||||
def self.create_for_all_groups(plan_params)
|
||||
plans = []
|
||||
Group.all.each do |group|
|
||||
if plan_params[:type] == 'PartnerPlan'
|
||||
plan = PartnerPlan.new(plan_params.except(:group_id, :type))
|
||||
else
|
||||
plan = Plan.new(plan_params.except(:group_id, :type))
|
||||
end
|
||||
Group.all_except_admins.each do |group|
|
||||
plan = if plan_params[:type] == 'PartnerPlan'
|
||||
PartnerPlan.new(plan_params.except(:group_id, :type))
|
||||
else
|
||||
Plan.new(plan_params.except(:group_id, :type))
|
||||
end
|
||||
plan.group = group
|
||||
if plan.save
|
||||
plans << plan
|
||||
@ -48,7 +48,7 @@ class Plan < ActiveRecord::Base
|
||||
return false
|
||||
end
|
||||
end
|
||||
return plans
|
||||
plans
|
||||
end
|
||||
|
||||
def destroyable?
|
||||
@ -73,27 +73,34 @@ class Plan < ActiveRecord::Base
|
||||
|
||||
def human_readable_duration
|
||||
i18n_key = "duration.#{interval}"
|
||||
"#{I18n.t(i18n_key, count: interval_count)}"
|
||||
I18n.t(i18n_key, count: interval_count).to_s
|
||||
end
|
||||
|
||||
def human_readable_name(opts = {})
|
||||
result = "#{base_name}"
|
||||
result = base_name.to_s
|
||||
result += " - #{group.slug}" if opts[:group]
|
||||
result + " - #{human_readable_duration}"
|
||||
end
|
||||
|
||||
# must be publicly accessible for the migration
|
||||
def create_statistic_type
|
||||
stat_index = StatisticIndex.where({es_type_key: 'subscription'})
|
||||
type = StatisticType.find_by(statistic_index_id: stat_index.first.id, key: self.duration.to_i)
|
||||
if type == nil
|
||||
type = StatisticType.create!({statistic_index_id: stat_index.first.id, key: self.duration.to_i, label: 'Durée : '+self.human_readable_duration, graph: true, simple: true})
|
||||
stat_index = StatisticIndex.where(es_type_key: 'subscription')
|
||||
type = StatisticType.find_by(statistic_index_id: stat_index.first.id, key: duration.to_i)
|
||||
if type.nil?
|
||||
type = StatisticType.create!(
|
||||
statistic_index_id: stat_index.first.id,
|
||||
key: duration.to_i,
|
||||
label: "Durée : #{human_readable_duration}",
|
||||
graph: true,
|
||||
simple: true
|
||||
)
|
||||
end
|
||||
subtype = create_statistic_subtype
|
||||
create_statistic_association(type, subtype)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_stripe_plan
|
||||
stripe_plan = Stripe::Plan.create(
|
||||
amount: amount,
|
||||
@ -108,12 +115,12 @@ class Plan < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def create_statistic_subtype
|
||||
StatisticSubType.create!({key: self.slug, label: self.name})
|
||||
StatisticSubType.create!(key: slug, label: name)
|
||||
end
|
||||
|
||||
def create_statistic_association(stat_type, stat_subtype)
|
||||
if stat_type != nil and stat_subtype != nil
|
||||
StatisticTypeSubType.create!({statistic_type: stat_type, statistic_sub_type: stat_subtype})
|
||||
if !stat_type.nil? && !stat_subtype.nil?
|
||||
StatisticTypeSubType.create!(statistic_type: stat_type, statistic_sub_type: stat_subtype)
|
||||
else
|
||||
puts 'ERROR: Unable to create the statistics association for the new plan. '+
|
||||
'Possible causes: the type or the subtype were not created successfully.'
|
||||
|
Loading…
x
Reference in New Issue
Block a user