Assigning Role via API

With all the changes surrounding users and roles in foreman 1.5 is it now
possible to assign a role to a user using the API? I dont see anything in
the documentation that suggests its possible.

Thanks
Jeff

Yes. Here is a ruby example using the apipie bindings for creating roles and filters[1] and then assigning to users[2].

[1] https://github.com/Katello/hammer-cli-csv/blob/master/lib/hammer_cli_csv/roles.rb#L78
[2] https://github.com/Katello/hammer-cli-csv/blob/master/lib/hammer_cli_csv/users.rb#L99

··· ----- Original Message ----- > With all the changes surrounding users and roles in foreman 1.5 is it now > possible to assign a role to a user using the API? I dont see anything in > the documentation that suggests its possible. > > Thanks > Jeff > > -- > You received this message because you are subscribed to the Google Groups > "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at http://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout. >

And the api docs Foreman

··· ----- Original Message ----- > > > ----- Original Message ----- > > With all the changes surrounding users and roles in foreman 1.5 is it now > > possible to assign a role to a user using the API? I dont see anything in > > the documentation that suggests its possible. > > > > Thanks > > Jeff > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Foreman users" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to foreman-users+unsubscribe@googlegroups.com. > > To post to this group, send email to foreman-users@googlegroups.com. > > Visit this group at http://groups.google.com/group/foreman-users. > > For more options, visit https://groups.google.com/d/optout. > > > > Yes. Here is a ruby example using the apipie bindings for creating roles and > filters[1] and then assigning to users[2]. > > [1] > https://github.com/Katello/hammer-cli-csv/blob/master/lib/hammer_cli_csv/roles.rb#L78 > [2] > https://github.com/Katello/hammer-cli-csv/blob/master/lib/hammer_cli_csv/users.rb#L99 > > -- > You received this message because you are subscribed to the Google Groups > "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at http://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout. >

This is what I have been using (the v2 REST API) but I dont see any methods
which allow assigning an existing role to an existing user. The user update
method (http://theforeman.org/api/apidoc/v2/users/update.html) doesnt
mention assigning roles.

··· On Wednesday, 21 May 2014 15:51:33 UTC+1, Tom McKay wrote: > > > > ----- Original Message ----- > > > And the api docs http://theforeman.org/api_v2.html >

Yes, you're right. There is at least one open issue[1] in this area. The apipie package, which is used to generate the api bindings and docs, does not include database relations. I don't have a good suggestion besides asking on irc or email. :slight_smile:

[1] Bug #3923: organzation relations not documented through apipie - Foreman

··· ----- Original Message ----- > > > On Wednesday, 21 May 2014 15:51:33 UTC+1, Tom McKay wrote: > > > > > > > > ----- Original Message ----- > > > > > > And the api docs http://theforeman.org/api_v2.html > > > > This is what I have been using (the v2 REST API) but I dont see any methods > which allow assigning an existing role to an existing user. The user update > method (http://theforeman.org/api/apidoc/v2/users/update.html) doesnt > mention assigning roles. >

Figured it out using the rest api, I just added "user[role_names]=Viewer"
which seems to work. The documentation could definitely be improved here
but at least it works :slight_smile:

··· On Wednesday, 21 May 2014 16:44:22 UTC+1, Tom McKay wrote: > > > Yes, you're right. There is at least one open issue[1] in this area. The > apipie package, which is used to generate the api bindings and docs, does > not include database relations. I don't have a good suggestion besides > asking on irc or email. :) > > [1] http://projects.theforeman.org/issues/3923 >