Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
end

def create
@activity = Activity.new(permitted_attributes.merge(created_by: current_user))
@activity = Activity.new(activity_params.merge(created_by: current_user))
authorize @activity

if @activity.save
Expand All @@ -61,7 +61,7 @@ def update
@activity = Activity.find(params[:id])
authorize @activity

if @activity.update(params.require(:activity).permit(%i[title]))
if @activity.update(activity_params_for_update)
flash[:success] = 'Activiteit hernoemd'
else
flash[:error] = "Activiteit hernoemen mislukt; #{@activity.errors.full_messages.join(', ')}"
Expand Down Expand Up @@ -177,7 +177,11 @@ def sorted_product_price(activity)
activity.price_list.product_price.sort_by { |p| p.product.id }
end

def permitted_attributes
params.require(:activity).permit(%i[title start_time end_time price_list_id])
def activity_params
params.require(:activity).permit(policy(Activity.new).permitted_attributes)
end

def activity_params_for_update
params.require(:activity).permit(policy(@activity).permitted_attributes_for_update)
end
end
6 changes: 3 additions & 3 deletions app/controllers/credit_mutations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index
end

def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@mutation = CreditMutation.new(permitted_attributes.merge(created_by: current_user))
@mutation = CreditMutation.new(credit_mutation_params.merge(created_by: current_user))
authorize @mutation

respond_to do |format|
Expand All @@ -40,7 +40,7 @@ def model_includes
%i[user activity created_by]
end

def permitted_attributes
params.require(:credit_mutation).permit(%i[description amount user_id activity_id])
def credit_mutation_params
params.require(:credit_mutation).permit(policy(CreditMutation).permitted_attributes)
Copy link

Copilot AI Jan 13, 2026

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.

Suggested change
params.require(:credit_mutation).permit(policy(CreditMutation).permitted_attributes)
params.require(:credit_mutation).permit(policy(CreditMutation.new).permitted_attributes)

Copilot uses AI. Check for mistakes.
end
end
6 changes: 3 additions & 3 deletions app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def show
end

def create
attributes = remove_empty(permitted_attributes.to_h)
attributes = remove_empty(invoice_params.to_h)
@invoice = Invoice.new(attributes)
authorize @invoice

Expand Down Expand Up @@ -80,7 +80,7 @@ def invoice
@invoice = Invoice.find_by!(token: params[:id])
end

def permitted_attributes
params.require(:invoice).permit(%i[user_id activity_id name_override email_override rows], rows_attributes: %i[name amount price])
def invoice_params
params.require(:invoice).permit(policy(Invoice.new).permitted_attributes)
end
end
13 changes: 6 additions & 7 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
end

def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@order = Order.new(permitted_attributes.merge(created_by: current_user))
@order = Order.new(order_params.merge(created_by: current_user))
authorize @order

current_credit = @order.user&.credit
Expand All @@ -43,7 +43,7 @@ def update

authorize @order

if @order.update(permitted_attributes_on_update)
if @order.update(order_params_for_update)
render json: @order.to_json(proper_json)
else
render json: @order.errors, status: :unprocessable_content
Expand Down Expand Up @@ -83,13 +83,12 @@ def send_insufficient_credit_mail?(user, old_credit)
user.provider.in?(%w[amber_oauth2 sofia_account]) && user.credit.negative? && old_credit.positive?
end

def permitted_attributes
params.require(:order).permit(%i[user_id paid_with_cash paid_with_pin activity_id],
order_rows_attributes: %i[id product_id product_count])
def order_params
params.require(:order).permit(policy(Order.new).permitted_attributes_for_create)
end

def permitted_attributes_on_update
params.require(:order).permit(:id, order_rows_attributes: %i[id product_count])
def order_params_for_update
params.require(:order).permit(policy(@order).permitted_attributes_for_update)
end

def proper_json
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/price_lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(', ')}"
Expand Down Expand Up @@ -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)
Copy link

Copilot AI Jan 13, 2026

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 PriceList 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 PriceList.new or @price_list here.

Suggested change
params.require(:price_list).permit(policy(PriceList).permitted_attributes)
params.require(:price_list).permit(policy(PriceList.new).permitted_attributes)

Copilot uses AI. Check for mistakes.
end
end
10 changes: 4 additions & 6 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProductsController < ApplicationController
after_action :verify_authorized

def create
@product = Product.new(permitted_attributes)
@product = Product.new(product_params)
authorize @product

if @product.save
Expand All @@ -18,7 +18,7 @@ def create
def update
authorize @product

if @product.update(permitted_attributes)
if @product.update(product_params)
render json: @product, include: json_includes, except: json_exludes, methods: :t_category
else
render json: @product.errors, status: :unprocessable_content
Expand All @@ -31,10 +31,8 @@ def set_model
@product = Product.find(params[:id])
end

def permitted_attributes
params.require(:product)
.permit(%i[name category color requires_age id],
product_prices_attributes: %i[id product_id price_list_id price _destroy])
def product_params
params.require(:product).permit(policy(Product.new).permitted_attributes)
end

