summaryrefslogtreecommitdiff
path: root/app/models/group_permission.rb
blob: fe988bac361c14a8ec320529401c4b68ba49f51f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class GroupPermission < ActiveRecord::Base
  attr_accessible :group_id, :permission, :target_group_id

  PERMISSION_TYPES = ['pickup']
  
  belongs_to :group
  belongs_to :target_group, :class_name => "Group"

  validates :target_group_id,
            :presence => true,
            :uniqueness => { :scope => [:group_id, :permission] }

  validates :target_group,
            :presence => true

  validates :permission,
            :presence => true,
            :uniqueness => { :scope => [:group_id, :target_group_id] },
            :inclusion => { :in => PERMISSION_TYPES }

  def to_s
    "#{self.permission} => #{self.target_group}"
  end
end