-
Notifications
You must be signed in to change notification settings - Fork 3
move Permited Atributes to Policy #1200
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: staging
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ def index | |||||
| end | ||||||
|
|
||||||
| def create | ||||||
| @price_list = PriceList.new(permitted_attributes) | ||||||
| @price_list = PriceList.new(price_list_params) | ||||||
| authorize @price_list | ||||||
|
|
||||||
| if @price_list.save | ||||||
|
|
@@ -36,7 +36,7 @@ def update | |||||
| @price_list = PriceList.find(params[:id]) | ||||||
| authorize @price_list | ||||||
|
|
||||||
| if @price_list.update(permitted_attributes) | ||||||
| if @price_list.update(price_list_params) | ||||||
| flash[:success] = 'Prijslijst opgeslagen' | ||||||
| else | ||||||
| flash[:error] = "Prijslijst wijzigen mislukt; #{@price_list.errors.full_messages.join(', ')}" | ||||||
|
|
@@ -76,7 +76,7 @@ def unarchive | |||||
|
|
||||||
| private | ||||||
|
|
||||||
| def permitted_attributes | ||||||
| params.require(:price_list).permit(:name) | ||||||
| def price_list_params | ||||||
| params.require(:price_list).permit(policy(PriceList).permitted_attributes) | ||||||
|
||||||
| params.require(:price_list).permit(policy(PriceList).permitted_attributes) | |
| params.require(:price_list).permit(policy(PriceList.new).permitted_attributes) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ def create # rubocop:disable Metrics/AbcSize, Metrics/MethodLength | |||||
| user = User.find_by(id: user_id) | ||||||
| validate_user(user) | ||||||
|
|
||||||
| sofia_account = SofiaAccount.new(permitted_attributes.merge(user_id:)) | ||||||
| sofia_account = SofiaAccount.new(sofia_account_params.merge(user_id:)) | ||||||
| raise normalize_error_messages(sofia_account.errors.full_messages) unless sofia_account.save | ||||||
|
|
||||||
| update_user_after_creation(user, sofia_account) | ||||||
|
|
@@ -256,7 +256,7 @@ def update_user_after_creation(user, sofia_account) # rubocop:disable Metrics/Ab | |||||
| raise normalize_error_messages(user.errors.full_messages) | ||||||
| end | ||||||
|
|
||||||
| def permitted_attributes | ||||||
| params.require(:sofia_account).permit(%i[username password password_confirmation]) | ||||||
| def sofia_account_params | ||||||
| params.require(:sofia_account).permit(policy(SofiaAccount).permitted_attributes) | ||||||
|
||||||
| params.require(:sofia_account).permit(policy(SofiaAccount).permitted_attributes) | |
| params.require(:sofia_account).permit(policy(SofiaAccount.new).permitted_attributes) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,8 @@ def index? | |
| def create? | ||
| user&.treasurer? || (user&.main_bartender? && record.activity.present?) | ||
| end | ||
|
|
||
| def permitted_attributes | ||
| %i[description amount user_id activity_id] | ||
| end | ||
|
Comment on lines
+20
to
+22
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,8 @@ def unarchive? | |
| def search? | ||
| index? | ||
| end | ||
|
|
||
| def permitted_attributes | ||
| %i[name] | ||
| end | ||
|
Comment on lines
+40
to
+42
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,18 @@ def activities? | |
| def update_with_sofia_account? | ||
| record == user | ||
| end | ||
|
|
||
| def permitted_attributes | ||
| %i[name email provider sub_provider] | ||
| end | ||
|
|
||
| def permitted_attributes_for_update | ||
| %i[name email deactivated] | ||
| end | ||
|
|
||
| def permitted_attributes_for_update_with_sofia_account | ||
| base = %i[email sub_provider] | ||
| base += %i[name deactivated] if user&.treasurer? | ||
| base + [{ sofia_account_attributes: %i[id username] }] | ||
| end | ||
|
Comment on lines
+26
to
+38
|
||
| 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.
The policy is called with the CreditMutation class instead of an instance. This will cause an error when trying to access permitted_attributes from the policy, as Pundit expects to initialize policies with a user and a record. You should pass an instance like CreditMutation.new here.