chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Lack of Permissions results in NoMethodError: `resolve_target': undefined method `klass' #79

Open rsennewald opened 12 years ago

rsennewald commented 12 years ago

Essentially when I do a lookup on any module I don't have access to, I get a response from the gem like:

/Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/association.rb:81:in resolve_target': undefined methodklass' for false:FalseClass (NoMethodError) from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/association.rb:25:in initialize' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/associations.rb:9:innew' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/associations.rb:9:in register' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/associations.rb:8:ineach_key' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/associations.rb:8:in register' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/associations/association_methods.rb:63:indefine_association_methods' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/base.rb:141:in initialize' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/base.rb:34:innew' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/base.rb:34:in find' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/finders/finder_methods.rb:182:infind_by_bug_number' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/finders/finder_methods.rb:187:in send' from /Users/rsennewald/.rvm/gems/ruby-1.8.7-p358/gems/sugarcrm-0.9.18/lib/sugarcrm/finders/finder_methods.rb:187:inmethod_missing' from ./update_blocklist.rb:151:in check_bug_closed' from ./update_blocklist.rb:114:incheck_blocklist' from /Users/rsennewald/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/rexml/element.rb:891:in each' from /Users/rsennewald/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/rexml/xpath.rb:53:ineach' from /Users/rsennewald/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/rexml/element.rb:891:in each' from ./update_blocklist.rb:107:incheck_blocklist' from ./update_blocklist.rb:97:in each' from ./update_blocklist.rb:97:incheck_blocklist' from ./update_blocklist.rb:66:in `Main' from ./update_blocklist.rb:189

This can be confusing, and I realized that it was due to permissions issues after the same request worked just fine under a user with proper permissions. If possible, I think it would be best to catch the resolve_target issues and if it's permissions related indicate that in an output message.

I found this against 6.5.0 RC3, but I'd imagine it is reproducible on any recent version of Sugar. To reproduce: setup an instance and ensure a user account doesn't have permissions to the module / or rest requests. Then setup a connection on the gem and do a lookup like SugarCRM::Bug.first and you'll see the error I posted above.

brunogh commented 12 years ago

I am running a 6.4.4 with an user that has all privileges, but when call SugarCRM::Account.first I got the same error. Not sure what it is.

chicks commented 12 years ago

I'll take a look tonight!