Commit 26fee3b6 authored by Furkan Ayhan's avatar Furkan Ayhan

Prevent updating trigger by other maintainers

In UI, it is prevented that updating a trigger that belongs to
other maintainer. However, it was not implemented in API.
parent bc23c3cc
---
title: Prevent updating trigger by other maintainers
merge_request:
author:
type: security
...@@ -109,6 +109,8 @@ module API ...@@ -109,6 +109,8 @@ module API
trigger = user_project.triggers.find(params.delete(:trigger_id)) trigger = user_project.triggers.find(params.delete(:trigger_id))
break not_found!('Trigger') unless trigger break not_found!('Trigger') unless trigger
authorize! :admin_trigger, trigger
if trigger.update(declared_params(include_missing: false)) if trigger.update(declared_params(include_missing: false))
present trigger, with: Entities::Trigger, current_user: current_user present trigger, with: Entities::Trigger, current_user: current_user
else else
......
...@@ -238,24 +238,44 @@ describe API::Triggers do ...@@ -238,24 +238,44 @@ describe API::Triggers do
end end
describe 'PUT /projects/:id/triggers/:trigger_id' do describe 'PUT /projects/:id/triggers/:trigger_id' do
context 'authenticated user with valid permissions' do context 'user is maintainer of the project' do
let(:new_description) { 'new description' } context 'the trigger belongs to user' do
let(:new_description) { 'new description' }
it 'updates description' do it 'updates description' do
put api("/projects/#{project.id}/triggers/#{trigger.id}", user), put api("/projects/#{project.id}/triggers/#{trigger.id}", user),
params: { description: new_description } params: { description: new_description }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to include('description' => new_description) expect(json_response).to include('description' => new_description)
expect(trigger.reload.description).to eq(new_description) expect(trigger.reload.description).to eq(new_description)
end
end
context 'the trigger does not belong to user' do
it 'does not update trigger' do
put api("/projects/#{project.id}/triggers/#{trigger2.id}", user)
expect(response).to have_gitlab_http_status(:forbidden)
end
end end
end end
context 'authenticated user with invalid permissions' do context 'user is developer of the project' do
it 'does not update trigger' do context 'the trigger belongs to user' do
put api("/projects/#{project.id}/triggers/#{trigger.id}", user2) it 'does not update trigger' do
put api("/projects/#{project.id}/triggers/#{trigger2.id}", user2)
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'the trigger does not belong to user' do
it 'does not update trigger' do
put api("/projects/#{project.id}/triggers/#{trigger.id}", user2)
expect(response).to have_gitlab_http_status(:forbidden)
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