c80_shared 0.1.88 → 0.1.93

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61b7931d732a9a523a5a51216ca21e61ddc316969b5d7ace49089c0eddd1468e
4
- data.tar.gz: d50bd2025b89ed7a4d3908c9286487471bc75213dfbfce75c7442f81ce47e65e
3
+ metadata.gz: e114f4ccad407d3a6732e2a0e07729773d6bb92472263cd3f70d9d5fd8b26117
4
+ data.tar.gz: 7691bb109800eb0b7ef0d68a673db25a79ecf065aa2fbabbebb5b06b064cce8b
5
5
  SHA512:
6
- metadata.gz: 182856e0f34f12af6989bc97f64d1a3bfedf770674a231080b1dcddecf1bf759008afb8c4fe066905edd405b95007861fbbfd3e0f1b31675e506e121e36a1cb0
7
- data.tar.gz: fb34a0f7ecbfa99f6fd789f8d5eb310bdaddc20f761c733cfc10a4535bb5a501a59ad98f58db585d8955ee4a2dbc8305616ec1057e77f8410faff162c8e6f41f
6
+ metadata.gz: 930f03a3425b558ee46aac194475c1de1eebb9e1af6ecfb8df3f3efe5f1e1640a8f79887e1eeecd1a3e590bb37450a60bc8e6dd5e2d040a30e3e095acc4bd045
7
+ data.tar.gz: bfb06d06cf07aeae05027f681db27c4c53c6da900814630dc6e5ffe0ed408e1a903464379a5511e248566000239c4fbfaf7e19fc7c9935818f1baede23c4c16e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- c80_shared (0.1.87)
4
+ c80_shared (0.1.90)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -7,6 +7,7 @@ class AccountSerializer < AbstractSerializer
7
7
  id
8
8
  type_index
9
9
  props
10
+ abilities
10
11
  ]
11
12
  end
12
13
 
@@ -38,5 +39,23 @@ class AccountSerializer < AbstractSerializer
38
39
  end
39
40
  { props: props }
40
41
  end
42
+
43
+ # список возможностей с учётом запретов
44
+ def abilities(account)
45
+ account_class = ::Dictionaries::AccountType::CLASS_BY_TYPE[account.type_id]
46
+ default_abilities = ::Dicts::Accounts::Ability.all_for_account_class(account_class)
47
+ prohibited = account.user.permissions
48
+
49
+ # отнимаем запрещённые действия из дефолтных
50
+ not_prohibited = ->(ability) { prohibited.none? { |a| a.action.to_s == ability.index.to_s } }
51
+ abilities = default_abilities.map do |a|
52
+ {
53
+ action: a.index,
54
+ can: not_prohibited[a]
55
+ }
56
+ end
57
+
58
+ { abilities: abilities }
59
+ end
41
60
  end
42
- end
61
+ end
@@ -192,7 +192,6 @@ class BoatSerializer < AbstractSerializer
192
192
  horn
193
193
  lifebuoy
194
194
  life_jackets
195
- personal_flotation_devices
196
195
  raft
197
196
  smoke_detector
198
197
  vessel_lighting
@@ -24,7 +24,6 @@ module Lease
24
24
  kids
25
25
  latitude
26
26
  longitude
27
- manager_email
28
27
  my_price
29
28
  my_price_currency
30
29
  name
@@ -32,6 +31,7 @@ module Lease
32
31
  period
33
32
  period_formatted
34
33
  phone_number
34
+ responsible_managers
35
35
  state
36
36
  to
37
37
  token
@@ -171,8 +171,13 @@ module Lease
171
171
  }
172
172
  end
173
173
 
174
- def manager_email(inquiry)
175
- { manager_email: inquiry.manager_account&.user&.email }
174
+ def responsible_managers(inquiry)
175
+ res = inquiry.responsible_managers.includes(:user).map do |acc|
176
+ { id: acc.user.id,
177
+ email: acc.user.email
178
+ }
179
+ end
180
+ { responsible_managers: res }
176
181
  end
177
182
 
178
183
  def hours_per_day(inquiry)
