2012-06-07 14:44:57 +02:00
|
|
|
module Team
|
|
|
|
def team_member_by_name_or_email(email = nil, name = nil)
|
|
|
|
user = users.where("email like ? or name like ?", email, name).first
|
|
|
|
users_projects.find_by_user_id(user.id) if user
|
|
|
|
end
|
|
|
|
|
2012-07-31 07:32:49 +02:00
|
|
|
# Get Team Member record by user id
|
2012-06-07 14:44:57 +02:00
|
|
|
def team_member_by_id(user_id)
|
|
|
|
users_projects.find_by_user_id(user_id)
|
|
|
|
end
|
2012-07-31 07:32:49 +02:00
|
|
|
|
|
|
|
# Add user to project
|
|
|
|
# with passed access role
|
|
|
|
def add_user_to_team(user, access_role)
|
|
|
|
add_user_id_to_team(user.id, access_role)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add multiple users to project
|
|
|
|
# with same access role
|
|
|
|
def add_users_to_team(users, access_role)
|
|
|
|
add_users_ids_to_team(users.map(&:id), access_role)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add user to project
|
|
|
|
# with passed access role by user id
|
|
|
|
def add_user_id_to_team(user_id, access_role)
|
|
|
|
users_projects.create(
|
2012-08-11 00:07:50 +02:00
|
|
|
user_id: user_id,
|
|
|
|
project_access: access_role
|
2012-07-31 07:32:49 +02:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add multiple users to project
|
|
|
|
# with same access role by user ids
|
|
|
|
def add_users_ids_to_team(users_ids, access_role)
|
|
|
|
UsersProject.bulk_import(self, users_ids, access_role)
|
|
|
|
self.update_repository
|
|
|
|
end
|
2012-09-06 22:14:42 +02:00
|
|
|
|
|
|
|
# Update multiple project users
|
|
|
|
# to same access role by user ids
|
|
|
|
def update_users_ids_to_role(users_ids, access_role)
|
|
|
|
UsersProject.bulk_update(self, users_ids, access_role)
|
|
|
|
self.update_repository
|
|
|
|
end
|
|
|
|
|
|
|
|
# Delete multiple users from project by user ids
|
2012-09-08 11:37:23 +02:00
|
|
|
def delete_users_ids_from_team(users_ids)
|
2012-09-06 22:14:42 +02:00
|
|
|
UsersProject.bulk_delete(self, users_ids)
|
|
|
|
self.update_repository
|
|
|
|
end
|
2012-06-07 14:44:57 +02:00
|
|
|
end
|