Creating a group with reserved name 'projects' ends with 500 error page when Mattermost team group is enabled

Summary

Merge request gitlab-ce!15052 freed up some reserved names, but creating a new group with 'projects' name fails with "500 Whoops, something went wrong on our end."

Renaming group to 'projects' fails with a decent error message, but it still doesn't allow the group to be named 'projects'.

Steps to reproduce

Try to create new group and name it 'projects', leave everything else to default, e.g. have "Create Mattermost team for this group" enabled. Click on 'Create'.

What is the current bug behavior?

500 error is shown.

What is the expected correct behavior?

Either group should be created as projects has moved to /-/projects/ or a graceful error message should be shown.

Relevant logs and/or screenshots

Started POST "/groups" for 149.20.66.202 at 2017-12-13 07:52:59 -0500
Processing by GroupsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "group"=>{"parent_id"=>"", "path"=>"projects", "name"=>"ISC Projects", "description"=>"", "visibility_level"=>"20", "create_chat_team"=>"true"}}
Completed 500 Internal Server Error in 26ms (ActiveRecord: 1.5ms | Elasticsearch: 0.0ms)

NoMethodError (undefined method `each' for nil:NilClass):
  lib/mattermost/session.rb:170:in `parse_cookie'
  lib/mattermost/session.rb:117:in `oauth_uri'
  lib/mattermost/session.rb:89:in `create'
  lib/mattermost/session.rb:39:in `block in with_session'
  lib/mattermost/session.rb:145:in `with_lease'
  lib/mattermost/session.rb:38:in `with_session'
  lib/mattermost/client.rb:12:in `with_session'
  lib/mattermost/client.rb:38:in `session_post'
  lib/mattermost/team.rb:11:in `create'
  app/services/mattermost/create_team_service.rb:9:in `execute'
  app/services/groups/create_service.rb:24:in `execute'
  app/controllers/groups_controller.rb:33:in `create'
  lib/gitlab/i18n.rb:47:in `with_locale'
  lib/gitlab/i18n.rb:53:in `with_user_locale'
  app/controllers/application_controller.rb:348:in `set_locale'
  lib/gitlab/middleware/multipart.rb:93:in `call'
  lib/gitlab/request_profiler/middleware.rb:14:in `call'
  lib/gitlab/jira/middleware.rb:15:in `call'
  lib/gitlab/middleware/go.rb:18:in `call'
  lib/gitlab/etag_caching/middleware.rb:11:in `call'
  lib/gitlab/middleware/read_only.rb:31:in `call'
  lib/gitlab/request_context.rb:18:in `call'
  lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'

Results of GitLab environment info

System information
System:
Proxy:		no
Current User:	git
Using RVM:	no
Ruby Version:	2.3.5p376
Gem Version:	2.6.13
Bundler Version:1.13.7
Rake Version:	12.1.0
Redis Version:	3.2.5
Git Version:	2.13.6
Sidekiq Version:5.0.4
Go Version:	unknown

GitLab information
Version:	10.2.4-ee
Revision:	a93af19
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	postgresql
DB Version:	9.6.5
URL:		https://gitlab.isc.org
HTTP Clone URL:	https://gitlab.isc.org/some-group/some-project.git
SSH Clone URL:	git@gitlab.isc.org:some-group/some-project.git
Elasticsearch:	no
Geo:		no
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers: gitlab

GitLab Shell
Version:	5.9.4
Repository storage paths:
- default: 	/var/opt/gitlab/git-data/repositories
Hooks:		/opt/gitlab/embedded/service/gitlab-shell/hooks
Git:		/opt/gitlab/embedded/bin/git

Results of GitLab application Check

Checking GitLab Shell ...

GitLab Shell version >= 5.9.4 ? ... OK (5.9.4)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
2/1 ... ok
6/2 ... ok
11/3 ... ok
11/4 ... ok
11/5 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK

Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

IMAP server credentials are correct? ... yes
Init.d configured correctly? ... skipped
MailRoom running? ... skipped

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
2/1 ... yes
6/2 ... yes
11/3 ... yes
11/4 ... yes
11/5 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.3.5)
Git version >= 2.7.3 ? ... yes (2.13.6)
Git user has default SSH configuration? ... yes
Active users: ... 13
Elasticsearch version 5.1 - 5.5? ... skipped (elasticsearch is disabled)

Checking GitLab ... Finished

Possible fixes

(If you can, link to the line of code that might be responsible for the problem)

Assignee Loading
Time tracking Loading