c80_shared 0.1.88 → 0.1.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/serializers/account_serializer.rb +20 -1
- data/app/serializers/boat_serializer.rb +0 -1
- data/app/serializers/lease/inquiry_serializer.rb +8 -3
- data/app/validators/boats/is_for_rent.rb +22 -0
- data/app/validators/boats/is_for_sell.rb +19 -0
- data/app/validators/currency_presence_validator.rb +17 -0
- data/app/validators/dimension_presence_validator.rb +17 -0
- data/app/validators/sale_inquiry_assign_validator.rb +8 -0
- data/app/validators/sale_inquiry_comment_validator.rb +9 -0
- data/app/validators/user_permission_validator.rb +7 -0
- data/lib/c80_shared/version.rb +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e114f4ccad407d3a6732e2a0e07729773d6bb92472263cd3f70d9d5fd8b26117
|
4
|
+
data.tar.gz: 7691bb109800eb0b7ef0d68a673db25a79ecf065aa2fbabbebb5b06b064cce8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930f03a3425b558ee46aac194475c1de1eebb9e1af6ecfb8df3f3efe5f1e1640a8f79887e1eeecd1a3e590bb37450a60bc8e6dd5e2d040a30e3e095acc4bd045
|
7
|
+
data.tar.gz: bfb06d06cf07aeae05027f681db27c4c53c6da900814630dc6e5ffe0ed408e1a903464379a5511e248566000239c4fbfaf7e19fc7c9935818f1baede23c4c16e
|
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -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
|
175
|
-
|
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
|
data/lib/c80_shared/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|