summaryrefslogtreecommitdiff
path: root/app/models/user_group_membership.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/models/user_group_membership.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'app/models/user_group_membership.rb')
-rw-r--r--app/models/user_group_membership.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/user_group_membership.rb b/app/models/user_group_membership.rb
new file mode 100644
index 0000000..18a8d48
--- /dev/null
+++ b/app/models/user_group_membership.rb
@@ -0,0 +1,26 @@
+class UserGroupMembership < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :user_group
+
+ validates_uniqueness_of :user_id, :scope => :user_group_id
+ validates_presence_of :user
+ validates_presence_of :user_group
+
+ validate :user_belongs_to_the_tenant_of_the_user_group
+
+ # State Machine stuff
+ default_scope where(:state => 'active')
+ state_machine :initial => :active do
+ end
+
+ def to_s
+ "#{self.user} / #{self.user_group}"
+ end
+
+ private
+ def user_belongs_to_the_tenant_of_the_user_group
+ if !self.user_group.tenant.users.include?(self.user)
+ errors.add(:user_id, "not a member of the tenant which this group belongs to")
+ end
+ end
+end