ish_models 0.0.33.166 → 0.0.33.169

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: 0d2c393a3ae573621c06610661cda6a73bf8173aeaeea1ee126256c31d0848a4
4
- data.tar.gz: ff72185a3f761ddd7dd5efdb8bbf99428763ab763319c6da3b3ad2d35216d575
3
+ metadata.gz: 1c0e3408ce26fe3d97602564c99955fa11a05c6584c2cf435a55edbbe2865c63
4
+ data.tar.gz: f984f36ddfc7d046a819d9966306d6e31192e008af037c77fad9bf2975557b42
5
5
  SHA512:
6
- metadata.gz: f3bc3cb6150bcc21a7f60ee41b66f694f6290677d5908e698d47d879a76298a3307e2871d54fde5fcdc911906b3a64052e6e2d4d94f98b481617386e0851653d
7
- data.tar.gz: c16e81ddfbb6051e2b2907e6685fb8dd77b7b9304ef9741191a3619b72c69317ddff2b78b84a0a665d0b3afe4016929e9efbd5664c87d4c733bdf4fd62914fb8
6
+ metadata.gz: 27f95caf60f39ce446b0b103be69cafc729a41dbd108833aefe5bcd3814ec1bba4499a5ad1943b4f7f4e5f728c798467c52fa60c43b3f37cf87675c61a149eae
7
+ data.tar.gz: 5a73b3adfe1953e2a3d84171880472dcfd6fe4bb0dfd615e000b0b7b53aec52eaba17383c6f6aaa73d36e4ba91df652e4d9b36524088eccaf070da893d0b75a5
@@ -0,0 +1,29 @@
1
+
2
+ require 'aws-sdk'
3
+
4
+ class ::Gameui::Asset3d
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+ include Mongoid::Paperclip
8
+ include Ish::Utils
9
+
10
+ belongs_to :marker, class_name: 'Gameui::Marker', optional: true
11
+
12
+ has_mongoid_attached_file :object,
13
+ :storage => :s3,
14
+ :s3_credentials => ::S3_CREDENTIALS,
15
+ :path => "assets3d/:id/:filename",
16
+ :s3_protocol => 'https',
17
+ :validate_media_type => false,
18
+ s3_region: ::S3_CREDENTIALS[:region]
19
+
20
+ do_not_validate_attachment_file_type :object
21
+
22
+ def export_fields
23
+ %w|
24
+ marker_id
25
+ asset3d_file_name asset3d_content_type asset3d_file_size asset3d_updated_at asset3d_fingerprint
26
+ |;
27
+ end
28
+
29
+ end
data/lib/gameui/marker.rb CHANGED
@@ -30,6 +30,7 @@ class ::Gameui::Marker
30
30
 
31
31
  has_one :image, class_name: '::Ish::ImageAsset', inverse_of: :marker
32
32
  has_one :title_image, class_name: '::Ish::ImageAsset', inverse_of: :marker_title
33
+ has_one :asset3d, class_name: '::Gameui::Asset3d'
33
34
 
34
35
  field :deleted_at, type: Time, default: nil # @TODO: replace with paranoia
35
36
 
@@ -0,0 +1,15 @@
1
+
2
+ ##
3
+ ## This shouldn't really be in Ish namespace... but oh well
4
+ ##
5
+
6
+ class Ish::EmailContext
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+
10
+ field :to_email
11
+ field :subject
12
+ field :template_name
13
+
14
+ end
15
+ EmailContext = Ish::EmailContext
@@ -0,0 +1,31 @@
1
+
2
+ class Ish::Meeting
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :datetime, type: DateTime
7
+ field :invitee_email, type: String
8
+ field :invitee_name, type: String
9
+ field :timezone, type: String, default: 'Central Time (US & Canada)'
10
+ field :template_name
11
+
12
+ field :send_reminder_morning, type: Boolean, default: false
13
+ field :send_reminder_15min, type: Boolean, default: false
14
+
15
+ def self.template_name_options
16
+ [
17
+ [ '', '' ],
18
+ ['calendly_meeting_v1', 'calendly_meeting_v1'],
19
+ ['calendly_meeting_v2', 'calendly_meeting_v2'],
20
+ ]
21
+ end
22
+
23
+ def host_name
24
+ 'Victor Puudeyev'
25
+ end
26
+
27
+ def host_email
28
+ 'piousbox@gmail.com'
29
+ end
30
+
31
+ end
@@ -4,8 +4,16 @@ class Ish::Unsubscribe
4
4
  include Mongoid::Timestamps
