diff options
author | Gemeinschaft Service Account <gs5@localhost.localdomain> | 2013-02-24 06:02:29 -0500 |
---|---|---|
committer | Gemeinschaft Service Account <gs5@localhost.localdomain> | 2013-02-24 06:02:29 -0500 |
commit | 966b8733a82f07f825ce07baff0d37e2a5863960 (patch) | |
tree | b7cb36d5d9e8015643870b452f960b80e226ac31 /app/models/user.rb | |
parent | 6acbd878be8b88f784a9813a9114773b87ee065f (diff) |
add default groups
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 6c67351..913d75f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,6 +6,7 @@ class User < ActiveRecord::Base # Sync other nodes when this is a cluster. # after_create :create_on_other_gs_nodes + after_create :create_default_group_memberships after_destroy :destroy_on_other_gs_nodes after_update :update_on_other_gs_nodes @@ -89,6 +90,9 @@ class User < ActiveRecord::Base belongs_to :gs_node has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy + + has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true + has_many :groups, :through => :group_memberships # Avatar like photo mount_uploader :image, ImageUploader @@ -226,4 +230,16 @@ class User < ActiveRecord::Base end end + def create_default_group_memberships + templates = GsParameter.get('User', 'group', 'default') + if templates.class == Array + templates.each do |group_name| + group = Group.where(:name => group_name).first + if group + self.group_memberships.create(:group_id => group.id) + end + end + end + end + end |