cmor_multi_tenancy 0.0.54.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/config/cmor/multi_tenancy_manifest.js +1 -0
  6. data/app/assets/exceptions/cmor/multi_tenancy/current_client_not_set.rb +6 -0
  7. data/app/assets/javascripts/cmor/multi_tenancy/application.js +2 -0
  8. data/app/assets/javascripts/cmor/multi_tenancy/application/keep.js +0 -0
  9. data/app/assets/javascripts/cmor_multi_tenancy.js +2 -0
  10. data/app/assets/stylesheets/cmor/multi_tenancy/application.css +3 -0
  11. data/app/assets/stylesheets/cmor/multi_tenancy/application/keep.css +0 -0
  12. data/app/assets/stylesheets/cmor_multi_tenancy.css +3 -0
  13. data/app/concerns/cmor/multi_tenancy/controller/current_client_concern.rb +64 -0
  14. data/app/concerns/cmor/multi_tenancy/model/client_concern.rb +13 -0
  15. data/app/controllers/cmor/multi_tenancy/clients_controller.rb +17 -0
  16. data/app/controllers/cmor/multi_tenancy/home_controller.rb +4 -0
  17. data/app/exceptions/cmor/multi_tenancy/current_client_not_set.rb +6 -0
  18. data/app/exceptions/cmor/multi_tenancy/default_client_not_found.rb +6 -0
  19. data/app/models/cmor/multi_tenancy/client.rb +44 -0
  20. data/app/routing_constraints/cmor/multi_tenancy/routing/subdomain_constraint.rb +22 -0
  21. data/app/services/cmor/multi_tenancy/create_client_service.rb +48 -0
  22. data/app/services/cmor/multi_tenancy/seed_service.rb +25 -0
  23. data/app/view_helpers/cmor/multi_tenancy/application_view_helper.rb +4 -0
  24. data/app/views/cmor/multi_tenancy/clients/_form.html.haml +6 -0
  25. data/config/initializers/assets.rb +2 -0
  26. data/config/initializers/cmor.rb +3 -0
  27. data/config/locales/de.yml +23 -0
  28. data/config/locales/en.yml +24 -0
  29. data/config/routes.rb +7 -0
  30. data/db/migrate/20200327161253_create_cmor_multi_tenancy_clients.rb +15 -0
  31. data/lib/cmor/multi_tenancy.rb +45 -0
  32. data/lib/cmor/multi_tenancy/configuration.rb +31 -0
  33. data/lib/cmor/multi_tenancy/engine.rb +5 -0
  34. data/lib/cmor/multi_tenancy/spec_helpers/generic.rb +21 -0
  35. data/lib/cmor/multi_tenancy/spec_helpers/system.rb +24 -0
  36. data/lib/cmor/multi_tenancy/version.rb +8 -0
  37. data/lib/cmor_multi_tenancy.rb +14 -0
  38. data/lib/generators/cmor/multi_tenancy/install/install_generator.rb +30 -0
  39. data/lib/generators/cmor/multi_tenancy/install/templates/app/models/client.rb +2 -0
  40. data/lib/generators/cmor/multi_tenancy/install/templates/initializer.rb +42 -0
  41. data/lib/generators/cmor/multi_tenancy/install/templates/routes.source +4 -0
  42. data/lib/tasks/cmor/multi_tenancy_tasks.rake +4 -0
  43. data/spec/factories/cmor_multi_tenancy_client.rb +8 -0
  44. metadata +450 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 10192faf6d5c93df4520970ebb8850787d2e3cdc6cc4aad9114120b0e60375fb
