[35815] Add visible show page for all users to groups (#8949)
To that end, move the show group routes out of /admin, that requires we use a different path helper for it as `group_path` will still link to the first admin resource.pull/8970/head
parent
8ec0fa8a87
commit
769be47723
@ -0,0 +1,195 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
require 'spec_helper' |
||||
|
||||
describe GroupsController, type: :controller do |
||||
let(:group) { FactoryBot.create :group } |
||||
|
||||
before do |
||||
login_as current_user |
||||
end |
||||
|
||||
context 'as admin' do |
||||
using_shared_fixtures :admin |
||||
let(:current_user) { admin } |
||||
|
||||
it 'should index' do |
||||
get :index |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'index' |
||||
end |
||||
|
||||
it 'should show' do |
||||
get :show, params: { id: group.id } |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'show' |
||||
end |
||||
|
||||
it 'should new' do |
||||
get :new |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'new' |
||||
end |
||||
|
||||
it 'should create' do |
||||
expect do |
||||
post :create, params: { group: { lastname: 'New group' } } |
||||
end.to change { Group.count }.by(1) |
||||
expect(response).to redirect_to groups_path |
||||
end |
||||
|
||||
it 'should edit' do |
||||
get :edit, params: { id: group.id } |
||||
|
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'edit' |
||||
end |
||||
|
||||
it 'should update' do |
||||
expect do |
||||
put :update, params: { id: group.id, group: { lastname: 'new name' } } |
||||
end.to change { group.reload.name }.to('new name') |
||||
|
||||
expect(response).to redirect_to groups_path |
||||
end |
||||
|
||||
it 'should destroy' do |
||||
delete :destroy, params: { id: group.id } |
||||
expect { group.reload }.to raise_error ActiveRecord::RecordNotFound |
||||
|
||||
expect(response).to redirect_to groups_path |
||||
end |
||||
|
||||
context 'with two existing users' do |
||||
let(:user1) { FactoryBot.create :user } |
||||
let(:user2) { FactoryBot.create :user } |
||||
|
||||
it 'should add users' do |
||||
post :add_users, params: { id: group.id, user_ids: [user1.id, user2.id] } |
||||
expect(group.reload.users.count).to eq 2 |
||||
end |
||||
end |
||||
|
||||
context 'with a group member' do |
||||
let(:user1) { FactoryBot.create :user } |
||||
let(:user2) { FactoryBot.create :user } |
||||
|
||||
it 'should add users' do |
||||
group.add_members! user1 |
||||
|
||||
post :add_users, params: { id: group.id, user_ids: [user2.id] } |
||||
expect(group.reload.users.count).to eq 2 |
||||
end |
||||
end |
||||
|
||||
context 'with project and role' do |
||||
let(:project) { FactoryBot.create :project } |
||||
let(:role1) { FactoryBot.create :role } |
||||
let(:role2) { FactoryBot.create :role } |
||||
|
||||
it 'should create membership' do |
||||
post :create_memberships, |
||||
params: { id: group.id, new_membership: { project_id: project.id, role_ids: [role1.id, role2.id] } } |
||||
|
||||
expect(group.reload.members.count).to eq 1 |
||||
expect(group.members.first.roles.count).to eq 2 |
||||
end |
||||
|
||||
context 'with an existing membership' do |
||||
let!(:member_group) do |
||||
FactoryBot.create(:member, |
||||
project: project, |
||||
principal: group, |
||||
roles: [role1]) |
||||
end |
||||
|
||||
it 'should edit a membership' do |
||||
expect(group.members.count).to eq 1 |
||||
expect(group.members.first.roles.count).to eq 1 |
||||
|
||||
put :edit_membership, |
||||
params: { |
||||
id: group.id, |
||||
membership_id: group.members.first.id, |
||||
membership: { project_id: project.id, role_ids: [role1.id, role2.id] } |
||||
} |
||||
|
||||
group.reload |
||||
expect(group.members.count).to eq 1 |
||||
expect(group.members.first.roles.count).to eq 2 |
||||
end |
||||
|
||||
it 'can destroy the membership' do |
||||
delete :destroy_membership, params: { id: group.id, membership_id: group.members.first.id } |
||||
expect(group.reload.members.count).to eq 0 |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'as regular user' do |
||||
let(:user) { FactoryBot.create :user } |
||||
let(:current_user) { user } |
||||
|
||||
it 'should forbid index' do |
||||
get :index |
||||
expect(response).not_to be_successful |
||||
expect(response.status).to eq 403 |
||||
end |
||||
|
||||
it 'should show' do |
||||
get :show, params: { id: group.id } |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'show' |
||||
end |
||||
|
||||
it 'should forbid new' do |
||||
get :new |
||||
expect(response).not_to be_successful |
||||
expect(response.status).to eq 403 |
||||
end |
||||
|
||||
it 'should forbid create' do |
||||
expect { |
||||
post :create, params: { group: { lastname: 'New group' } } |
||||
}.not_to change { Group.count } |
||||
|
||||
expect(response).not_to be_successful |
||||
expect(response.status).to eq 403 |
||||
end |
||||
|
||||
it 'should forbid edit' do |
||||
get :edit, params: { id: group.id } |
||||
|
||||
expect(response).not_to be_successful |
||||
expect(response.status).to eq 403 |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,61 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
feature 'group show page', type: :feature do |
||||
let!(:member) { FactoryBot.create :user } |
||||
let!(:group) { FactoryBot.create :group, lastname: "Bob's Team", members: [member] } |
||||
|
||||
before do |
||||
login_as current_user |
||||
end |
||||
|
||||
context 'as an admin' do |
||||
using_shared_fixtures :admin |
||||
let(:current_user) { admin } |
||||
|
||||
scenario 'I can visit the group page' do |
||||
visit show_group_path(group) |
||||
expect(page).to have_selector('h2', text: "Bob's Team") |
||||
expect(page).to have_selector('.toolbar-item', text: 'Edit') |
||||
expect(page).to have_selector('li', text: member.name) |
||||
end |
||||
end |
||||
|
||||
context 'as a regular user' do |
||||
let(:current_user) { FactoryBot.create :user } |
||||
|
||||
scenario 'I can visit the group page' do |
||||
visit show_group_path(group) |
||||
expect(page).to have_selector('h2', text: "Bob's Team") |
||||
expect(page).to have_no_selector('.toolbar-item') |
||||
expect(page).to have_no_selector('li', text: member.name) |
||||
end |
||||
end |
||||
end |
@ -1,113 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
require_relative '../legacy_spec_helper' |
||||
require 'groups_controller' |
||||
|
||||
describe GroupsController, type: :controller do |
||||
fixtures :all |
||||
|
||||
before do |
||||
User.current = nil |
||||
session[:user_id] = 1 |
||||
end |
||||
|
||||
it 'should index' do |
||||
get :index |
||||
assert_response :success |
||||
assert_template 'index' |
||||
end |
||||
|
||||
it 'should show' do |
||||
get :show, params: { id: 10 } |
||||
assert_response :success |
||||
assert_template 'show' |
||||
end |
||||
|
||||
it 'should new' do |
||||
get :new |
||||
assert_response :success |
||||
assert_template 'new' |
||||
end |
||||
|
||||
it 'should create' do |
||||
assert_difference 'Group.count' do |
||||
post :create, params: { group: { lastname: 'New group' } } |
||||
end |
||||
assert_redirected_to groups_path |
||||
end |
||||
|
||||
it 'should edit' do |
||||
get :edit, params: { id: 10 } |
||||
assert_response :success |
||||
assert_template 'edit' |
||||
end |
||||
|
||||
it 'should update' do |
||||
put :update, params: { id: 10, group: { lastname: 'new name' } } |
||||
assert_redirected_to groups_path |
||||
end |
||||
|
||||
it 'should destroy' do |
||||
assert_difference 'Group.count', -1 do |
||||
delete :destroy, params: { id: 10 } |
||||
end |
||||
assert_redirected_to groups_path |
||||
end |
||||
|
||||
it 'should add users' do |
||||
assert_difference 'Group.find(10).users.count', 2 do |
||||
post :add_users, params: { id: 10, user_ids: ['2', '3'] } |
||||
end |
||||
end |
||||
|
||||
it 'should remove user' do |
||||
assert_difference 'Group.find(10).users.count', -1 do |
||||
delete :remove_user, params: { id: 10, user_id: '8' } |
||||
end |
||||
end |
||||
|
||||
it 'should create membership' do |
||||
assert_difference 'Group.find(10).members.count' do |
||||
post :create_memberships, params: { id: 10, new_membership: { project_id: 2, role_ids: ['1', '2'] } } |
||||
end |
||||
end |
||||
|
||||
it 'should edit membership' do |
||||
assert_no_difference 'Group.find(10).members.count' do |
||||
put :edit_membership, params: { id: 10, membership_id: 6, membership: { role_ids: ['1', '3'] } } |
||||
end |
||||
end |
||||
|
||||
it 'should destroy membership' do |
||||
assert_difference 'Group.find(10).members.count', -1 do |
||||
delete :destroy_membership, params: { id: 10, membership_id: 6 } |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue