File tree Expand file tree Collapse file tree 5 files changed +28
-20
lines changed
Expand file tree Collapse file tree 5 files changed +28
-20
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ class Invoices::MarkAsPaidsController < BaseController
33 rescue_from Errors ::InvoiceAlreadyPaid , with : :invoice_already_paid
44
55 before_action :set_invoice
6- before_action :authorize_user
7- before_action :authorize_for_update
6+
7+ # order is important! before set invoice, otherwise @invoice wont be set
8+ include ::Invoices ::UpdateAuthorizable
89
910 def edit ; end
1011
@@ -30,14 +31,6 @@ def invoice_already_paid
3031 redirect_to admin_invoice_path ( @invoice ) , status : :see_other
3132 end
3233
33- def authorize_user
34- authorize! :read , Invoice
35- end
36-
37- def authorize_for_update
38- authorize! :update , @invoice
39- end
40-
4134 def invoice_params
4235 params . require ( :invoice ) . permit ( :notes , :paid_at )
4336 end
Original file line number Diff line number Diff line change 11module Admin
22 class Invoices ::TogglePartialPaymentsController < BaseController
33 before_action :set_invoice
4- before_action :authorize_user
5- before_action :authorize_for_update
4+
5+ # order is important! before set invoice, otherwise @invoice wont be set
6+ include ::Invoices ::UpdateAuthorizable
67
78 def update
89 if @invoice . toggle ( :partial_payments ) . save
@@ -19,13 +20,5 @@ def update
1920 def set_invoice
2021 @invoice = Invoice . find ( params [ :invoice_id ] )
2122 end
22-
23- def authorize_user
24- authorize! :read , Invoice
25- end
26-
27- def authorize_for_update
28- authorize! :update , @invoice
29- end
3023 end
3124end
Original file line number Diff line number Diff line change 1+ module Invoices
2+ module UpdateAuthorizable
3+ extend ActiveSupport ::Concern
4+
5+ included do
6+ before_action :authorize_user
7+ before_action :authorize_for_update
8+ end
9+
10+ private
11+
12+ def authorize_user
13+ authorize! :read , Invoice
14+ end
15+
16+ def authorize_for_update
17+ authorize! :update , @invoice
18+ end
19+ end
20+ end
Original file line number Diff line number Diff line change 4545 paid_deposit_title : " Paid deposits"
4646 pay_all : Pay all invoices
4747 partial_payments_activated : " Allowed clients to make partial payments for this invoice"
48+ partial_payments_deactivated : " Disallowed clients to make partial payments for this invoice"
4849 allow_partial_payments : " Allow partial payments"
4950 disallow_partial_payments : " Disallow partial payments"
5051 amount_must_be_positive : " Amount must be greater than 0"
Original file line number Diff line number Diff line change 4646 paid_deposit_title : Deposiidimaksed
4747 pay_all : " Maksa kõik arved"
4848 partial_payments_activated : " Lubatud klientidel teha selle arve osalisi makseid"
49+ partial_payments_deactivated : " Keelatud klientidel teha selle arve osalisi makseid"
4950 allow_partial_payments : " Luba osalisi makseid"
5051 disallow_partial_payments : " Keela osalised maksed"
5152 amount_must_be_positive : " Summa peab olema suurem kui 0"
You can’t perform that action at this time.
0 commit comments