maxrossello / redmine_app_timesheets

A true timesheet plugin using orders, not bound to timelogs over issues
GNU General Public License v2.0
32 stars 10 forks source link

Error 404 when trying to create a new order or access the config of an existing one #24

Closed frconil closed 10 years ago

frconil commented 10 years ago

We're getting the following error:

Started GET "/apps/order_users/552" for 127.0.0.1 at 2014-06-30 12:32:12 +1000
Processing by OrderUsersController#index as HTML
  Parameters: {"id"=>"552"}
  Current user: admin (id=1)
  Rendered common/error.html.erb within layouts/base (0.2ms)
  Rendered plugins/redmine_rouge/app/views/application/_rouge_css.erb (0.6ms)
Completed 404 Not Found in 48.5ms (Views: 33.9ms | ActiveRecord: 6.6ms)

system info:

Environment:
  Redmine version                2.5.0.stable.12119
  Ruby version                   rbx-2.2.9 [x86_64-linux-gnu]
  Rails version                  3.2.17
  Environment                    production
  Database adapter               PostgreSQL

Let me know if you need more info.

frconil commented 10 years ago

tried with MRI ruby to no avail:

Environment:
  Redmine version                2.5.0.stable.12119
  Ruby version                   2.1.2-p95 (2014-05-08) [x86_64-linux]
  Rails version                  3.2.17
  Environment                    production
  Database adapter               PostgreSQL
maxrossello commented 10 years ago

Is your admin user listed into the group assigned to manage orders into /settings/plugin/redmine_app__space ? Even the admin needs to be.

frconil commented 10 years ago

Yes, we tried with both admin and another user added to the order admins group.

maxrossello commented 10 years ago

I need to check what queries are made to Postgresql since I don't have an instance of it. A 404 error is emitted whenever an exception is risen, and sometimes ActiveRecord doesn't behave the same as in MySql.

Please add the following statements to your config/environments/production.rb (or development.rb) and report the log:

config.log_path = '<some path>/production.log'
config.logger = Logger.new(config.log_path, 7, 1048576)
config.logger.level = Logger::DEBUG

Thanks

frconil commented 10 years ago
TsPermission Load (0.5ms)  SELECT "ts_permissions".* FROM "ts_permissions" WHERE "ts_permissions"."is_primary" = 't' AND "ts_permissions"."order_id" = 552 ORDER BY '---
:access: :desc
'
PG::SyntaxError: ERROR:  non-integer constant in ORDER BY
LINE 1: ...y" = 't' AND "ts_permissions"."order_id" = 552 ORDER BY '---
                                                                   ^
: SELECT "ts_permissions".* FROM "ts_permissions"  WHERE "ts_permissions"."is_primary" = 't' AND "ts_permissions"."order_id" = 552 ORDER BY '---
:access: :desc
'

I guess that would explain the error.

frconil commented 10 years ago

I can edit a new order by replacing the following line:

diff /tmp/order_users_controller.rb plugins/redmine_app_timesheets/app/controllers/order_users_controller.rb
14,15c14,15
<       @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order(:access => :desc).map{|p| p.principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }
<           @activities = TsActivity.where(:order_id => @order).map(&:activity_id)
---
>       @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order('access desc').map{|p| p.principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }
>       @activities = TsActivity.where(:order_id => @order).map(&:activity_id)
maxrossello commented 10 years ago

Thank you.

I have to double check because the syntax order(:access: => :desc) was accepted under MySql but didn't work (no ordering seemed to happen).

Unfortunately active record has several of these incompatibilities. If nothing better, I will explicitly add a switch.

Thanks!

Francois Conil notifications@github.com ha scritto:

I can edit a new order by replacing the following line:

14 @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order('access desc').map{|p| p. principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }

instead of

14 @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order(:access: => :desc).map{|p| p. principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }

— Reply to this email directly or view it on GitHub.

maxrossello commented 10 years ago

Would

order('access DESC')

(with capital DESC) fail in postgresql as well?

Francois Conil notifications@github.com ha scritto:

I can edit a new order by replacing the following line:

14 @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order('access desc').map{|p| p. principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }

instead of

14 @members = TsPermission.where(:is_primary => true, :order_id => @order.id).order(:access: => :desc).map{|p| p. principal}.sort{|a,b| a.is_a?(User) ? (b.is_a?(User) ? 0 : -1) : (b.is_a?(Group) ? 0 : 1) }

— Reply to this email directly or view it on GitHub.

frconil commented 10 years ago
redmine=# SELECT "ts_permissions".* FROM "ts_permissions"  WHERE "ts_permissions"."is_primary" = 't' AND "ts_permissions"."order_id" = 554 ORDER BY access DESC;
 id | order_id | access | principal_id | is_primary
----+----------+--------+--------------+------------
(0 rows)

It seems to be working just fine.