-
Notifications
You must be signed in to change notification settings - Fork 71
THREESCALE-12434: Migrate from protected attributes to strong parameters - Part 2 #4249
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
base: strong-params-part1
Are you sure you want to change the base?
Changes from 5 commits
789ae3e
16f4bd2
987a8d1
14797a9
f56d132
6e62f9e
6d9e844
fd9fc80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| class Admin::Api::BuyersUsersController < Admin::Api::BuyersBaseController | ||
| representer User | ||
|
|
||
| before_action :find_user, except: %i[create index] | ||
| before_action :build_new_user, only: %i[create] | ||
|
|
||
| attr_reader :user | ||
|
|
||
| # User List | ||
| # GET /admin/api/accounts/{account_id}/users.xml | ||
| def index | ||
|
|
@@ -12,14 +17,9 @@ def index | |
| # User Create | ||
| # POST /admin/api/accounts/{account_id}/users.xml | ||
| def create | ||
| user = new_user | ||
|
|
||
| authorize! :create, user | ||
|
|
||
| user.unflattened_attributes = flat_params | ||
| user.signup_type = :api | ||
|
|
||
| user.save | ||
| user.update(user_params.merge(signup_type: :api)) | ||
|
|
||
| respond_with(user) | ||
| end | ||
|
|
@@ -37,7 +37,7 @@ def show | |
| def update | ||
| authorize! :update, user | ||
|
|
||
| user.update_with_flattened_attributes(flat_params) | ||
| user.update(user_params) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the underlying method is not used anymore and can be removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yes, and probably But I guess I was unsure if this was actually needed for something...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: f56d132 |
||
|
|
||
| respond_with(user) | ||
| end | ||
|
|
@@ -108,19 +108,24 @@ def authorize!(*args) | |
| current_user ? super : logged_in? | ||
| end | ||
|
|
||
| def new_user | ||
| @new_user ||= buyer.users.new | ||
| end | ||
|
|
||
| def users | ||
| @users ||= begin | ||
| conditions = params.slice(:state, :role) | ||
| buyer.users.where(conditions) | ||
| end | ||
| end | ||
|
|
||
| def user | ||
| @user ||= buyer.users.find(params[:id]) | ||
| private | ||
|
|
||
| def build_new_user | ||
| @user = buyer.users.new | ||
| end | ||
|
|
||
| def find_user | ||
| @user = buyer.users.find(params[:id]) | ||
| end | ||
|
|
||
| def user_params | ||
| params.permit(*user.defined_fields_names, :password, :password_confirmation) | ||
| end | ||
| end | ||
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.
why disable this?
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.
Because it was annoying me every time 😬
Apparently, nobody ever cared about following a specific order, except @jlledom who has his own preference (which does not coincide with the default), see #4241 (comment)
So, now each controller has its own order, and as I was touching controllers, I kept getting these warnings.
We may chose to stick to the same order everywhere, and to fix all controllers and enable this rule again. But in another PR.
Or we may keep ignoring it 😬