Possible fix for external_usergroups_controller when using api/v2/usergroups/:usergroup/external_usergroups

Hi all

I was creating a docker image for the 1.19 RC, with some initial configuration. For adding some user groups and testing the link to ldap I was using the REST api, more specifically a POST to api/v2/usergroups/:usergroup/external_usergroups as explained in API documentation. I was using this command, to create the external usergroup.

curl -s -H Accept:application/json -H Content-Type:application/json -k -u admin:changeme -X POST -d {“name”:“administrator”,“auth_source_id”:34} https://172.19.0.1/api/v2/usergroups/1/external_usergroups

I found an error using it, the server was complaining about: “Usergroup can’t be blank”, crashing with “NoMethodError: undefined method ‘users’ for nil:NilClass”. Even if I have no experience with ruby after some research, finally I fixed it modifiing the file app/controllers/api/v2/external_usergroups_controller.rb at the line 36. I include the resulting patch:

diff --git a/app/controllers/api/v2/external_usergroups_controller.rb b/app/controllers/api/v2/external_usergroups_controller.rb
index 71102c375..da827657d 100644
--- a/app/controllers/api/v2/external_usergroups_controller.rb
+++ b/app/controllers/api/v2/external_usergroups_controller.rb
@@ -36,7 +36,7 @@ module Api
       param_group :external_usergroup, :as => :create
 
       def create
-        @external_usergroup = @nested_obj.external_usergroups.new(external_usergroup_params)
+        @external_usergroup = @nested_obj.external_usergroups.new(external_usergroup_params.merge(:usergroup_id => params[:usergroup_id]))
         process_response @external_usergroup.save
       end

Kind regards

Gorka

Hi Gorka,

Thanks for the feedback and for suggesting a patch!
Can you please report the issue on our issue tracker and open a pull request on GitHub with the fix so we can properly review it and track getting it into a release?

I will try to do so. In fact I was not sure if this was the proper way to report an issue.

thanks for the information

1 Like