Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix T&C page when no apps are present #264

Merged
merged 1 commit into from
Mar 27, 2017

Conversation

adamaziz15
Copy link
Contributor

@ouranos There were errors when trying to go to the terms of use page. After looking at the logs it seems the error happens whenever a marketplace does not have apps yet. I'm not sure if this is actually an issue though as a dashboard wouldn't really be functional without any applications anyway. Please review.

@adamaziz15
Copy link
Contributor Author

2017-03-23T18:59:02.280036469Z 18:59:02 web.1 | Started GET "/mnoe/terms" for 204.148.20.206 at 2017-03-23 18:59:02 +0000 2017-03-23T18:59:02.281073934Z 18:59:02 web.1 | Processing by MnoEnterprise::PagesController#terms as HTML 2017-03-23T18:59:02.331744822Z 18:59:02 web.1 | Completed 500 Internal Server Error in 51ms 2017-03-23T18:59:02.333463427Z 18:59:02 web.1 | 2017-03-23T18:59:02.333700469Z 18:59:02 web.1 | NoMethodError (undefined method updated_at' for nil:NilClass):
2017-03-23T18:59:02.333853485Z 18:59:02 web.1 | /usr/local/bundle/bundler/gems/mno-enterprise-82ab134e6b32/api/lib/mno_enterprise/concerns/controllers/pages_controller.rb:62:in terms' 2017-03-23T18:59:02.334201027Z 18:59:02 web.1 | actionpack (4.2.8) lib/action_controller/metal/implicit_render.rb:4:in send_action'
2017-03-23T18:59:02.334216899Z 18:59:02 web.1 | actionpack (4.2.8) lib/abstract_controller/base.rb:198:in process_action' 2017-03-23T18:59:02.334225797Z 18:59:02 web.1 | actionpack (4.2.8) lib/action_controller/metal/rendering.rb:10:in process_action'
2017-03-23T18:59:02.334233435Z 18:59:02 web.1 | actionpack (4.2.8) lib/abstract_controller/callbacks.rb:20:in block in process_action' 2017-03-23T18:59:02.334654975Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:117:in call'
2017-03-23T18:59:02.334672556Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:555:in block (2 levels) in compile' 2017-03-23T18:59:02.334678605Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:505:in call'
2017-03-23T18:59:02.334682879Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:92:in __run_callbacks__' 2017-03-23T18:59:02.334848707Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:778:in _run_process_action_callbacks'
2017-03-23T18:59:02.335032585Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/callbacks.rb:81:in run_callbacks' 2017-03-23T18:59:02.335045305Z 18:59:02 web.1 | actionpack (4.2.8) lib/abstract_controller/callbacks.rb:19:in process_action'
2017-03-23T18:59:02.335049964Z 18:59:02 web.1 | actionpack (4.2.8) lib/action_controller/metal/rescue.rb:29:in process_action' 2017-03-23T18:59:02.335366204Z 18:59:02 web.1 | actionpack (4.2.8) lib/action_controller/metal/instrumentation.rb:32:in block in process_action'
2017-03-23T18:59:02.335381228Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/notifications.rb:164:in block in instrument' 2017-03-23T18:59:02.335387077Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/notifications/instrumenter.rb:20:in instrument'
2017-03-23T18:59:02.335531706Z 18:59:02 web.1 | activesupport (4.2.8) lib/active_support/notifications.rb:164:in instrument' 2017-03-23T18:59:02.335867645Z 18:59:02 web.1 | actionpack (4.2.8) lib/action_controller/metal/instrumentation.rb:30:in process_action'`

@ouranos ouranos changed the title [CR-35] Update pages controller Fix T&C page when no apps are present Mar 23, 2017
@apps = Rails.cache.fetch(['pages/terms/app-list', ts]) do
MnoEnterprise::App.order_by("name.ac").reject{|i| i.terms_url.blank?}

ts = MnoEnterprise::App.order_by("updated_at.desc").first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it this way.

ts = MnoEnterprise::App.order_by("updated_at.desc").first.try(:updated_at)
@apps = if ts
  Rails.cache.fetch(['pages/terms/app-list', ts]) do
    MnoEnterprise::App.order_by("name.ac").reject{|i| i.terms_url.blank?}
  end
else
  []
end

what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ouranos The issue here is when there are no apps. In that case an empty array is returned. That would result in try being called on nil which will throw an error. What if we did it this way?

ts = MnoEnterprise::App.order_by("updated_at.desc").first&.updated_at @apps = if ts Rails.cache.fetch(['pages/terms/app-list', ts]) do MnoEnterprise::App.order_by("name.ac").reject{|i| i.terms_url.blank?} end else [] end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to work:

2.3.3 :001 > [].first.try(:updated_at)
 => nil 

http://api.rubyonrails.org/classes/Object.html#method-i-try

The safe navigation operator is a good idea but only works with ruby 2.3+ so we'd break the compatibility with older versions (as you can see with the failing specs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I replaced it with the try method. I was trying to run that line of code in my terminal but was using irb/pry instead of rails console. Didn't realize the method was coming from rails. 👍

Copy link
Contributor

@ouranos ouranos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Could you squash the commits and also rebase/open the PR on 3.2
git rebase -i --onto 3.2 4ca9a07^

@ouranos ouranos changed the base branch from master to 3.2 March 27, 2017 21:57
@ouranos ouranos self-assigned this Mar 27, 2017
@ouranos ouranos added the bug label Mar 27, 2017
@ouranos ouranos merged commit f9744e4 into maestrano:3.2 Mar 27, 2017
@adamaziz15 adamaziz15 deleted the bug/35-terms-error branch June 14, 2017 18:30
aluqueGH pushed a commit to aluqueGH/mno-enterprise that referenced this pull request Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants