ish_models 0.0.33.304 → 3.1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +15 -0
- data/app/assets/config/ish_models_manifest.js +1 -0
- data/app/assets/stylesheets/ish_models/application.css +15 -0
- data/app/controllers/ish_models/application_controller.rb +4 -0
- data/app/helpers/ish_models/application_helper.rb +4 -0
- data/app/jobs/ish_models/application_job.rb +4 -0
- data/app/mailers/ish_models/application_mailer.rb +6 -0
- data/app/models/ish_models/application_record.rb +5 -0
- data/app/views/layouts/ish_models/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/lib/ish_models/engine.rb +5 -0
- data/lib/ish_models/version.rb +3 -0
- data/lib/ish_models.rb +4 -89
- data/lib/tasks/ish_models_tasks.rake +4 -0
- data/lib/{office/admin_message.rb → wco/profile.rb} +2 -5
- metadata +32 -221
- data/lib/address.rb +0 -20
- data/lib/feature.rb +0 -32
- data/lib/gallery.rb +0 -66
- data/lib/gameui/asset3d.rb +0 -35
- data/lib/gameui/map.rb +0 -260
- data/lib/gameui/map_bookmark.rb +0 -9
- data/lib/gameui/marker.rb +0 -128
- data/lib/iro/alert.rb-bk +0 -72
- data/lib/ish/cache_key.rb +0 -14
- data/lib/ish/configuration.rb +0 -11
- data/lib/ish/crawler.rb +0 -26
- data/lib/ish/email_campaign.rb +0 -55
- data/lib/ish/email_context.rb +0 -113
- data/lib/ish/email_template.rb +0 -115
- data/lib/ish/email_unsubscribe.rb +0 -19
- data/lib/ish/event.rb +0 -20
- data/lib/ish/image_asset.rb +0 -38
- data/lib/ish/invoice.rb +0 -130
- data/lib/ish/lorem_ipsum.rb +0 -30
- data/lib/ish/meeting.rb +0 -31
- data/lib/ish/payment.rb +0 -29
- data/lib/ish/premium_item.rb +0 -13
- data/lib/ish/railtie.rb +0 -8
- data/lib/ish/user_profile.rb +0 -146
- data/lib/ish/utils.rb +0 -45
- data/lib/mongoid/votable.rb +0 -247
- data/lib/mongoid/voter.rb +0 -96
- data/lib/newsitem.rb +0 -94
- data/lib/office/action.rb +0 -32
- data/lib/office/action_tie.rb +0 -16
- data/lib/office/directmail_envelope.rb +0 -51
- data/lib/office/email_action.rb +0 -34
- data/lib/office/email_action_tie.rb +0 -18
- data/lib/office/email_attachment.rb +0 -12
- data/lib/office/email_conversation.rb +0 -86
- data/lib/office/email_conversation_lead.rb +0 -11
- data/lib/office/email_conversation_tag.rb +0 -14
- data/lib/office/email_filter.rb +0 -45
- data/lib/office/email_message.rb +0 -229
- data/lib/office/email_message_stub.rb +0 -22
- data/lib/office/lead_action.rb +0 -24
- data/lib/office/lead_action_template.rb +0 -47
- data/lib/office/obfuscated_redirect.rb +0 -12
- data/lib/office/scheduled_email_action.rb +0 -62
- data/lib/photo.rb +0 -87
- data/lib/report.rb +0 -65
- data/lib/video.rb +0 -91
- data/lib/wco/appliance.rb +0 -43
- data/lib/wco/appliance_tmpl.rb +0 -36
- data/lib/wco/leadset.rb +0 -17
- data/lib/wco/price.rb +0 -30
- data/lib/wco/product.rb +0 -35
- data/lib/wco/serverhost.rb +0 -100
- data/lib/wco/subscription.rb +0 -25
data/lib/ish/user_profile.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'ish/utils'
|
3
|
-
require 'mongoid/votable'
|
4
|
-
|
5
|
-
##
|
6
|
-
## It explicitly doesn't have a relation to user! Use email as key.
|
7
|
-
##
|
8
|
-
class Ish::UserProfile
|
9
|
-
include Mongoid::Document
|
10
|
-
include Mongoid::Timestamps
|
11
|
-
include Mongoid::Voter
|
12
|
-
include Ish::Utils
|
13
|
-
|
14
|
-
store_in collection: 'ish_user_profiles'
|
15
|
-
|
16
|
-
field :email
|
17
|
-
validates_format_of :email,:with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
|
18
|
-
validates_uniqueness_of :email
|
19
|
-
|
20
|
-
field :name
|
21
|
-
|
22
|
-
def export_fields
|
23
|
-
%w|
|
24
|
-
email
|
25
|
-
role_name
|
26
|
-
|
|
27
|
-
end
|
28
|
-
|
29
|
-
field :scratchpad, default: ''
|
30
|
-
|
31
|
-
field :fb_access_token
|
32
|
-
field :fb_long_access_token
|
33
|
-
field :fb_expires_in
|
34
|
-
|
35
|
-
field :lang, default: 'en'
|
36
|
-
field :leadset_id, type: Integer
|
37
|
-
def organization_name
|
38
|
-
'Some Org'
|
39
|
-
# ::Leadset.find( leadset_id )&.name || 'Some Org'
|
40
|
-
end
|
41
|
-
# def leadset
|
42
|
-
# ::Leadset.find( leadset_id )
|
43
|
-
# end
|
44
|
-
# @TODO: change _vp_ 2023-08-21
|
45
|
-
def next_serverhost
|
46
|
-
Wco::Serverhost.where({ leadset_id: leadset_id }).first
|
47
|
-
end
|
48
|
-
|
49
|
-
ROLE_GUY = :guy
|
50
|
-
ROLE_MANAGER = :manager
|
51
|
-
ROLE_ADMIN = :admin
|
52
|
-
ROLES = [ :guy, :manager, :admin ]
|
53
|
-
field :role_name, :type => Symbol, default: :guy
|
54
|
-
|
55
|
-
has_one :profile_photo, inverse_of: :profile_city, class_name: 'Photo'
|
56
|
-
has_many :galleries, inverse_of: :user_profile
|
57
|
-
has_and_belongs_to_many :shared_galleries, inverse_of: :shared_profiles, class_name: 'Gallery'
|
58
|
-
has_and_belongs_to_many :shared_markers, inverse_of: :shared_profiles, class_name: 'Gameui::Marker'
|
59
|
-
has_and_belongs_to_many :shared_locations, inverse_of: :shared_profiles, class_name: 'Gameui::Map'
|
60
|
-
has_and_belongs_to_many :shared_reports, inverse_of: :shared_profiles, class_name: '::Report'
|
61
|
-
has_and_belongs_to_many :shared_videos, inverse_of: :shared_profiles, class_name: '::Video'
|
62
|
-
has_many :my_markers, inverse_of: :creator_profile, class_name: 'Gameui::Marker'
|
63
|
-
has_many :my_locations, inverse_of: :creator_profile, class_name: 'Gameui::Map'
|
64
|
-
has_many :invoices, class_name: '::Ish::Invoice'
|
65
|
-
has_many :photos
|
66
|
-
has_many :reports, inverse_of: :user_profile
|
67
|
-
has_many :videos, inverse_of: :user_profile
|
68
|
-
has_many :newsitems, inverse_of: :profile
|
69
|
-
has_and_belongs_to_many :friends, :class_name => '::Ish::UserProfile', inverse_of: :friendeds
|
70
|
-
has_and_belongs_to_many :friendeds, :class_name => '::Ish::UserProfile', inverse_of: :friends
|
71
|
-
|
72
|
-
def sudoer?
|
73
|
-
%w( piousbox@gmail.com victor@wasya.co ).include?( self.email )
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.list
|
77
|
-
out = self.all
|
78
|
-
[['', nil]] + out.map { |item| [ item.email, item.id ] }
|
79
|
-
end
|
80
|
-
def self.list_lg
|
81
|
-
out = self.all
|
82
|
-
[['', nil]] + out.map { |item| [ "#{item.email} :: #{item.name}", item.id ] }
|
83
|
-
end
|
84
|
-
|
85
|
-
field :n_unlocks, type: Integer, default: 0
|
86
|
-
|
87
|
-
has_many :payments, :class_name => '::Ish::Payment'
|
88
|
-
has_many :subscriptions, class_name: 'Wco::Subscription', inverse_of: :profile
|
89
|
-
|
90
|
-
def has_premium_purchase item
|
91
|
-
payments.confirmed.where( item: item ).exists?
|
92
|
-
end
|
93
|
-
|
94
|
-
field :is_purchasing, type: Boolean, default: false
|
95
|
-
|
96
|
-
field :customer_id # stripe
|
97
|
-
|
98
|
-
def customer_id
|
99
|
-
if !self[:customer_id]
|
100
|
-
# return nil if !email
|
101
|
-
existing = Stripe::Customer.search({ query: "email: '#{email}'" })
|
102
|
-
# puts! existing, 'existing'
|
103
|
-
if existing.data.present?
|
104
|
-
update_attributes( customer_id: existing.data[0][:id] )
|
105
|
-
else
|
106
|
-
customer = Stripe::Customer.create({ email: email })
|
107
|
-
# puts! customer, 'customer'
|
108
|
-
update_attributes( customer_id: customer[:id] )
|
109
|
-
end
|
110
|
-
end
|
111
|
-
self[:customer_id]
|
112
|
-
end
|
113
|
-
|
114
|
-
# used in rake tasks
|
115
|
-
def self.generate delta
|
116
|
-
email = delta[:email]
|
117
|
-
password = delta[:password]
|
118
|
-
role_name = delta[:role_name]
|
119
|
-
|
120
|
-
profile = Ish::UserProfile.where( email: email ).first
|
121
|
-
if profile
|
122
|
-
return
|
123
|
-
end
|
124
|
-
|
125
|
-
user = User.where( email: email ).first
|
126
|
-
if !user
|
127
|
-
user = User.new({ email: email, password: password })
|
128
|
-
end
|
129
|
-
profile = Ish::UserProfile.new({
|
130
|
-
email: email,
|
131
|
-
role_name: role_name,
|
132
|
-
})
|
133
|
-
profile.save
|
134
|
-
|
135
|
-
if profile.persisted?
|
136
|
-
;
|
137
|
-
else
|
138
|
-
puts! profile.errors.full_messages, "Cannot save profile"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
field :per_page, type: Integer, default: 100
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
Profile = Ish::UserProfile
|
data/lib/ish/utils.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
|
2
|
-
module Ish::Utils
|
3
|
-
|
4
|
-
def export
|
5
|
-
out = {}
|
6
|
-
%w| created_at updated_at |.map do |f|
|
7
|
-
out[f] = send(f)
|
8
|
-
end
|
9
|
-
export_fields.map do |field|
|
10
|
-
if field[-3..-1] == '_id'
|
11
|
-
out[field] = send(field).to_s
|
12
|
-
else
|
13
|
-
out[field] = send(field)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
out[:_id] = id.to_s
|
17
|
-
out.with_indifferent_access
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def set_slug
|
23
|
-
return if slug
|
24
|
-
if name
|
25
|
-
new_slug = name.downcase.gsub(/[^a-z0-9\s]/i, '').gsub(' ', '-')
|
26
|
-
else
|
27
|
-
new_slug = '1'
|
28
|
-
end
|
29
|
-
if self.class.where( slug: new_slug ).first
|
30
|
-
loop do
|
31
|
-
if new_slug[new_slug.length-1].to_i != 0
|
32
|
-
# inrement last digit
|
33
|
-
last_digit = new_slug[new_slug.length-1].to_i
|
34
|
-
new_slug = "#{new_slug[0...new_slug.length-1]}#{last_digit+1}"
|
35
|
-
else
|
36
|
-
# add '-1' to the end
|
37
|
-
new_slug = "#{new_slug}-1"
|
38
|
-
end
|
39
|
-
break if !self.class.where( slug: new_slug ).first
|
40
|
-
end
|
41
|
-
end
|
42
|
-
self.slug = new_slug
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/lib/mongoid/votable.rb
DELETED
@@ -1,247 +0,0 @@
|
|
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
|
-
## The last last one, voter.id not voter.id.to_s _vp_ 2022-09-19
|
194
|
-
voter_id = voter.is_a?(BSON::ObjectId) ? voter : voter.is_a?(String) ? voter : voter.id
|
195
|
-
|
196
|
-
return :up if up_voter_ids.try(:include?, voter_id)
|
197
|
-
return :down if down_voter_ids.try(:include?, voter_id)
|
198
|
-
end
|
199
|
-
|
200
|
-
# Get the number of up votes
|
201
|
-
def up_votes_count
|
202
|
-
up_voter_ids.length
|
203
|
-
end
|
204
|
-
|
205
|
-
# Get the number of down votes
|
206
|
-
def down_votes_count
|
207
|
-
down_voter_ids.length
|
208
|
-
end
|
209
|
-
|
210
|
-
# Get the number of votes count
|
211
|
-
def votes_count
|
212
|
-
if self.has_attribute?(:votable)
|
213
|
-
self["votable"]["votes_count"]
|
214
|
-
else
|
215
|
-
0
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
# Get the votes point
|
220
|
-
def votes_point
|
221
|
-
if self.has_attribute?(:votable)
|
222
|
-
self["votable"]["votes_point"]
|
223
|
-
else
|
224
|
-
0
|
225
|
-
end
|
226
|
-
end
|
227
|
-
alias :votes_score :votes_point
|
228
|
-
|
229
|
-
# Array of up voter ids
|
230
|
-
def up_voter_ids
|
231
|
-
if self.has_attribute?(:votable)
|
232
|
-
self['votable']["up_voter_ids"]
|
233
|
-
else
|
234
|
-
[]
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
# Array of down voter ids
|
239
|
-
def down_voter_ids
|
240
|
-
if self.has_attribute?(:votable)
|
241
|
-
self["votable"]["down_voter_ids"]
|
242
|
-
else
|
243
|
-
[]
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
data/lib/mongoid/voter.rb
DELETED
@@ -1,96 +0,0 @@
|
|
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
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'ish/utils'
|
3
|
-
|
4
|
-
# require_relative './mongoid/votable.rb'
|
5
|
-
|
6
|
-
class Newsitem
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Timestamps
|
9
|
-
include Ish::Utils
|
10
|
-
|
11
|
-
include Mongoid::Votable
|
12
|
-
vote_point self, :up => +1, :down => -1
|
13
|
-
|
14
|
-
belongs_to :gallery, optional: true # seems correct. _vp_ 2022-03-21
|
15
|
-
def gallery
|
16
|
-
self.gallery_id ? Gallery.unscoped.find( self.gallery_id ) : nil
|
17
|
-
end
|
18
|
-
belongs_to :map, optional: true, class_name: '::Gameui::Map'
|
19
|
-
belongs_to :profile, optional: true, class_name: '::Ish::UserProfile'
|
20
|
-
belongs_to :photo, optional: true
|
21
|
-
belongs_to :report, optional: true
|
22
|
-
belongs_to :video, optional: true
|
23
|
-
|
24
|
-
field :name
|
25
|
-
field :descr
|
26
|
-
def description; descr; end
|
27
|
-
field :subhead
|
28
|
-
|
29
|
-
field :weight, :type => Integer, :default => 10
|
30
|
-
field :n_upvotes, :type => Integer, :default => 0
|
31
|
-
field :n_downvotes, :type => Integer, :default => 0
|
32
|
-
field :upvoting_users, :type => Array, :default => []
|
33
|
-
field :downvoting_users, :type => Array, :default => []
|
34
|
-
|
35
|
-
field :image_path # @deprecated ?
|
36
|
-
field :link_path # @deprecated ?
|
37
|
-
field :iframe_src
|
38
|
-
|
39
|
-
## This is used.
|
40
|
-
TYPE_GALLERY = :type_gallery
|
41
|
-
TYPE_PHOTO = :type_photo
|
42
|
-
TYPE_REPORT = :type_report
|
43
|
-
TYPE_VIDEO = :type_video
|
44
|
-
def item_type
|
45
|
-
return TYPE_GALLERY if gallery_id
|
46
|
-
return TYPE_PHOTO if photo_id
|
47
|
-
return TYPE_REPORT if report_id
|
48
|
-
return TYPE_VIDEO if video_id
|
49
|
-
end
|
50
|
-
|
51
|
-
default_scope ->{ order_by({ :created_at => :desc }) }
|
52
|
-
|
53
|
-
def self.from_params item
|
54
|
-
n = Newsitem.new
|
55
|
-
n.descr = item[:descr]
|
56
|
-
n.username = item[:username]
|
57
|
-
|
58
|
-
unless item[:report_id].blank?
|
59
|
-
n.report = Report.find item[:report_id]
|
60
|
-
end
|
61
|
-
|
62
|
-
unless item[:gallery_id].blank?
|
63
|
-
n.gallery = Gallery.find item[:gallery_id]
|
64
|
-
end
|
65
|
-
|
66
|
-
n.partial_name = item.partial_name unless item.partial_name.blank?
|
67
|
-
|
68
|
-
return n
|
69
|
-
end
|
70
|
-
|
71
|
-
def export_fields
|
72
|
-
%w|
|
73
|
-
descr
|
74
|
-
name
|
75
|
-
|
76
|
-
image_path
|
77
|
-
link_path
|
78
|
-
|
79
|
-
map_id
|
80
|
-
gallery_id
|
81
|
-
photo_id
|
82
|
-
report_id
|
83
|
-
video_id
|
84
|
-
|
|
85
|
-
end
|
86
|
-
|
87
|
-
def collect export_object
|
88
|
-
export_object[:galleries][gallery.id.to_s] = gallery.id.to_s if gallery
|
89
|
-
export_object[:photos][photo.id.to_s] = photo.id.to_s if photo
|
90
|
-
export_object[:reports][report.id.to_s] = report.id.to_s if report
|
91
|
-
export_object[:videos][video.id.to_s] = video.id.to_s if video
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
data/lib/office/action.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
|
2
|
-
##
|
3
|
-
## 2023-09-13 _vp_ I don't know if it's even used.
|
4
|
-
##
|
5
|
-
class Office::Action
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::Timestamps
|
8
|
-
store_in collection: 'office_actions'
|
9
|
-
|
10
|
-
field :slug, type: :string
|
11
|
-
validates :slug, uniqueness: true, allow_nil: true
|
12
|
-
|
13
|
-
field :descr, type: :string ## optional
|
14
|
-
|
15
|
-
|
16
|
-
STATE_ACTIVE = 'active'
|
17
|
-
STATE_INACTIVE = 'inactive'
|
18
|
-
STATES = [ STATE_ACTIVE, STATE_INACTIVE ]
|
19
|
-
field :state, type: :string
|
20
|
-
scope :active, ->{ where( state: STATE_ACTIVE ) }
|
21
|
-
|
22
|
-
|
23
|
-
has_many :ties, class_name: '::Office::ActionTie', inverse_of: :office_action
|
24
|
-
has_many :prev_ties, class_name: '::Office::ActionTie', inverse_of: :next_office_action
|
25
|
-
accepts_nested_attributes_for :ties
|
26
|
-
|
27
|
-
field :action_exe, type: :string
|
28
|
-
|
29
|
-
field :perform_at, type: :time
|
30
|
-
|
31
|
-
end
|
32
|
-
OAct = Office::Action
|
data/lib/office/action_tie.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
|
2
|
-
class Office::ActionTie
|
3
|
-
include Mongoid::Document
|
4
|
-
include Mongoid::Timestamps
|
5
|
-
store_in collection: 'office_action_ties'
|
6
|
-
|
7
|
-
attr_accessor :to_delete
|
8
|
-
|
9
|
-
belongs_to :office_action, class_name: '::Office::Action', inverse_of: :ties
|
10
|
-
belongs_to :next_office_action, class_name: '::Office::Action', inverse_of: :prev_ties
|
11
|
-
|
12
|
-
field :next_at_exe, type: :string
|
13
|
-
validates :next_at_exe, presence: true
|
14
|
-
|
15
|
-
end
|
16
|
-
OActie = Office::ActionTie
|