Created
January 24, 2018 18:20
-
-
Save indec/9208bf25c977d4a39b0153cf7382fd16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/api/projects.rb b/app/api/projects.rb | |
index cbfe5e8fdd1..2e6cc251270 100644 | |
--- a/app/api/projects.rb | |
+++ b/app/api/projects.rb | |
@@ -977,8 +977,8 @@ class Api::Projects < Api::App | |
end | |
AddProjectCardMutation = PlatformClient.parse <<-'GRAPHQL' | |
- mutation($projectColumnId: ID!, $contentId: ID, $note: String) { | |
- addProjectCard(input: { projectColumnId: $projectColumnId, contentId: $contentId, note: $note }) { | |
+ mutation($projectId: ID!, $projectColumnId: ID!, $contentId: ID, $note: String) { | |
+ addProjectCard(input: { projectId: $projectId, projectColumnId: $projectColumnId, contentId: $contentId, note: $note }) { | |
cardEdge { | |
card: node { | |
...Api::Serializer::ProjectColumnCardFragment | |
@@ -1007,20 +1007,13 @@ class Api::Projects < Api::App | |
card_content_id = data["content_id"] | |
column_id = data["column_id"] | |
- if column.nil? && column_id.present? | |
- column = ProjectColumn.find_by_id(column_id) | |
- if column | |
- if column.project_id != project.id | |
- deliver_error! 422, errors: ["The specified column isn't in the project"], | |
- documentation_url: @documentation_url | |
- end | |
- else | |
- deliver_error! 422, errors: ["Can't find a column with the specified ID"], | |
- documentation_url: @documentation_url | |
- end | |
+ column_relay_id = if column | |
+ column.global_relay_id | |
+ elsif column_id.present? | |
+ Platform::Helpers::NodeIdentification.to_global_id("ProjectColumn", column_id) | |
end | |
- if card_content_id.present? || column.nil? | |
+ if card_content_id.present? || column_relay_id.nil? | |
if card_content_id.present? && card_content_type.present? | |
content_relay_id = Platform::Helpers::NodeIdentification.to_global_id(card_content_type, card_content_id) | |
else | |
@@ -1029,19 +1022,18 @@ class Api::Projects < Api::App | |
end | |
end | |
- if column | |
- variables = { | |
- "projectColumnId" => column.global_relay_id, | |
- "contentId" => content_relay_id, | |
+ variables = { | |
+ "projectId" => project.global_relay_id, | |
+ "contentId" => content_relay_id, | |
+ } | |
+ if column_relay_id.nil? | |
+ results = platform_execute(AddPendingProjectCardMutation, variables: variables) | |
+ else | |
+ variables.merge!({ | |
+ "projectColumnId" => column_relay_id, | |
"note" => data["note"], | |
- } | |
+ }) | |
results = platform_execute(AddProjectCardMutation, variables: variables) | |
- else | |
- variables = { | |
- "projectId" => project.global_relay_id, | |
- "contentId" => content_relay_id, | |
- } | |
- results = platform_execute(AddPendingProjectCardMutation, variables: variables) | |
end | |
if results.errors.all.any? | |
diff --git a/lib/platform/mutations/add_project_card.rb b/lib/platform/mutations/add_project_card.rb | |
index 8fd7deb9fd8..0daec6f5d4b 100644 | |
--- a/lib/platform/mutations/add_project_card.rb | |
+++ b/lib/platform/mutations/add_project_card.rb | |
@@ -8,6 +8,7 @@ module Platform | |
minimum_accepted_scopes ["public_repo"] | |
+ input_field :projectId, types.ID, "The Node ID of the Project.", visibility: :internal | |
input_field :projectColumnId, !types.ID, "The Node ID of the ProjectColumn." | |
input_field :contentId, types.ID, "The content of the card. Must be a member of the ProjectCardItem union" | |
input_field :note, types.String, "The note on the card." | |
@@ -20,6 +21,12 @@ module Platform | |
[Objects::ProjectColumn], inputs[:projectColumnId], context | |
) | |
project = column.project | |
+ if inputs[:projectId].present? | |
+ if inputs[:projectId] != project.global_relay_id | |
+ raise Errors::Validation.new("The specified column isn't in the project") | |
+ end | |
+ end | |
+ | |
helper = Platform::Helpers::AddProjectCard.new(project, inputs, context) | |
helper.check_permissions | |
diff --git a/test/integration/api/projects_test.rb b/test/integration/api/projects_test.rb | |
index 368f71a3db6..368c9640fb9 100644 | |
--- a/test/integration/api/projects_test.rb | |
+++ b/test/integration/api/projects_test.rb | |
@@ -1392,7 +1392,8 @@ class Api::ProjectsTest < Api::TestCase | |
@column_one.lock_for_rebalance do | |
data = api :post, "/projects/#{@column_one.project.id}/cards", {}, input: { | |
- note: "I hope this works", | |
+ content_id: @issue_three.id, | |
+ content_type: @issue_three.class.name, | |
column_id: @column_one.id, | |
}.to_json | |
end | |
@@ -1415,7 +1416,8 @@ class Api::ProjectsTest < Api::TestCase | |
assert_equal 422, last_response.status | |
error = data["errors"].shift | |
assert data["errors"].empty? | |
- assert_equal "Can't find a column with the specified ID", error | |
+ # TODO: Make this error message less opaque: | |
+ # "Could not resolve to a node with the global id of 'MDEzOlByb2plY3RDb2x1bW4xMzgy'." | |
end | |
test "fails on creating project card with a column that doesn't belong to the project" do | |
@@ -1431,7 +1433,7 @@ class Api::ProjectsTest < Api::TestCase | |
assert_equal 422, last_response.status | |
error = data["errors"].shift | |
assert data["errors"].empty? | |
- assert_equal "The specified column isn't in the project", error | |
+ assert_equal "The specified column isn't in the project", error["message"] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment