Commit 87dd3f21 authored by Douwe Maan's avatar Douwe Maan

Let members be invited from Add members pane.

parent 717fa136
...@@ -8,6 +8,7 @@ class @UsersSelect ...@@ -8,6 +8,7 @@ class @UsersSelect
@groupId = $(select).data('group-id') @groupId = $(select).data('group-id')
showNullUser = $(select).data('null-user') showNullUser = $(select).data('null-user')
showAnyUser = $(select).data('any-user') showAnyUser = $(select).data('any-user')
showEmailUser = $(select).data('email-user')
firstUser = $(select).data('first-user') firstUser = $(select).data('first-user')
$(select).select2 $(select).select2
...@@ -19,20 +20,6 @@ class @UsersSelect ...@@ -19,20 +20,6 @@ class @UsersSelect
data = { results: users } data = { results: users }
if query.term.length == 0 if query.term.length == 0
anyUser = {
name: 'Any',
avatar: null,
username: 'none',
id: null
}
nullUser = {
name: 'Unassigned',
avatar: null,
username: 'none',
id: 0
}
if firstUser if firstUser
# Move current user to the front of the list # Move current user to the front of the list
for obj, index in data.results for obj, index in data.results
...@@ -40,11 +27,34 @@ class @UsersSelect ...@@ -40,11 +27,34 @@ class @UsersSelect
data.results.splice(index, 1) data.results.splice(index, 1)
data.results.unshift(obj) data.results.unshift(obj)
break break
if showNullUser if showNullUser
nullUser = {
name: 'Unassigned',
avatar: null,
username: 'none',
id: 0
}
data.results.unshift(nullUser) data.results.unshift(nullUser)
if showAnyUser if showAnyUser
anyUser = {
name: 'Any',
avatar: null,
username: 'none',
id: null
}
data.results.unshift(anyUser) data.results.unshift(anyUser)
if showEmailUser && data.results.length == 0 && query.term.match(/^[^@]+@[^@]+$/)
emailUser = {
name: "Invite \"#{query.term}\"",
avatar: null,
username: query.term,
id: query.term
}
data.results.unshift(emailUser)
query.callback(data) query.callback(data)
initSelection: (element, callback) => initSelection: (element, callback) =>
......
...@@ -36,8 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -36,8 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end end
def create def create
users = User.where(id: params[:user_ids].split(',')) @project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user)
@project.team << [users, params[:access_level]]
redirect_to namespace_project_project_members_path(@project.namespace, @project) redirect_to namespace_project_project_members_path(@project.namespace, @project)
end end
......
...@@ -8,6 +8,7 @@ module SelectsHelper ...@@ -8,6 +8,7 @@ module SelectsHelper
null_user = opts[:null_user] || false null_user = opts[:null_user] || false
any_user = opts[:any_user] || false any_user = opts[:any_user] || false
email_user = opts[:email_user] || false
first_user = opts[:first_user] && current_user ? current_user.username : false first_user = opts[:first_user] && current_user ? current_user.username : false
html = { html = {
...@@ -15,6 +16,7 @@ module SelectsHelper ...@@ -15,6 +16,7 @@ module SelectsHelper
'data-placeholder' => placeholder, 'data-placeholder' => placeholder,
'data-null-user' => null_user, 'data-null-user' => null_user,
'data-any-user' => any_user, 'data-any-user' => any_user,
'data-email-user' => email_user,
'data-first-user' => first_user 'data-first-user' => first_user
} }
......
...@@ -47,10 +47,24 @@ class Group < Namespace ...@@ -47,10 +47,24 @@ class Group < Namespace
end end
def add_users(user_ids, access_level, current_user = nil) def add_users(user_ids, access_level, current_user = nil)
user_ids.compact.each do |user_id| users = user_ids.map do |user_id|
member = self.group_members.find_or_initialize_by(user_id: user_id) (user_id if user_id.is_a?(User)) ||
member.access_level = access_level User.find_by(id: user_id) ||
User.find_by(email: user_id) ||
user_id
end
users.compact.each do |user|
if user.is_a?(User)
member = self.group_members.find_or_initialize_by(user_id: user.id)
else
member = self.group_members.build
member.invite_email = user
end
member.created_by ||= current_user member.created_by ||= current_user
member.access_level = access_level
member.save member.save
end end
end end
......
...@@ -60,12 +60,28 @@ class ProjectMember < Member ...@@ -60,12 +60,28 @@ class ProjectMember < Member
raise "Non valid access" raise "Non valid access"
end end
users = user_ids.map do |user_id|
(user_id if user_id.is_a?(User)) ||
User.find_by(id: user_id) ||
User.find_by(email: user_id) ||
user_id
end
ProjectMember.transaction do ProjectMember.transaction do
project_ids.each do |project_id| project_ids.each do |project_id|
user_ids.each do |user_id| project = Project.find(project_id)
member = ProjectMember.new(access_level: access_level, user_id: user_id)
member.source_id = project_id users.each do |user|
if user.is_a?(User)
member = project.project_members.find_or_initialize_by(user_id: user.id)
else
member = project.project_members.build
member.invite_email = user
end
member.created_by ||= current_user member.created_by ||= current_user
member.access_level = access_level
member.save member.save
end end
end end
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
= form_tag members_update_admin_group_path(@group), id: "new_project_member", class: "bulk_import", method: :put do = form_tag members_update_admin_group_path(@group), id: "new_project_member", class: "bulk_import", method: :put do
%div %div
= users_select_tag(:user_ids, multiple: true) = users_select_tag(:user_ids, multiple: true, email_user: true)
%div.prepend-top-10 %div.prepend-top-10
= select_tag :access_level, options_for_select(GroupMember.access_level_roles), class: "project-access-select select2" = select_tag :access_level, options_for_select(GroupMember.access_level_roles), class: "project-access-select select2"
%hr %hr
......
= form_for @group_member, url: group_group_members_path(@group), html: { class: 'form-horizontal users-group-form' } do |f| = form_for @group_member, url: group_group_members_path(@group), html: { class: 'form-horizontal users-group-form' } do |f|
.form-group .form-group
= f.label :user_ids, "People", class: 'control-label' = f.label :user_ids, "People", class: 'control-label'
.col-sm-10= users_select_tag(:user_ids, multiple: true, class: 'input-large', scope: :all) .col-sm-10
= users_select_tag(:user_ids, multiple: true, class: 'input-large', scope: :all, email_user: true)
.help-block
Search for existing users or invite new ones using their email address.
.form-group .form-group
= f.label :access_level, "Group Access", class: 'control-label' = f.label :access_level, "Group Access", class: 'control-label'
......
= form_for @project_member, as: :project_member, url: namespace_project_project_members_path(@project.namespace, @project), html: { class: 'form-horizontal users-project-form' } do |f| = form_for @project_member, as: :project_member, url: namespace_project_project_members_path(@project.namespace, @project), html: { class: 'form-horizontal users-project-form' } do |f|
.form-group .form-group
= f.label :user_ids, "People", class: 'control-label' = f.label :user_ids, "People", class: 'control-label'
.col-sm-10= users_select_tag(:user_ids, multiple: true, class: 'input-large', scope: :all) .col-sm-10
= users_select_tag(:user_ids, multiple: true, class: 'input-large', scope: :all, email_user: true)
.help-block
Search for existing users or invite new ones using their email address.
.form-group .form-group
= f.label :access_level, "Project Access", class: 'control-label' = f.label :access_level, "Project Access", class: 'control-label'
......
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