comable-apartment 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
@@ -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
|
data/.travis.yml
ADDED
@@ -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
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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
|
data/Rakefile
ADDED
@@ -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
|
File without changes
|
@@ -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,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,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,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
|