summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb16
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