Correctly map work package permissions onto possible actions in API

Also fixes the context menu and features/work_packages/moves/work_package_moves_new_copy.feature
pull/1282/head
Till Breuer 11 years ago
parent ad21d66829
commit 34c1b2a104
  1. 8
      app/views/api/v3/work_packages/index.api.rabl
  2. 2
      config/locales/js-de.yml
  3. 2
      config/locales/js-en.yml
  4. 24
      spec/views/api/v3/work_packages/index_api_json_spec.rb

@ -62,8 +62,12 @@ child @work_packages => :work_packages do
end end
node :_actions do |wp| node :_actions do |wp|
if !!@can[:move]
@can.each_with_object([]) { |(k, v), a| a << k if v } | [:copy, :duplicate]
else
@can.each_with_object([]) { |(k, v), a| a << k if v } @can.each_with_object([]) { |(k, v), a| a << k if v }
end end
end
node :_links do |wp| node :_links do |wp|
if wp.persisted? if wp.persisted?
@ -71,11 +75,11 @@ child @work_packages => :work_packages do
edit: -> { edit_work_package_path(wp) }, edit: -> { edit_work_package_path(wp) },
log_time: -> { new_work_package_time_entry_path(wp) }, log_time: -> { new_work_package_time_entry_path(wp) },
watch: -> { watcher_link(wp, User.current) }, watch: -> { watcher_link(wp, User.current) },
duplicate: -> { new_project_work_package_path({ project_id: @project, copy_from: wp }) }, duplicate: -> { new_project_work_package_path({ project_id: wp.project, copy_from: wp }) },
move: -> { new_move_work_packages_path(ids: [wp.id]) }, move: -> { new_move_work_packages_path(ids: [wp.id]) },
copy: -> { new_move_work_packages_path(ids: [wp.id], copy: true) }, copy: -> { new_move_work_packages_path(ids: [wp.id], copy: true) },
delete: -> { work_packages_bulk_path(ids: [wp.id], method: :delete) } delete: -> { work_packages_bulk_path(ids: [wp.id], method: :delete) }
}.select { |action, link| @can[action] } }.select { |action, link| @can[action] || @can[:move] && [:copy, :duplicate].include?(action) }
links = links.update(links) { |key, old_val, new_val| new_val.() } links = links.update(links) { |key, old_val, new_val| new_val.() }
end end
end end

@ -32,7 +32,9 @@ de:
hide: "Verbergen" hide: "Verbergen"
loading: "Lädt ..." loading: "Lädt ..."
button_check_all: "Alles auswählen" button_check_all: "Alles auswählen"
button_copy: "Kopieren"
button_delete: "Löschen" button_delete: "Löschen"
button_duplicate: "Duplizieren"
button_edit: "Bearbeiten" button_edit: "Bearbeiten"
button_log_time: "Aufwand buchen" button_log_time: "Aufwand buchen"
button_move: "Verschieben" button_move: "Verschieben"

@ -32,7 +32,9 @@ en:
hide: "Hide" hide: "Hide"
loading: "Loading ..." loading: "Loading ..."
button_check_all: "Check all" button_check_all: "Check all"
button_copy: "Copy"
button_delete: "Delete" button_delete: "Delete"
button_duplicate: "Duplicate"
button_edit: "Edit" button_edit: "Edit"
button_log_time: "Log time" button_log_time: "Log time"
button_move: "Move" button_move: "Move"

@ -116,8 +116,7 @@ describe 'api/v3/work_packages/index.api.rabl' do
log_time: true, log_time: true,
update: false, update: false,
move: nil, move: nil,
copy: true, delete: true
delete: false
} }
} }
@ -132,10 +131,6 @@ describe 'api/v3/work_packages/index.api.rabl' do
specify { specify {
expect(parse_json(subject, 'work_packages/0/_links/log_time')).to match(%r{/work_packages/(\d+)/time_entries/new}) expect(parse_json(subject, 'work_packages/0/_links/log_time')).to match(%r{/work_packages/(\d+)/time_entries/new})
} }
specify {
expect(parse_json(subject, 'work_packages/0/_links/copy')).to match(%r{/work_packages/move/new\?copy\=true})
}
end end
context 'with all actions' do context 'with all actions' do
@ -145,20 +140,31 @@ describe 'api/v3/work_packages/index.api.rabl' do
log_time: true, log_time: true,
update: true, update: true,
move: true, move: true,
copy: true,
delete: true delete: true
} }
} }
it { should have_json_path('work_packages/0/_actions') } it { should have_json_path('work_packages/0/_actions') }
it { should have_json_type(Array).at_path('work_packages/0/_actions') } it { should have_json_type(Array).at_path('work_packages/0/_actions') }
it { should have_json_size(6).at_path('work_packages/0/_actions') } it { should have_json_size(7).at_path('work_packages/0/_actions') }
it { should have_json_path('work_packages/0/_actions/' ) }
specify {
expect(parse_json(subject, 'work_packages/0/_actions/5')).to match(%r{copy})
}
specify {
expect(parse_json(subject, 'work_packages/0/_actions/6')).to match(%r{duplicate})
}
it { should have_json_path('work_packages/0/_links') } it { should have_json_path('work_packages/0/_links') }
it { should have_json_type(Hash).at_path('work_packages/0/_links') } it { should have_json_type(Hash).at_path('work_packages/0/_links') }
# FIXME: check missing permission # FIXME: check missing permission
it { should have_json_size(5).at_path('work_packages/0/_links') } it { should have_json_size(6).at_path('work_packages/0/_links') }
specify {
expect(parse_json(subject, 'work_packages/0/_links/copy')).to match(%r{/work_packages/move/new\?copy\=true})
}
specify { specify {
expect(parse_json(subject, 'work_packages/0/_links/edit')).to match(%r{/work_packages/(\d+)/edit}) expect(parse_json(subject, 'work_packages/0/_links/edit')).to match(%r{/work_packages/(\d+)/edit})

Loading…
Cancel
Save