add author and responsible to wp resource signaling

pull/10337/head
ulferts 3 years ago
parent 9322c378c4
commit 2fdfa45d3a
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 10
      lib/api/decorators/sql/hal.rb
  2. 22
      lib/api/decorators/sql/hal_associated_resource.rb
  3. 4
      lib/api/v3/work_packages/work_package_sql_representer.rb
  4. 106
      spec/lib/api/v3/work_packages/work_package_sql_representer_rendering_spec.rb

@ -141,7 +141,7 @@ module API
SQL
else
<<-SQL.squish
'#{name}', json_build_object(#{link_attributes.join(', ')})
'#{name}', '{ "href": null }'::jsonb || json_strip_nulls(json_build_object(#{link_attributes.join(', ')}))::jsonb
SQL
end
end
@ -177,9 +177,9 @@ module API
def select_sql(select, walker_result)
<<~SELECT
json_strip_nulls(json_build_object(
json_build_object(
#{json_object_string(select, walker_result)}
))
)
SELECT
end
@ -280,9 +280,9 @@ module API
return if json_object.blank?
<<~SELECT
'#{namespace}', json_strip_nulls(json_build_object(
'#{namespace}', json_build_object(
#{json_object}
))
)
SELECT
end

@ -49,7 +49,8 @@ module API
CASE #{table_name}_type
WHEN 'Group' THEN format('#{api_v3_paths.group('%s')}', #{column_name})
WHEN 'PlaceholderUser' THEN format('#{api_v3_paths.placeholder_user('%s')}', #{column_name})
ELSE format('#{api_v3_paths.user('%s')}', #{column_name})
WHEN 'User' THEN format('#{api_v3_paths.user('%s')}', #{column_name})
ELSE NULL
END
SQL
}
@ -63,11 +64,16 @@ module API
" || ' ' || "
end
user_format = User::USER_FORMATS_STRUCTURE[Setting.user_format]
.map { |column| "#{table_name}_#{column}"}
.join(join_string)
<<~SQL.squish
CASE #{table_name}_type
WHEN 'Group' THEN lastname
WHEN 'PlaceholderUser' THEN lastname
ELSE #{User::USER_FORMATS_STRUCTURE[Setting.user_format].join(join_string)}
WHEN 'Group' THEN #{table_name}_lastname
WHEN 'PlaceholderUser' THEN #{table_name}_lastname
WHEN 'User' THEN #{user_format}
ELSE NULL
END
SQL
}
@ -76,10 +82,10 @@ module API
def associated_user_link_join(table_name, column_name)
{ table: :users,
condition: "#{table_name}.id = #{column_name}",
select: ["#{table_name}.firstname",
"#{table_name}.lastname",
"#{table_name}.login",
"#{table_name}.mail",
select: ["#{table_name}.firstname #{table_name}_firstname",
"#{table_name}.lastname #{table_name}_lastname",
"#{table_name}.login #{table_name}_login",
"#{table_name}.mail #{table_name}_mail",
"#{table_name}.type #{table_name}_type"] }
end
end

@ -44,9 +44,13 @@ module API
condition: 'projects.id = project_id',
select: ['projects.name project_name'] }
associated_user_link :author
associated_user_link :assignee,
column_name: :assigned_to_id
associated_user_link :responsible
property :_type,
representation: ->(*) { "'WorkPackage'" }

@ -46,10 +46,14 @@ describe ::API::V3::WorkPackages::WorkPackageSqlRepresenter, 'rendering' do
let(:rendered_work_package) do
create(:work_package,
project: project,
assigned_to: assignee)
assigned_to: assignee,
author: author,
responsible: responsible)
end
let(:project) { create(:project) }
let(:assignee) { create(:user) }
let(:assignee) { nil }
let(:author) { create(:user) }
let(:responsible) { nil }
let(:select) { { '*' => {} } }
@ -73,8 +77,14 @@ describe ::API::V3::WorkPackages::WorkPackageSqlRepresenter, 'rendering' do
title: project.name
},
assignee: {
href: api_v3_paths.user(assignee.id),
title: assignee.name
href: nil
},
responsible: {
href: nil
},
author: {
href: api_v3_paths.user(author.id),
title: author.name
}
}
}
@ -86,16 +96,18 @@ describe ::API::V3::WorkPackages::WorkPackageSqlRepresenter, 'rendering' do
end
end
describe 'assignee link' do
let(:select) { { 'assignee' => {} } }
shared_examples_for 'principal link' do |link_name, only_user: false|
let(:select) { { link_name => {} } }
context 'with a user' do
let(:principal_object) { create(:user) }
let(:expected) do
{
_links: {
assignee: {
href: api_v3_paths.user(assignee.id),
title: assignee.name
link_name => {
href: api_v3_paths.user(principal_object.id),
title: principal_object.name
}
}
}
@ -107,44 +119,64 @@ describe ::API::V3::WorkPackages::WorkPackageSqlRepresenter, 'rendering' do
end
end
context 'with a group' do
let(:assignee) { create(:group) }
let(:expected) do
{
_links: {
assignee: {
href: api_v3_paths.group(assignee.id),
title: assignee.name
unless only_user
context 'with a group' do
let(:principal_object) { create(:group) }
let(:expected) do
{
_links: {
link_name => {
href: api_v3_paths.group(principal_object.id),
title: principal_object.name
}
}
}
}
end
end
it 'renders as expected' do
expect(json)
.to be_json_eql(expected.to_json)
it 'renders as expected' do
expect(json)
.to be_json_eql(expected.to_json)
end
end
end
context 'with a placeholder user' do
let(:assignee) { create(:placeholder_user) }
context 'with a placeholder user' do
let(:principal_object) { create(:placeholder_user) }
let(:expected) do
{
_links: {
assignee: {
href: api_v3_paths.placeholder_user(assignee.id),
title: assignee.name
let(:expected) do
{
_links: {
link_name => {
href: api_v3_paths.placeholder_user(principal_object.id),
title: principal_object.name
}
}
}
}
end
end
it 'renders as expected' do
expect(json)
.to be_json_eql(expected.to_json)
it 'renders as expected' do
expect(json)
.to be_json_eql(expected.to_json)
end
end
end
end
describe 'assignee link' do
it_behaves_like 'principal link', 'assignee' do
let(:assignee) { principal_object }
end
end
describe 'responsible link' do
it_behaves_like 'principal link', 'responsible' do
let(:responsible) { principal_object }
end
end
describe 'author link' do
it_behaves_like 'principal link', 'author', only_user: true do
let(:author) { principal_object }
end
end
end

Loading…
Cancel
Save