diff options
| author | Kir | 2011-11-21 11:48:10 +0400 |
|---|---|---|
| committer | Kir | 2011-11-21 11:48:10 +0400 |
| commit | 580bc3eaad6ed578b5d33256e6eda3e282aa91cd (patch) | |
| tree | 0ae8321fe716504c2050e3bbc0294844ee3f18aa /app | |
| parent | bd1ee727b44381f1755858b7e3c0bb7ddf87b0cd (diff) | |
| download | inboxes-580bc3eaad6ed578b5d33256e6eda3e282aa91cd.tar.bz2 | |
Integration with Cancan
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/inboxes/base_controller.rb | 6 | ||||
| -rw-r--r-- | app/models/inboxes/ability.rb | 38 |
2 files changed, 44 insertions, 0 deletions
diff --git a/app/controllers/inboxes/base_controller.rb b/app/controllers/inboxes/base_controller.rb index da116a0..680e38c 100644 --- a/app/controllers/inboxes/base_controller.rb +++ b/app/controllers/inboxes/base_controller.rb @@ -4,4 +4,10 @@ class Inboxes::BaseController < ApplicationController def init_discussion @discussion = Discussion.find(params[:discussion_id]) end + + # Needs to be overriden so that we use Spree's Ability rather than anyone else's. + def current_ability + # raise "Loading Ability" + @current_ability ||= Inboxes::Ability.new(current_user) + end end
\ No newline at end of file diff --git a/app/models/inboxes/ability.rb b/app/models/inboxes/ability.rb new file mode 100644 index 0000000..4d8408f --- /dev/null +++ b/app/models/inboxes/ability.rb @@ -0,0 +1,38 @@ +# Implementation class for Cancan gem. Instead of overriding this class, consider adding new permissions +# using the special +register_ability+ method which allows extensions to add their own abilities. +# +# See http://github.com/ryanb/cancan for more details on cancan. +module Inboxes + class Ability + include CanCan::Ability + + class_attribute :abilities + self.abilities = Set.new + + # Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to + # modify the default +Ability+ of an application. The +ability+ argument must be a class that includes + # the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class + # and therefore should be easy to test in isolation. + def self.register_ability(ability) + self.abilities.add(ability) + + end + + def initialize(user) + # raise "Initializing 3rd patry" + # self.clear_aliased_actions + + # can [:index, :create], Discussion + # can :read, Discussion do |discussion| + # discussion.can_participate?(user) + # end + + #include any abilities registered by extensions, etc. + + Ability.abilities.each do |clazz| + ability = clazz.send(:new, user) + @rules = rules + ability.send(:rules) + end + end + end +end |
