Commit d839f6c5 authored by Andrey Kumanyaev's avatar Andrey Kumanyaev Committed by Dmitriy Zaporozhets

Remove simple code duplication in members controllers

parent e52fec9c
class Admin::Teams::MembersController < Admin::Teams::ApplicationController class Admin::Teams::MembersController < Admin::Teams::ApplicationController
def new def new
@users = User.active @users = User.potential_team_members(user_team)
@users = @users.not_in_team(user_team) if user_team.members.any?
@users = UserDecorator.decorate @users @users = UserDecorator.decorate @users
end end
......
...@@ -7,8 +7,7 @@ class Teams::MembersController < Teams::ApplicationController ...@@ -7,8 +7,7 @@ class Teams::MembersController < Teams::ApplicationController
end end
def new def new
@users = User.active @users = User.potential_team_members(user_team)
@users = @users.not_in_team(user_team) if user_team.members.any?
@users = UserDecorator.decorate @users @users = UserDecorator.decorate @users
end end
......
...@@ -91,6 +91,7 @@ class User < ActiveRecord::Base ...@@ -91,6 +91,7 @@ class User < ActiveRecord::Base
scope :alphabetically, order('name ASC') scope :alphabetically, order('name ASC')
scope :in_team, ->(team){ where(id: team.member_ids) } scope :in_team, ->(team){ where(id: team.member_ids) }
scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) }
scope :potential_team_members, ->(team) { team.members.any? ? active : active.not_in_team(team) }
# #
# Class methods # Class methods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment