OSDN Git Service

User#owned_groups is now respect group membership
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Fri, 21 Jun 2013 19:38:43 +0000 (22:38 +0300)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Fri, 21 Jun 2013 19:38:43 +0000 (22:38 +0300)
app/models/user.rb

index ddea2da..30f5aae 100644 (file)
@@ -74,6 +74,8 @@ class User < ActiveRecord::Base
 
   # Groups
   has_many :own_groups, class_name: "Group", foreign_key: :owner_id
+  has_many :owned_groups, through: :users_groups, source: :group, conditions: { users_groups: { group_access: UsersGroup::OWNER } }
+
   has_many :users_groups, dependent: :destroy
   has_many :groups, through: :users_groups
 
@@ -225,11 +227,6 @@ class User < ActiveRecord::Base
     end
   end
 
-  # Groups where user is an owner
-  def owned_groups
-    own_groups
-  end
-
   # Groups user has access to
   def authorized_groups
     @authorized_groups ||= begin