Show better errors on project creation via API or project transfer via UI when "Default project creation level" is set to "No one" at group-level
Summary
We have the ability to allow no one to create a project in a group. With this option set, no user can create a project via the API or transfer a project to the group.
Obviously, this will fail.
Unfortunately, the errors shown in both cases do not clearly point to why project creation or transfer fails.
We should try make the errors more clear as currently this makes troubleshooting very difficult. Support had a back-and-forth with a customer who ran into this until the customer figured out the cause.
Zendesk ticket: https://gitlab.zendesk.com/agent/tickets/97292 (GitLab internal-only link).
Steps to reproduce, logs, and screenshot(s)
- For any group, navigate to Settings > General and set "Allowed to create projects" to "No one"
- Attempt to create a project in the group via the API
- Example:
curl --header "PRIVATE-TOKEN: <token>" -X POST "https://<domain>/api/v4/projects?name=project-b&namespace_id=2&visibility=public" - That attmept will fail with
{"message":{"namespace":["is not valid"],"limit_reached":[]}} - In the logs we see only a 400 error:
==> /var/log/gitlab/gitlab-rails/api_json.log <==
{"time":"2018-05-31T14:06:35.244Z","severity":"INFO","duration":37.54,"db":2.7,"view":34.839999999999996,"status":400,"method":"POST","path":"/api/v4/projects","params":{"name":"project-b","namespace_id":"2","visibility":"public"},"host":"collen-gitlab-test","ip":"127.0.0.1","ua":"curl/7.47.0","user_id":1,"username":"root"}
==> /var/log/gitlab/gitlab-workhorse/current <==
2018-05-31_14:06:35.25132 collen-gitlab-test @ - - [2018/05/31:14:06:35 +0000] "POST /api/v4/projects?name=project-b&namespace_id=2&visibility=public HTTP/1.1" 400 61 "" "curl/7.47.0" 0.055
- Next, try to transfer a project to this group via the UI
- This fails with
Transfer failed, please contact an adminshown in the UI. (see below screenshot) - In the logs the
ProjectsController#transferaction shows aCompleted 200 OKand"status":200. See below:
==> /var/log/gitlab/gitlab-rails/production.log <==
Started PUT "/root/test-file-lock/transfer" for 155.93.248.136 at 2018-05-31 14:15:18 +0000
Processing by ProjectsController#transfer as JS
Parameters: {"utf8"=>"✓", "new_namespace_id"=>"2", "commit"=>"Transfer project", "namespace_id"=>"root", "id"=>"test-file-lock"}
Completed 200 OK in 35ms (Views: 14.6ms | ActiveRecord: 3.7ms | Elasticsearch: 0.0ms)
==> /var/log/gitlab/gitlab-rails/production_json.log <==
{"method":"PUT","path":"/root/test-file-lock/transfer","format":"js","controller":"ProjectsController","action":"transfer","status":200,"duration":36.12,"view":14.64,"db":3.65,"time":"2018-05-31T14:15:18.634Z","params":[{"key":"utf8","value":"✓"},{"key":"_method","value":"put"},{"key":"new_namespace_id","value":"2"},{"key":"commit","value":"Transfer project"},{"key":"namespace_id","value":"root"},{"key":"id","value":"test-file-lock"}],"remote_ip":"155.93.248.136","user_id":1,"username":"root"}
==> /var/log/gitlab/gitlab-workhorse/current <==
2018-05-31_14:15:18.67185 collen-gitlab-test @ - - [2018/05/31:14:15:18 +0000] "POST /root/test-file-lock/transfer HTTP/1.1" 200 46 "https://collen-gitlab-test/root/test-file-lock/edit" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" 0.055
