Skip to content

Fix subscription banner on New Project page

What does this MR do?

When we try to show the subscription banner on a page that has @project variable assigned, but it is not persisted yet and has no namespace assigned it throws an error:

ActionView::Template::Error (Project#closest_gitlab_subscription delegated to namespace.closest_gitlab_subscription, but namespace is nil: #<Project id: >>):
    21:           - if subscribable.block_changes?
    22:             = link_to _('Upgrade your plan'), upgrade_subscription_path, class: 'btn gl-button btn-primary', data: { track_event: 'click_text', track_label: 'subscribable_action', track_property: 'upgrade' }
    23:           - else
    24:             = link_to _('Renew subscription'), renew_subscription_path, class: 'btn gl-button btn-primary gl-mr-3 gl-mb-2', data: { track_event: 'click_text', track_label: 'subscribable_action', track_property: 'renew' }
    25:             = link_to _('That is ok, I do not want to renew'), '#', data: { track_event: 'click_text', track_label: 'subscribable_action', track_property: 'thats_ok' }, 'aria-label' => 'Dismiss', class: 'btn gl-button btn-info btn-info-secondary js-close gl-mb-2'

ee/app/models/ee/project.rb:202:in `rescue in closest_gitlab_subscription'
ee/app/models/ee/project.rb:202:in `closest_gitlab_subscription'
ee/app/helpers/ee/subscribable_banner_helper.rb:61:in `decorated_subscription'
ee/app/helpers/ee/subscribable_banner_helper.rb:25:in `renew_subscription_path'
ee/app/views/layouts/header/_ee_subscribable_banner.html.haml:24

This MR adds addition return unless entity && entity.persisted? check to fix this.

Related to #322546 (closed)

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Krasimir Angelov

Merge request reports

Loading