comable-apartment 0.0.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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.md +56 -0
- data/Rakefile +19 -0
- data/app/assets/javascripts/comable/apartment/application.coffee +14 -0
- data/app/assets/javascripts/comable/apartment/dispatcher.coffee +0 -0
- data/app/assets/stylesheets/comable/apartment/application.scss +10 -0
- data/app/controllers/comable/apartment/application_controller.rb +57 -0
- data/app/controllers/comable/apartment/dashboard_controller.rb +10 -0
- data/app/controllers/comable/apartment/tenants_controller.rb +55 -0
- data/app/controllers/comable/apartment/user_sessions_controller.rb +8 -0
- data/app/controllers/comable/apartment/users_controller.rb +67 -0
- data/app/decorators/comable/ability_decorator.rb +17 -0
- data/app/decorators/comable/user_decorator.rb +8 -0
- data/app/helpers/comable/apartment/application_helper.rb +19 -0
- data/app/models/comable/tenant.rb +59 -0
- data/app/navigations/comable/apartment/application.rb +34 -0
- data/app/views/comable/apartment/dashboard/show.slim +8 -0
- data/app/views/comable/apartment/tenants/_form.slim +19 -0
- data/app/views/comable/apartment/tenants/edit.slim +27 -0
- data/app/views/comable/apartment/tenants/index.slim +54 -0
- data/app/views/comable/apartment/tenants/new.slim +16 -0
- data/app/views/comable/apartment/user_sessions/new.slim +25 -0
- data/app/views/comable/apartment/users/_form.slim +24 -0
- data/app/views/comable/apartment/users/edit.slim +34 -0
- data/app/views/comable/apartment/users/index.slim +34 -0
- data/app/views/comable/apartment/users/new.slim +21 -0
- data/app/views/comable/apartment/users/show.slim +33 -0
- data/app/views/layouts/comable/apartment/application.slim +17 -0
- data/comable-apartment.gemspec +46 -0
- data/config/initializers/comable-apartment.rb +4 -0
- data/config/initializers/devise.rb +3 -0
- data/config/locales/en.yml +27 -0
- data/config/locales/ja.yml +27 -0
- data/config/routes.rb +14 -0
- data/db/migrate/20150729091221_create_comable_tenant.rb +9 -0
- data/db/seeds.rb +5 -0
- data/db/seeds/comable/users.rb +51 -0
- data/gemfiles/active_record_40.gemfile +4 -0
- data/gemfiles/active_record_41.gemfile +4 -0
- data/gemfiles/active_record_42.gemfile +4 -0
- data/gemfiles/active_record_edge.gemfile +8 -0
- data/gemfiles/common.gemfile +2 -0
- data/lib/comable/apartment.rb +62 -0
- data/lib/comable/apartment/constraint.rb +19 -0
- data/lib/comable/apartment/engine.rb +13 -0
- data/lib/comable/apartment/tasks/release.rake +50 -0
- data/lib/comable/apartment/version.rb +5 -0
- data/test/controllers/comable/apartment/tenants_controller_test.rb +71 -0
- data/test/controllers/comable/apartment/users_controller_test.rb +80 -0
- data/test/dummy/Rakefile +2 -0
- data/test/dummy/bin/rails +3 -0
- data/test/dummy/config.ru +2 -0
- data/test/dummy/config/application.rb +53 -0
- data/test/dummy/config/database.yml +18 -0
- data/test/dummy/db/.gitkeep +0 -0
- data/test/dummy/db/migrate/20150814140744_create_comable_products.comable.rb +16 -0
- data/test/dummy/db/migrate/20150814140745_create_comable_users.comable.rb +47 -0
- data/test/dummy/db/migrate/20150814140746_create_comable_stocks.comable.rb +15 -0
- data/test/dummy/db/migrate/20150814140747_create_comable_orders.comable.rb +21 -0
- data/test/dummy/db/migrate/20150814140748_create_comable_order_items.comable.rb +20 -0
- data/test/dummy/db/migrate/20150814140749_create_comable_payment_methods.comable.rb +14 -0
- data/test/dummy/db/migrate/20150814140750_create_comable_shipment_methods.comable.rb +12 -0
- data/test/dummy/db/migrate/20150814140751_create_comable_stores.comable.rb +12 -0
- data/test/dummy/db/migrate/20150814140752_create_comable_addresses.comable.rb +18 -0
- data/test/dummy/db/migrate/20150814140753_create_comable_categories.comable.rb +11 -0
- data/test/dummy/db/migrate/20150814140754_create_comable_products_categories.comable.rb +9 -0
- data/test/dummy/db/migrate/20150814140755_create_comable_images.comable.rb +10 -0
- data/test/dummy/db/migrate/20150814140756_create_comable_shipments.comable.rb +14 -0
- data/test/dummy/db/migrate/20150814140757_create_comable_payments.comable.rb +13 -0
- data/test/dummy/db/migrate/20150814140758_create_comable_trackers.comable.rb +13 -0
- data/test/dummy/db/migrate/20150814140759_create_comable_pages.comable.rb +18 -0
- data/test/dummy/db/migrate/20150814140760_create_comable_themes.comable.rb +16 -0
- data/test/dummy/db/migrate/20150814140761_add_theme_id_to_comable_stores.comable.rb +8 -0
- data/test/factories/comable/tenants.rb +6 -0
- data/test/factories/comable/users.rb +6 -0
- data/test/lib/comable/apartment/version_test.rb +7 -0
- data/test/lib/comable/apartment_test.rb +27 -0
- data/test/minitest_helper.rb +29 -0
- data/test/models/comable/tenant_test.rb +81 -0
- data/test/support/have_attributes.rb +36 -0
- metadata +529 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
en:
|
2
|
+
comable:
|
3
|
+
apartment:
|
4
|
+
access_denied: 'Access denied'
|
5
|
+
comable_apartment_provides_multi_tenancy: 'Comable Apartment provides multi-tenancy.'
|
6
|
+
confirmation_before_destroy: 'This operation cannot be undone. Would you like to proceed?'
|
7
|
+
dashboard: 'Dashboard'
|
8
|
+
destroy: 'Destory'
|
9
|
+
edit: 'Edit'
|
10
|
+
general: 'General'
|
11
|
+
manage_tenants: 'Manage the tenants'
|
12
|
+
new: 'New'
|
13
|
+
not_found: 'Record not found.'
|
14
|
+
results: 'results'
|
15
|
+
save: 'Save'
|
16
|
+
sign_in: 'Login'
|
17
|
+
sign_out: 'Logout'
|
18
|
+
tenants: 'Tenants'
|
19
|
+
users: 'Admin users'
|
20
|
+
visit_store: 'Visit the store'
|
21
|
+
visit_admin: 'Visit the admin panel'
|
22
|
+
you_can_manage_tenants_form_this_page: 'You can manage the tenants form this page.'
|
23
|
+
|
24
|
+
enumerize:
|
25
|
+
comable/user:
|
26
|
+
role:
|
27
|
+
root: 'Superuser'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
ja:
|
2
|
+
comable:
|
3
|
+
apartment:
|
4
|
+
access_denied: 'アクセス権がありません'
|
5
|
+
comable_apartment_provides_multi_tenancy: 'Comable Apartmentはマルチテナントを実現を可能にします。'
|
6
|
+
confirmation_before_destroy: 'この操作は元に戻せません。本当に削除してもよろしいですか?'
|
7
|
+
dashboard: 'ダッシュボード'
|
8
|
+
destroy: '削除'
|
9
|
+
edit: '編集'
|
10
|
+
general: '一般'
|
11
|
+
manage_tenants: 'テナント管理'
|
12
|
+
new: '新規作成'
|
13
|
+
not_found: 'レコードが見つかりませんでした。'
|
14
|
+
results: '件'
|
15
|
+
save: '保存'
|
16
|
+
sign_in: 'ログイン'
|
17
|
+
sign_out: 'ログアウト'
|
18
|
+
tenants: 'テナント'
|
19
|
+
users: '管理者'
|
20
|
+
visit_store: 'ストアを見る'
|
21
|
+
visit_admin: '管理画面を見る'
|
22
|
+
you_can_manage_tenants_form_this_page: 'このページからテナントを管理することができます。'
|
23
|
+
|
24
|
+
enumerize:
|
25
|
+
comable/user:
|
26
|
+
role:
|
27
|
+
root: 'スーパーユーザー'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Comable::Apartment::Engine.routes.draw do
|
2
|
+
root to: 'dashboard#show'
|
3
|
+
|
4
|
+
devise_for :root_user, path: :user, class_name: Comable::User.name, module: :devise, router_name: :comable_apartment, controllers: {
|
5
|
+
sessions: 'comable/apartment/user_sessions'
|
6
|
+
}
|
7
|
+
|
8
|
+
resources :tenants do
|
9
|
+
resources :users
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO: Change to 404 page
|
13
|
+
get '*path', controller: :dashboard, action: :show
|
14
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'highline/import'
|
2
|
+
|
3
|
+
def default_email
|
4
|
+
'comable@example.com'
|
5
|
+
end
|
6
|
+
|
7
|
+
def default_password
|
8
|
+
'password'
|
9
|
+
end
|
10
|
+
|
11
|
+
def ask_root_email
|
12
|
+
if ENV['ROOT_EMAIL']
|
13
|
+
ENV['ROOT_EMAIL']
|
14
|
+
else
|
15
|
+
ask("Email [#{default_email}]: ") do |q|
|
16
|
+
q.echo = true
|
17
|
+
q.whitespace = :strip
|
18
|
+
end
|
19
|
+
end.presence || default_email
|
20
|
+
end
|
21
|
+
|
22
|
+
def ask_root_password
|
23
|
+
if ENV['ROOT_PASSWORD']
|
24
|
+
ENV['ROOT_PASSWORD']
|
25
|
+
else
|
26
|
+
ask("Password [#{default_password}]: ") do |q|
|
27
|
+
q.echo = false
|
28
|
+
q.whitespace = :strip
|
29
|
+
end
|
30
|
+
end.presence || default_password
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_root_user
|
34
|
+
email = ask_root_email
|
35
|
+
password = ask_root_password
|
36
|
+
|
37
|
+
if Comable::User.where(email: email).exists?
|
38
|
+
puts "WARNING: The email address has already existed: #{email}"
|
39
|
+
else
|
40
|
+
Comable::User.with_role(:root).new do |obj|
|
41
|
+
obj.email = email
|
42
|
+
obj.password = password
|
43
|
+
end.save!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if Comable::User.with_role(:root).exists?
|
48
|
+
puts 'Root user has already been previously created.'
|
49
|
+
else
|
50
|
+
create_root_user
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'slim-rails'
|
2
|
+
require 'sass-rails'
|
3
|
+
require 'coffee-rails'
|
4
|
+
require 'compass-rails'
|
5
|
+
require 'uglifier'
|
6
|
+
require 'bootstrap-sass'
|
7
|
+
require 'font-awesome-rails'
|
8
|
+
require 'dynamic_form'
|
9
|
+
require 'jquery-rails'
|
10
|
+
require 'jquery-ui-rails'
|
11
|
+
require 'raphael-rails'
|
12
|
+
require 'morrisjs-rails'
|
13
|
+
require 'nprogress-rails'
|
14
|
+
require 'turbolinks'
|
15
|
+
require 'jquery-turbolinks'
|
16
|
+
require 'awesome_admin_layout'
|
17
|
+
|
18
|
+
require 'apartment'
|
19
|
+
require 'apartment/elevators/generic'
|
20
|
+
require 'comable/core'
|
21
|
+
require 'comable/apartment/constraint'
|
22
|
+
require 'comable/apartment/engine'
|
23
|
+
require 'comable/apartment/version'
|
24
|
+
|
25
|
+
module Comable
|
26
|
+
module Apartment
|
27
|
+
DEFAULT_EXCLUDED_MODELS = %w(
|
28
|
+
Comable::Tenant
|
29
|
+
)
|
30
|
+
|
31
|
+
class << self
|
32
|
+
delegate :excluded_models, :tenant_names, to: ::Apartment
|
33
|
+
|
34
|
+
def config
|
35
|
+
yield self if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
def excluded_models=(models)
|
39
|
+
::Apartment.configure { |config| config.excluded_models = models }
|
40
|
+
end
|
41
|
+
|
42
|
+
def tenant_names=(names)
|
43
|
+
::Apartment.configure { |config| config.tenant_names = names }
|
44
|
+
end
|
45
|
+
|
46
|
+
def translate(key, options = {})
|
47
|
+
I18n.translate("comable.apartment.#{key}", options)
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :t, :translate
|
51
|
+
|
52
|
+
def routes(router, options = {})
|
53
|
+
options.reverse_merge! at: '/'
|
54
|
+
router.instance_eval do
|
55
|
+
constraints Comable::Apartment::Constraint do
|
56
|
+
mount Comable::Apartment::Engine, options
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Comable
|
2
|
+
module Apartment
|
3
|
+
class Constraint
|
4
|
+
class << self
|
5
|
+
def matches?(request)
|
6
|
+
request_to_apartment? request
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def request_to_apartment?(request)
|
12
|
+
tenant = Comable::Tenant.from_request(request)
|
13
|
+
tenant.switch!
|
14
|
+
tenant.new_record?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Comable
|
2
|
+
module Apartment
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
isolate_namespace Comable::Apartment
|
5
|
+
|
6
|
+
config.to_prepare do
|
7
|
+
Dir.glob(Comable::Apartment::Engine.root.join('app/decorators/comable/*_decorator.rb')).each do |c|
|
8
|
+
Rails.configuration.cache_classes ? require_dependency(c) : load(c)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'comable/apartment/version'
|
2
|
+
|
3
|
+
root = File.expand_path('../../../../../', __FILE__)
|
4
|
+
version = Comable::Apartment::VERSION
|
5
|
+
tag = "v#{version}"
|
6
|
+
|
7
|
+
directory 'pkg'
|
8
|
+
|
9
|
+
namespace :comable do
|
10
|
+
namespace :apartment do
|
11
|
+
gemname = 'comable-apartment'
|
12
|
+
gem = "#{gemname}-#{version}.gem"
|
13
|
+
gemspec = "#{gemname}.gemspec"
|
14
|
+
|
15
|
+
task :clean do
|
16
|
+
rm_f "pkg/#{gem}"
|
17
|
+
end
|
18
|
+
|
19
|
+
task :build => :pkg do
|
20
|
+
sh "gem build #{gemspec} && mv #{gem} #{root}/pkg/"
|
21
|
+
end
|
22
|
+
|
23
|
+
task :install => :build do
|
24
|
+
sh "gem install pkg/#{gem}"
|
25
|
+
end
|
26
|
+
|
27
|
+
task :push => :build do
|
28
|
+
sh 'git push'
|
29
|
+
sh "gem push pkg/#{gem}"
|
30
|
+
end
|
31
|
+
|
32
|
+
task :commit do
|
33
|
+
File.open('pkg/commit_message.txt', 'w') do |f|
|
34
|
+
f.puts "# Bump to #{version}\n"
|
35
|
+
f.puts
|
36
|
+
f.puts '# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT'
|
37
|
+
end
|
38
|
+
|
39
|
+
sh 'git commit --verbose --template=pkg/commit_message.txt'
|
40
|
+
rm_f 'pkg/commit_message.txt'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :tag do
|
44
|
+
sh "git tag -m '#{tag} release' #{tag}"
|
45
|
+
sh 'git push --tags'
|
46
|
+
end
|
47
|
+
|
48
|
+
task :release => %w(clean build commit tag push)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class Comable::Apartment::TenantsControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@routes = Comable::Apartment::Engine.routes
|
6
|
+
|
7
|
+
sign_in :root_user, create(:user, role: :root)
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'should get index' do
|
11
|
+
tenant = create(:tenant)
|
12
|
+
tenant.create
|
13
|
+
get :index
|
14
|
+
assert_includes assigns(:tenants), tenant
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'should get new tenant' do
|
18
|
+
get :new
|
19
|
+
assert_instance_of Comable::Tenant, assigns(:tenant)
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should create tenant' do
|
23
|
+
assert_difference('Comable::Tenant.count') do
|
24
|
+
post :create, tenant: attributes_for(:tenant)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'should redirect to the tenant after create tenant' do
|
29
|
+
post :create, tenant: attributes_for(:tenant)
|
30
|
+
assert_redirected_to tenant_path(assigns(:tenant))
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'should show tenant' do
|
34
|
+
tenant = create(:tenant)
|
35
|
+
get :show, id: tenant
|
36
|
+
assert_response :success
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'should get edit' do
|
40
|
+
tenant = create(:tenant)
|
41
|
+
get :edit, id: tenant
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'should update tenant' do
|
46
|
+
tenant = create(:tenant)
|
47
|
+
valid_attributes = { domain: "new-#{tenant.domain}" }
|
48
|
+
patch :update, id: tenant, tenant: valid_attributes
|
49
|
+
assert_have_attributes valid_attributes, tenant.reload.attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'should redirect to the tenant after update tenant' do
|
53
|
+
tenant = create(:tenant)
|
54
|
+
valid_attributes = { domain: "new-#{tenant.domain}" }
|
55
|
+
patch :update, id: tenant, tenant: valid_attributes
|
56
|
+
assert_redirected_to tenant_path(assigns(:tenant))
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'should destroy tenant' do
|
60
|
+
tenant = create(:tenant)
|
61
|
+
assert_difference('Comable::Tenant.count', -1) do
|
62
|
+
delete :destroy, id: tenant
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'should redirect to index after destroy tenant' do
|
67
|
+
tenant = create(:tenant)
|
68
|
+
delete :destroy, id: tenant
|
69
|
+
assert_redirected_to tenants_path
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class Comable::Apartment::UsersControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@routes = Comable::Apartment::Engine.routes
|
6
|
+
|
7
|
+
@tenant = create(:tenant)
|
8
|
+
@tenant.create
|
9
|
+
@tenant.switch!
|
10
|
+
|
11
|
+
# TODO: Create into the "public" schema
|
12
|
+
sign_in :root_user, create(:user, role: :root)
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
@tenant.reset!
|
17
|
+
@tenant.drop
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'should get index' do
|
21
|
+
user = create(:user)
|
22
|
+
get :index, tenant_id: @tenant
|
23
|
+
assert_includes assigns(:users), user
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'should get new user' do
|
27
|
+
get :new, tenant_id: @tenant
|
28
|
+
assert_instance_of Comable::User, assigns(:user)
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should create user' do
|
32
|
+
assert_difference('@tenant.switch { Comable::User.count }') do
|
33
|
+
post :create, tenant_id: @tenant, user: attributes_for(:user)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should redirect to the user after create user' do
|
38
|
+
post :create, tenant_id: @tenant, user: attributes_for(:user)
|
39
|
+
assert_redirected_to tenant_user_path(@tenant, assigns(:user))
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'should show user' do
|
43
|
+
user = create(:user)
|
44
|
+
get :show, tenant_id: @tenant, id: user
|
45
|
+
assert_response :success
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'should get edit' do
|
49
|
+
user = create(:user)
|
50
|
+
get :edit, tenant_id: @tenant, id: user
|
51
|
+
assert_response :success
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'should update user' do
|
55
|
+
user = create(:user)
|
56
|
+
valid_attributes = { email: "new-#{user.email}" }
|
57
|
+
patch :update, tenant_id: @tenant, id: user, user: valid_attributes
|
58
|
+
assert_have_attributes valid_attributes, @tenant.switch { user.reload.attributes }
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'should redirect to the user after update user' do
|
62
|
+
user = create(:user)
|
63
|
+
valid_attributes = { email: "new-#{user.email}" }
|
64
|
+
patch :update, tenant_id: @tenant, id: user, user: valid_attributes
|
65
|
+
assert_redirected_to tenant_user_path(@tenant, assigns(:user))
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'should destroy user' do
|
69
|
+
user = create(:user)
|
70
|
+
assert_difference('@tenant.switch { Comable::User.count }', -1) do
|
71
|
+
delete :destroy, tenant_id: @tenant, id: user
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'should redirect to index after destroy user' do
|
76
|
+
user = create(:user)
|
77
|
+
delete :destroy, tenant_id: @tenant, id: user
|
78
|
+
assert_redirected_to tenant_users_path(@tenant)
|
79
|
+
end
|
80
|
+
end
|