diff --git a/api/v1/routes/core.rb b/api/v1/routes/core.rb index 1b3661f308..9059992ea1 100644 --- a/api/v1/routes/core.rb +++ b/api/v1/routes/core.rb @@ -45,6 +45,10 @@ def current_user def find_user User.where(key: params[:key]).first if params[:key] end + + def site_root + request.host_with_port + '/' + end end end end diff --git a/api/v1/routes/iterations.rb b/api/v1/routes/iterations.rb index 6a868b997d..07a626f301 100644 --- a/api/v1/routes/iterations.rb +++ b/api/v1/routes/iterations.rb @@ -115,6 +115,7 @@ class Iterations < Core locals = { submission: attempt.submission, domain: request.url.gsub(/#{request.path}$/, ""), + what_next_instructions: what_next_instructions(attempt) } pg :attempt, locals: locals end @@ -135,6 +136,28 @@ class Iterations < Core pg :iterations, locals: { submissions: submissions } end + + private + + def what_next_instructions(attempt) + return '' unless $flipper['cli-call-to-action'].enabled?(attempt.user) + + track = attempt.iteration.track_id + exercise = attempt.iteration.slug + url = File.join('http://', site_root, 'tracks', track, 'exercises', exercise) + <<~INSTRUCTIONS + Your #{track} solution for #{exercise} has been submitted. + + Programmers generally spend far more time reading code than writing it. + To benefit the most from this exercise, find 3 or more submissions that you can + learn something from, have questions about, or have suggestions for. + Post your thoughts and questions in the comments, and start a discussion. + Consider revising your solution to incorporate what you learn. + + Yours and others' solutions to this problem: + #{url} + INSTRUCTIONS + end end end end diff --git a/api/v1/views/attempt.pg b/api/v1/views/attempt.pg index 59a524e8a4..453d4fa183 100644 --- a/api/v1/views/attempt.pg +++ b/api/v1/views/attempt.pg @@ -4,6 +4,7 @@ node language: submission.problem.language node slug: submission.slug node name: submission.problem.name node iteration: submission.version +node what_next_instructions: what_next_instructions # deprecated node id: submission.key diff --git a/test/api/assignments_test.rb b/test/api/assignments_test.rb index 9bedc60301..854c7795b4 100644 --- a/test/api/assignments_test.rb +++ b/test/api/assignments_test.rb @@ -12,6 +12,7 @@ def app attr_reader :alice def setup super + $flipper['cli-call-to-action'].enable @alice = User.create(username: 'alice', github_id: 1) Language.instance_variable_set(:"@by_track_id", "fake" => "Fake") end diff --git a/test/fixtures/approvals/api_multifile_submission_accepted.approved.json b/test/fixtures/approvals/api_multifile_submission_accepted.approved.json index 1fc86c296b..ed42e3c813 100644 --- a/test/fixtures/approvals/api_multifile_submission_accepted.approved.json +++ b/test/fixtures/approvals/api_multifile_submission_accepted.approved.json @@ -5,6 +5,7 @@ "slug": "one", "name": "One", "iteration": 1, + "what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n", "id": "", "status": "saved", "track": "fake", diff --git a/test/fixtures/approvals/api_submission_accepted.approved.json b/test/fixtures/approvals/api_submission_accepted.approved.json index 1fc86c296b..ed42e3c813 100644 --- a/test/fixtures/approvals/api_submission_accepted.approved.json +++ b/test/fixtures/approvals/api_submission_accepted.approved.json @@ -5,6 +5,7 @@ "slug": "one", "name": "One", "iteration": 1, + "what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n", "id": "", "status": "saved", "track": "fake", diff --git a/test/fixtures/approvals/api_submission_accepted_on_completed.approved.json b/test/fixtures/approvals/api_submission_accepted_on_completed.approved.json index 1fc86c296b..ed42e3c813 100644 --- a/test/fixtures/approvals/api_submission_accepted_on_completed.approved.json +++ b/test/fixtures/approvals/api_submission_accepted_on_completed.approved.json @@ -5,6 +5,7 @@ "slug": "one", "name": "One", "iteration": 1, + "what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n", "id": "", "status": "saved", "track": "fake",