def json_includes
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/sofia_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Copy link

Copilot AI Jan 13, 2026

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 SofiaAccount 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 SofiaAccount.new here.

Suggested change
params.require(:sofia_account).permit(policy(SofiaAccount).permitted_attributes)
params.require(:sofia_account).permit(policy(SofiaAccount.new).permitted_attributes)

Copilot uses AI. Check for mistakes.
end
end
16 changes: 10 additions & 6 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def json
end

def create
@user = User.new(permitted_attributes)
@user = User.new(user_params)
authorize @user

if @user.save
Expand All @@ -88,7 +88,7 @@ def update
@user = User.find(params[:id])
authorize @user

if @user.update(params.require(:user).permit(%i[name email deactivated]))
if update_user
flash[:success] = 'Gebruiker geupdate'
else
flash[:error] = "Gebruiker updaten mislukt; #{@user.errors.full_messages.join(', ')}"
Expand Down Expand Up @@ -140,8 +140,7 @@ def update_with_sofia_account # rubocop:disable Metrics/AbcSize, Metrics/MethodL
end
authorize @sofia_account

if @user.update(params.require(:user).permit(%i[email sub_provider] + (current_user.treasurer? ? %i[name deactivated] : []),
sofia_account_attributes: %i[id username]))
if @user.update(params.require(:user).permit(policy(@user).permitted_attributes_for_update_with_sofia_account))
flash[:success] = 'Gegevens gewijzigd'
else
flash[:error] = "Gegevens wijzigen mislukt; #{@user.errors.full_messages.join(', ')}"
Expand All @@ -152,6 +151,11 @@ def update_with_sofia_account # rubocop:disable Metrics/AbcSize, Metrics/MethodL

private

def update_user
permitted_params = params.require(:user).permit(policy(@user).permitted_attributes_for_update)
@user.update(permitted_params)
end

def find_or_create_user(user_json) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
fields = user_json['attributes']
u = User.find_or_initialize_by(uid: user_json['id'])
Expand All @@ -166,7 +170,7 @@ def find_or_create_user(user_json) # rubocop:disable Metrics/AbcSize, Metrics/Me
u.save
end

def permitted_attributes
params.require(:user).permit(%w[name email provider sub_provider])
def user_params
params.require(:user).permit(policy(User.new).permitted_attributes)
end
end
8 changes: 8 additions & 0 deletions app/policies/activity_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ def orders?
def credit_mutations?
user&.treasurer?
end

def permitted_attributes
%i[title start_time end_time price_list_id]
end

def permitted_attributes_for_update
%i[title]
end
end
4 changes: 4 additions & 0 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def scope
Pundit.policy_scope!(user, record.class)
end

def permitted_attributes
[]
end

class Scope
attr_reader :user, :scope

Expand Down
4 changes: 4 additions & 0 deletions app/policies/credit_mutation_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added permitted_attributes method lacks test coverage. Since this repository has comprehensive controller tests, consider adding tests to verify that the permitted_attributes method returns the correct attributes.

Copilot uses AI. Check for mistakes.
end
7 changes: 7 additions & 0 deletions app/policies/invoice_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ def send_invoice?
def pay?
show?
end

def permitted_attributes
[
:user_id, :activity_id, :name_override, :email_override,
{ rows_attributes: %i[name amount price] }
]
end
end
12 changes: 12 additions & 0 deletions app/policies/order_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ def index?
def create?
user&.treasurer? || user&.renting_manager? || user&.main_bartender?
end

def permitted_attributes
%i[user_id paid_with_cash paid_with_pin activity_id]
end

def permitted_attributes_for_create
permitted_attributes + [order_rows_attributes: %i[id product_id product_count]]
end

def permitted_attributes_for_update
[:id, { order_rows_attributes: %i[id product_count] }]
end
end
4 changes: 4 additions & 0 deletions app/policies/price_list_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ def unarchive?
def search?
index?
end

def permitted_attributes
%i[name]
end
Comment on lines +40 to +42
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added permitted_attributes method lacks test coverage. Since this repository has comprehensive controller tests, consider adding tests to verify that the permitted_attributes method returns the correct attributes.

Copilot uses AI. Check for mistakes.
end
7 changes: 7 additions & 0 deletions app/policies/product_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ def create?
def update?
create?
end

def permitted_attributes
[
:name, :category, :color, :requires_age,
{ product_prices_attributes: %i[id product_id price_list_id price _destroy] }
]
end
end
4 changes: 4 additions & 0 deletions app/policies/sofia_account_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def enable_otp?
def disable_otp?
update?
end

def permitted_attributes
%i[username password password_confirmation]
end
end
14 changes: 14 additions & 0 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added permitted_attributes methods in the policy classes lack test coverage. Since this repository has comprehensive controller tests, consider adding tests to verify that the permitted_attributes methods return the correct attributes for different scenarios, especially for methods like permitted_attributes_for_update_with_sofia_account that have conditional logic based on user roles.

Copilot uses AI. Check for mistakes.
end