Commit 687f27c2 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Do not cast project IDs to string in API response

Previously we were casting the invalid project IDs to strings because
we were trying to cover the case where the client sends an invalid ID
to the backend. This was causing problems on client application because
it was expecting the IDs to be integers. I do believe that the effort
of covering the case where client sends an invalid ID will cause more
problems than it solves therefore I am removing the related logic and
assuming the client is always sending us valid IDs.

/closes https://gitlab.com/gitlab-org/gitlab/-/issues/196729
parent ea921859
......@@ -31,9 +31,9 @@ module Dashboard
end
def find_invalid_ids(projects_to_add, project_ids)
found_ids = projects_to_add.map(&:id).map(&:to_s)
found_ids = projects_to_add.map(&:id)
project_ids.map(&:to_s) - found_ids
project_ids.map(&:to_i) - found_ids
end
def add_projects(projects)
......
......@@ -722,7 +722,7 @@ describe OperationsController do
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
expect(json_response['added']).to be_empty
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to contain_exactly('', '-1', '-2')
expect(json_response['invalid']).to contain_exactly(0, -1, -2)
user.reload
expect(user.ops_dashboard_projects).to be_empty
......
......@@ -107,7 +107,7 @@ describe Security::ProjectsController do
expect(json_response).to eq({
'added' => [],
'duplicate' => [],
'invalid' => ['-1']
'invalid' => [-1]
})
end
end
......
......@@ -17,10 +17,7 @@
"invalid": {
"type": "array",
"items": {
"oneOf": [
{ "type": "string" },
{ "type": "null" }
]
"items": { "type": "integer" }
}
}
},
......
......@@ -57,15 +57,6 @@ describe Dashboard::Projects::CreateService do
end
end
end
context 'with invalid project ids' do
let(:input) { [nil, -1, '-1', :symbol] }
let(:output) { [] }
it 'does not add invalid project ids' do
expect(result).to eq(expected_result(invalid_project_ids: input.map(&:to_s)))
end
end
end
private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment