Commit a17a1556 authored by Jan Provaznik's avatar Jan Provaznik Committed by Thong Kuah

API issues - minor cleanup of permission check

Adds `set_issue_updated_at` similar to `set_issue_created_at`
permission and cleans up the related permission check in issues
API.
parent 2a29f910
......@@ -164,6 +164,7 @@ class ProjectPolicy < BasePolicy
enable :set_issue_iid
enable :set_issue_created_at
enable :set_issue_updated_at
enable :set_note_created_at
end
......
......@@ -252,14 +252,9 @@ module API
issue = user_project.issues.find_by!(iid: params.delete(:issue_iid))
authorize! :update_issue, issue
# Setting updated_at only allowed for admins and owners as well
if params[:updated_at].present?
if current_user.admin? || user_project.owner == current_user || current_user.owned_groups.include?(user_project.owner)
issue.system_note_timestamp = params[:updated_at]
else
params.delete(:updated_at)
end
end
# Setting updated_at is allowed only for admins and owners
params.delete(:updated_at) unless current_user.can?(:set_issue_updated_at, user_project)
issue.system_note_timestamp = params[:updated_at]
update_params = declared_params(include_missing: false).merge(request: request, api: true)
......
......@@ -66,7 +66,7 @@ describe ProjectPolicy do
%i[
change_namespace change_visibility_level rename_project remove_project
archive_project remove_fork_project destroy_merge_request destroy_issue
set_issue_iid set_issue_created_at set_note_created_at
set_issue_iid set_issue_created_at set_issue_updated_at set_note_created_at
]
end
......
......@@ -64,7 +64,7 @@ RSpec.shared_context 'ProjectPolicy context' do
%i[
change_namespace change_visibility_level rename_project remove_project
archive_project remove_fork_project destroy_merge_request destroy_issue
set_issue_iid set_issue_created_at set_note_created_at
set_issue_iid set_issue_created_at set_issue_updated_at set_note_created_at
]
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