milia 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +35 -26
- data/lib/milia/control.rb +1 -2
- data/lib/milia/version.rb +1 -1
- data/test/Gemfile.lock +1 -1
- data/test/config/application.rb +4 -4
- data/test/config/environments/production.rb +2 -2
- data/test/config/environments/test.rb +3 -3
- data/test/test/controllers/home_controller_test.rb +8 -9
- data/test/test/ctlr_test_helper.rb +4 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b17d04a8171ccbdc169aa06e5f1d28c5e850c3e2
|
4
|
+
data.tar.gz: c5d93e06cbd053b83c4704ba0fabcd6b1c809c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76db8065475838404861cada72daaad22cd582c3233ff455ce411a3daf512de8bad59c71788684db5e6cb524758af7620d15013c7efe4df502b62811bc00b81a
|
7
|
+
data.tar.gz: 1fa75ebac26ede1a0f394e3fac189e20753af27bcd44d6247377856d1ab1838c4a6f10be693d091ac7a3698fb95cd80cad791a544fc13f0652e434313e424889
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,29 +1,38 @@
|
|
1
|
-
# milia
|
1
|
+
# milia
|
2
|
+
[](https://travis-ci.org/jekuno/milia)
|
2
3
|
|
3
|
-
Milia is a multi-tenanting gem for
|
4
|
-
|
5
|
-
|
4
|
+
Milia is a multi-tenanting gem for Ruby on Rails applications.
|
5
|
+
|
6
|
+
* Milia is a solid choice for (SaaS) applications which are used by more than one tenant (i.e. companies or organizations) and is tailored for common use cases of multi-tenanted applications.
|
7
|
+
* Milia allows to save the data of all tenants in the same database and enforces row based separation of the tenant data.
|
8
|
+
* Milia uses the devise gem for user authentication and registration.
|
9
|
+
|
10
|
+
You are viewing the documentation of the milia branch for **Rails 4.2.x** applications.
|
11
|
+
Milia also supports **Rails 5.x**. Please consider the according [README](../rails5-support/README.md) of the [Rails5 branch](../../tree/rails5-support/).
|
6
12
|
|
7
13
|
## Basic concepts for the milia multi-tenanting gem
|
8
14
|
|
9
|
-
###
|
10
|
-
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
*
|
18
|
-
*
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
the
|
23
|
-
rows but not an enormous number of schema (tables)
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
### Milia highlights
|
16
|
+
|
17
|
+
* Transparent to the main application code
|
18
|
+
* Symbiotic with user authentication
|
19
|
+
* Raises exceptions upon attempted illegal access
|
20
|
+
* Enforces tenanting (not allow sloppy access to all tenant records)
|
21
|
+
* Allows application flexibility upon new tenant sign-up, usage of eula information, etc
|
22
|
+
* As non-invasive (as possible) to Rails code
|
23
|
+
* Uses row-based tenanting
|
24
|
+
* Uses default_scope to enforce tenanting
|
25
|
+
|
26
|
+
### Row based vs. schema based tenanting
|
27
|
+
* Milia uses row based tenanting.
|
28
|
+
* The author used schema-based tenanting in the past but found it deficient for the following reasons. Schema-based tenancy
|
29
|
+
* is not what DBMS are optimized for (most DBMS are optimized to handle enormous number of rows but not an enormous number of schema (tables)),
|
30
|
+
* took a performance hit,
|
31
|
+
* was seriously time-consuming to backup and restore,
|
32
|
+
* was invasive into the Rails code structure (monkey patching),
|
33
|
+
* was complex to implement, and
|
34
|
+
* couldn't use Rails migration tools as-is.
|
35
|
+
* Heroku also [strongly recommends against](https://devcenter.heroku.com/articles/heroku-postgresql#multiple-schemas) using schema based tenanting.
|
27
36
|
|
28
37
|
### tenants/users vs organizations/members
|
29
38
|
|
@@ -93,7 +102,7 @@ Further details about this process can be found via the sources listed below:
|
|
93
102
|
this sample on github, however, will always be for the latest release or latest beta (whichever is most recent).
|
94
103
|
* find it at: https://github.com/dsaronin/sample-milia-app
|
95
104
|
|
96
|
-
### Available
|
105
|
+
### Available documentation resources for milia
|
97
106
|
|
98
107
|
* doc/sample.sh -- this document will ALWAYS be the most recent
|
99
108
|
(for example in the edge branch: "newdev")
|
@@ -819,13 +828,13 @@ tenanted areas even if no records are returned. This is a potential security
|
|
819
828
|
breach. Further details can be found in various discussions about the
|
820
829
|
behavior of databases such as POSTGRES.
|
821
830
|
|
822
|
-
The milia workaround is to add an additional .where(
|
831
|
+
The milia workaround is to add an additional .where( where_restrict_tenant(klass1, klass2,...))
|
823
832
|
for each of the subordinate models in the join.
|
824
833
|
|
825
|
-
### usage of
|
834
|
+
### usage of where_restrict_tenant
|
826
835
|
|
827
836
|
```ruby
|
828
|
-
Comment.joins(stuff).where(
|
837
|
+
Comment.joins(stuff).where( where_restrict_tenant(Post, Author) ).all
|
829
838
|
```
|
830
839
|
|
831
840
|
## no tenant authorization required controller actions: root_path
|
data/lib/milia/control.rb
CHANGED
@@ -99,11 +99,10 @@ module Milia
|
|
99
99
|
# -- sets current tenant
|
100
100
|
# ------------------------------------------------------------------------------
|
101
101
|
def authenticate_tenant!()
|
102
|
-
unless authenticate_user!
|
102
|
+
unless authenticate_user!(force: true)
|
103
103
|
email = ( params.nil? || params[:user].nil? ? "<email missing>" : params[:user][:email] )
|
104
104
|
flash[:error] = "cannot sign in as #{email}; check email/password"
|
105
105
|
logger.info("MILIA >>>>> [failed auth user] ") unless logger.nil?
|
106
|
-
return false # abort the before_filter chain
|
107
106
|
end
|
108
107
|
|
109
108
|
trace_tenanting( "authenticate_tenant!" )
|
data/lib/milia/version.rb
CHANGED
data/test/Gemfile.lock
CHANGED
data/test/config/application.rb
CHANGED
@@ -14,10 +14,10 @@ module Miliatest
|
|
14
14
|
# uncomment to ensure a common layout for devise forms
|
15
15
|
|
16
16
|
config.to_prepare do # Devise
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
Devise::SessionsController.layout "sign"
|
18
|
+
Devise::RegistrationsController.layout "sign"
|
19
|
+
Devise::ConfirmationsController.layout "sign"
|
20
|
+
Devise::PasswordsController.layout "sign"
|
21
21
|
end # Devise
|
22
22
|
|
23
23
|
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Miliatest::Application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
3
|
+
|
4
4
|
# devise says to define default url
|
5
5
|
config.action_mailer.default_url_options = { :host => 'secure.simple-milia-app.com', :protocol => 'https' }
|
6
6
|
|
@@ -35,7 +35,7 @@ Miliatest::Application.configure do
|
|
35
35
|
# config.action_dispatch.rack_cache = true
|
36
36
|
|
37
37
|
# Disable Rails's static asset server (Apache or nginx will already do this).
|
38
|
-
config.
|
38
|
+
config.serve_static_files = false
|
39
39
|
|
40
40
|
# Compress JavaScripts and CSS.
|
41
41
|
config.assets.js_compressor = :uglifier
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Miliatest::Application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
3
|
+
|
4
4
|
# devise says to define default url
|
5
5
|
config.action_mailer.default_url_options = { :host => "www.example.com" }
|
6
6
|
|
@@ -17,7 +17,7 @@ Miliatest::Application.configure do
|
|
17
17
|
config.eager_load = false
|
18
18
|
|
19
19
|
# Configure static asset server for tests with Cache-Control for performance.
|
20
|
-
config.
|
20
|
+
config.serve_static_files = true
|
21
21
|
config.static_cache_control = "public, max-age=3600"
|
22
22
|
|
23
23
|
# Show full error reports and disable caching.
|
@@ -34,7 +34,7 @@ Miliatest::Application.configure do
|
|
34
34
|
# The :test delivery method accumulates sent emails in the
|
35
35
|
# ActionMailer::Base.deliveries array.
|
36
36
|
config.action_mailer.delivery_method = :test
|
37
|
-
|
37
|
+
|
38
38
|
config.active_record.logger = nil
|
39
39
|
|
40
40
|
# Print deprecation notices to the stderr.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ctlr_test_helper'
|
2
2
|
|
3
3
|
class HomeControllerTest < ActionController::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context 'home ctlr' do
|
6
6
|
setup do
|
7
7
|
Tenant.set_current_tenant( tenants( :tenant_1 ).id )
|
@@ -20,11 +20,10 @@ class HomeControllerTest < ActionController::TestCase
|
|
20
20
|
end # should do
|
21
21
|
|
22
22
|
should 'not get show without login' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end # should do
|
23
|
+
get :show
|
24
|
+
# redirects to sign in page
|
25
|
+
assert_redirected_to new_user_session_path
|
26
|
+
end # should do
|
28
27
|
|
29
28
|
should 'reset tenant' do
|
30
29
|
assert Tenant.current_tenant_id
|
@@ -70,9 +69,9 @@ class HomeControllerTest < ActionController::TestCase
|
|
70
69
|
|
71
70
|
should 'prep signup view' do
|
72
71
|
assert_nil @controller.instance_eval( "@tenant" )
|
73
|
-
@controller.prep_signup_view(
|
74
|
-
{ name: 'Mangoland' },
|
75
|
-
{email: 'billybob@bob.com', password: 'monkeymocha', password_confirmation: 'monkeymocha'}
|
72
|
+
@controller.prep_signup_view(
|
73
|
+
{ name: 'Mangoland' },
|
74
|
+
{email: 'billybob@bob.com', password: 'monkeymocha', password_confirmation: 'monkeymocha'}
|
76
75
|
)
|
77
76
|
assert_equal 'Mangoland', @controller.instance_eval( "@tenant" ).name
|
78
77
|
end # should do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: milia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daudi amani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- ".ruby-gemset"
|
122
122
|
- ".ruby-version"
|
123
123
|
- ".slugignore"
|
124
|
+
- ".travis.yml"
|
124
125
|
- Gemfile
|
125
126
|
- LICENSE.txt
|
126
127
|
- README.md
|