Commit f108153c authored by Kamil Trzcinski's avatar Kamil Trzcinski

Remove update|admin_pipeline_schedule from Project, and grant it in PipelineSchedule

parent 1ee9f7db
...@@ -73,4 +73,8 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController ...@@ -73,4 +73,8 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
def authorize_update_pipeline_schedule! def authorize_update_pipeline_schedule!
return access_denied! unless can?(current_user, :update_pipeline_schedule, schedule) return access_denied! unless can?(current_user, :update_pipeline_schedule, schedule)
end end
def authorize_admin_pipeline_schedule!
return access_denied! unless can?(current_user, :admin_pipeline_schedule, schedule)
end
end end
...@@ -2,24 +2,13 @@ module Ci ...@@ -2,24 +2,13 @@ module Ci
class PipelineSchedulePolicy < PipelinePolicy class PipelineSchedulePolicy < PipelinePolicy
alias_method :pipeline_schedule, :subject alias_method :pipeline_schedule, :subject
condition(:protected_action) do condition(:owner_of_schedule) do
owned_by_developer? && owned_by_another? can?(:developer_access) && pipeline_schedule.owned_by?(@user)
end end
rule { protected_action }.prevent :update_pipeline_schedule rule { can?(:master_access) | owner_of_schedule }.policy do
enable :update_pipeline_schedule
private enable :admin_pipeline_schedule
def owned_by_developer?
return false unless @user
pipeline_schedule.project.team.developer?(@user)
end
def owned_by_another?
return false unless @user
!pipeline_schedule.owned_by?(@user)
end end
end end
end end
...@@ -162,7 +162,6 @@ class ProjectPolicy < BasePolicy ...@@ -162,7 +162,6 @@ class ProjectPolicy < BasePolicy
enable :create_pipeline enable :create_pipeline
enable :update_pipeline enable :update_pipeline
enable :create_pipeline_schedule enable :create_pipeline_schedule
enable :update_pipeline_schedule
enable :create_merge_request enable :create_merge_request
enable :create_wiki enable :create_wiki
enable :push_code enable :push_code
...@@ -188,7 +187,6 @@ class ProjectPolicy < BasePolicy ...@@ -188,7 +187,6 @@ class ProjectPolicy < BasePolicy
enable :admin_build enable :admin_build
enable :admin_container_image enable :admin_container_image
enable :admin_pipeline enable :admin_pipeline
enable :admin_pipeline_schedule
enable :admin_environment enable :admin_environment
enable :admin_deployment enable :admin_deployment
enable :admin_pages enable :admin_pages
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
= pipeline_schedule.owner&.name = pipeline_schedule.owner&.name
%td %td
.pull-right.btn-group .pull-right.btn-group
- if can?(current_user, :update_pipeline_schedule, @project) && !pipeline_schedule.owned_by?(current_user) - if can?(current_user, :update_pipeline_schedule, pipeline_schedule)
= link_to take_ownership_pipeline_schedule_path(pipeline_schedule), method: :post, title: s_('PipelineSchedules|Take ownership'), class: 'btn' do = link_to take_ownership_pipeline_schedule_path(pipeline_schedule), method: :post, title: s_('PipelineSchedules|Take ownership'), class: 'btn' do
= s_('PipelineSchedules|Take ownership') = s_('PipelineSchedules|Take ownership')
- if can?(current_user, :update_pipeline_schedule, pipeline_schedule) - if can?(current_user, :update_pipeline_schedule, pipeline_schedule)
......
...@@ -74,9 +74,10 @@ module API ...@@ -74,9 +74,10 @@ module API
optional :active, type: Boolean, desc: 'The activation of pipeline schedule' optional :active, type: Boolean, desc: 'The activation of pipeline schedule'
end end
put ':id/pipeline_schedules/:pipeline_schedule_id' do put ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :update_pipeline_schedule, user_project authorize! :read_pipeline_schedule, user_project
not_found!('PipelineSchedule') unless pipeline_schedule not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.update(declared_params(include_missing: false)) if pipeline_schedule.update(declared_params(include_missing: false))
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::PipelineScheduleDetails
...@@ -92,9 +93,10 @@ module API ...@@ -92,9 +93,10 @@ module API
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do
authorize! :update_pipeline_schedule, user_project authorize! :read_pipeline_schedule, user_project
not_found!('PipelineSchedule') unless pipeline_schedule not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.own!(current_user) if pipeline_schedule.own!(current_user)
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::PipelineScheduleDetails
...@@ -110,9 +112,10 @@ module API ...@@ -110,9 +112,10 @@ module API
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
delete ':id/pipeline_schedules/:pipeline_schedule_id' do delete ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :admin_pipeline_schedule, user_project authorize! :read_pipeline_schedule, user_project
not_found!('PipelineSchedule') unless pipeline_schedule not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :admin_pipeline_schedule, pipeline_schedule
status :accepted status :accepted
present pipeline_schedule.destroy, with: Entities::PipelineScheduleDetails present pipeline_schedule.destroy, with: Entities::PipelineScheduleDetails
......
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