summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index e0cfaab..6c65f70 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -5,7 +5,28 @@ class Group < ActiveRecord::Base
has_many :group_permissions, :dependent => :destroy
has_many :permittances, :foreign_key => :target_group_id, :class_name => "GroupPermission", :dependent => :destroy
+ validates :name,
+ :presence => true
+
def to_s
self.name
end
+
+ def permission_targets(permission)
+ group_permissions.where(:permission => permission).pluck(:target_group_id)
+ end
+
+ def has_permission(target_type, target_id, permission)
+ target_group_ids = GroupMembership.where(:item_id => target_id, :item_type => target_type).pluck(:group_id)
+ return group_permissions.where(:permission => permission, :target_group_id => target_group_ids).first != nil
+ end
+
+ def self.union(sets=[])
+ group_ids = []
+ sets.each do |set|
+ group_ids = group_ids + set
+ end
+
+ return group_ids.uniq
+ end
end