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.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +22 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +4 -0
  6. data/MIT-LICENSE +22 -0
  7. data/README.md +56 -0
  8. data/Rakefile +19 -0
  9. data/app/assets/javascripts/comable/apartment/application.coffee +14 -0
  10. data/app/assets/javascripts/comable/apartment/dispatcher.coffee +0 -0
  11. data/app/assets/stylesheets/comable/apartment/application.scss +10 -0
  12. data/app/controllers/comable/apartment/application_controller.rb +57 -0
  13. data/app/controllers/comable/apartment/dashboard_controller.rb +10 -0
  14. data/app/controllers/comable/apartment/tenants_controller.rb +55 -0
  15. data/app/controllers/comable/apartment/user_sessions_controller.rb +8 -0
  16. data/app/controllers/comable/apartment/users_controller.rb +67 -0
  17. data/app/decorators/comable/ability_decorator.rb +17 -0
  18. data/app/decorators/comable/user_decorator.rb +8 -0
  19. data/app/helpers/comable/apartment/application_helper.rb +19 -0
  20. data/app/models/comable/tenant.rb +59 -0
  21. data/app/navigations/comable/apartment/application.rb +34 -0
  22. data/app/views/comable/apartment/dashboard/show.slim +8 -0
  23. data/app/views/comable/apartment/tenants/_form.slim +19 -0
  24. data/app/views/comable/apartment/tenants/edit.slim +27 -0
  25. data/app/views/comable/apartment/tenants/index.slim +54 -0
  26. data/app/views/comable/apartment/tenants/new.slim +16 -0
  27. data/app/views/comable/apartment/user_sessions/new.slim +25 -0
  28. data/app/views/comable/apartment/users/_form.slim +24 -0
  29. data/app/views/comable/apartment/users/edit.slim +34 -0
  30. data/app/views/comable/apartment/users/index.slim +34 -0
  31. data/app/views/comable/apartment/users/new.slim +21 -0
  32. data/app/views/comable/apartment/users/show.slim +33 -0
  33. data/app/views/layouts/comable/apartment/application.slim +17 -0
  34. data/comable-apartment.gemspec +46 -0
  35. data/config/initializers/comable-apartment.rb +4 -0
  36. data/config/initializers/devise.rb +3 -0
  37. data/config/locales/en.yml +27 -0
  38. data/config/locales/ja.yml +27 -0
  39. data/config/routes.rb +14 -0
  40. data/db/migrate/20150729091221_create_comable_tenant.rb +9 -0
  41. data/db/seeds.rb +5 -0
  42. data/db/seeds/comable/users.rb +51 -0
  43. data/gemfiles/active_record_40.gemfile +4 -0
  44. data/gemfiles/active_record_41.gemfile +4 -0
  45. data/gemfiles/active_record_42.gemfile +4 -0
  46. data/gemfiles/active_record_edge.gemfile +8 -0
  47. data/gemfiles/common.gemfile +2 -0
  48. data/lib/comable/apartment.rb +62 -0
  49. data/lib/comable/apartment/constraint.rb +19 -0
  50. data/lib/comable/apartment/engine.rb +13 -0
  51. data/lib/comable/apartment/tasks/release.rake +50 -0
  52. data/lib/comable/apartment/version.rb +5 -0
  53. data/test/controllers/comable/apartment/tenants_controller_test.rb +71 -0
  54. data/test/controllers/comable/apartment/users_controller_test.rb +80 -0
  55. data/test/dummy/Rakefile +2 -0
  56. data/test/dummy/bin/rails +3 -0
  57. data/test/dummy/config.ru +2 -0
  58. data/test/dummy/config/application.rb +53 -0
  59. data/test/dummy/config/database.yml +18 -0
  60. data/test/dummy/db/.gitkeep +0 -0
  61. data/test/dummy/db/migrate/20150814140744_create_comable_products.comable.rb +16 -0
  62. data/test/dummy/db/migrate/20150814140745_create_comable_users.comable.rb +47 -0
  63. data/test/dummy/db/migrate/20150814140746_create_comable_stocks.comable.rb +15 -0
  64. data/test/dummy/db/migrate/20150814140747_create_comable_orders.comable.rb +21 -0
  65. data/test/dummy/db/migrate/20150814140748_create_comable_order_items.comable.rb +20 -0
  66. data/test/dummy/db/migrate/20150814140749_create_comable_payment_methods.comable.rb +14 -0
  67. data/test/dummy/db/migrate/20150814140750_create_comable_shipment_methods.comable.rb +12 -0
  68. data/test/dummy/db/migrate/20150814140751_create_comable_stores.comable.rb +12 -0
  69. data/test/dummy/db/migrate/20150814140752_create_comable_addresses.comable.rb +18 -0
  70. data/test/dummy/db/migrate/20150814140753_create_comable_categories.comable.rb +11 -0
  71. data/test/dummy/db/migrate/20150814140754_create_comable_products_categories.comable.rb +9 -0
  72. data/test/dummy/db/migrate/20150814140755_create_comable_images.comable.rb +10 -0
  73. data/test/dummy/db/migrate/20150814140756_create_comable_shipments.comable.rb +14 -0
  74. data/test/dummy/db/migrate/20150814140757_create_comable_payments.comable.rb +13 -0
  75. data/test/dummy/db/migrate/20150814140758_create_comable_trackers.comable.rb +13 -0
  76. data/test/dummy/db/migrate/20150814140759_create_comable_pages.comable.rb +18 -0
  77. data/test/dummy/db/migrate/20150814140760_create_comable_themes.comable.rb +16 -0
  78. data/test/dummy/db/migrate/20150814140761_add_theme_id_to_comable_stores.comable.rb +8 -0
  79. data/test/factories/comable/tenants.rb +6 -0
  80. data/test/factories/comable/users.rb +6 -0
  81. data/test/lib/comable/apartment/version_test.rb +7 -0
  82. data/test/lib/comable/apartment_test.rb +27 -0
  83. data/test/minitest_helper.rb +29 -0
  84. data/test/models/comable/tenant_test.rb +81 -0
  85. data/test/support/have_attributes.rb +36 -0
  86. metadata +529 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c93c6a457345f154d239049943e3e195dc38757d
