ish_lib 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/Gemfile.lock +5 -3
  4. data/Rakefile +3 -0
  5. data/VERSION +1 -1
  6. data/ish_lib.gemspec +50 -7
  7. data/lib/app/models/ability.rb +151 -0
  8. data/lib/app/models/admin_user.rb +113 -0
  9. data/lib/app/models/app_model2.rb +33 -0
  10. data/lib/app/models/auth_token.rb +17 -0
  11. data/lib/app/models/aux_model.rb +22 -0
  12. data/lib/app/models/cities_user.rb +17 -0
  13. data/lib/app/models/city.rb +117 -0
  14. data/lib/app/models/country.rb +13 -0
  15. data/lib/app/models/day.rb +21 -0
  16. data/lib/app/models/decoded_auth_token.rb +6 -0
  17. data/lib/app/models/event.rb +21 -0
  18. data/lib/app/models/feature.rb +38 -0
  19. data/lib/app/models/gallery.rb +57 -0
  20. data/lib/app/models/manager.rb +10 -0
  21. data/lib/app/models/manager_city.rb +4 -0
  22. data/lib/app/models/manager_feature.rb +4 -0
  23. data/lib/app/models/manager_gallery.rb +3 -0
  24. data/lib/app/models/manager_newsitem.rb +5 -0
  25. data/lib/app/models/manager_photo.rb +3 -0
  26. data/lib/app/models/manager_report.rb +4 -0
  27. data/lib/app/models/manager_site.rb +4 -0
  28. data/lib/app/models/manager_tag.rb +6 -0
  29. data/lib/app/models/manager_user.rb +3 -0
  30. data/lib/app/models/manager_venue.rb +4 -0
  31. data/lib/app/models/message.rb +14 -0
  32. data/lib/app/models/newsitem.rb +50 -0
  33. data/lib/app/models/nodeitem.rb +18 -0
  34. data/lib/app/models/photo.rb +68 -0
  35. data/lib/app/models/rate_me.rb +13 -0
  36. data/lib/app/models/report.rb +144 -0
  37. data/lib/app/models/review.rb +4 -0
  38. data/lib/app/models/site.rb +85 -0
  39. data/lib/app/models/tag.rb +78 -0
  40. data/lib/app/models/user.rb +122 -0
  41. data/lib/app/models/user_profile.rb +20 -0
  42. data/lib/app/models/venue.rb +69 -0
  43. data/lib/app/models/video.rb +48 -0
  44. data/lib/app/models/welcome.rb +6 -0
  45. data/lib/app/models/wikitravel_page.rb +19 -0
  46. data/lib/ish_lib.rb +19 -0
  47. data/lib/string.rb +15 -0
  48. metadata +59 -5
