Limit number of external services per org/user
Created by: miveronese
Ticket: https://sourcegraph.atlassian.net/browse/CLOUD-150
This PR adds, to the backend, on the Cloud mode, a limit to external services, allowing a max of 1 Github service + 1 Gitlab service per org/user.
As a result:
- the API cannot be used to add more than 1 external_service of a given type
- the API cannot be used to add external services that are not currently supported (only Github and Gitlab are currently supported)
Test plan
Unit tests
New unit tests have been added to cover the new checks. You can run them with go test ./cmd/frontend/graphqlbackend/. -v -run TestAddExternalService
Manual tests
Manual tests were done (see video) using the /api/console with the following mutation.
mutation AddExternalService($input: AddExternalServiceInput!) {
addExternalService(input: $input) {
kind,
displayName,
config,
}
}
Query Variables:
{
"input": {
"kind": "Test",
"displayName": "Test",
"namespace": "Test",
"config": "{\n \"url\": \"https://test.com\",\n \"token\": \"testest\",\n \"projectQuery\": [\n \"projects?membership=true&archived=no\"\n ]\n}"
}
}
https://user-images.githubusercontent.com/1552863/162556880-4cd634c5-30b8-4400-9e9b-554cf4f57aa9.mov