ish_models 3.1.0.4 → 3.1.0.7

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: 5ff669625b9720fedc93aa4cbdf6a1e6f63487e99809509e8ccb1e1836f31c51
4
- data.tar.gz: 6151060a4c9923fcecef5c958dd7f6838b929bf262e22fa8e8f2c4681568dbff
3
+ metadata.gz: 311e454526047accffea05d6ed3630ac6f9a12596ec4ea9adb8f6523859de410
4
+ data.tar.gz: 6fffeee07a49484b4589ab4f113464443b132d588490ff1283ff930d2545c0d9
5
5
  SHA512:
6
- metadata.gz: 571319fb131431fc116aea7aa82edeb4bf31148e597f9dd70415d2ec64d78b8be1b2b922a1e6a8db4fd00413903c19e84cc131da2d7d4dff981b3384341769c5
7
- data.tar.gz: 86c8d47abcedd8e6d2cf6665123395533dc8060f40667890832e5b0d83374db73707027e4e0ceea179061108d2e9bf9dc4b5d42a0668a0a7ecc4ebba0d2ca30f
6
+ metadata.gz: 7565027390f8d754f8f6e5816f22b69c00d1a1a7ff41895364a7af8c64a77dbb7af0bd9ff775702c0add9feed945972d69cb84b6c41ef118326b723271fd26a4
7
+ data.tar.gz: 9a821f96be5824bd6cbf2ad01255a2c985417c5984ad6c4283485a76b5f95c9103fc0127f6fad015e56032f347c2f73e3f2049cfa1bede67f98ca4b1845a7646
data/lib/ish_models.rb CHANGED
@@ -5,8 +5,20 @@ require "ish_models/engine"
5
5
 
6
6
  module IshModels; end
7
7
  module Wco; end
8
+ module WcoEmail; end
9
+ module WcoHosting; end
8
10
 
11
+ require 'wco/leadset'
9
12
  require 'wco/profile'
10
13
  require 'wco/tag'
11
14
 
15
+ require 'wco_email/conversation'
16
+ require 'wco_email/email_filter'
17
+ require 'wco_email/message_template'
18
+
19
+ require 'wco_hosting/appliance'
20
+ require 'wco_hosting/appliance_tmpl'
21
+ require 'wco_hosting/domain'
22
+ require 'wco_hosting/serverhost'
23
+
12
24
 
@@ -0,0 +1,24 @@
1
+
2
+ class Wco::Leadset
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'wco_leadsets'
6
+
7
+ field :company_url
8
+ def domain; company_url; end
9
+ validates :company_url, presence: true, uniqueness: true
10
+ index({ company_url: 1 }, { name: 'company_url' })
11
+
12
+ field :email
13
+ index({ email: 1 }, { name: 'email' })
14
+ validates :email, presence: true, uniqueness: true
15
+
16
+ has_many :profiles, class_name: 'Wco::Profile', inverse_of: :leadset
17
+ has_many :appliances, class_name: 'WcoHosting::Appliance', inverse_of: :leadset
18
+
19
+ has_many :serverhosts, class_name: 'WcoHosting::Serverhost', inverse_of: :leadset
20
+ def next_serverhost
21
+ serverhosts.first
22
+ end
23
+
24
+ end
data/lib/wco/profile.rb CHANGED
@@ -2,9 +2,14 @@
2
2
  class Wco::Profile
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps
5
+ store_in collection: 'ish_user_profiles'
5
6
 
6
7
  field :email
8
+ index({ email: 1 }, { name: 'email' })
9
+ validates :email, presence: true, uniqueness: true
7
10
 
8
11
  field :per_page, type: :integer, default: 25
9
12
 
13
+ belongs_to :leadset, class_name: 'Wco::Leadset', inverse_of: :profile, optional: true
14
+
10
15
  end
data/lib/wco/tag.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  class Wco::Tag
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps
5
+ store_in collection: 'wco_tags'
5
6
 
6
7
  field :slug
7
8
  # index
@@ -0,0 +1,49 @@
1
+
2
+ class WcoEmail::Conversation
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ # include Mongoid::Paranoia
6
+
7
+ store_in collection: 'office_email_conversations'
8
+
9
+ STATE_UNREAD = 'state_unread'
10
+ STATE_READ = 'state_read'
11
+ STATES = [ STATE_UNREAD, STATE_READ ]
12
+ field :state
13
+
14
+ field :subject
15
+ index({ subject: -1 })
16
+
17
+ field :latest_at
18
+ index({ latest_at: -1 })
19
+
20
+ field :from_emails, type: :array, default: []
21
+ index({ from_emails: -1 })
22
+
23
+ field :preview, default: ''
24
+
25
+ # has_many :lead_ties, class_name: 'Office::EmailConversationLead'
26
+ # def lead_ids
27
+ # email_conversation_leads.map( &:lead_id )
28
+ # end
29
+ # field :lead_ids, type: :array, default: []
30
+ def leads
31
+ Lead.find( lead_ties.map( &:lead_id ) )
32
+ end
33
+
34
+ # has_many :email_messages, class_name: 'Office::EmailMessage'
35
+ # has_many :email_conversation_tags, class_name: 'Office::EmailConversationTag'
36
+
37
+ # has_and_belongs_to_many :tags, class_name: 'WcoEmail::Tag'
38
+
39
+ ## @TODO: test, rspec
40
+ def self.in_tag tag
41
+ case tag.class
42
+ when String
43
+ tag = WcoEmail::Tag.find_by slug: tag
44
+ end
45
+ where( :tag_ids => tag.id )
46
+ end
47
+
48
+ end
49
+ Conv = WcoEmail::Conversation
@@ -0,0 +1,45 @@
1
+
2
+ ##
3
+ ## 2023-03-04 _vp_ When I receive one.
4
+ ##
5
+ class WcoEmail::EmailFilter
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ field :from_regex
10
+ field :from_exact
11
+ field :subject_regex
12
+ field :subject_exact
13
+ field :body_regex
14
+ field :body_exact
15
+
16
+
17
+ KIND_AUTORESPOND_TMPL = 'autorespond-template'
18
+ KIND_AUTORESPOND_EACT = 'autorespond-email-action'
19
+ KIND_REMOVE_TAG = 'remove-tag'
20
+ KIND_ADD_TAG = 'add-tag'
21
+ KIND_DESTROY_SCHS = 'destroy-schs'
22
+
23
+ KIND_AUTORESPOND = 'autorespond' # @deprecated, DO NOT USE!
24
+ KIND_DELETE = 'delete' # @deprecated, use add-tag
25
+ KIND_SKIP_INBOX = 'skip-inbox' # @deprecated, use remove-tag
26
+
27
+ KINDS = [ nil, KIND_AUTORESPOND_TMPL, KIND_AUTORESPOND_EACT, KIND_ADD_TAG, KIND_REMOVE_TAG, KIND_DESTROY_SCHS]
28
+ field :kind
29
+
30
+ STATE_ACTIVE = 'active'
31
+ STATE_INACTIVE = 'inactive'
32
+ STATES = [ STATE_ACTIVE, STATE_INACTIVE ]
33
+ field :state, type: :string, default: STATE_ACTIVE
34
+ scope :active, ->{ where( state: STATE_ACTIVE ) }
35
+
36
+ belongs_to :email_template, class_name: 'Ish::EmailTemplate', optional: true
37
+ belongs_to :email_action, class_name: 'Office::EmailAction', optional: true
38
+
39
+ field :wp_term_id, type: :integer
40
+ def category
41
+ self.wp_term_id && WpTag.find( self.wp_term_id )
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,6 @@
1
+
2
+ class WcoEmail::MessageTemplate
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class WcoEmail::Tag
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :slug
7
+ # index
8
+ # validate presence
9
+ # validate uniqueness ?
10
+
11
+ # parent-child
12
+
13
+ has_and_belongs_to_many :email_conversations, class_name: 'Wco::EmailConversation'
14
+
15
+ end
@@ -0,0 +1,48 @@
1
+
2
+ class WcoHosting::Appliance
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'wco_appliances'
6
+
7
+ field :name
8
+ validates :name, uniqueness: { scope: :leadset }, presence: true
9
+ before_validation :set_name, on: :create, unless: ->{ name }
10
+ def set_name
11
+ name = "#{Time.now.strftime('%Y%m%d')}-#{(0...8).map { (65 + rand(26)).chr }.join}"
12
+ end
13
+
14
+ belongs_to :leadset, class_name: 'Wco::Leadset', inverse_of: :appliances
15
+
16
+
17
+
18
+
19
+ field :kind
20
+
21
+ field :service_name
22
+ field :environment
23
+
24
+ field :subdomain
25
+ field :domain
26
+ def host
27
+ "#{subdomain}.#{domain}"
28
+ end
29
+
30
+ belongs_to :appliance_tmpl, class_name: 'Wco::ApplianceTmpl'
31
+ def tmpl
32
+ appliance_tmpl
33
+ end
34
+
35
+ belongs_to :serverhost, class_name: 'Wco::Serverhost'
36
+ belongs_to :wco_leadset, class_name: 'Wco::Leadset', inverse_of: :appliances
37
+
38
+ # field :ip
39
+ field :port
40
+
41
+ STATE_PENDING = 'state-pending'
42
+ STATE_LIVE = 'state-live'
43
+ STATE_TERM = 'state-term'
44
+ field :state, default: STATE_PENDING
45
+
46
+ end
47
+
48
+
@@ -0,0 +1,57 @@
1
+
2
+ class WcoHosting::ApplianceTmpl
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'wco_appliance_tmpls'
6
+
7
+ field :kind
8
+ validates :kind, uniqueness: { scope: :version }, presence: true
9
+
10
+ field :version, type: :string, default: '0.0.0'
11
+ validates :version, uniqueness: { scope: :kind }, presence: true
12
+ index({ kind: -1, version: -1 }, { name: :kind_version })
13
+
14
+ field :descr, type: :string
15
+
16
+ field :image
17
+ validates :image, presence: true
18
+
19
+ field :volume_zip
20
+ validates :volume_zip, presence: true
21
+
22
+ ## Only underscores! These become variable names.
23
+ # KIND_CRM = 'kind_crm'
24
+ # KIND_DRUPAL = 'kind_drupal'
25
+ # KIND_HELLOWORLD = 'kind_helloworld'
26
+ # KIND_IROWOR = 'kind_irowor'
27
+ # KIND_JENKINS = 'kind_jenkins'
28
+ # KIND_MATOMO = 'kind_matomo'
29
+ # KIND_MOODLE = 'kind_moodle'
30
+ # KIND_PRESTASHOP = 'kind_prestashop'
31
+ # KIND_SMT = 'kind_smt'
32
+ # KIND_WORDPRESS = 'kind_wordpress'
33
+
34
+ ## 2023-12-08 :: These names are impossible to change already.
35
+ KIND_CRM = 'crm'
36
+ KIND_DRUPAL = 'drupal'
37
+ KIND_HELLOWORLD = 'helloworld'
38
+ KIND_IROWOR = 'irowor'
39
+ KIND_JENKINS = 'jenkins'
40
+ KIND_MATOMO = 'matomo'
41
+ KIND_MOODLE = 'moodle'
42
+ KIND_PRESTASHOP = 'prestashop'
43
+ KIND_SMT = 'smt'
44
+ KIND_WORDPRESS = 'wordpress'
45
+
46
+ KINDS = [ KIND_CRM, KIND_DRUPAL, KIND_HELLOWORLD, KIND_IROWOR,
47
+ KIND_JENKINS, KIND_MATOMO, KIND_MOODLE, KIND_PRESTASHOP, KIND_SMT,
48
+ KIND_WORDPRESS ]
49
+
50
+ has_many :appliances, class_name: 'Wco::Appliance'
51
+
52
+ def self.latest_of kind
53
+ where({ kind: kind }).order_by({ version: :desc }).first
54
+ end
55
+
56
+ end
57
+ AppTmpl = WcoHosting::ApplianceTmpl
@@ -0,0 +1,24 @@
1
+
2
+ class WcoHosting::Domain
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'wco_dns_domains'
6
+
7
+ field :name
8
+ validates :name, presence: true, uniqueness: true
9
+
10
+ ## orbital.city : Z0145070C3DD1OJWHTXJ
11
+ ## oquaney-splicing.com : Z060228025Y0JHUA35GN5
12
+ field :route53_zone
13
+ validates :route53_zone, presence: true
14
+
15
+ STATE_ACTIVE = 'active'
16
+ STATE_INACTIVE = 'inactive'
17
+ STATES = [ 'active', 'inactive' ]
18
+ field :state, default: STATE_ACTIVE
19
+
20
+ def self.list
21
+ [[nil,nil]] + all.where({ state: STATE_ACTIVE }).map { |i| [i.name, i.name ] }
22
+ end
23
+
24
+ end
@@ -0,0 +1,140 @@
1
+
2
+ require 'net/scp'
3
+
4
+ class WcoHosting::Serverhost
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+ # include Mongoid::Autoinc
8
+ store_in collection: 'wco_serverhosts'
9
+
10
+ field :name, type: :string
11
+ # validates :name, uniqueness: { scope: :leadset_id }, presence: true
12
+ validates :name, uniqueness: { scope: :wco_leadset }, presence: true
13
+
14
+ # field :leadset_id, type: :integer
15
+ # has_and_belongs_to_many :leadsets, class_name: 'Wco::Leadset', inverse_of: :serverhosts
16
+ belongs_to :wco_leadset, class_name: 'Wco::Leadset'
17
+
18
+ field :next_port, type: :integer, default: 8000
19
+
20
+ field :nginx_root, default: '/opt/nginx'
21
+ field :public_ip
22
+
23
+ ## net-ssh, sshkit
24
+ field :ssh_host
25
+ # field :ssh_username
26
+ # field :ssh_key
27
+
28
+ has_many :appliances, class_name: 'WcoHosting::Appliance'
29
+
30
+ def add_nginx_site app
31
+ ac = ActionController::Base.new
32
+ ac.instance_variable_set( :@app, app )
33
+ rendered_str = ac.render_to_string("scripts/nginx_site.conf")
34
+ puts '+++ add_nginx_site rendered_str:'
35
+ print rendered_str
36
+
37
+ file = Tempfile.new('prefix')
38
+ file.write rendered_str
39
+ file.close
40
+
41
+ cmd = "scp #{file.path} #{ssh_host}:/etc/nginx/sites-available/#{app.service_name}.conf "
42
+ puts! cmd, 'cmd'
43
+ `#{cmd}`
44
+
45
+ cmd = "ssh #{ssh_host} 'ln -s /etc/nginx/sites-available/#{app.service_name}.conf /etc/nginx/sites-enabled/#{app.service_name}.conf ' "
46
+ puts! cmd, 'cmd'
47
+ `#{cmd}`
48
+
49
+ cmd = "ssh #{ssh_host} 'nginx -s reload ' "
50
+ puts! cmd, 'cmd'
51
+ `#{cmd}`
52
+
53
+ cmd = "ssh #{ssh_host} 'certbot run -d #{app.origin} --nginx -n ' "
54
+ puts! cmd, 'cmd'
55
+ `#{cmd}`
56
+
57
+ end
58
+
59
+ WORKDIR = "/opt/projects/docker"
60
+
61
+ def add_docker_service app
62
+ puts! app, '#add_docker_service'
63
+
64
+ ac = ActionController::Base.new
65
+ ac.instance_variable_set( :@app, app )
66
+ ac.instance_variable_set( :@workdir, WORKDIR )
67
+ rendered_str = ac.render_to_string("docker-compose/dc-#{app.kind}")
68
+ puts '+++ add_docker_service rendered_str:'
69
+ print rendered_str
70
+
71
+ file = Tempfile.new('prefix')
72
+ file.write rendered_str
73
+ file.close
74
+ puts! file.path, 'file.path'
75
+
76
+ cmd = "scp #{file.path} #{ssh_host}:#{WORKDIR}/dc-#{app.service_name}.yml "
77
+ puts! cmd, 'cmd'
78
+ `#{cmd}`
79
+
80
+ cmd = "ssh #{ssh_host} 'cd #{WORKDIR} ; \
81
+ docker compose -f dc-#{app.service_name}.yml up -d #{app.service_name} ; \
82
+ echo ok #add_docker_service ' "
83
+ puts! cmd, 'cmd'
84
+ `#{cmd}`
85
+
86
+ puts "ok '#add_docker_service'"
87
+ end
88
+
89
+ def create_wordpress_volume app
90
+ ac = ActionController::Base.new
91
+ ac.instance_variable_set( :@app, app )
92
+ ac.instance_variable_set( :@workdir, WORKDIR )
93
+ rendered_str = ac.render_to_string("scripts/create_volume")
94
+ # puts '+++ create_volume rendered_str:'
95
+ # print rendered_str
96
+
97
+ file = Tempfile.new('prefix')
98
+ file.write rendered_str
99
+ file.close
100
+ # puts! file.path, 'file.path'
101
+
102
+ cmd = "scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume"
103
+ puts! cmd, 'cmd'
104
+ `#{cmd}`
105
+
106
+ cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
107
+ #{WORKDIR}/scripts/create_volume ' "
108
+ puts! cmd, 'cmd'
109
+ `#{cmd}`
110
+
111
+ puts 'ok #create_volume'
112
+ end
113
+
114
+ def create_volume app
115
+ ac = ActionController::Base.new
116
+ ac.instance_variable_set( :@app, app )
117
+ ac.instance_variable_set( :@workdir, WORKDIR )
118
+ rendered_str = ac.render_to_string("scripts/create_volume")
119
+ # puts '+++ create_volume rendered_str:'
120
+ # print rendered_str
121
+
122
+ file = Tempfile.new('prefix')
123
+ file.write rendered_str
124
+ file.close
125
+ # puts! file.path, 'file.path'
126
+
127
+ cmd = "scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume"
128
+ puts! cmd, 'cmd'
129
+ `#{cmd}`
130
+
131
+ cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
132
+ #{WORKDIR}/scripts/create_volume ' "
133
+ puts! cmd, 'cmd'
134
+ `#{cmd}`
135
+
136
+ puts 'ok #create_volume'
137
+ end
138
+
139
+
140
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.4
4
+ version: 3.1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - mac_a2141
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-16 00:00:00.000000000 Z
11
+ date: 2023-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: net-ssh
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 7.2.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 7.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: net-scp
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 4.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 4.0.0
97
125
  description: https://wasya.co
