add updateImmediately link to query representer

pull/5219/head
Jens Ulferts 8 years ago
parent cc89242df9
commit 374a608f99
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 4
      docs/api/apiv3/endpoints/queries.apib
  2. 9
      lib/api/v3/queries/query_representer.rb
  3. 36
      spec/lib/api/v3/queries/query_representer_spec.rb

@ -8,8 +8,8 @@ A query defines how work packages can be filtered and displayed. Clients can def
|:-------------------:|----------------------------------------------------------------------| --------------------------------------- |
| star | Elevates the query to the status of 'starred' | **Permission**: save queries for own queries, manage public queries for public queries; Only present if query is not yet starred |
| unstar | Removes the 'starred' status | **Permission**: save queries for own queries, manage public queries for public queries; Only present if query is starred |
As of now, no actions are defined.
| update | Use the Form based process to verify the query before persisting | **Permission**: view work packages |
| updateImmediately | Persist the query without using a Form based process for guidance | **Permission**: save queries for own queries, manage public queries for public queries; |
## Linked Properties

@ -145,6 +145,15 @@ module API
}
end
link :updateImmediately do
next unless represented.new_record? && allowed_to?(:create) ||
represented.persisted? && allowed_to?(:update)
{
href: api_v3_paths.query(represented.id),
method: :patch
}
end
link :delete do
next if represented.new_record? ||
!allowed_to?(:destroy)

@ -185,6 +185,42 @@ describe ::API::V3::Queries::QueryRepresenter do
end
end
describe 'updateImmediately action link' do
let(:permissions) { [:update] }
it_behaves_like 'has an untitled link' do
let(:link) { 'updateImmediately' }
let(:href) { api_v3_paths.query query.id }
end
context 'when not persisted and lacking permission' do
let(:query) { FactoryGirl.build(:query, project: project) }
it_behaves_like 'has no link' do
let(:link) { 'updateImmediately' }
end
end
context 'when not persisted and having permission' do
let(:permissions) { [:create] }
let(:query) { FactoryGirl.build(:query, project: project) }
it_behaves_like 'has an untitled link' do
let(:link) { 'updateImmediately' }
let(:href) { api_v3_paths.query query.id }
end
end
context 'when not allowed to update' do
let(:permissions) { [] }
it_behaves_like 'has no link' do
let(:link) { 'updateImmediately' }
end
end
end
context 'with filter, sort, group by and pageSize' do
let(:representer) do
described_class.new(query,

Loading…
Cancel
Save