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. 10
      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,7 +62,11 @@ child @work_packages => :work_packages do
end
node :_actions do |wp|
@can.each_with_object([]) { |(k, v), a| a << k if v }
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 }
end
end
node :_links do |wp|
@ -71,11 +75,11 @@ child @work_packages => :work_packages do
edit: -> { edit_work_package_path(wp) },
log_time: -> { new_work_package_time_entry_path(wp) },
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]) },
copy: -> { new_move_work_packages_path(ids: [wp.id], copy: true) },
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.() }
end
end

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

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

@ -116,8 +116,7 @@ describe 'api/v3/work_packages/index.api.rabl' do
log_time: true,
update: false,
move: nil,
copy: true,
delete: false
delete: true
}
}
@ -132,10 +131,6 @@ describe 'api/v3/work_packages/index.api.rabl' do
specify {
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
context 'with all actions' do
@ -145,20 +140,31 @@ describe 'api/v3/work_packages/index.api.rabl' do
log_time: true,
update: true,
move: true,
copy: true,
delete: true
}
}
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_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_type(Hash).at_path('work_packages/0/_links') }
# 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 {
expect(parse_json(subject, 'work_packages/0/_links/edit')).to match(%r{/work_packages/(\d+)/edit})

Loading…
Cancel
Save