Cohorts page throws "undefined method add_on?" when license is not added

Summary

Going to /admin/cohorts page when the license is not applied gives a 500 error.

Steps to reproduce

Install a new instance and navigate to the /admin/cohorts page before adding a license

What is the current bug behavior?

Something went wrong is shown on the page

What is the expected correct behavior?

No error.

Relevant logs and/or screenshots

NoMethodError (undefined method `add_on?' for nil:NilClass):
  lib/gitlab/usage_data.rb:57:in `service_desk_counts'
  lib/gitlab/usage_data.rb:52:in `system_usage_data'
  lib/gitlab/usage_data.rb:11:in `uncached_data'
  lib/gitlab/usage_data.rb:7:in `block in data'
  lib/gitlab/usage_data.rb:7:in `data'
  app/controllers/admin/application_settings_controller.rb:23:in `block (2 levels) in usage_data'
  app/controllers/admin/application_settings_controller.rb:21:in `usage_data'
  lib/gitlab/middleware/multipart.rb:93:in `call'
  lib/gitlab/request_profiler/middleware.rb:14:in `call'
  lib/gitlab/middleware/go.rb:16:in `call'
  lib/gitlab/etag_caching/middleware.rb:10:in `call'
  lib/gitlab/middleware/readonly_geo.rb:30:in `call'
  lib/gitlab/request_context.rb:18:in `call'

Possible fixes

https://gitlab.com/gitlab-org/gitlab-ee/blob/9-1-stable-ee/lib/gitlab/usage_data.rb#L57

license = ::License.current
return {} if license.nil?
return {} unless license.add_on?('GitLab_ServiceDesk')`
Assignee Loading
Time tracking Loading