Commit 1f84dbaa authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'yesbabyyes/gitlab-ce-22967-adding-zero-users-to-group-reports-success'

Merge request - https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6979
parents 6e693771 7ded7c17
...@@ -16,6 +16,8 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -16,6 +16,8 @@ Please view this file on the master branch, on stable branches it's out of date.
- Fix reply-by-email not working due to queue name mismatch - Fix reply-by-email not working due to queue name mismatch
- Expire and build repository cache after project import - Expire and build repository cache after project import
- Fix 404 for group pages when GitLab setup uses relative url - Fix 404 for group pages when GitLab setup uses relative url
- Simpler arguments passed to named_route on toggle_award_url helper method
- Better handle when no users were selected for adding to group or project. (Linus Thiel)
## 8.13.0 (2016-10-22) ## 8.13.0 (2016-10-22)
- Removes extra line for empty issue description. (!7045) - Removes extra line for empty issue description. (!7045)
......
...@@ -83,14 +83,15 @@ ...@@ -83,14 +83,15 @@
}; };
// Disable button if text field is empty // Disable button if text field is empty
window.disableButtonIfEmptyField = function(field_selector, button_selector) { window.disableButtonIfEmptyField = function(field_selector, button_selector, event_name) {
event_name = event_name || 'input';
var closest_submit, field; var closest_submit, field;
field = $(field_selector); field = $(field_selector);
closest_submit = field.closest('form').find(button_selector); closest_submit = field.closest('form').find(button_selector);
if (rstrip(field.val()) === "") { if (rstrip(field.val()) === "") {
closest_submit.disable(); closest_submit.disable();
} }
return field.on('input', function() { return field.on(event_name, function() {
if (rstrip($(this).val()) === "") { if (rstrip($(this).val()) === "") {
return closest_submit.disable(); return closest_submit.disable();
} else { } else {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
$('.project_member, .group_member').off('ajax:success').on('ajax:success', this.removeRow); $('.project_member, .group_member').off('ajax:success').on('ajax:success', this.removeRow);
$('.js-member-update-control').off('change').on('change', this.formSubmit); $('.js-member-update-control').off('change').on('change', this.formSubmit);
$('.js-edit-member-form').off('ajax:success').on('ajax:success', this.formSuccess); $('.js-edit-member-form').off('ajax:success').on('ajax:success', this.formSuccess);
disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change');
} }
removeRow(e) { removeRow(e) {
......
...@@ -21,6 +21,10 @@ class Groups::GroupMembersController < Groups::ApplicationController ...@@ -21,6 +21,10 @@ class Groups::GroupMembersController < Groups::ApplicationController
end end
def create def create
if params[:user_ids].blank?
return redirect_to(group_group_members_path(@group), alert: 'No users specified.')
end
@group.add_users( @group.add_users(
params[:user_ids].split(','), params[:user_ids].split(','),
params[:access_level], params[:access_level],
......
...@@ -25,6 +25,10 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -25,6 +25,10 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end end
def create def create
if params[:user_ids].blank?
return redirect_to(namespace_project_project_members_path(@project.namespace, @project), alert: 'No users or groups specified.')
end
@project.team.add_users( @project.team.add_users(
params[:user_ids].split(','), params[:user_ids].split(','),
params[:access_level], params[:access_level],
...@@ -32,7 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -32,7 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
current_user: current_user current_user: current_user
) )
redirect_to namespace_project_project_members_path(@project.namespace, @project) redirect_to namespace_project_project_members_path(@project.namespace, @project), notice: 'Users were successfully added.'
end end
def update def update
......
...@@ -68,7 +68,7 @@ class Group < Namespace ...@@ -68,7 +68,7 @@ class Group < Namespace
end end
def web_url def web_url
Gitlab::Routing.url_helpers.group_canonical_url(self) Gitlab::Routing.url_helpers.group_url(self)
end end
def human_name def human_name
......
...@@ -12,26 +12,23 @@ constraints(GroupUrlConstrainer.new) do ...@@ -12,26 +12,23 @@ constraints(GroupUrlConstrainer.new) do
end end
end end
scope constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ } do resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ } do
resources :groups, except: [:show] do member do
member do get :issues
get :issues get :merge_requests
get :merge_requests get :projects
get :projects get :activity
get :activity end
end
scope module: :groups do scope module: :groups do
resources :group_members, only: [:index, :create, :update, :destroy], concerns: :access_requestable do resources :group_members, only: [:index, :create, :update, :destroy], concerns: :access_requestable do
post :resend_invite, on: :member post :resend_invite, on: :member
delete :leave, on: :collection delete :leave, on: :collection
end end
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create] resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
resources :labels, except: [:show], constraints: { id: /\d+/ } resources :labels, except: [:show], constraints: { id: /\d+/ }
end
end end
get 'groups/:id' => 'groups#show', as: :group_canonical
end end
...@@ -13,6 +13,49 @@ describe Groups::GroupMembersController do ...@@ -13,6 +13,49 @@ describe Groups::GroupMembersController do
end end
end end
describe 'POST create' do
let(:group_user) { create(:user) }
before { sign_in(user) }
context 'when user does not have enough rights' do
before { group.add_developer(user) }
it 'returns 403' do
post :create, group_id: group,
user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to have_http_status(403)
expect(group.users).not_to include group_user
end
end
context 'when user has enough rights' do
before { group.add_owner(user) }
it 'adds user to members' do
post :create, group_id: group,
user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user
end
it 'adds no user to members' do
post :create, group_id: group,
user_ids: '',
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'No users specified.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).not_to include group_user
end
end
end
describe 'DELETE destroy' do describe 'DELETE destroy' do
let(:member) { create(:group_member, :developer, group: group) } let(:member) { create(:group_member, :developer, group: group) }
......
...@@ -13,6 +13,54 @@ describe Projects::ProjectMembersController do ...@@ -13,6 +13,54 @@ describe Projects::ProjectMembersController do
end end
end end
describe 'POST create' do
context 'when users are added' do
let(:project_user) { create(:user) }
before { sign_in(user) }
context 'when user does not have enough rights' do
before { project.team << [user, :developer] }
it 'returns 404' do
post :create, namespace_id: project.namespace,
project_id: project,
user_ids: project_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to have_http_status(404)
expect(project.users).not_to include project_user
end
end
context 'when user has enough rights' do
before { project.team << [user, :master] }
it 'adds user to members' do
post :create, namespace_id: project.namespace,
project_id: project,
user_ids: project_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(namespace_project_project_members_path(project.namespace, project))
expect(project.users).to include project_user
end
it 'adds no user to members' do
post :create, namespace_id: project.namespace,
project_id: project,
user_ids: '',
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'No users or groups specified.'
expect(response).to redirect_to(namespace_project_project_members_path(project.namespace, project))
expect(project.users).not_to include project_user
end
end
end
end
describe 'DELETE destroy' do describe 'DELETE destroy' do
let(:member) { create(:project_member, :developer, project: project) } let(:member) { create(:project_member, :developer, project: project) }
......
...@@ -265,10 +265,4 @@ describe Group, models: true do ...@@ -265,10 +265,4 @@ describe Group, models: true do
members members
end end
describe '#web_url' do
it 'returns the canonical URL' do
expect(group.web_url).to include("groups/#{group.name}")
end
end
end end
...@@ -17,9 +17,9 @@ module Select2Helper ...@@ -17,9 +17,9 @@ module Select2Helper
selector = options.fetch(:from) selector = options.fetch(:from)
if options[:multiple] if options[:multiple]
execute_script("$('#{selector}').select2('val', ['#{value}'], true);") execute_script("$('#{selector}').select2('val', ['#{value}']).trigger('change');")
else else
execute_script("$('#{selector}').select2('val', '#{value}', true);") execute_script("$('#{selector}').select2('val', '#{value}').trigger('change');")
end end
end end
end end
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