Signed in admin should be able to add/remove himself to a project

parent 9ab7bdf7
...@@ -365,12 +365,10 @@ class Ability ...@@ -365,12 +365,10 @@ class Ability
unless target_user == project.owner unless target_user == project.owner
can_manage = project_abilities(user, project).include?(:admin_project_member) can_manage = project_abilities(user, project).include?(:admin_project_member)
if can_manage && user != target_user if can_manage
rules << :update_project_member rules << :update_project_member
rules << :destroy_project_member rules << :destroy_project_member
end elsif user == target_user
if user == target_user
rules << :destroy_project_member rules << :destroy_project_member
end end
end end
......
...@@ -27,3 +27,19 @@ Feature: Admin Projects ...@@ -27,3 +27,19 @@ Feature: Admin Projects
And I visit admin project page And I visit admin project page
When I transfer project to group 'Web' When I transfer project to group 'Web'
Then I should see project transfered Then I should see project transfered
@javascript
Scenario: Signed in admin should be able to add himself to a project
Given "John Doe" owns private project "Enterprise"
When I visit project "Enterprise" members page
When I select current user as "Developer"
Then I should see current user as "Developer"
@javascript
Scenario: Signed in admin should be able to remove himself from a project
Given "John Doe" owns private project "Enterprise"
And current user is developer of project "Enterprise"
When I visit project "Enterprise" members page
Then I should see current user as "Developer"
When I click on the "Remove User From Project" button for current user
Then I should not see current user as "Developer"
...@@ -3,6 +3,8 @@ class Spinach::Features::AdminProjects < Spinach::FeatureSteps ...@@ -3,6 +3,8 @@ class Spinach::Features::AdminProjects < Spinach::FeatureSteps
include SharedPaths include SharedPaths
include SharedAdmin include SharedAdmin
include SharedProject include SharedProject
include SharedUser
include Select2Helper
step 'I should see all non-archived projects' do step 'I should see all non-archived projects' do
Project.non_archived.each do |p| Project.non_archived.each do |p|
...@@ -56,6 +58,41 @@ class Spinach::Features::AdminProjects < Spinach::FeatureSteps ...@@ -56,6 +58,41 @@ class Spinach::Features::AdminProjects < Spinach::FeatureSteps
expect(page).to have_content 'Namespace: Web' expect(page).to have_content 'Namespace: Web'
end end
step 'I visit project "Enterprise" members page' do
project = Project.find_by!(name: "Enterprise")
visit namespace_project_project_members_path(project.namespace, project)
end
step 'I select current user as "Developer"' do
page.within ".users-project-form" do
select2(current_user.id, from: "#user_ids", multiple: true)
select "Developer", from: "access_level"
end
click_button "Add users to project"
end
step 'I should see current user as "Developer"' do
page.within '.content-list' do
expect(page).to have_content(current_user.name)
expect(page).to have_content('Developer')
end
end
step 'current user is developer of project "Enterprise"' do
project = Project.find_by!(name: "Enterprise")
project.team << [current_user, :developer]
end
step 'I click on the "Remove User From Project" button for current user' do
find(:css, 'li', text: current_user.name).find(:css, 'a.btn-remove').click
# poltergeist always confirms popups.
end
step 'I should not see current_user as "Developer"' do
expect(page).not_to have_selector(:css, '.content-list')
end
def project def project
@project ||= Project.first @project ||= Project.first
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