Project

General

Profile

Actions

Defect #17904

closed

group membership cannot be added to a project via REST API

Added by Alex Last about 10 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
Normal
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Wont fix
Affected version:

Description

environment: Redmine 2.5.2

adding a user with some roles works fine:

Started POST "/redmine/projects/524/memberships.json" for 76.126.10.142 at 2014-09-17 21:04:51 -0700
Processing by MembersController#create as JSON
Parameters: {"membership"=>{"user_id"=>276, "role_ids"=>[3, 4, 5]}, "project_id"=>"524"}
Current user: user (id=1)
Rendered members/show.api.rsb (0.5ms)
Completed 201 Created in 33.9ms (Views: 1.1ms | ActiveRecord: 15.4ms)

but Redmine throws an error when I send a membership object with group_id instead of user_id: {"membership"=>{"group_id"=>275, "role_ids"=>[3]}, "project_id"=>"523"}

log:

Started POST "/redmine/projects/523/memberships.json" for 76.126.10.142 at 2014-09-17 21:02:48 -0700
Processing by MembersController#create as JSON
Parameters: {"membership"=>{"group_id"=>275, "role_ids"=>[3]}, "project_id"=>"523"}
Current user: user (id=1)
Rendered common/error_messages.api.rsb (0.3ms)
Completed 422 Unprocessable Entity in 23.1ms (Views: 1.2ms | ActiveRecord: 4.7ms)

I looked at members_controller.rb file:

def create
members = []
if params[:membership]
if params[:membership][:user_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
end
else
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership] [:user_id])
end
@project.members << members
end

- there is nothing there to support adding group memberships.

Actions #1

Updated by Annabel Schmidt about 10 years ago

I tried to add a group membership in
environment: Redmine 2.3.0 stable.

It doesn't work, like Alex said before.

That feature would be great!
We could use it in automated project creation, which is absolutely necessary for our purpose.
Can you tell, if you are going to implement that feature?

Actions #2

Updated by Jean-Philippe Lang about 10 years ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Wont fix

You just need to use the regular user_id param to add a group membership, eg.

{"membership"=>{"user_id"=>275, "role_ids"=>[3]}, "project_id"=>"523"}

where 275 is your group id. I updated the doc: Rest_Memberships

Actions #3

Updated by Alex Last about 10 years ago

I don't think this is a proper solution. this is a bug in the API design and it should not be masked by documenting it on the wiki.

Actions

Also available in: Atom PDF