Defect #28686

/users API does not accept boolean-like String values for generate_password

Added by Gregor Schmidt 18 days ago. Updated 16 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:REST API
Target version:4.0.0
Resolution:Fixed Affected version:

Description

When creating a new user using the XML Rest API and the following XML, Redmine is not generating a new password.

<user>
    <login>test</login>
    <firstname>test</firstname>
    <lastname>test</lastname>
    <mail>test@example.org</mail>
    <generate_password>true</generate_password>
    <must_change_passwd>true</must_change_passwd>
</user>

The true value for must_change_passwd works as expected, the one for generate_password is ignored.

The reason for that is, that must_change_passwd is a proper database column and ActiveRecord will translate certain expected values to Boolean true. Among these are "1", "true", and true. In contrast generate_password is a virtual attribute, which is not backed by a database column. Redmine has its own code to handle the translation here. But this custom code only accepts "1" and true, i.e it's missing the "true" option.

The attached patch fixes this shortcoming by using ActiveRecord's translation method directly.

0001-users-API-accepts-boolean-strings-for-generate_passw.patch Magnifier (1.79 KB) Gregor Schmidt, 2018-05-04 12:06

Associated revisions

Revision 17327
Added by Go MAEDA 17 days ago

/users API accepts boolean strings for generate_password field (#28686).

Patch by Gregor Schmidt.

History

#1 Updated by Gregor Schmidt 18 days ago

Please note, that since Rails 5 the way how strings are converted to booleans has changed. Previously anything but a small well known list of values was considered true. Now anything but a small well know list of strings is considered false. Consequently, with the proposed change this would also be applied to the generate_password field.

I think this would be a good thing, since it's improving consistency. But I wanted to mention it anyway.

#2 Updated by Go MAEDA 18 days ago

  • Status changed from New to Confirmed
  • Target version set to 4.1.0

Confirmed the problem. Setting target version to 4.1.0.

#3 Updated by Go MAEDA 17 days ago

  • Status changed from Confirmed to Closed
  • Target version changed from 4.1.0 to 4.0.0
  • Resolution set to Fixed

Committed. Thank you for detecting and fixing this issue.

#4 Updated by Go MAEDA 16 days ago

  • Assignee set to Go MAEDA

Also available in: Atom PDF