ish_models 3.1.0.3 → 3.1.0.6

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: 3968226198f0d0e6cf875e3f347755c09f408c5eb8801d22caf1db1788b03005
4
- data.tar.gz: a93175a27b7f4f565ea5d39c14579c78bee4f47e2a8be435928d9ff4bb5c1831
3
+ metadata.gz: 79b866df45b1f836996eae873bb73bdad131d78fc60d35e1dbf09918792dc73c
4
+ data.tar.gz: 1a094e1696284dd4c74dcca8b2e8abd5d1abfe3722e7a20d3d69b5e593a48494
5
5
  SHA512:
6
- metadata.gz: 0db60fb6fec07fe3145415a77aed59d3ab3c3438ee350425574d621b4f52dcbdd17b4d70a8e392ffd2ed8ea766ec92c07606b1465607b51a5f01e70b7188e08a
7
- data.tar.gz: ab7f866d340f00996d18adbc53ed9439b87ce4db69621da7be0217570de97a649e436a46044e2b444d004fa117dfe55814abf683773b0a37023df6283d4e93e9
6
+ metadata.gz: d7472f45bceb194872bd369b0dd6c5fd1c29ceb35a6d8dbeaccd99bd5c0c0ad59847bef1b79f29ac20abe790c00925cf0fe77dca1a118b892ec9ebdc416cf876
7
+ data.tar.gz: 4702a3f0c1a8962f7ebbf9a2a6d7a4fbdf4a64339dd5092a88edf4523a552c87bc9caa672b727f6feae7a791adb7baa19981bcda0c47e2798e1395ef98a559ca
data/lib/ish_models.rb CHANGED
@@ -5,7 +5,19 @@ 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'
13
+ require 'wco/tag'
14
+
15
+ require 'wco_email/conversation'
16
+ require 'wco_email/message_template'
17
+
18
+ require 'wco_hosting/appliance'
19
+ require 'wco_hosting/appliance_tmpl'
20
+ require 'wco_hosting/domain'
21
+ require 'wco_hosting/serverhost'
10
22
 
11
23
 
@@ -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 ADDED
@@ -0,0 +1,15 @@
1
+
2
+ class Wco::Tag
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'wco_tags'
6
+
7
+ field :slug
8
+ # index
9
+ # validate presence
10
+ # validate uniqueness ?
11
+
12
+ # parent-child
13
+
14
+
15
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cancancan'
4
+
5
+ class WcoEmail::Ability
6
+ include ::CanCan::Ability
7
+
8
+ def initialize(user)
9
+
10
+ if user
11
+
12
+ if [ 'piousbox@gmail.com', 'victor@piousbox.com', 'victor@wasya.co' ].include? user.email
13
+ can :manage, :all
14
+ end
15
+
16
+ end
17
+
18
+ # Define abilities for the user here. For example:
19
+ #
20
+ # return unless user.present?
21
+ # can :read, :all
22
+ # return unless user.admin?
23
+ # can :manage, :all
24
+ #
25
+ # The first argument to `can` is the action you are giving the user
26
+ # permission to do.
27
+ # If you pass :manage it will apply to every action. Other common actions
28
+ # here are :read, :create, :update and :destroy.
29
+ #
30
+ # The second argument is the resource the user can perform the action on.
31
+ # If you pass :all it will apply to every resource. Otherwise pass a Ruby
32
+ # class of the resource.
33
+ #
34
+ # The third argument is an optional hash of conditions to further filter the
35
+ # objects.
36
+ # For example, here the user can only update published articles.
37
+ #
38
+ # can :update, Article, published: true
39
+ #
40
+ # See the wiki for details:
41
+ # https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md
42
+ end
43
+ end
@@ -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,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.3
4
+ version: 3.1.0.6
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-15 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
@@ -101,8 +129,6 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
104
- - MIT-LICENSE
105
- - README.md
106
132
  - Rakefile
107
133
  - app/assets/config/ish_models_manifest.js
108
134
  - app/assets/stylesheets/ish_models/application.css
@@ -117,7 +143,17 @@ files:
117
143
  - lib/ish_models/engine.rb
118
144
  - lib/ish_models/version.rb-trash
119
145
  - lib/tasks/ish_models_tasks.rake
146
+ - lib/wco/leadset.rb
120
147
  - lib/wco/profile.rb
148
+ - lib/wco/tag.rb
149
+ - lib/wco_email/ability.rb-trash
150
+ - lib/wco_email/conversation.rb
151
+ - lib/wco_email/message_template.rb
152
+ - lib/wco_email/tag.rb-trash
153
+ - lib/wco_hosting/appliance.rb
154
+ - lib/wco_hosting/appliance_tmpl.rb
155
+ - lib/wco_hosting/domain.rb
156
+ - lib/wco_hosting/serverhost.rb
121
157
  homepage: https://wasya.co
122
158
  licenses:
123
159
  - MIT
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2023 mac_a2141
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,28 +0,0 @@
1
- # IshModels
2
- Short description and motivation.
3
-
4
- ## Usage
5
- How to use my plugin.
6
-
7
- ## Installation
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem 'ish_models'
12
- ```
13
-
14
- And then execute:
15
- ```bash
16
- $ bundle
17
- ```
18
-
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install ish_models
22
- ```
23
-
24
- ## Contributing
25
- Contribution directions go here.
26
-
27
- ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).