4
+ data.tar.gz: afe389707fa07620d18a25b822e550969d8e23ac90db829a9d9fd98b3129fd16
5
+ SHA512:
6
+ metadata.gz: 8532baaadee8baf7cb3e63b75a2ca44367a9b5e9e4d426a4171ab89d69df474e71c556519f9e017c853d018b6b1a1077a3f12ef2ac8cbc6b048807e2496c91f2
7
+ data.tar.gz: 1e4ed395736baea0d21e2debea6bfe21b8bf08b41f78541a8e7a5fc3f6cc98387fafa40734faf54df54dcd1c72169c50bd99234fe5357a0b50c495342268eb6f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Roberto Vasquez Angel
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 ADDED
@@ -0,0 +1,28 @@
1
+ # Cmor::MultiTenancy
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 'cmor/multi_tenancy'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install cmor/multi_tenancy
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).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Cmor::MultiTenancy'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rails/dummy/tasks'
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/cmor/multi_tenancy .css
@@ -0,0 +1,6 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class CurrentClientNotSet < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ //= require_tree ./application
2
+
@@ -0,0 +1,2 @@
1
+ //= require ./cmor/multi_tenancy/application
2
+
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./application
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require ./cmor/multi_tenancy/application
3
+ */
@@ -0,0 +1,64 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module Controller
4
+ # Example:
5
+ #
6
+ # # app/controllers/application_controller.rb
7
+ # class ApplicationController < ActionController::Base
8
+ # include Cmor::MultiTenancy::Controller::CurrentClientConcern
9
+ #
10
+ # around_action :set_current_client
11
+ # end
12
+ #
13
+ module CurrentClientConcern
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+ helper_method :current_client if respond_to?(:helper_method)
18
+ end
19
+
20
+ private
21
+
22
+ def current_client
23
+ Cmor::MultiTenancy.current_client
24
+ end
25
+
26
+ def set_current_client
27
+ if client = load_current_client
28
+ with_client(client) { yield }
29
+ else
30
+ redirect_to_default_client
31
+ end
32
+ end
33
+
34
+ def load_current_client
35
+ if Cmor::MultiTenancy::Configuration.aliases_for_default_client.include?(current_client_identifier)
36
+ ::Client.active.default.first!
37
+ else
38
+ ::Client.active.where(identifier: current_client_identifier).first
39
+ end
40
+ end
41
+
42
+ def load_default_client
43
+ ::Client.active.default.first!
44
+ end
45
+
46
+ def current_client_identifier
47
+ params[:client_identifier] || ENV.fetch('client_identifier') { Cmor::MultiTenancy::Configuration.aliases_for_default_client.first }
48
+ end
49
+
50
+ def with_client(client)
51
+ Cmor::MultiTenancy.with_client(client) { yield }
52
+ end
53
+
54
+ def redirect_to_default_client
55
+ redirect_to(current_client_key => load_default_client.identifier)
56
+ end
57
+
58
+ def current_client_key
59
+ :subdomain
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module Model
4
+ module ClientConcern
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ belongs_to :client
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class ClientsController < Cmor::Core::Backend::ResourcesController::Base
4
+ include Rao::ResourcesController::ActsAsListConcern
5
+
6
+ def self.resource_class
7
+ Cmor::MultiTenancy::Client
8
+ end
9
+
10
+ private
11
+
12
+ def permitted_params
13
+ params.require(:client).permit(:identifier, :title, :description, :active_from, :active_to, :default)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Cmor::MultiTenancy
2
+ class HomeController < Cmor::Core::Backend::HomeController::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class CurrentClientNotSet < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class DefaultClientNotFound < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,44 @@
1
+ module Cmor::MultiTenancy
2
+ class Client < ApplicationRecord
3
+ validates :identifier, presence: true, uniqueness: true, format: { with: /\A[a-z0-9-]+\z/ }, length: { minimum: 2, maximum: 63 }
4
+ validates :title, presence: true, uniqueness: true
5
+
6
+ def human
7
+ title
8
+ end
9
+
10
+ module ActiveConcern
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ validates :active_from, presence: true
15
+ validates :active_to, presence: true
16
+
17
+ scope :active, -> { active_at(Time.zone.now) }
18
+ scope :active_at, ->(point_in_time) {
19
+ t = arel_table
20
+ where(t[:active_from].lteq(point_in_time)).where(t[:active_to].gteq(point_in_time))
21
+ }
22
+
23
+ after_initialize do
24
+ self.active_from ||= Time.at(0)
25
+ self.active_to ||= Time.new(9999, 12, 31, 23, 59, 59)
26
+ end
27
+ end
28
+ end
29
+
30
+ include ActiveConcern
31
+
32
+ module DefaultConcern
33
+ extend ActiveSupport::Concern
34
+
35
+ included do
36
+ validates :default, uniqueness: true, if: :default
37
+
38
+ scope :default, -> { where(default: true) }
39
+ end
40
+ end
41
+
42
+ include DefaultConcern
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module Routing
4
+ # Example:
5
+ #
6
+ # config/routes.rb:
7
+ # Rails.application.routes.draw do
8
+ # constraints Cmor::MultiTenancy::Routing::SubdomainConstraint do
9
+ # root to: 'home#index'
10
+ # end
11
+ # end
12
+ class SubdomainConstraint
13
+ def self.matches?(request)
14
+ if request.subdomain.present?
15
+ ENV['client_identifier'] = request.subdomain
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class CreateClientService < Rao::Service::Base
4
+ class Result < Rao::Service::Result::Base
5
+ attr_accessor :client, :identifier, :title, :description, :active_form, :active_to, :default
6
+ end
7
+
8
+ attr_accessor :identifier, :title, :description, :active_form, :active_to, :default
9
+
10
+ def _perform
11
+ @result.client = create_client
12
+ end
13
+
14
+ private
15
+
16
+ def create_client
17
+ client = ::Client.new(client_attributes)
18
+ say "Creating client [#{client.identifier}]" do
19
+ if client.save
20
+ say '=> [OK]'
21
+ else
22
+ add_error_and_say(:base, "=> [FAILED] Errors: #{client.errors.full_messages.to_sentence}")
23
+ end
24
+ client
25
+ end
26
+ end
27
+
28
+ def client_attributes
29
+ client_attribute_defaults.merge(client_attribute_overrides)
30
+ end
31
+
32
+ def client_attribute_overrides
33
+ { identifier: identifier, title: title, description: description, active_form: active_form, active_to: active_to, default: default }.compact
34
+ end
35
+
36
+ def client_attribute_defaults
37
+ {
38
+ identifier: "default-client",
39
+ title: "Default",
40
+ description: "This is the default client.",
41
+ active_from: Time.at(0),
42
+ active_to: Time.parse("9999-12-31 23:59:59"),
43
+ default: true,
44
+ }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ class SeedService < Rao::Service::Base
4
+ class Result < Rao::Service::Result::Base
5
+ attr_accessor :client
6
+ end
7
+
8
+ def _perform
9
+ @result.client = create_client
10
+ end
11
+
12
+ private
13
+
14
+ def create_client
15
+ r = Cmor::MultiTenancy::CreateClientService.call
16
+ if r.success?
17
+ r.client
18
+ else
19
+ add_error_and_say(:client_service, r.errors.full_messages.to_sentence)
20
+ nil
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ module Cmor::MultiTenancy
2
+ class ApplicationViewHelper < Rao::ViewHelper::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ = form.input :identifier
2
+ = form.input :title
3
+ = form.input :description
4
+ = form.input :active_from, as: :string
5
+ = form.input :active_to, as: :string
6
+ = form.input :default
@@ -0,0 +1,2 @@
1
+ Rails.application.config.assets.precompile += %w( cmor_multi_tenancy.css )
2
+ Rails.application.config.assets.precompile += %w( cmor_multi_tenancy.js )
@@ -0,0 +1,3 @@
1
+ Cmor.configure do |config|
2
+ config.administrador.register_engine('Cmor::MultiTenancy::Engine', {})
3
+ end
@@ -0,0 +1,23 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ cmor/multi_tenancy/client:
5
+ one: Mandant
6
+ other: Mandanten
7
+ attributes:
8
+ cmor/multi_tenancy/client:
9
+ id: ID
10
+ active_from: Aktiv ab
11
+ active_to: Aktiv bis
12
+ default: Standard
13
+ default_at: Standard seit
14
+ description: Beschreibung
15
+ identifier: Bezeichner
16
+ position: Position
17
+ title: Titel
18
+ created_at: Erstellt am
19
+ updated_at: Aktualisiert am
20
+ classes:
21
+ cmor/multi_tenancy/engine: Mandantensteuerung
22
+ routes:
23
+ cmor-multi-tenancy-engine: mandantensteuerung
@@ -0,0 +1,24 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ cmor/multi_tenancy/client:
5
+ one: Client
6
+ other: Clients
7
+ attributes:
8
+ cmor/multi_tenancy/client:
9
+ id: ID
10
+ active_from: Active from
11
+ active_to: Active to
12
+ default: Default
13
+ default_at: Default since
14
+ description: Description
15
+ identifier: Identifier
16
+ position: Position
17
+ title: Title
18
+ created_at: Created at
19
+ updated_at: Updated at
20
+ classes:
21
+ cmor/multi_tenancy/engine: Multi Tenancy
22
+ routes:
23
+ cmor-multi-tenancy-engine: multi-tenancy
24
+
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Cmor::MultiTenancy::Engine.routes.draw do
2
+ resources :clients do
3
+ post :reposition, on: :member
4
+ end
5
+
6
+ root to: 'home#index'
7
+ end
@@ -0,0 +1,15 @@
1
+ class CreateCmorMultiTenancyClients < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cmor_multi_tenancy_clients do |t|
4
+ t.string :identifier
5
+ t.string :title
6
+ t.text :description
7
+ t.string :position
8
+ t.timestamp :active_from
9
+ t.timestamp :active_to
10
+ t.boolean :default, default: false
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ # A word of warning: This method changes the current client *per request*.
4
+ # In most cases this should be no problem, but do not use this method when
5
+ # you have concurrency inside one request.
6
+ #
7
+ # You can run specs that need a client like this:
8
+ # Rspec.describe Post, type: :model do
9
+ # let(:default_client) { Cmor::MultiTenancy::CreateClientService.call.client }
10
+ #
11
+ # around(:each) do |example|
12
+ # Cmor::MultiTenancy.with_client(default_client) do
13
+ # example.run
14
+ # end
15
+ # end
16
+ #
17
+ # subject { create(:post, client: Cmor::MultiTenancy.current_client) }
18
+ #
19
+ # it { expect(subject.client).to eq(default_client) }
20
+ # end
21
+ def self.with_client(client)
22
+ client = Cmor::MultiTenancy::Client.active.default.first! if client == :default
23
+ client = Cmor::MultiTenancy::Client.active.where(identifier: client.to_s).first unless client.is_a?(Cmor::MultiTenancy::Client)
24
+ puts "[Cmor::MultiTenancy] With client #{client.identifier}"
25
+ previous_client = RequestStore.store[:current_client]
26
+ RequestStore.store[:current_client] = client
27
+ output = yield
28
+ RequestStore.store[:current_client] = previous_client
29
+ puts "[Cmor::MultiTenancy] => Done"
30
+ output
31
+ end
32
+
33
+ def self.current_client
34
+ RequestStore.store[:current_client]
35
+ end
36
+
37
+ def self.current_client!
38
+ current_client || raise(Cmor::MultiTenancy::CurrentClientNotSet)
39
+ end
40
+
41
+ def self.default_client
42
+ Cmor::MultiTenancy::Client.active.default.first!
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ module Cmor::MultiTenancy
2
+ module Configuration
3
+ def configure
4
+ yield self
5
+ end
6
+
7
+ mattr_accessor :resources_controllers do
8
+ -> {[]}
9
+ end
10
+
11
+ mattr_accessor :resource_controllers do
12
+ -> {[]}
13
+ end
14
+
15
+ mattr_accessor :service_controllers do
16
+ -> {[]}
17
+ end
18
+
19
+ mattr_accessor :sidebar_controllers do
20
+ -> {[]}
21
+ end
22
+
23
+ mattr_accessor :current_client_key do
24
+ :subdomain
25
+ end
26
+
27
+ mattr_accessor :aliases_for_default_client do
28
+ %w( www )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Cmor::MultiTenancy
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Cmor::MultiTenancy
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module SpecHelpers
4
+ # Usage:
5
+ #
6
+ # # spec/support/cmor_multi_tenancy.rb
7
+ # require 'cmor/multi_tenancy/spec_helpers/system'
8
+ #
9
+ # RSpec.configure do |config|
10
+ # config.include Cmor::MultiTenancy::SpecHelpers::System, type: :feature
11
+ # config.include Cmor::MultiTenancy::SpecHelpers::System, type: :system
12
+ # end
13
+ #
14
+ module Generic
15
+ def with_client(client)
16
+ Cmor::MultiTenancy.with_client(client) { yield }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module SpecHelpers
4
+ # Usage:
5
+ #
6
+ # # spec/support/cmor_multi_tenancy.rb
7
+ # require 'cmor/multi_tenancy/spec_helpers/system'
8
+ #
9
+ # RSpec.configure do |config|
10
+ # config.include Cmor::MultiTenancy::SpecHelpers::System, type: :feature
11
+ # config.include Cmor::MultiTenancy::SpecHelpers::System, type: :system
12
+ # end
13
+ #
14
+ module System
15
+ def with_subdomain(identfier)
16
+ @_original_host = Capybara.default_host
17
+ Capybara.default_host = @_original_host.gsub(/(\:\/\/[a-z0-9-]{1,})\./, "://#{identfier}.")
18
+ yield
19
+ Capybara.default_host = @_original_host
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ require "cmor/version"
2
+
3
+ module Cmor
4
+ module MultiTenancy
5
+ VERSION = ::Cmor::VERSION
6
+ end
7
+ end
8
+
@@ -0,0 +1,14 @@
1
+ require "cmor_core_backend"
2
+ require "request_store"
3
+ require "rao-service"
4
+
5
+ require "cmor/multi_tenancy"
6
+ require "cmor/multi_tenancy/version"
7
+ require "cmor/multi_tenancy/configuration"
8
+ require "cmor/multi_tenancy/engine"
9
+
10
+ module Cmor
11
+ module MultiTenancy
12
+ extend Configuration
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ module Cmor
2
+ module MultiTenancy
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc 'Generates the initializer'
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ attr_reader :base_controller_class_name
10
+
11
+ def initialize(*args)
12
+ super
13
+ @base_controller_class_name = ENV.fetch('BASE_CONTROLLER_CLASS_NAME') { '::ApplicationController' }
14
+ end
15
+
16
+ def generate_initializer
17
+ template 'initializer.rb', 'config/initializers/cmor_multi_tenancy.rb'
18
+ end
19
+
20
+ def generate_routes
21
+ route File.read(File.join(File.expand_path('../templates', __FILE__), 'routes.source'))
22
+ end
23
+
24
+ def generate_client_model
25
+ copy_file 'app/models/client.rb', 'app/models/client.rb'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ class Client < Cmor::MultiTenancy::Client
2
+ end
@@ -0,0 +1,42 @@
1
+ Cmor::MultiTenancy.configure do |config|
2
+ # Set the resources, that will be shown in the backend menu.
3
+ #
4
+ # Default: config.resources_controllers = -> {[
5
+ # Cmor::MultiTenancy::ClientsController
6
+ # ]}
7
+ #
8
+ config.resources_controllers = -> {[
9
+ Cmor::MultiTenancy::ClientsController
10
+ ]}
11
+
12
+ # Set the resources, that will be shown in the backend menu.
13
+ #
14
+ # Default: config.resource_controllers = -> {[]}
15
+ #
16
+ config.resource_controllers = -> {[]}
17
+
18
+ # Set the services, that will be shown in the backend menu.
19
+ #
20
+ # Default: config.service_controllers = -> {[]}
21
+ #
22
+ config.service_controllers = -> {[]}
23
+
24
+ # Set the sidebars, that will be shown in the backend menu.
25
+ #
26
+ # Default: config.sidebar_controllers = -> {[]}
27
+ #
28
+ config.sidebar_controllers = -> {[]}
29
+
30
+ # Set which key to use when redirecting to a client. This can
31
+ # either be :subdomain or :client_identifier
32
+ #
33
+ # Default: config.current_client_key = :subdomain
34
+ #
35
+ config.current_client_key = :subdomain
36
+
37
+ # Sets the aliases that will match the default client.
38
+ #
39
+ # Default: aliases_for_default_client = %w( www )
40
+ #
41
+ config.aliases_for_default_client = %w( www )
42
+ end
@@ -0,0 +1,4 @@
1
+
2
+ localized do
3
+ mount Cmor::MultiTenancy::Engine, at: '/backend/cmor-multi-tenancy-engine'
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cmor/multi_tenancy do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :cmor_multi_tenancy_client, class: Cmor::MultiTenancy::Client do
3
+ sequence(:identifier) { |i| "client-#{i}" }
4
+ sequence(:title) { |i| "Client ##{i}" }
5
+ active_from { Time.at(0) }
6
+ active_to { Time.new(9999, 12, 31, 23, 59, 59) }
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,450 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmor_multi_tenancy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.54.pre
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Vasquez Angel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: cmor_core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.54.pre
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.54.pre
41
+ - !ruby/object:Gem::Dependency
42
+ name: cmor_core_backend
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.54.pre
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.54.pre
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: responders
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: capybara
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: git_log_generator
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry-rails
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rails-dummy
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rails-i18n
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rao-shoulda_matchers
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rspec-rails
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: factory_bot_rails
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: rubocop
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: rubocop-rails_config
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: shoulda-matchers
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: simplecov
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: simplecov-console
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :development
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - ">="
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: request_store
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
328
+ type: :runtime
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
335
+ - !ruby/object:Gem::Dependency
336
+ name: rao-service
337
+ requirement: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - ">="
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ type: :runtime
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - ">="
347
+ - !ruby/object:Gem::Version
348
+ version: '0'
349
+ - !ruby/object:Gem::Dependency
350
+ name: bootsnap
351
+ requirement: !ruby/object:Gem::Requirement
352
+ requirements:
353
+ - - ">="
354
+ - !ruby/object:Gem::Version
355
+ version: '0'
356
+ type: :development
357
+ prerelease: false
358
+ version_requirements: !ruby/object:Gem::Requirement
359
+ requirements:
360
+ - - ">="
361
+ - !ruby/object:Gem::Version
362
+ version: '0'
363
+ - !ruby/object:Gem::Dependency
364
+ name: turbolinks
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - ">="
368
+ - !ruby/object:Gem::Version
369
+ version: '0'
370
+ type: :development
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - ">="
375
+ - !ruby/object:Gem::Version
376
+ version: '0'
377
+ description:
378
+ email:
379
+ - roberto@vasquez-angel.de
380
+ executables: []
381
+ extensions: []
382
+ extra_rdoc_files: []
383
+ files:
384
+ - MIT-LICENSE
385
+ - README.md
386
+ - Rakefile
387
+ - app/assets/config/cmor/multi_tenancy_manifest.js
388
+ - app/assets/exceptions/cmor/multi_tenancy/current_client_not_set.rb
389
+ - app/assets/javascripts/cmor/multi_tenancy/application.js
390
+ - app/assets/javascripts/cmor/multi_tenancy/application/keep.js
391
+ - app/assets/javascripts/cmor_multi_tenancy.js
392
+ - app/assets/stylesheets/cmor/multi_tenancy/application.css
393
+ - app/assets/stylesheets/cmor/multi_tenancy/application/keep.css
394
+ - app/assets/stylesheets/cmor_multi_tenancy.css
395
+ - app/concerns/cmor/multi_tenancy/controller/current_client_concern.rb
396
+ - app/concerns/cmor/multi_tenancy/model/client_concern.rb
397
+ - app/controllers/cmor/multi_tenancy/clients_controller.rb
398
+ - app/controllers/cmor/multi_tenancy/home_controller.rb
399
+ - app/exceptions/cmor/multi_tenancy/current_client_not_set.rb
400
+ - app/exceptions/cmor/multi_tenancy/default_client_not_found.rb
401
+ - app/models/cmor/multi_tenancy/client.rb
402
+ - app/routing_constraints/cmor/multi_tenancy/routing/subdomain_constraint.rb
403
+ - app/services/cmor/multi_tenancy/create_client_service.rb
404
+ - app/services/cmor/multi_tenancy/seed_service.rb
405
+ - app/view_helpers/cmor/multi_tenancy/application_view_helper.rb
406
+ - app/views/cmor/multi_tenancy/clients/_form.html.haml
407
+ - config/initializers/assets.rb
408
+ - config/initializers/cmor.rb
409
+ - config/locales/de.yml
410
+ - config/locales/en.yml
411
+ - config/routes.rb
412
+ - db/migrate/20200327161253_create_cmor_multi_tenancy_clients.rb
413
+ - lib/cmor/multi_tenancy.rb
414
+ - lib/cmor/multi_tenancy/configuration.rb
415
+ - lib/cmor/multi_tenancy/engine.rb
416
+ - lib/cmor/multi_tenancy/spec_helpers/generic.rb
417
+ - lib/cmor/multi_tenancy/spec_helpers/system.rb
418
+ - lib/cmor/multi_tenancy/version.rb
419
+ - lib/cmor_multi_tenancy.rb
420
+ - lib/generators/cmor/multi_tenancy/install/install_generator.rb
421
+ - lib/generators/cmor/multi_tenancy/install/templates/app/models/client.rb
422
+ - lib/generators/cmor/multi_tenancy/install/templates/initializer.rb
423
+ - lib/generators/cmor/multi_tenancy/install/templates/routes.source
424
+ - lib/tasks/cmor/multi_tenancy_tasks.rake
425
+ - spec/factories/cmor_multi_tenancy_client.rb
426
+ homepage: https://github.com/content-management-on-rails
427
+ licenses:
428
+ - MIT
429
+ metadata:
430
+ allowed_push_host: https://rubygems.org
431
+ post_install_message:
432
+ rdoc_options: []
433
+ require_paths:
434
+ - lib
435
+ required_ruby_version: !ruby/object:Gem::Requirement
436
+ requirements:
437
+ - - ">="
438
+ - !ruby/object:Gem::Version
439
+ version: '0'
440
+ required_rubygems_version: !ruby/object:Gem::Requirement
441
+ requirements:
442
+ - - ">"
443
+ - !ruby/object:Gem::Version
444
+ version: 1.3.1
445
+ requirements: []
446
+ rubygems_version: 3.1.3
447
+ signing_key:
448
+ specification_version: 4
449
+ summary: Cmor::MultiTenancy Module.
450
+ test_files: []