Class | Permission |
In: |
app/models/permission.rb
|
Parent: | ActiveRecord::Base |
権限の参照のモデル。
不可視権限の対象になっており型 type を持つレコードを配列で返す。
# File app/models/permission.rb, line 66 66: def self.invisible(type) 67: result, alt = specified(type).partition {|perm| perm.value == "invisible"} 68: result.inject [] do |seed, perm| 69: temp = alt.select {|x| x.grant_targettable_id == perm.grant_targettable_id} 70: if (temp.empty? || perm.priority < temp.map {|x| x.priority}.min) 71: seed << perm 72: else 73: seed 74: end 75: end 76: end
不可視権限の対象で型 type を持つ条件節を返す。
# File app/models/permission.rb, line 89 89: def self.invisible_conditions(type) 90: (User.current.nil? || User.admin?) ? "0 = 1" : {:id => invisible(type).map(&:grant_targettable_id)} 91: end
全権限の対象になっており型 type を持つレコードを配列で返す。
# File app/models/permission.rb, line 56 56: def self.modifiable(type) 57: positive(type, "full") 58: end
全権限の対象で型 type を持つ条件節を返す。
# File app/models/permission.rb, line 79 79: def self.modifiable_conditions(type) 80: (User.current.nil? || User.admin?) ? "1 = 1" : {:id => modifiable(type).map(&:grant_targettable_id)} 81: end
読み取りもしくは全権限の対象になっており型 type を持つレコードを配列で返す。
# File app/models/permission.rb, line 61 61: def self.permissible(type) 62: positive(type, "full", "visible") 63: end
読み取りもしくは全権限の対象で型 type を持つ条件節を返す。
# File app/models/permission.rb, line 84 84: def self.permissible_conditions(type) 85: (User.current.nil? || User.admin?) ? "1 = 1" : {:id => permissible(type).map(&:grant_targettable_id)} 86: end
# File app/models/permission.rb, line 43 43: def self.positive(type, *values) 44: result, alt = specified(type).partition {|perm| values.include?(perm.value)} 45: result.inject [] do|seed, perm| 46: temp = alt.select {|x| x.grant_targettable_id == perm.grant_targettable_id} 47: if (temp.empty? || perm.priority <= temp.map {|x| x.priority}.min) 48: seed << perm 49: else 50: seed 51: end 52: end 53: end
権限の対象になっており型 type を持つレコードを配列で返す。
# File app/models/permission.rb, line 38 38: def self.specified(type) 39: condition = "grant_targettable_type = '#{type.to_s.classify}'" 40: find(:all, :conditions => (User.current ? ["user_id = :user_id AND #{condition}", {:user_id => User.current.id}] : condition)) 41: end