98
126
  email:
99
127
  - victor@piousbox.com
@@ -112,11 +140,18 @@ files:
112
140
  - app/views/layouts/ish_models/application.html.erb
113
141
  - config/routes.rb
114
142
  - lib/ish_models.rb
115
- - lib/ish_models/engine.rb
116
- - lib/ish_models/version.rb-trash
117
143
  - lib/tasks/ish_models_tasks.rake
144
+ - lib/wco/leadset.rb
118
145
  - lib/wco/profile.rb
119
146
  - lib/wco/tag.rb
147
+ - lib/wco_email/conversation.rb
148
+ - lib/wco_email/email_filter.rb
149
+ - lib/wco_email/message_template.rb
150
+ - lib/wco_email/tag.rb-trash
151
+ - lib/wco_hosting/appliance.rb
152
+ - lib/wco_hosting/appliance_tmpl.rb
153
+ - lib/wco_hosting/domain.rb
154
+ - lib/wco_hosting/serverhost.rb
120
155
  homepage: https://wasya.co
121
156
  licenses:
122
157
  - MIT
@@ -1,5 +0,0 @@
1
- module IshModels
2
- class Engine < ::Rails::Engine
3
- isolate_namespace IshModels
4
- end
5
- end
@@ -1,3 +0,0 @@
1
- module IshModels
2
- VERSION = File.read 'VERSION'
3
- end