Skip to content
Closed
4 changes: 4 additions & 0 deletions app/controllers/api/v2/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def show
raise Pundit::NotAuthorizedError unless plans_policy.show?

@items = [@plan]
@question_and_answer = ActiveModel::Type::Boolean.new.cast(params[:question_and_answer])

render '/api/v2/plans/index', status: :ok
end

Expand All @@ -26,6 +28,8 @@ def index

@plans = PlansPolicy::Scope.new(@resource_owner).resolve
@items = paginate_response(results: @plans)
@question_and_answer = ActiveModel::Type::Boolean.new.cast(params[:question_and_answer])

render '/api/v2/plans/index', status: :ok
end
end
Expand Down
16 changes: 16 additions & 0 deletions app/presenters/api/v2/research_output_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def fetch_q_and_a(themes:)
end
ret.select { |item| item[:description].present? }
end

# Fetch all questions and answers from a plan, regardless of theme
def fetch_all_q_and_a(plan:)
return [] unless plan&.questions.present?

plan.questions.filter_map do |q|
a = plan.answers.find { |ans| ans.question_id == q.id }
next unless a.present? && !a.blank?

{
title: "Question #{q.number || q.id}",
question: q.text.to_s,
answer: a.text.to_s
}
end
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
end
end
Expand Down
18 changes: 18 additions & 0 deletions app/views/api/v2/plans/_show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ unless @minimal

outputs = plan.research_outputs.any? ? plan.research_outputs : [plan]

if @question_and_answer
json.questions_and_answers do
outputs.each do |output|
presenter = Api::V2::ResearchOutputPresenter.new(output: output)
Comment thread
momo3404 marked this conversation as resolved.
Outdated
q_and_a = presenter.send(:fetch_all_q_and_a, plan: plan)
next if q_and_a.blank?

json.set! output.id.to_s do
json.array! q_and_a do |item|
json.title item[:title]
json.question item[:question]
json.answer item[:answer]
end
end
end
end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at the comment at the top of this file:

# Note the symbol of the dmproadmap json object
# nested in extensions which is the container for the json template object, etc.
# A JSON representation of a Data Management Plan in the
# RDA Common Standard format

With the exception of json.extension, I think all of the keys here map onto the RDA-DMP-Common-Standard structure. Maybe this additional data should also be placed inside of json.extension?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably have to get Marcus to sign off on what the schema should look like in the end, but I agree additional data like this should be inside the extension category. I moved it there.

Copy link
Copy Markdown
Collaborator Author

@momo3404 momo3404 Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marcus signed off on putting it into extension, and he also said the flag should be titled complete and the JSON should have complete_plan, like this:

        "complete_plan": [
            {
              "title": "Question 1",
              "question": "<p>What considerations will you take into account with respect to ethical, legal, or commercial issues?</p>\r\n<p><br>Describe any applicable ethical, legal, or commercial considerations related to your project and data. This includes research involving Indigenous communities and knowledges, human subjects, legal and commercial considerations/agreements, partnerships or data with a high level of risk associated with it.</p>",
              "answer": "<p>test</p>"
            },
            {
              "title": "Question 2",
              "question": "<p>What data will you collect or otherwise bring into your project under this plan?</p>\r\n<p><br>Describe the data that will be collected, generated, and/or acquired.</p>",
              "answer": "<p>test</p>"
            },
          ]

I added those changes to this PR.


json.dataset outputs do |output|
json.partial! "api/v2/datasets/show", output: output
end
Expand Down