@@ -0,0 +1,21 @@
1
+
2
+ class Day
3
+
4
+ include Mongoid::Document
5
+
6
+ field :date, :type => String
7
+ validates :date, :presence => true, :uniqueness => { :scope => :user }
8
+
9
+ belongs_to :user
10
+ validates :user, :presence => true
11
+
12
+ field :a1, :type => String
13
+ field :a2, :type => String
14
+ field :a3, :type => String
15
+ field :a4, :type => String
16
+ field :a5, :type => String
17
+
18
+ field :work, :type => String
19
+ field :dream, :type => String
20
+
21
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class DecodedAuthToken < HashWithIndifferentAccess
3
+ def expired?
4
+ self[:exp] <= Time.now.to_i
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+
2
+ class Event
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, :type => String
8
+ validates :name, :presence => true, :uniqueness => true
9
+
10
+ field :name_seo, :type => String
11
+ validates :name_seo, :presence => true, :uniqueness => true
12
+
13
+ field :descr, :type => String
14
+
15
+ field :date, :type => DateTime
16
+ validates :date, :presence => true
17
+
18
+ belongs_to :city
19
+ validates :city, :presence => true
20
+
21
+ end
@@ -0,0 +1,38 @@
1
+
2
+ class Feature
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, :type => String
8
+ field :subhead, :type => String
9
+
10
+ field :image_path, :type => String
11
+ field :link_path, :type => String
12
+ field :partial_name, :type => String, :default => nil
13
+
14
+ field :weight, :type => Integer, :default => 10
15
+
16
+ belongs_to :photo
17
+ belongs_to :report
18
+ belongs_to :gallery
19
+ belongs_to :video
20
+ # has_one :photo
21
+ # has_one :report
22
+ # has_one :gallery
23
+ # has_one :video
24
+
25
+ embedded_in :venue
26
+ embedded_in :site
27
+ embedded_in :city
28
+ embedded_in :tag
29
+
30
+ def self.all
31
+ self.order_by( :created_at => :desc )
32
+ end
33
+
34
+ def self.n_features
35
+ 4
36
+ end
37
+
38
+ end
@@ -0,0 +1,57 @@
1
+
2
+ require_relative '../../string'
3
+ require_relative 'app_model2'
4
+
5
+ class Gallery < AppModel2
6
+
7
+ belongs_to :site
8
+ validates :site, :presence => true
9
+
10
+ belongs_to :user
11
+ validates :user, :presence => true
12
+ field :username, :type => String
13
+
14
+ field :name, :type => String
15
+ validates :name, :uniqueness => true, :allow_nil => false
16
+
17
+ field :galleryname, :type => String
18
+ validates :galleryname, :uniqueness => true, :allow_nil => false
19
+
20
+ field :subhead, :type => String
21
+ field :descr, :type => String
22
+ field :lang, :type => String, :default => 'en'
23
+
24
+ has_many :photos
25
+
26
+ belongs_to :tag
27
+ belongs_to :city
28
+ belongs_to :venue
29
+
30
+ set_callback(:create, :before) do |doc|
31
+ doc.username = doc.user.username
32
+ doc.galleryname = doc.name.to_simple_string
33
+
34
+ # for the homepage
35
+ if doc.is_public && doc.site
36
+ n = Newsitem.new {}
37
+ n.gallery = doc
38
+ n.username = doc.user.username
39
+ sites = Site.where( :domain => doc.site.domain )
40
+ sites.each do |site|
41
+ site.newsitems << n
42
+ flag = site.save
43
+ if !flag
44
+ puts! site.errors
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # @deprecated, use Gallery::ACTIONS
51
+ def self.actions
52
+ [ 'show_mini', 'show_long', 'show' ]
53
+ end
54
+ ACTIONS = [ 'show_mini', 'show_long', 'show' ]
55
+
56
+ end
57
+
@@ -0,0 +1,10 @@
1
+
2
+ #
3
+ # I need this thing for permissions, after all
4
+ #
5
+ class Manager
6
+
7
+ PHOTOS_PER_PAGE = 100
8
+
9
+ end
10
+
@@ -0,0 +1,4 @@
1
+
2
+ class ManagerCity
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class ManagerFeature
3
+ # for Ability
4
+ end
@@ -0,0 +1,3 @@
1
+
2
+ class ManagerGallery
3
+ end
@@ -0,0 +1,5 @@
1
+
2
+ class ManagerNewsitem
3
+ # for ability
4
+
5
+ end
@@ -0,0 +1,3 @@
1
+
2
+ class ManagerPhoto
3
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class ManagerReport
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class ManagerSite
3
+
4
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class ManagerTag
3
+ # for ability
4
+
5
+ end
6
+
@@ -0,0 +1,3 @@
1
+
2
+ class ManagerUser
3
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class ManagerVenue
3
+
4
+ end
@@ -0,0 +1,14 @@
1
+
2
+
3
+ class Message
4
+
5
+ include Mongoid::Document
6
+
7
+ field :from_email, :type => String
8
+ field :name, :type => String
9
+ field :subject, :type => String
10
+ field :body, :type => String
11
+
12
+ field :to_email, :type => String
13
+
14
+ end
@@ -0,0 +1,50 @@
1
+ class Newsitem
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Paranoia
5
+
6
+ embedded_in :user
7
+ embedded_in :site
8
+ embedded_in :city
9
+ embedded_in :tag
10
+
11
+ belongs_to :photo
12
+ belongs_to :report
13
+ belongs_to :gallery
14
+ belongs_to :video
15
+
16
+ field :name, :type => String
17
+ field :descr, :type => String
18
+ field :image_path, :type => String
19
+ field :link_path, :type => String
20
+ field :username, :type => String # @TODO do I use this???
21
+ field :partial_name, :type => String, :default => nil # @deprecated, but let's not remove it.
22
+
23
+ field :weight, :type => Integer, :default => 10
24
+ field :n_upvotes, :type => Integer, :default => 0
25
+ field :n_downvotes, :type => Integer, :default => 0
26
+ field :upvoting_users, :type => Array, :default => []
27
+ field :downvoting_users, :type => Array, :default => []
28
+ field :is_feature, :type => Boolean, :default => false
29
+
30
+ default_scope ->{ order_by({ :created_at => :desc }) }
31
+
32
+ def self.from_params item
33
+ n = Newsitem.new
34
+ n.descr = item[:descr]
35
+ n.username = item[:username]
36
+
37
+ unless item[:report_id].blank?
38
+ n.report = Report.find item[:report_id]
39
+ end
40
+
41
+ unless item[:gallery_id].blank?
42
+ n.gallery = Gallery.find item[:gallery_id]
43
+ end
44
+
45
+ n.partial_name = item.partial_name unless item.partial_name.blank?
46
+
47
+ return n
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+
2
+ class Nodeitem
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :repository, :type => String
8
+ validates :repository, :presence => true
9
+
10
+ field :branch, :type => String
11
+ validates :branch, :presence => true
12
+
13
+ field :subdomain, :type => String
14
+ validates :subdomain, :presence => true, :uniqueness => true
15
+
16
+ field :status, :type => String
17
+
18
+ end
@@ -0,0 +1,68 @@
1
+
2
+ class Photo
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ include Mongoid::Paperclip
7
+
8
+ belongs_to :user, :inverse_of => :photos
9
+ validates :user, :presence => true
10
+ field :username, :type => String
11
+
12
+ has_and_belongs_to_many :viewers, :class_name => 'User', :inverse_of => :viewable_photos
13
+
14
+ belongs_to :profile_user, :class_name => 'User', :inverse_of => :profile_photo
15
+ belongs_to :profile_city, :class_name => 'City', :inverse_of => :profile_photo
16
+ belongs_to :profile_venue, :class_name => 'Venue', :inverse_of => :profile_photo
17
+
18
+ belongs_to :report
19
+ belongs_to :tag
20
+ belongs_to :venue
21
+ belongs_to :feature
22
+ belongs_to :gallery
23
+
24
+ field :name, :type => String
25
+ field :descr, :type => String
26
+
27
+ field :weight, :type => Integer, :default => 10
28
+
29
+ field :is_public, :type => Boolean, :default => true
30
+ field :is_trash, :type => Boolean, :default => false
31
+
32
+ # default_scope ->{ where({ :is_trash => false, :is_public => true }) }
33
+ default_scope ->{ where({ :is_trash => false }) }
34
+
35
+ has_mongoid_attached_file :photo,
36
+ :styles => {
37
+ :mini => '20x20#',
38
+ :thumb => "100x100#",
39
+ # :two_hundred => '200x200#',
40
+ :small => "400x400>",
41
+ # :small_square => "400x400#",
42
+ # :large_square => '950x650',
43
+ :large => '950x650>'
44
+ },
45
+ :storage => :s3,
46
+ :s3_credentials => ::S3_CREDENTIALS,
47
+ :path => "photos/:style/:id/:filename"
48
+
49
+ def self.n_per_manager_gallery
50
+ 25
51
+ end
52
+
53
+ validates_attachment_content_type :photo, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
54
+
55
+ set_callback(:create, :before) do |doc|
56
+ # if doc.is_public
57
+ # Site.languages.each do |lang|
58
+ # n = Newsitem.new({
59
+ # # :descr => t('photos.new'),
60
+ # :photo => doc, :username => doc.user.username })
61
+ # Site.where( :domain => DOMAIN, :lang => lang ).first.newsitems << n
62
+ # end
63
+ # end
64
+ end
65
+
66
+ end
67
+
68
+
@@ -0,0 +1,13 @@
1
+
2
+ module RateMe
3
+
4
+ def self.included(base)
5
+ base.send :field, :n_upvotes, :type => Integer, :default => 1
6
+ base.send :field, :n_downvotes, :type => Integer, :default => 0
7
+ base.send :field, :upvoters, :type => Array, :default => [ 'anonymous' ]
8
+ base.send :field, :downvoters, :type => Array, :default => []
9
+ end
10
+
11
+ end
12
+
13
+
@@ -0,0 +1,144 @@
1
+ class Report
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :name, :type => String
6
+ validates :name, :presence => true
7
+ index({ :name => 1 }, { :unique => true })
8
+ index({ :name => 1, :is_trash => 1 })
9
+
10
+ field :name_seo, :type => String
11
+ validates :name_seo, :uniqueness => true, :presence => true
12
+ index({ :name_seo => 1 }, { :unique => true })
13
+
14
+ field :descr, :type => String
15
+
16
+ field :is_trash, :type => Boolean, :default => false
17
+ index :is_trash => 1, :is_public => 1
18
+
19
+ field :is_public, :type => Boolean, :default => true
20
+ index({ :is_public => 1 })
21
+ scope :public, ->{
22
+ where({ is_public: true })
23
+ }
24
+
25
+ field :is_feature, :type => Boolean, :default => false
26
+ index({ :is_feature => 1 })
27
+
28
+ field :is_done, :type => Boolean, :default => true
29
+ index({ :is_done => 1 })
30
+
31
+ field :x, :type => Float
32
+ field :y, :type => Float
33
+
34
+ field :lang, :type => String, :default => 'en'
35
+ index({ :lang => 1 })
36
+
37
+ field :username, :type => String, :default => 'anonymous'
38
+ validates :username, :presence => true, :allow_nil => false
39
+ belongs_to :user
40
+ validates :user, :presence => true, :allow_nil => false
41
+ index({ :username => 1 })
42
+
43
+ field :subhead, :type => String
44
+
45
+ belongs_to :tag
46
+ belongs_to :city
47
+
48
+ belongs_to :site
49
+ validates :site, :presence => true
50
+
51
+ has_and_belongs_to_many :venues
52
+ belongs_to :cities_user
53
+
54
+ has_one :photo
55
+
56
+ field :n_upvotes, :default => 0
57
+ field :n_spamvotes, :default => 0
58
+
59
+ default_scope ->{
60
+ where({ is_public: true, is_trash: false }).order_by({ created_at: :desc })
61
+ }
62
+
63
+ def self.list conditions = { :is_trash => false }
64
+ out = self.where( conditions ).order_by( :name => :asc ).limit( 100 )
65
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
66
+ end
67
+
68
+ PER_PAGE = 20
69
+ def self.paginates_per
70
+ self::PER_PAGE
71
+ end
72
+
73
+ def venue
74
+ return self.venues[0] || nil
75
+ end
76
+
77
+ def self.all
78
+ self.where( :is_public => true, :is_trash => false ).order_by( :created_at => :desc )
79
+ end
80
+
81
+ def self.not_tagged
82
+ Report.where( :tag_id => nil, :city => nil )
83
+ end
84
+
85
+ def self.for_homepage args
86
+ begin
87
+ tag_ids = args[:main_tag].children_tags.map { |tag| tag._id } + [ args[:main_tag]._id ]
88
+ return Report.where( :tag_id.in => tag_ids ).page args[:page]
89
+ rescue
90
+ return Report.page args[:page]
91
+ end
92
+ end
93
+
94
+ set_callback :create, :after do |doc|
95
+ if doc.is_public
96
+
97
+ if !doc.venue_ids.blank?
98
+ ( doc.venue_ids || [] ).each do |venue_id|
99
+ v = Venue.find venue_id
100
+ u = User.find doc.user_id
101
+ n = Newsitem.new
102
+ n.username = u.username unless u.blank?
103
+ n.report = doc
104
+ v.newsitems << n
105
+ v.save
106
+ end
107
+ end
108
+
109
+ #
110
+ # hidden
111
+ proc do # nothing
112
+ unless doc.site.blank?
113
+ username = doc.user.username || 'anonymous'
114
+ doc.site.newsitems << Newsitem.new({ :report_id => doc.id, :username => username, :descr => doc.subhead, :name => doc.name })
115
+ flag = doc.site.save
116
+ puts! flag unless flag
117
+ end
118
+ end
119
+
120
+ unless doc.city.blank?
121
+ city = City.find doc.city.id
122
+ username = doc.user.username || 'anon'
123
+ n = Newsitem.new :report => doc, :username => username
124
+ city.newsitems << n
125
+ city.save
126
+ end
127
+ end
128
+ end
129
+
130
+ def self.clear
131
+ if Rails.env.test?
132
+ self.unscoped.each { |r| r.remove }
133
+ end
134
+ end
135
+
136
+ def self.not_tagged
137
+ Report.where( :tag_id => nil, :city => nil )
138
+ end
139
+
140
+ def venue
141
+ self.venues[0] || nil
142
+ end
143
+
144
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class Review
3
+
4
+ end
@@ -0,0 +1,85 @@
1
+
2
+ require_relative 'aux_model'
3
+
4
+ class Site
5
+
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+ include AuxModel
9
+
10
+ field :domain, :type => String
11
+
12
+ field :lang, :type => String, :default => 'en'
13
+ # validates :lang, { :uniqueness => :true, :scope => :domain }
14
+
15
+ field :title, :type => String
16
+ field :subhead, :type => String
17
+ field :home_redirect_path, :type => String, :default => nil
18
+
19
+ field :n_features, :type => Integer, :default => 4
20
+ field :n_newsitems, :type => Integer, :default => 20
21
+
22
+ # denormalized
23
+ field :n_reports, :type => Integer
24
+ field :n_galleries, :type => Integer
25
+
26
+ field :is_video_enabled, :type => Boolean, :default => false
27
+ field :is_resume_enabled, :type => Boolean, :default => false
28
+ field :is_ads_enabled, :type => Boolean, :default => true
29
+ field :is_trash, :type => Boolean, :default => false
30
+ field :is_primary, :type => Boolean, :default => false
31
+ field :is_private, :type => Boolean, :default => false
32
+
33
+ field :homepage_layout, :type => String, :default => 'show'
34
+ field :layout, :type => String, :default => 'application'
35
+
36
+ has_many :reports
37
+ has_many :galleries
38
+ has_many :tags
39
+ has_many :videos
40
+
41
+ embeds_many :features
42
+ embeds_many :newsitems
43
+
44
+ default_scope ->{ where({ :is_trash => false }).order_by({ :domain => :asc, :lang => :asc }) }
45
+
46
+ set_callback :create, :before do |doc|
47
+ if Site.where( :lang => doc.lang, :domain => doc.domain ).length > 0
48
+ return false
49
+ end
50
+ end
51
+
52
+ set_callback :update, :before do |doc|
53
+ possible_duplicate = Site.where( :lang => doc.lang, :domain => doc.domain ).first
54
+ if possible_duplicate.blank?
55
+ true
56
+ elsif doc.id != possible_duplicate.id
57
+ false
58
+ end
59
+ end
60
+
61
+ LANGUAGES = [ 'en', 'ru', 'pt' ]
62
+
63
+ # manager uses it.
64
+ def self.list
65
+ out = self.all.order_by( :domain => :asc, :lang => :asc )
66
+ [['', nil]] + out.map { |item| [ "#{item.domain} #{item.lang}", item.id ] }
67
+ end
68
+
69
+ def self.mobi
70
+ Site.where( :domain => 'travel-guide.mobi', :lang => 'en' ).first
71
+ end
72
+
73
+ def n_reports
74
+ self.reports.unscoped.where( :is_trash => false ).length
75
+ end
76
+
77
+ def n_private_reports
78
+ self.reports.unscoped.where( :is_public => false, :is_trash => false ).length
79
+ end
80
+
81
+ def its_locales
82
+ Site.where( :domain => self.domain ).map { |s| s.lang.to_sym }
83
+ end
84
+
85
+ end