Class: ActiveRecord::Base::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/red_base/active_record.rb

Constant Summary collapse

@@permissions =
{
  :read => nil,
  :update => nil,
  :create => nil,
  :destory => nil,
}
@@only_owner =
false

Class Method Summary collapse

Class Method Details

.only_his_objectsObject

This force user to have access to resources which is his.



68
69
70
# File 'lib/red_base/active_record.rb', line 68

def self.only_his_objects
  @@only_owner = true
end

.only_his_objects?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/red_base/active_record.rb', line 72

def self.only_his_objects?
  @@only_owner
end

.permission_strings(model) ⇒ Object

return an array of strings representation of permissions



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/red_base/active_record.rb', line 34

def self.permission_strings(model)
  strings = []
  @@permissions.each do |key, value|
    strings << {
      :name => "#{key}|#{model.model_name}",
      :string => _("can %s %s") % [_(key.to_s), model.model_name.human]
    }

  end
  strings
end

.permissions(*args) ⇒ Object

Define permissions using this method



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/red_base/active_record.rb', line 47

def self.permissions(*args)

  args.each do |permission|
    if permission.class == Symbol
      if not @@permissions.include? permission
        @@permission[permission] = nil

      elsif permission.class == Hash

        permission.each do |key, value|
          @@permissions[key.to_sym] = value
        end

      end
    end


  end
end