summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
commit67c1a0a951403a546250ea860a3e3d199cae2fce (patch)
treef86ec6cedf081a1a57005eca1661e9bead34e4de /app/models/user.rb
parent5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (diff)
parent211f558a86ae30cdd5b392ab1376e1393f97e22c (diff)
Merge branch 'develop'5.1-beta6
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