scottmotte-merb-auth-slice-multisite 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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 scottmotte
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.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = merb-auth-slice-multisite
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 scottmotte. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
@@ -0,0 +1,105 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ require 'merb-slices'
6
+ require 'merb-auth-core'
7
+ require 'merb-auth-more'
8
+ require(File.expand_path(File.dirname(__FILE__) / "merb-auth-slice-multisite" / "mixins") / "user_belongs_to_site")
9
+
10
+ Merb::Plugins.add_rakefiles "merb-auth-slice-multisite/merbtasks", "merb-auth-slice-multisite/slicetasks", "merb-auth-slice-multisite/spectasks"
11
+
12
+ # Register the Slice for the current host application
13
+ Merb::Slices::register(__FILE__)
14
+
15
+ # Slice configuration - set this in a before_app_loads callback.
16
+ # By default a Slice uses its own layout, so you can swicht to
17
+ # the main application layout or no layout at all if needed.
18
+ #
19
+ # Configuration options:
20
+ # :layout - the layout to use; defaults to :merb-auth-slice-multisite
21
+ # :mirror - which path component types to use on copy operations; defaults to all
22
+ Merb::Slices::config[:"merb-auth-slice-multisite"][:layout] ||= :application
23
+
24
+ # All Slice code is expected to be namespaced inside a module
25
+ module MerbAuthSliceMultisite
26
+
27
+ # Slice metadata
28
+ self.description = "Merb Slice that adds basic multisite functionality to merb-auth."
29
+ self.version = "0.2"
30
+ self.author = "Scott Motte"
31
+
32
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
33
+ # right after a slice's classes have been loaded internally.
34
+ def self.loaded
35
+ end
36
+
37
+ # Initialization hook - runs before AfterAppLoads BootLoader
38
+ def self.init
39
+ # Actually check if the user belongs to the site
40
+ ::Merb::Authentication.after_authentication do |user, request, params|
41
+ # clean this up somehow
42
+ if request.first_subdomain != nil
43
+ current_site = Site.first(:subdomain => request.first_subdomain)
44
+ if user.site_id != current_site.id
45
+ errors = request.session.authentication.errors
46
+ errors.clear!
47
+ errors.add("Label", "User does not belong to this site.")
48
+ nil
49
+ else
50
+ user
51
+ end
52
+ else
53
+ current_site = Site.first(:domain => request.domain)
54
+ if user.site_id != current_site.id
55
+ errors = request.session.authentication.errors
56
+ errors.clear!
57
+ errors.add("Label", "User does not belong to this site.")
58
+ nil
59
+ else
60
+ user
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ # Activation hook - runs after AfterAppLoads BootLoader
67
+ def self.activate
68
+ end
69
+
70
+ # Deactivation hook - triggered by Merb::Slices.deactivate(MerbAuthSliceMultisite)
71
+ def self.deactivate
72
+ end
73
+
74
+ # Setup routes inside the host application
75
+ #
76
+ # @param scope<Merb::Router::Behaviour>
77
+ # Routes will be added within this scope (namespace). In fact, any
78
+ # router behaviour is a valid namespace, so you can attach
79
+ # routes at any level of your router setup.
80
+ #
81
+ # @note prefix your named routes with :"merb-auth-slice-multisite-
82
+ # to avoid potential conflicts with global named routes.
83
+ def self.setup_router(scope)
84
+ end
85
+
86
+ end
87
+
88
+ # Setup the slice layout for MerbAuthSliceMultisite
89
+ #
90
+ # Use MerbAuthSliceMultisite.push_path and MerbAuthSliceMultisite.push_app_path
91
+ # to set paths to merb-auth-slice-multisite-level and app-level paths. Example:
92
+ #
93
+ # MerbAuthSliceMultisite.push_path(:application, MerbAuthSliceMultisite.root)
94
+ # MerbAuthSliceMultisite.push_app_path(:application, Merb.root / 'slices' / 'merb-auth-slice-multisite')
95
+ # ...
96
+ #
97
+ # Any component path that hasn't been set will default to MerbAuthSliceMultisite.root
98
+ #
99
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
100
+ MerbAuthSliceMultisite.setup_default_structure!
101
+
102
+ # Add dependencies for other MerbAuthSliceMultisite classes below. Example:
103
+ # dependency "merb-auth-slice-multisite/other"
104
+
105
+ end
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :"merb-auth-slice-multisite" do
3
+
4
+ desc "Install MerbAuthSliceMultisite"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ MerbAuthSliceMultisite.mirrored_components.each do |type|
15
+ if File.directory?(MerbAuthSliceMultisite.dir_for(type))
16
+ if !File.directory?(dst_path = MerbAuthSliceMultisite.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for MerbAuthSliceMultisite - resolves any collisions"
28
+ copied, preserved = MerbAuthSliceMultisite.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for MerbAuthSliceMultisite - resolves any collisions"
40
+ copied, preserved = MerbAuthSliceMultisite.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze MerbAuthSliceMultisite into your app (only merb-auth-slice-multisite/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ # desc "Freezes MerbAuthSliceMultisite by installing the gem into application/gems"
56
+ # task :gem do
57
+ # ENV["GEM"] ||= "merb-auth-slice-multisite"
58
+ # Rake::Task['slices:install_as_gem'].invoke
59
+ # end
60
+
61
+ desc "Freezes MerbAuthSliceMultisite by copying all files from merb-auth-slice-multisite/app to your application"
62
+ task :app do
63
+ puts "Copying all merb-auth-slice-multisite/app files to your application - resolves any collisions"
64
+ copied, preserved = MerbAuthSliceMultisite.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = MerbAuthSliceMultisite.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = MerbAuthSliceMultisite.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes MerbAuthSliceMultisite as a gem and copies over merb-auth-slice-multisite/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes MerbAuthSliceMultisite by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking MerbAuthSliceMultisite files to your application - resolves any collisions"
94
+ copied, preserved = MerbAuthSliceMultisite.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,62 @@
1
+ module Merb
2
+ class Authentication
3
+ module Mixins
4
+ # This mixin provides basic user authentication by a site_id.
5
+ #
6
+ # Added properties:
7
+ # :site_id, Integer
8
+ #
9
+ # Added Relationships
10
+ # belongs_to :site
11
+ #
12
+ # Added Validations
13
+ # validates_is_unique :login, :scope => :site_id
14
+ #
15
+ #
16
+ # To use it simply require it and include it into your user class.
17
+ #
18
+ # class User
19
+ # include Authentication::Mixins::UserBelongsToSite
20
+ #
21
+ # end
22
+ #
23
+ #
24
+ # OR I RECOMMEND recommend that you put it in your application under merb/merb-auth/setup.rb so it looks like this:
25
+ # # require 'merb-auth-more/mixins/salted_user'
26
+ # # Merb::Authentication.user_class.class_eval{
27
+ # # include Merb::Authentication::Mixins::SaltedUser
28
+ # # include Merb::Authentication::Mixins::UserBelongsToSite
29
+ # # }
30
+ #
31
+ module UserBelongsToSite
32
+ def self.included(base)
33
+ base.class_eval do
34
+ include Merb::Authentication::Mixins::UserBelongsToSite::InstanceMethods
35
+ extend Merb::Authentication::Mixins::UserBelongsToSite::ClassMethods
36
+
37
+ path = File.expand_path(File.dirname(__FILE__)) / "user_belongs_to_site"
38
+ if defined?(DataMapper) && DataMapper::Resource > self
39
+ require path / "dm_user_belongs_to_site"
40
+ extend(Merb::Authentication::Mixins::UserBelongsToSite::DMClassMethods)
41
+ elsif defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
42
+ require path / "ar_user_belongs_to_site"
43
+ extend(Merb::Authentication::Mixins::UserBelongsToSite::ARClassMethods)
44
+ elsif defined?(Sequel) && ancestors.include?(Sequel::Model)
45
+ require path / "sq_user_belongs_to_site"
46
+ extend(Merb::Authentication::Mixins::UserBelongsToSite::SQClassMethods)
47
+ end
48
+
49
+ end # base.class_eval
50
+ end # self.included
51
+
52
+ module ClassMethods
53
+ #
54
+ end # ClassMethods
55
+
56
+ module InstanceMethods
57
+ #
58
+ end # InstanceMethods
59
+ end # UserBelongsToSite
60
+ end # Mixins
61
+ end # Authentication
62
+ end # Merb
@@ -0,0 +1,26 @@
1
+ module Merb
2
+ class Authentication
3
+ module Mixins
4
+ module UserBelongsToSite
5
+ module DMClassMethods
6
+ def self.extended(base)
7
+ base.class_eval do
8
+ # Schema
9
+ property :site_id, Integer
10
+ # Validations
11
+ validates_is_unique :login, :scope => :site_id
12
+ # Relationships/Associations
13
+ belongs_to :site
14
+ end # base.class_eval
15
+ end # self.extended
16
+ end # DMClassMethods
17
+ end # UserBelongsToSite
18
+ end # Mixins
19
+ end # Authentication
20
+
21
+ class Request
22
+ def first_subdomain
23
+ subdomains.first #subdomains is a request variable array so we take the first array entry
24
+ end #first_subdomain
25
+ end #Request
26
+ end #Merb
@@ -0,0 +1,20 @@
1
+ namespace :slices do
2
+ namespace :"merb-auth-slice-multisite" do
3
+
4
+ # add your own merb-auth-slice-multisite tasks here
5
+
6
+ # # Uncomment the following lines and edit the pre defined tasks
7
+ #
8
+ # # implement this to test for structural/code dependencies
9
+ # # like certain directories or availability of other files
10
+ # desc "Test for any dependencies"
11
+ # task :preflight do
12
+ # end
13
+ #
14
+ # # implement this to perform any database related setup steps
15
+ # desc "Migrate the database"
16
+ # task :migrate do
17
+ # end
18
+
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ namespace :slices do
2
+ namespace :"merb-auth-slice-multisite" do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running MerbAuthSliceMultisite specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all request specs, run a spec for a specific request with REQUEST=MyRequest"
34
+ Spec::Rake::SpecTask.new('request') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['REQUEST'])
37
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/#{ENV['REQUEST']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all specs and output the result in html"
44
+ Spec::Rake::SpecTask.new('html') do |t|
45
+ t.spec_opts = ["--format", "html"]
46
+ t.libs = ['lib', 'server/lib' ]
47
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
File without changes
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "MerbAuthSliceMultisite (module)" do
4
+
5
+ # Implement your MerbAuthSliceMultisite specs here
6
+
7
+ # To spec MerbAuthSliceMultisite you need to hook it up to the router like this:
8
+
9
+ # before :all do
10
+ # Merb::Router.prepare { add_slice(:MerbAuthSliceMultisite) } if standalone?
11
+ # end
12
+ #
13
+ # after :all do
14
+ # Merb::Router.reset! if standalone?
15
+ # end
16
+ #
17
+ #
18
+ # it "should have proper specs"
19
+
20
+ end
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'merb-slices'
4
+ require 'spec'
5
+
6
+ # Add merb-auth-slice-multisite.rb to the search path
7
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
8
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb-auth-slice-multisite.rb')
9
+
10
+ # Require merb-auth-slice-multisite.rb explicitly so any dependencies are loaded
11
+ require Merb::Plugins.config[:merb_slices][:search_path]
12
+
13
+ # Using Merb.root below makes sure that the correct root is set for
14
+ # - testing standalone, without being installed as a gem and no host application
15
+ # - testing from within the host application; its root will be used
16
+ Merb.start_environment(
17
+ :testing => true,
18
+ :adapter => 'runner',
19
+ :environment => ENV['MERB_ENV'] || 'test',
20
+ :session_store => 'memory'
21
+ )
22
+
23
+ module Merb
24
+ module Test
25
+ module SliceHelper
26
+
27
+ # The absolute path to the current slice
28
+ def current_slice_root
29
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
30
+ end
31
+
32
+ # Whether the specs are being run from a host application or standalone
33
+ def standalone?
34
+ Merb.root == ::MerbAuthSliceMultisite.root
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ Spec::Runner.configure do |config|
42
+ config.include(Merb::Test::ViewHelper)
43
+ config.include(Merb::Test::RouteHelper)
44
+ config.include(Merb::Test::ControllerHelper)
45
+ config.include(Merb::Test::SliceHelper)
46
+ end
47
+
48
+ # You can add your own helpers here
49
+ #
50
+ Merb::Test.add_helpers do
51
+ def mount_slice
52
+ Merb::Router.prepare { add_slice(:MerbAuthSliceMultisite, "merb-auth-slice-multisite") } if standalone?
53
+ end
54
+
55
+ def dismount_slice
56
+ Merb::Router.reset! if standalone?
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MerbAuthSliceMultisiteTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'merb_auth_slice_multisite'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scottmotte-merb-auth-slice-multisite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - scottmotte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: scott@scottmotte.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/merb-auth-slice-multisite
29
+ - lib/merb-auth-slice-multisite/merbtasks.rb
30
+ - lib/merb-auth-slice-multisite/mixins
31
+ - lib/merb-auth-slice-multisite/mixins/user_belongs_to_site
32
+ - lib/merb-auth-slice-multisite/mixins/user_belongs_to_site/dm_user_belongs_to_site.rb
33
+ - lib/merb-auth-slice-multisite/mixins/user_belongs_to_site.rb
34
+ - lib/merb-auth-slice-multisite/slicetasks.rb
35
+ - lib/merb-auth-slice-multisite/spectasks.rb
36
+ - lib/merb-auth-slice-multisite.rb
37
+ - lib/merb_auth_slice_multisite.rb
38
+ - test/merb_auth_slice_multisite_test.rb
39
+ - test/test_helper.rb
40
+ - spec/merb-auth-slice-multisite_spec.rb
41
+ - spec/spec_helper.rb
42
+ - LICENSE
43
+ has_rdoc: true
44
+ homepage: http://github.com/scottmotte/merb-auth-slice-multisite
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --inline-source
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Merb Slice that adds basic multisite functionality to merb-auth.
70
+ test_files: []
71
+