Bug #5963

Role function has_permissions? fails when called

Added by Martin Ducar over 3 years ago. Updated over 3 years ago.

Status:Closed
Priority:Normal
Assigned To:Martin Ducar
Category:Authorization
Target version:Sprint 24
Difficulty:trivial Bugzilla link:1107669
Found in release:1.4.0 Pull request:
Story points-
Velocity based estimate-
Release1.5.1Release relationshipAuto

Description

called like this:
p_obj = Permission.find_by_name(perm)
if role.has_permission?(p_obj)
...

returns this
rake aborted!
undefined method `to_sym' for #<Permission:0x000000061b8540>
/opt/rh/ruby193/root/usr/share/gems/gems/activemodel-3.2.8/lib/active_model/attribute_methods.rb:407:in `method_missing'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/attribute_methods.rb:149:in `method_missing'
/usr/share/foreman/app/models/role.rb:56:in `has_permission?'
/usr/share/foreman/db/seeds.d/901_add_gdc_roles.rb:101:in `block (2 levels) in <top (required)>'
/usr/share/foreman/db/seeds.d/901_add_gdc_roles.rb:98:in `each'
/usr/share/foreman/db/seeds.d/901_add_gdc_roles.rb:98:in `block in <top (required)>'
/opt/rh/ruby193/root/usr/share/gems/gems/audited-3.0.0/lib/audited/auditor.rb:250:in `call'
/opt/rh/ruby193/root/usr/share/gems/gems/audited-3.0.0/lib/audited/auditor.rb:250:in `without_auditing'
/usr/share/foreman/db/seeds.d/901_add_gdc_roles.rb:1:in `<top (required)>'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/usr/share/foreman/db/seeds.rb:53:in `block in <top (required)>'
/usr/share/foreman/db/seeds.rb:51:in `each'
/usr/share/foreman/db/seeds.rb:51:in `<top (required)>'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/opt/rh/ruby193/root/usr/share/gems/gems/railties-3.2.8/lib/rails/engine.rb:520:in `load_seed'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:309:in `block (2 levels) in <top (required)>'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:in `call'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:in `block in execute'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:in `each'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:in `execute'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:158:in `block in invoke_with_call_chain'
/opt/rh/ruby193/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:151:in `invoke_with_call_chain'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:144:in `invoke'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:116:in `invoke_task'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `block (2 levels) in top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `each'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `block in top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:in `standard_exception_handling'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:88:in `top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:66:in `block in run'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:in `standard_exception_handling'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:63:in `run'
/opt/rh/ruby193/root/usr/bin/rake:32:in `<main>'
Tasks: TOP => db:seed

problem is in this code:
https://github.com/theforeman/foreman/blob/1.5-stable/app/models/role.rb#L56

affected versions are at least foreman 1.4, 1.5

Preparing the fix, which is really simple

Associated revisions

Revision 3f5ddc49
Added by Martin Ducar over 3 years ago

fixes #5963 - fix Role has_permission? function

Revision c9d6b910
Added by Martin Ducar over 3 years ago

fixes #5963 - fix Role has_permission? function

(cherry picked from commit 3f5ddc49bd321a23dd8fc17e6b3cd64bfd3f5e4a)

History

#1 Updated by Martin Ducar over 3 years ago

What is recommended way to push to 1.4 and 1.5 stable and also develop? pushing to develop and than you will cherry-pick?

#2 Updated by Dominic Cleal over 3 years ago

  • Status changed from New to Ready For Testing
  • Target version set to Sprint 24
  • Release set to 1.5.1

Martin Ducar wrote:

What is recommended way to push to 1.4 and 1.5 stable and also develop? pushing to develop and than you will cherry-pick?

Correct, pull requests to develop and it gets cherry picked for release. We won't do any new 1.4 releases at this stage (save for critical security issues perhaps), but I can include it in a 1.5 release.

https://github.com/theforeman/foreman/pull/1482

#3 Updated by Martin Ducar over 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by Bryan Kearney over 3 years ago

  • Bugzilla link set to https://bugzilla.redhat.com/show_bug.cgi?id=1107669

Also available in: Atom PDF