5
5
 
6
6
  field :email
7
- field :unsubscribed_at
7
+ validates_presence_of :email
8
+ validates_uniqueness_of :email
9
+
10
+ field :mailer_type
11
+
8
12
  field :reason
9
13
 
14
+ field :unsubscribed_at
15
+
16
+
17
+
10
18
  end
11
19
 
@@ -1,10 +1,12 @@
1
1
 
2
2
  require 'ish/utils'
3
+ require 'mongoid/votable'
3
4
 
4
5
  ## @TODO: rename to Ish::Profile
5
6
  class Ish::UserProfile
6
7
  include Mongoid::Document
7
8
  include Mongoid::Timestamps
9
+ include Mongoid::Voter
8
10
  include Ish::Utils
9
11
 
10
12
  store_in collection: 'ish_user_profiles'
@@ -30,15 +32,17 @@ class Ish::UserProfile
30
32
 
31
33
  field :lang, default: 'en'
32
34
 
33
- ROLES = [ :admin, :manager, :guy ]
34
- ROLE_ADMIN = :admin
35
- ROLE_MANAGER = :manager
35
+ ROLES = [ :guy, :manager, :admin ]
36
36
  ROLE_GUY = :guy
37
- field :role_name, :type => Symbol
37
+ ROLE_MANAGER = :manager
38
+ ROLE_ADMIN = :admin
39
+ field :role_name, :type => Symbol, default: :guy
38
40
 
39
41
  has_one :profile_photo, :class_name => 'Photo', :inverse_of => :profile_city
40
42
 
41
43
  belongs_to :user
44
+ validates_presence_of :user
45
+
42
46
  belongs_to :current_city, :class_name => 'City', :inverse_of => :current_users, :optional => true
43
47
  belongs_to :guide_city, :class_name => 'City', :inverse_of => :guide, :optional => true
44
48
 
data/lib/ish_models.rb CHANGED
@@ -4,11 +4,13 @@ require 'ish/configuration'
4
4
 
5
5
  ::S3_CREDENTIALS ||= {}
6
6
 
7
- module CoTailors; end
8
7
  class Gameui; end
8
+
9
9
  module Ish; end
10
- # I need this thing for permissions#
10
+
11
+ # I need this thing for permissions???
11
12
  class Manager; end
13
+
12
14
  module Warbler; end
13
15
 
14
16
  module IshModels
@@ -26,6 +28,13 @@ module IshModels
26
28
  end
27
29
  end
28
30
 
31
+ ## Needs to be before gameui/asset3d
32
+ require 'ish/utils'
33
+
34
+ require 'mongoid/votable'
35
+ require 'mongoid/voter'
36
+
37
+ require 'gameui/asset3d'
29
38
  require 'gameui/map'
30
39
  require 'gameui/map_bookmark'
31
40
  require 'gameui/marker'
@@ -34,16 +43,17 @@ require 'gameui/premium_purchase'
34
43
  require 'ish/cache_key'
35
44
  require 'ish/campaign'
36
45
  require 'ish/crawler'
46
+ require 'ish/email_context'
37
47
  require 'ish/gallery_name'
38
48
  require 'ish/image_asset'
39
49
  require 'ish/input_error'
40
50
  require 'ish/invoice'