@@ -0,0 +1,22 @@
1
+ module Boats
2
+ # определяем, указана ли хоть какая-нибудь цена аренды?
3
+ #
4
+ module IsForRent
5
+ module_function
6
+
7
+ # @param [Boat || Form] record
8
+ # @return [TrueClass || FalseClass]
9
+ #
10
+ def check?(record)
11
+ ::Dictionaries::BoatCharterAttribute::ALL.map do |attr|
12
+ ::Dicts::Currency::ALL.map do |currency|
13
+ field = Currency.attribute_name currency.index, attr
14
+ value = record.try field
15
+ # puts '%s = %s' % [field, value]
16
+ # noinspection RubySimplifyBooleanInspection
17
+ !!(value&.>0)
18
+ end
19
+ end.flatten.any?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Boats
2
+ # определяем, указана ли хоть какая-нибудь цена продажи?
3
+ #
4
+ module IsForSell
5
+ module_function
6
+
7
+ # @param [Boat] record
8
+ # @return [TrueClass || FalseClass]
9
+ #
10
+ def check?(record)
11
+ ::Dicts::Currency::ALL.map do |currency|
12
+ field = Currency.attribute_name currency.index, 'sale_price'
13
+ value = record.send field
14
+ # noinspection RubySimplifyBooleanInspection
15
+ !!(value&.>0)
16
+ end.any?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ class CurrencyPresenceValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless record.currency
4
+ raise ArgumentError, 'record.currency does not exist'
5
+ end
6
+ available_currencies = I18n::t('static.currencies').map{|currency| currency[:id]}
7
+ record_currency = record.currency.upcase
8
+ if available_currencies.include? record_currency
9
+ attribute_currency = attribute.to_s.split('_')[-1].upcase
10
+ if record_currency == attribute_currency && record.attributes[attribute.to_s].nil?
11
+ record.errors[attribute] << "can't be blank!"
12
+ end
13
+ else
14
+ raise ArgumentError, 'Model record.currency does not exist in I18n::t(\'static.currencies\')'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class DimensionPresenceValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless record.dimension
4
+ raise ArgumentError, 'record.dimension does not exist'
5
+ end
6
+ available_dimensions = I18n::t('static.dimensions').map{|dimension| dimension[:id]}
7
+ record_dimension = record.dimension.downcase
8
+ if available_dimensions.include? record_dimension
9
+ attribute_dimension = attribute.to_s.split('_')[-1].downcase
10
+ if record_dimension == attribute_dimension && record.attributes[attribute.to_s].nil?
11
+ record.errors[attribute] << "can't be blank!"
12
+ end
13
+ else
14
+ raise ArgumentError, 'Model record.dimension does not exist in I18n::(\'static.dimensions\')'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ class SaleInquiryAssignValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:sale_inquiry, :blank) and return false if record.sale_inquiry.nil?
4
+ record.errors.add(:assignee, :blank) and return false if record.assignee.nil?
5
+ record.errors.add(:author, :blank) and return false if record.author.nil?
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class SaleInquiryCommentValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:sale_inquiry, :blank) and return false if record.sale_inquiry.nil?
4
+ record.errors.add(:author, :blank) and return false if record.author.nil?
5
+ record.errors.add(:text, :blank) and return false unless record.text.present?
6
+ record.errors.add(:text, :less_than_or_equal_to, count: 1024) and return false if record.text.size > 1024
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class UserPermissionValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:can, :blank) and return false if record.can.nil?
4
+ record.errors.add(:action, :blank) and return false if record.action.nil?
5
+ true
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module C80Shared
2
- VERSION = "0.1.88"
2
+ VERSION = "0.1.93"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_shared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.88
4
+ version: 0.1.93
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,13 @@ files:
120
120
  - app/services/sale/inquiry_asked_prices_save_service.rb
121
121
  - app/services/users/find_or_generate_email_token_service.rb
122
122
  - app/services/users/generate_email_token_service.rb
123
+ - app/validators/boats/is_for_rent.rb
124
+ - app/validators/boats/is_for_sell.rb
125
+ - app/validators/currency_presence_validator.rb
126
+ - app/validators/dimension_presence_validator.rb
127
+ - app/validators/sale_inquiry_assign_validator.rb
128
+ - app/validators/sale_inquiry_comment_validator.rb
129
+ - app/validators/user_permission_validator.rb
123
130
  - bin/console
124
131
  - bin/rails
125
132
  - bin/setup
@@ -206,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
213
  - !ruby/object:Gem::Version
207
214
  version: '0'
208
215
  requirements: []
209
- rubygems_version: 3.0.6
216
+ rubygems_version: 3.0.8
210
217
  signing_key:
211
218
  specification_version: 4
212
219
  summary: Write a short summary, because RubyGems requires one.