-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refs #37936 - Correct success method for jwt api #10412
Refs #37936 - Correct success method for jwt api #10412
Conversation
41940ce
to
48bd82d
Compare
Test failures seem unrelated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This controller still weirds me out :/ But if it's agreed upon 🤷, some notes:
-
Shouldn't this include rather
Foreman::Controller::UserAware
instead ofForeman::Controller::UsersMixin
? There is already logic for self editing check. If it's only forexcept_hidden
, then it's probably worth to either update re-usable place or include only that explicitly. -
Why does it have
include Foreman::Controller::Parameters::User
? It doesn't seem to be used in any way. -
It also doesn't need
include Foreman::Controller::AutoCompleteSearch
, since this concern is for UI controllers. -
In API description
api :DELETE, '/users/:id/registration_tokens'
should rather have:user_id
instead of just:id
@@ -36,7 +36,8 @@ def invalidate_jwt | |||
raise ::Foreman::Exception.new(N_("No record found for %s"), params[:id]) | |||
end | |||
@user.jwt_secret&.destroy | |||
process_success _("Successfully invalidated registration tokens for %s.\n" % @user.login) | |||
login = @user.login | |||
render :json => {:status => 'success', :message => _("Successfully invalidated registration tokens for %s." % login), :user => login}, :status => :ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render :json => {:status => 'success', :message => _("Successfully invalidated registration tokens for %s." % login), :user => login}, :status => :ok | |
render :json => { :message => _("Successfully invalidated registration tokens for %s." % login), :user => login }, :status => :ok |
There is no value in :status => 'success'
entry: it's more or less duplicate of the 200 OK
status.
Also, having both the success message and :user => login
seems like redundance of the information. I'd suggest either not include logins in the message or drop the :user
entry.
@@ -51,7 +52,8 @@ def invalidate_jwt_tokens | |||
if @users.blank? | |||
raise ::Foreman::Exception.new(N_("No record found for search '%s'"), params[:search]) end | |||
JwtSecret.where(user_id: @users).destroy_all | |||
process_success _("Successfully invalidated registration tokens for %s.\n" % @users.pluck(:login).to_sentence) | |||
login = @users.pluck(:login).to_sentence | |||
render :json => {:status => 'success', :message => _("Successfully invalidated registration tokens for %s." % login), :users => login}, :status => :ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
48bd82d
to
d91068e
Compare
Please, fix API descriptions and I won't be blocking any longer:
|
Many places else we're using dots after description. Example. Is there any reason to remove it here
We are mentioning in the description that id means id of the user. I would change it but it means I would also have to change it here and it might break things and I might have to change it at many places. I would prefer not doing that unless absolutely necessary, what do you think? |
I should've mentioned that I meant short description instead of full description:
Yeap. The already stable controllers (https://github.com/theforeman/foreman/blob/develop/app/models/user.rb#L465-L479) can be left untouched, but the new one (https://github.com/theforeman/foreman/blob/develop/app/models/user.rb#L480-L482) is better to follow already established pattern (https://github.com/theforeman/foreman/blob/develop/app/models/user.rb#L474-L479)
This feature was added during current development cycle and wasn't released yet. It's just the right time to break and fix stuff.
I think it's better to polish the new feature than deal with inconsistencies later potentially leaving "as is" since it's API and we always fear to break it piling up tech dept and answer future questions with "well, it was just made like this 🤷 " |
d91068e
to
0c8fcd0
Compare
Thanks @ofedoren , I have addressed and tested everything :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 LGTM, but I'll leave final ACK to @ofedoren
Sorry to bother you once more, but as the last thing: I've added a commit with some smaller fixes. @girijaasoni, please re-test if it still works as you'd expect. @stejskalleos, please feel free to merge once is green. |
Refs #37936 - Remove dead code, fix not_found message
f9d6292
to
198316e
Compare
Thanks @girijaasoni @ofedoren |
No description provided.