41
51
  require 'ish/issue'
42
52
  require 'ish/lead'
53
+ require 'ish/meeting'
43
54
  require 'ish/payment'
44
55
  require 'ish/premium_item'
45
56
  require 'ish/unsubscribe'
46
- require 'ish/utils'
47
57
  require 'ish/user_profile'
48
58
 
49
59
  require 'city'
@@ -62,3 +72,4 @@ require 'video'
62
72
 
63
73
 
64
74
 
75
+
@@ -0,0 +1,246 @@
1
+ module Mongoid
2
+ module Votable
3
+ extend ActiveSupport::Concern
4
+
5
+ # How many points should be assigned for each up or down vote.
6
+ # This array should be manipulated using Votable.vote_point method
7
+ VOTE_POINT = {}
8
+
9
+ included do
10
+ field :votable, type: Hash
11
+
12
+ index({ "votable.votes_count" => 1 })
13
+ index({ "votable.votes_point" => 1 })
14
+
15
+ scope :most_voted, -> { order_by(["votable.votes_count", :desc]) }
16
+ scope :best_voted, -> { order_by(["votable.votes_point", :desc]) }
17
+
18
+ # Set vote point for each up (down) vote on an object of this class
19
+ def self.vote_point(klass = self, options = nil)
20
+ VOTE_POINT[self.name] ||= {}
21
+ VOTE_POINT[self.name][klass.name] ||= options
22
+ end
23
+
24
+ #
25
+ # We usually need to show current_user his voting value on votable object
26
+ # voting value can be nil (not voted yet), :up or :down
27
+ # from voting value, we can decide it should be new vote or revote with :up or :down
28
+ # In this case, validation can be skip to maximize performance
29
+ #
30
+ # Make a vote on an object of this class
31
+ #
32
+ # @param [Hash] options a hash containings:
33
+ # - :votee_id: the votee document id
34
+ # - :voter_id: the voter document id
35
+ # - :value: :up or :down
36
+ # - :revote: change from vote up to vote down
37
+ # - :unvote: unvote the vote value (:up or :down)
38
+ #
39
+ def self.vote(options)
40
+ options.symbolize_keys!
41
+ value = options[:value]
42
+ votee_id = options[:votee_id]
43
+ voter_id = options[:voter_id]
44
+
45
+ klass = options[:class]
46
+ klass ||= VOTE_POINT.keys.include?(name) ? name : collection.name.classify
47
+ value_point = VOTE_POINT[klass][klass]
48
+
49
+ if options[:revote]
50
+ if value == :up
51
+ positive_field = :up_voter_ids
52
+ negative_field = :down_voter_ids
53
+ point_delta = value_point[:up] - value_point[:down]
54
+ else
55
+ positive_field = :down_voter_ids
56
+ negative_field = :up_voter_ids
57
+ point_delta = -value_point[:up] + value_point[:down]
58
+ end
59
+
60
+ update_result = collection.update_one({
61
+ # Validate voter_id did a vote with value for votee_id
62
+ :_id => votee_id,
63
+ "votable.#{positive_field.to_s}" => { '$ne' => voter_id },
64
+ "votable.#{negative_field.to_s}" => voter_id
65
+ }, {
66
+ # then update
67
+ '$pull' => { "votable.#{negative_field.to_s}" => voter_id },
68
+ '$push' => { "votable.#{positive_field.to_s}" => voter_id },
69
+ '$inc' => {
70
+ "votable.votes_point" => point_delta
71
+ }
72
+ }, {
73
+ :safe => true
74
+ })
75
+
76
+ elsif options[:unvote]
77
+ if value == :down
78
+ positive_field = :down_voter_ids
79
+ negative_field = :up_voter_ids
80
+ else
81
+ positive_field = :up_voter_ids
82
+ negative_field = :down_voter_ids
83
+ end
84
+
85
+ # Check if voter_id did a vote with value for votee_id
86
+ update_result = collection.update_one({
87
+ # Validate voter_id did a vote with value for votee_id
88
+ :_id => votee_id,
89
+ "votable.#{negative_field.to_s}" => { '$ne' => voter_id },
90
+ "votable.#{positive_field.to_s}" => voter_id
91
+ }, {
92
+ # then update
93
+ '$pull' => { "votable.#{positive_field.to_s}" => voter_id },
94
+ '$inc' => {
95
+ "votable.votes_count" => -1,
96
+ "votable.votes_point" => -value_point[value]
97
+ }
98
+ }, {
99
+ :safe => true
100
+ })
101
+
102
+ else # new vote
103
+ if value == :up
104
+ positive_field = :up_voter_ids
105
+ else
106
+ positive_field = :down_voter_ids
107
+ end
108
+
109
+ update_result = collection.update_one({
110
+ # Validate voter_id did not vote for votee_id yet
111
+ :_id => votee_id,
112
+ "votable.up_voter_ids" => { '$ne' => voter_id },
113
+ "votable.down_voter_ids" => { '$ne' => voter_id }
114
+ }, {
115
+ # then update
116
+ '$push' => { "votable.#{positive_field.to_s}" => voter_id },
117
+ '$inc' => {
118
+ "votable.votes_count" => +1,
119
+ "votable.votes_point" => value_point[value] }
120
+ }, {
121
+ :safe => true
122
+ })
123
+ end
124
+
125
+ # Only update parent class if votee is updated successfully
126
+ success = ( update_result.documents[0]['err'] == nil and
127
+ update_result.documents[0]['nModified'] == 1 and
128
+ update_result.documents[0]['n'] == 1 )
129
+
130
+ if success
131
+ VOTE_POINT[klass].each do |class_name, value_point|
132
+ # For other class in VOTE_POINT options, if is parent of current class
133
+ next unless relation_metadata = relations[class_name.underscore]
134
+ votee ||= options[:votee] || find(options[:votee_id])
135
+ # If can find current votee foreign_key value for that class
136
+ next unless foreign_key_value = votee.read_attribute(relation_metadata.foreign_key.to_sym)
137
+
138
+ # Update that class / collection
139
+ inc_options = if options[:revote]
140
+ {
141
+ "votable.votes_point" => ( value == :up ?
142
+ value_point[:up] - value_point[:down] :
143
+ -value_point[:up] + value_point[:down] )
144
+ }
145
+ elsif options[:unvote]
146
+ {
147
+ "votable.votes_count" => value_point[:not_increase_votes_count] ? 0 : -1,
148
+ "votable.votes_point" => -value_point[value]
149
+ }
150
+ else
151
+ {
152
+ "votable.votes_count" => value_point[:not_increase_votes_count] ? 0 : 1,
153
+ "votable.votes_point" => value_point[value]
154
+ }
155
+ end
156
+
157
+ class_name.constantize.collection.update_one(
158
+ { :_id => foreign_key_value },
159
+ { '$inc' => inc_options }
160
+ )
161
+ end
162
+ end
163
+
164
+ success
165
+ end
166
+
167
+ end
168
+
169
+ # Make a vote on this votee
170
+ #
171
+ # @param [Hash] options a hash containings:
172
+ # - :voter_id: the voter document id
173
+ # - :value: vote :up or vote :down
174
+ def vote(options)
175
+ options[:votee_id] ||= _id
176
+ options[:votee] ||= self
177
+
178
+ if options[:unvote]
179
+ options[:value] ||= vote_value(options[:voter_id])
180
+ else
181
+ options[:revote] ||= !vote_value(options[:voter_id]).nil?
182
+ end
183
+
184
+ self.class.vote(options)
185
+ end
186
+
187
+ # Get a voted value on this votee
188
+ #
189
+ # Let's NOT CONVERT bson::objectid's to strings. _vp_ 2022-08-31
190
+ #
191
+ # @param [Mongoid Object, BSON::ObjectId] voter is Mongoid object the id of the voter who made the vote
192
+ def vote_value(voter)
193
+ voter_id = voter.is_a?(BSON::ObjectId) ? voter : voter.is_a?(String) ? voter : voter.id
194
+
195
+ return :up if up_voter_ids.try(:include?, voter_id)
196
+ return :down if down_voter_ids.try(:include?, voter_id)
197
+ end
198
+
199
+ # Get the number of up votes
200
+ def up_votes_count
201
+ up_voter_ids.length
202
+ end
203
+
204
+ # Get the number of down votes
205
+ def down_votes_count
206
+ down_voter_ids.length
207
+ end
208
+
209
+ # Get the number of votes count
210
+ def votes_count
211
+ if self.has_attribute?(:votable)
212
+ self["votable"]["votes_count"]
213
+ else
214
+ 0
215
+ end
216
+ end
217
+
218
+ # Get the votes point
219
+ def votes_point
220
+ if self.has_attribute?(:votable)
221
+ self["votable"]["votes_point"]
222
+ else
223
+ 0
224
+ end
225
+ end
226
+ alias :votes_score :votes_point
227
+
228
+ # Array of up voter ids
229
+ def up_voter_ids
230
+ if self.has_attribute?(:votable)
231
+ self['votable']["up_voter_ids"]
232
+ else
233
+ []
234
+ end
235
+ end
236
+
237
+ # Array of down voter ids
238
+ def down_voter_ids
239
+ if self.has_attribute?(:votable)
240
+ self["votable"]["down_voter_ids"]
241
+ else
242
+ []
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,96 @@
1
+ module Mongoid
2
+ module Voter
3
+ extend ActiveSupport::Concern
4
+
5
+ # Get list of voted votees
6
+ #
7
+ # @param [Class] klass the votee class, e.g. `Post` or `Comment`
8
+ # @return [Array, nil] an array of votable objects voted by this voter
9
+ def votees(klass)
10
+ # Is this id, or id.to_s ?
11
+ # let's not convert to string, lets use bson::objectid.
12
+ # _vp_ 2022-08-31
13
+ klass.any_of({ "votable.up_voter_ids" => _id }, { "votable.down_voter_ids" => _id })
14
+ end
15
+
16
+ # Check to see if this voter voted on the votee or not
17
+ #
18
+ # @param [Hash, Object] options the hash containing the votee, or the votee itself
19
+ # @return [true, false] true if voted, false otherwise
20
+ def voted?(options)
21
+ unless options.is_a?(Hash)
22
+ votee_class = options.class
23
+ votee_id = options._id
24
+ else
25
+ votee = options[:votee]
26
+ if votee
27
+ votee_class = votee.class
28
+ votee_id = votee._id
29
+ else
30
+ votee_class = options[:votee_type].classify.constantize
31
+ votee_id = options[:votee_id]
32
+ end
33
+ end
34
+
35
+ votees(votee_class).where(:_id => votee_id).count == 1
36
+ end
37
+
38
+ # Get the voted value on a votee
39
+ #
40
+ # @param (see #voted?)
41
+ # @return [Symbol, nil] :up or :down or nil if not voted
42
+ def vote_value(options)
43
+ votee = unless options.is_a?(Hash)
44
+ options
45
+ else
46
+ options[:votee] || options[:votee_type].classify.constantize.only(:up_vote_ids, :down_vote_ids).where(
47
+ :_id => options[:votee_id]
48
+ ).first
49
+ end
50
+ votee.vote_value(_id)
51
+ end
52
+
53
+ # Cancel the vote on a votee
54
+ #
55
+ # @param [Object] votee the votee to be unvoted
56
+ def unvote(options)
57
+ unless options.is_a?(Hash)
58
+ options = { :votee => options }
59
+ end
60
+ options[:unvote] = true
61
+ options[:revote] = false
62
+ vote(options)
63
+ end
64
+
65
+ # Vote on a votee
66
+ #
67
+ # @param (see #voted?)
68
+ # @param [:up, :down] vote_value vote up or vote down, nil to unvote
69
+ def vote(options, value = nil)
70
+ if options.is_a?(Hash)
71
+ votee = options[:votee]
72
+ else
73
+ votee = options
74
+ options = { :votee => votee, :value => value }
75
+ end
76
+
77
+ if votee
78
+ options[:votee_id] = votee._id
79
+ votee_class = votee.class
80
+ else
81
+ votee_class = options[:votee_type].classify.constantize
82
+ end
83
+
84
+ if options[:value].nil?
85
+ options[:unvote] = true
86
+ options[:value] = vote_value(options)
87
+ else
88
+ options[:revote] = options.has_key?(:revote) ? !options[:revote].blank? : voted?(options)
89
+ end
90
+
91
+ options[:voter_id] = _id
92
+
93
+ ( votee || votee_class ).vote(options)
94
+ end
95
+ end
96
+ end
data/lib/newsitem.rb CHANGED
@@ -1,11 +1,15 @@
1
1
 
2
2
  require 'ish/utils'
3
+ # require_relative './mongoid/votable.rb'
3
4
 
4
5
  class Newsitem
5
6
  include Mongoid::Document
6
7
  include Mongoid::Timestamps
7
8
  include Ish::Utils
8
9
 
10
+ include Mongoid::Votable
11
+ vote_point self, :up => +1, :down => -1
12
+
9
13
  belongs_to :city, optional: true
10
14
  belongs_to :gallery, optional: true # seems correct. _vp_ 2022-03-21
11
15
  def gallery
data/lib/video.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'mongoid/paranoia'
2
+ require_relative './mongoid/votable.rb'
2
3
 
3
4
  class Video
4
5
  include Mongoid::Document
@@ -7,6 +8,9 @@ class Video
7
8
  include Mongoid::Paranoia
8
9
  include Ish::Utils
9
10
 
11
+ include Mongoid::Votable
12
+ vote_point self, :up => +1, :down => -1
13
+
10
14
  PER_PAGE = 6
11
15
 
12
16
  field :name, :type => String
@@ -101,4 +105,6 @@ class Video
101
105
  %w| name descr |
102
106
  end
103
107
 
108
+
109
+
104
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.166
4
+ version: 0.0.33.169
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -121,6 +121,7 @@ files:
121
121
  - lib/event.rb
122
122
  - lib/feature.rb
123
123
  - lib/gallery.rb
124
+ - lib/gameui/asset3d.rb
124
125
  - lib/gameui/map.rb
125
126
  - lib/gameui/map_bookmark.rb
126
127
  - lib/gameui/marker.rb
@@ -130,12 +131,14 @@ files:
130
131
  - lib/ish/campaign.rb
131
132
  - lib/ish/configuration.rb
132
133
  - lib/ish/crawler.rb
134
+ - lib/ish/email_context.rb
133
135
  - lib/ish/gallery_name.rb
134
136
  - lib/ish/image_asset.rb
135
137
  - lib/ish/input_error.rb
136
138
  - lib/ish/invoice.rb
137
139
  - lib/ish/issue.rb
138
140
  - lib/ish/lead.rb
141
+ - lib/ish/meeting.rb
139
142
  - lib/ish/payment.rb
140
143
  - lib/ish/premium_item.rb
141
144
  - lib/ish/railtie.rb
@@ -143,6 +146,8 @@ files:
143
146
  - lib/ish/user_profile.rb
144
147
  - lib/ish/utils.rb
145
148
  - lib/ish_models.rb
149
+ - lib/mongoid/votable.rb
150
+ - lib/mongoid/voter.rb
146
151
  - lib/newsitem.rb
147
152
  - lib/photo.rb
148
153
  - lib/report.rb