4
+ data.tar.gz: 94408d664caba6d8a375b8b3dd042696d5705ecd
5
+ SHA512:
6
+ metadata.gz: e42b89a3ae224801685f3741432ab08e2fb12c5e707a9f569e77041df7be993f76f9b5655d1023d0b6f180460248df25c2df26b80c61188d8aad541028d592c5
7
+ data.tar.gz: 40fd2fb36c1d4d5e3625b63f2908410281601a6e26b9409d933bb825d592bd0d80789a5431c1ee67455ffe97263ca03310b0370d0655330a691cdf374e1d92a9
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /gemfiles/*.lock
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/dummy/db/schema.rb
11
+ /test/dummy/log/
12
+ /test/dummy/tmp/
13
+ /tmp/
14
+ /vendor/
15
+ *.bundle
16
+ *.so
17
+ *.o
18
+ *.a
19
+ mkmf.log
@@ -0,0 +1,22 @@
1
+ language:
2
+ - ruby
3
+ rvm:
4
+ - 2.1.5
5
+ - 2.2.0
6
+ - ruby-head
7
+ gemfile:
8
+ - gemfiles/active_record_40.gemfile
9
+ - gemfiles/active_record_41.gemfile
10
+ - gemfiles/active_record_42.gemfile
11
+ - gemfiles/active_record_edge.gemfile
12
+ before_script:
13
+ - psql -U postgres -c 'CREATE ROLE dummy WITH LOGIN CREATEDB;'
14
+ # Replace below line after close the folloing issue:
15
+ # https://github.com/influitive/apartment/issues/145
16
+ # `bundle exec rake db:create RAILS_ENV=test`
17
+ - psql -U postgres -c 'CREATE DATABASE dummy_test WITH OWNER=dummy;'
18
+ - bundle exec rake db:migrate RAILS_ENV=test
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+ - gemfile: gemfiles/active_record_edge.gemfile
@@ -0,0 +1,3 @@
1
+ ## Comable::Apartment 0.0.1 (September 15, 2015) ##
2
+
3
+ * Initialize gem.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in comable-apartment.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright 2015 YOSHIDA Hiroki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Comable::Apartment
2
+
3
+ [![Build Status](https://img.shields.io/travis/appirits/comable-apartment.svg?style=flat-square)](http://travis-ci.org/appirits/comable-apartment)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/appirits/comable-apartment.svg?style=flat-square)](https://codeclimate.com/github/appirits/comable-apartment)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/appirits/comable-apartment.svg?style=flat-square)](https://gemnasium.com/appirits/comable-apartment)
6
+ [![Gem Version](https://img.shields.io/gem/v/comable-apartment.svg?style=flat-square)](https://rubygems.org/gems/comable-apartment)
7
+
8
+ Multi-tenancy with [Comable](https://github.com/appirits/comable) using the [Apartment](https://github.com/influitive/apartment) gem.
9
+
10
+ ## Installation
11
+
12
+ 1. Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'comable-apartment'
16
+ ```
17
+
18
+ 2. And then execute:
19
+
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```bash
27
+ $ gem install comable-apartment
28
+ ```
29
+
30
+ 3. Run the generator:
31
+
32
+ ```bash
33
+ $ bin/rake comable_apartment:install:migrations
34
+ ```
35
+
36
+ 4. Add the following to your `config/routes.rb`:
37
+
38
+ ```ruby
39
+ Rails.application.routes.draw do
40
+ Comable::Apartment.routes self
41
+
42
+ ...
43
+ end
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ TODO: Write usage instructions here
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/comable-apartment/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Dir.glob('lib/comable/apartment/tasks/*.rake').each { |r| load r }
5
+
6
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
7
+ load 'rails/tasks/engine.rake'
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ end
13
+
14
+ description = Rake::Task[:release].comment
15
+ Rake::Task[:release].clear
16
+ desc description
17
+ task release: 'comable:apartment:release'
18
+
19
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #= require jquery
2
+ #= require jquery.turbolinks
3
+ #= require jquery_ujs
4
+ #= require jquery-ui
5
+ #= require bootstrap-sprockets
6
+ #= require raphael
7
+ #= require morris
8
+ #= require nprogress
9
+ #= require nprogress-turbolinks
10
+ #= require awesome_admin_layout
11
+ #= require comable/apartment/dispatcher
12
+ #= require_tree .
13
+ #= require_self
14
+ #= require turbolinks
@@ -0,0 +1,10 @@
1
+ @import 'compass/utilities';
2
+ @import 'compass/css3';
3
+ @import 'bootstrap-sprockets';
4
+ @import 'bootstrap';
5
+ @import 'font-awesome';
6
+ @import 'jquery-ui';
7
+ @import 'morris';
8
+ @import 'nprogress';
9
+ @import 'nprogress-bootstrap';
10
+ @import 'awesome_admin_layout';
@@ -0,0 +1,57 @@
1
+ module Comable
2
+ module Apartment
3
+ class ApplicationController < ActionController::Base
4
+ include Comable::ApplicationHelper
5
+ include Comable::Apartment::ApplicationHelper
6
+
7
+ helper_method :current_comable_user
8
+
9
+ before_filter :authenticate_root_user!
10
+
11
+ layout 'comable/apartment/application'
12
+
13
+ def current_ability
14
+ Comable::Ability.new(current_comable_user)
15
+ end
16
+
17
+ def current_comable_user
18
+ current_root_user || Comable::User.new
19
+ end
20
+
21
+ private
22
+
23
+ rescue_from CanCan::AccessDenied, with: :unauthorized
24
+
25
+ def unauthorized
26
+ if current_comable_user.signed_in?
27
+ flash[:alert] = Comable::Apartment.t(:access_denied)
28
+ redirect_to after_access_denied_path
29
+ else
30
+ store_location
31
+ redirect_to comable_apartment.new_root_user_session_path
32
+ end
33
+ end
34
+
35
+ # TODO: Implement this method after add the page for sign in as a another user
36
+ def after_access_denied_path
37
+ fail 'Please implement this method'
38
+ end
39
+
40
+ def after_sign_in_path_for(_resource_or_scope)
41
+ case resource_name
42
+ when :root_user
43
+ comable_apartment.root_path
44
+ # TODO: Delegate to Comable::ApplicationHelper
45
+ when :admin_user
46
+ comable.admin_root_path
47
+ else
48
+ session.delete(:user_return_to) || comable.root_path
49
+ end
50
+ end
51
+
52
+ def after_sign_out_path_for(scope)
53
+ after_sign_in_path_for(scope)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ require_dependency 'comable/apartment/application_controller'
2
+
3
+ module Comable
4
+ module Apartment
5
+ class DashboardController < Comable::Apartment::ApplicationController
6
+ def show
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,55 @@
1
+ require_dependency 'comable/apartment/application_controller'
2
+
3
+ module Comable
4
+ module Apartment
5
+ class TenantsController < Comable::Apartment::ApplicationController
6
+ load_and_authorize_resource class: Comable::Tenant.name, find_by: :name
7
+
8
+ def index
9
+ @tenants = @tenants.order(:created_at)
10
+ end
11
+
12
+ def show
13
+ render :edit
14
+ end
15
+
16
+ def new
17
+ end
18
+
19
+ def create
20
+ if @tenant.save
21
+ redirect_to comable_apartment.tenant_path(@tenant), notice: Comable.t(:successful)
22
+ else
23
+ flash.now[:alert] = Comable.t(:failure)
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def edit
29
+ end
30
+
31
+ def update
32
+ if @tenant.update_attributes(tenant_params)
33
+ redirect_to comable_apartment.tenant_path(@tenant), notice: Comable.t(:successful)
34
+ else
35
+ flash.now[:alert] = Comable.t(:failure)
36
+ render :edit
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @tenant.destroy
42
+ redirect_to comable_apartment.tenants_path, notice: Comable.t(:successful)
43
+ end
44
+
45
+ private
46
+
47
+ def tenant_params
48
+ params.require(:tenant).permit(
49
+ :name,
50
+ :domain
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ module Comable
2
+ module Apartment
3
+ class UserSessionsController < Devise::SessionsController
4
+ helper Comable::Apartment::ApplicationHelper
5
+ layout 'comable/apartment/application'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ require_dependency 'comable/apartment/application_controller'
2
+
3
+ module Comable
4
+ module Apartment
5
+ class UsersController < Comable::Apartment::ApplicationController
6
+ load_and_authorize_resource :tenant, class: Comable::Tenant.name, find_by: :name
7
+ before_filter :switch_tenant
8
+ load_and_authorize_resource :user, class: Comable::User.name
9
+ after_filter :reset_tenant
10
+
11
+ def index
12
+ @users = @users.with_role(*admin_roles)
13
+ end
14
+
15
+ def show
16
+ render :edit
17
+ end
18
+
19
+ def new
20
+ end
21
+
22
+ def create
23
+ if @user.save
24
+ redirect_to comable_apartment.tenant_user_path(@tenant, @user), notice: Comable.t(:successful)
25
+ else
26
+ flash.now[:alert] = Comable.t(:failure)
27
+ render :new
28
+ end
29
+ end
30
+
31
+ def edit
32
+ end
33
+
34
+ def update
35
+ if @user.update_attributes(user_params)
36
+ redirect_to comable_apartment.tenant_user_path(@tenant, @user), notice: Comable.t(:successful)
37
+ else
38
+ flash.now[:alert] = Comable.t(:failure)
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @user.destroy
45
+ redirect_to comable_apartment.tenant_users_path(@tenant), notice: Comable.t(:successful)
46
+ end
47
+
48
+ private
49
+
50
+ def user_params
51
+ params.require(:user).permit(
52
+ :email,
53
+ :password,
54
+ :role
55
+ )
56
+ end
57
+
58
+ def switch_tenant
59
+ @tenant.switch!
60
+ end
61
+
62
+ def reset_tenant
63
+ @tenant.reset!
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ Comable::Ability.class_eval do
2
+ def initialize_with_root(user)
3
+ case user.try(:role)
4
+ when 'root'
5
+ can :manage, :all
6
+ return
7
+ when 'admin'
8
+ cannot :manage, Comable::Tenant
9
+ when 'reporter'
10
+ cannot :read, Comable::Tenant
11
+ end
12
+
13
+ initialize_without_root(user)
14
+ end
15
+
16
+ alias_method_chain :initialize, :root
17
+ end
@@ -0,0 +1,8 @@
1
+ Comable::User.class_eval do
2
+ enumerize :role, in: %i(
3
+ root
4
+ admin
5
+ reporter
6
+ customer
7
+ ), default: :customer, predicates: true, scope: true
8
+ end
@@ -0,0 +1,19 @@
1
+ module Comable
2
+ module Apartment
3
+ module ApplicationHelper
4
+ def link_to_save
5
+ link_to Comable.t('apartment.save'), 'javascript:$("form").submit()', class: 'btn btn-primary'
6
+ end
7
+
8
+ def store_url_options(tenant)
9
+ domain = tenant.domain.presence || request.domain
10
+ subdomain = tenant.name if tenant.domain.blank?
11
+ { domain: domain, subdomain: subdomain }
12
+ end
13
+
14
+ def admin_roles
15
+ Comable::User.role.values - ['customer']
16
+ end
17
+ end
18
+ end
19
+ end