Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 1af3e58f5cfb2de8aebaa2a5f2c103f70ad00e1a @kristianmandrup committed Aug 4, 2011
Showing 374 changed files with 19,415 additions and 0 deletions.
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
@@ -0,0 +1,53 @@
+Gemfile.lock
+*.sqlite3
+*.swp
+*.log
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+.DS_Store
+*/.DS_Store
+
+# For TextMate
+#*.tmproj
+#tmtags
+
+# For emacs:
+#*~
+#\#*
+#.\#*
+
+# For vim:
+*.swp
+
+# For redcar:
+.redcar
+
+# For rubinius:
+#*.rbc
1 .rspec
@@ -0,0 +1 @@
+--format nested --color
53 Gemfile
@@ -0,0 +1,53 @@
+source 'http://rubygems.org'
+
+group :default do
+ gem 'rails', '>= 3.0.1'
+ gem 'cancan', '>= 1.4'
+ gem 'sugar-high', '>= 0.5'
+ gem 'sqlite3'
+ gem 'hashie', '>= 0.4'
+ gem 'dkastner-moneta', '>= 1.0'
+ gem "friendly_id"
+
+ # adapters
+ # gem 'meta_where'
+ # gem 'mongoid'
+end
+
+group :test do
+ gem 'require_all', '~> 1.2.0'
+
+ # Data
+ # gem 'database_cleaner', '~> 0.6.7', :git => "git://github.com/stanislaw/database_cleaner.git"
+ gem 'database_cleaner', '~> 0.6.8', :git => "git://github.com/kristianmandrup/database_cleaner.git"
+
+ gem 'factory_girl'
+
+ # Specs
+ gem 'spork'
+ gem "rspec-rails", '>= 2.5'
+ gem 'capybara'
+ gem 'rails-app-spec'
+ gem 'mocha'
+
+ # Debug
+ gem 'cutter'
+
+ # Rails
+ gem 'haml'
+ gem 'decent_exposure'
+
+ gem 'generator-spec'
+end
+
+group :development do
+ gem "rspec", ">= 2.5.0"
+ gem "jeweler", ">= 1.6.4"
+ gem "bundler", "~> 1.0.10"
+ gem "rdoc"
+
+ # gem 'logging_assist'
+ # gem 'meta_where'
+ # gem 'mongoid'
+end
+
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Kristian Mandrup
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,155 @@
+h1. CanTango
+
+CanTango extends "CanCan":http://github.com/ryanb/cancan and offers a role oriented
+permissions design. CanTango also integrates well with "Devise":https://github.com/plataformatec/devise and scenarios with multiple user accounts.
+
+h2. Supported ruby versions
+
+Tested to work with:
+* Ruby 1.9+
+
+Currently doesn't support:
+* Ruby 1.8.7
+
+h2. Should I use CanTango for my permission requirements?
+
+* "When and Why?":https://github.com/kristianmandrup/cantango/wiki/When-and-why-to-use-cantango
+* "CanTango overview":https://github.com/kristianmandrup/cantango/wiki
+
+h2. Install
+
+@gem install cantango@
+
+h2. Usage in a Rails 3 app
+
+Insert into Gemfile
+
+@gem 'cantango'@
+
+Run bundler to bundle gems in the app
+
+@$ bundle@
+
+h2. Design overview
+
+The CanTango pattern is simple:
+1. Return cached rules (if available)
+2. Generate rules
+3. Cache rules
+
+_CanTango::Ability#initialize_
+
+1. Use cached rules and return if user has cached rules
+2. Generate rules for Permits if 'Permits engine' is turned on
+3. Generate rules for Permissions if 'Permissions engine' is turned on
+4. Cache generated rules with unique key for current user
+
+See "CanTango Ability":https://github.com/kristianmandrup/cantango/wiki/Cantango-ability
+
+h2. Rails 3 configuration
+
+See "Configuration":https://github.com/kristianmandrup/cantango/wiki/Configuration
+
+h3. Minimal role system requirements
+
+_CanTango_ requires that you have some kind of 'role system' in place (see "Role system requirement":https://github.com/kristianmandrup/cantango/wiki/Role-system-requirements)
+
+h3. Supported role systems
+
+Currently the role system "Troles":https://github.com/kristianmandrup/troles is targeted, but any role system will do with a few minor patches on top
+
+h2. Permission configuration
+
+Permission rules can be defined in:
+* Permission store
+* Permit classes
+
+h3. Permits
+
+See "Permits":https://github.com/kristianmandrup/cantango/wiki/Permits
+
+h3. Permissions store
+
+Permission rules can be stored and maintained in a "Permissions store":https://github.com/kristianmandrup/cantango/wiki/Permissions-store
+A Permissions store can be either a simple YAML file or a key-value store supported by "Moneta":https://github.com/dkastner/moneta
+
+
+h2. Application configuration for CanTango
+
+* Define roles that Users can have
+* Define which roles are available
+* Define a Permit for each role.
+* For each Permit, define what Users with a role matching the permit can do
+
+h2. Extensions
+
+CanTango is integrated with "CanCan REST links":https://github.com/kristianmandrup/cancan-rest-links, letting you easily control which users have access to which models in your app.
+
+The coming Rails 3 engine "Dancing":https://github.com/kristianmandrup/dancing will include a _full_config_ generator that you can use to configure your Rails app for devise, cancan, cantango and troles.
+
+h2. Quickstart
+
+h3. Define Permits
+
+Permits can be defined for any of the following:
+
+* Roles
+* Role groups
+
+In addition you can also define _licenses_, that are sets of permit rules that can be reused in various role and role group permits.
+
+You can use the _Permits generator_ to generate your permits. All Permit classes should be placed in the app/permits folder of a Rails app.
+
+See "Role permits":https://github.com/kristianmandrup/cantango/wiki/Role-Permits in the wiki.
+
+h2. Account permits
+
+See "Account permits":https://github.com/kristianmandrup/cantango/wiki/Account-permits on the wiki
+
+h3. Permit for Role group
+
+See "Role group permits":https://github.com/kristianmandrup/cantango/wiki/Role-Group-permits
+
+h3. Special permits
+
+The Permits system uses some special permits _System_ and _Any_, that can be configured for
+advanced permission scenarios as described in the wiki.
+
+h2. Licenses
+
+See "Licenses":https://github.com/kristianmandrup/cantango/wiki/Licenses in the wiki.
+
+h2. Advanced Permits
+
+See "Advanced Permits":https://github.com/kristianmandrup/cantango/wiki/Advanced-permits
+
+h2. Generators
+
+The gem comes with the following generators
+
+* can_tango:role_permits - generate multiple permits
+* can_tango:role_permit - generate a single permit
+* can_tango:licenses - generate multiple licenses
+* can_tango:license - generate a single license
+
+See "Generators":https://github.com/kristianmandrup/cantango/wiki/Generators
+
+h2. You need help?
+
+Please post ideas, questions etc. in the "cantango group":http://groups.google.com/group/cantango on Google.
+
+h3. Bugs, issues or feature request/ideas?
+
+If you encounter bugs, raise an issue or:
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+h2. Copyright
+
+Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
@@ -0,0 +1,48 @@
+# encoding: utf-8
+
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "cantango"
+ gem.homepage = "http://github.com/kristianmandrup/cantango"
+ gem.license = "MIT"
+ gem.summary = %Q{CanCan extension with role oriented permission management and more}
+ gem.description = %Q{Define your permission rules as role- or role group specific permits.
+Integrates well with multiple Devise user acounts.
+Includes rules caching.
+Store permissions in yaml file or key-value store}
+ gem.email = "kmandrup@gmail.com, s.pankevich@gmail.com"
+ gem.authors = ["Kristian Mandrup", "Stanislaw Pankevich"]
+ # dependencies defined in Gemfile
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+task :default => :test
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "cantango #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1 @@
+0.6.0
@@ -0,0 +1,46 @@
+module CanTango
+ module Generators
+ class Base < Rails::Generators::Base
+ def self.inherited(subclass)
+ subclass.extend ClassMethods
+ end
+
+ module ClassMethods
+ def can_actions
+ [:create, :update, :manage, :read, :access]
+ end
+ end
+
+ can_actions.each do |action|
+ class_eval %{
+ class_option :#{action}, :type => :array, :default => [], :desc => "Models allowed to #{action}"
+ }
+ end
+
+ protected
+
+ can_actions.each do |action|
+ class_eval %{
+ def #{action}
+ options[:#{action}]
+ end
+ }
+ end
+
+ def rules_logic
+ self.class.can_actions.map do |action|
+ send(action).map do |c|
+ "can(:#{action}, #{act_model(c)})"
+ end.join("\n ")
+ end.join("\n ")
+ end
+
+ def act_model name
+ return ':all' if name == 'all'
+ name.camelize
+ end
+ end
+ end
+end
+
+
Oops, something went wrong.

0 comments on commit 1af3e58

Please sign in to comment.