-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shipments, refactoring of HasState and strong params
* IMPORTANT: tests for the new functionality are still missing!! * New type of state machine: shipment (for booth boxes and similar) * New roles to support the shipment workflow * Strong parameters instead of protected_attributes * Refactoring of HasState, moving more and more logic into the concern * State machines (Request, Reimbursement, Shipment) can only be edited by the requester and only in initial state. Added additional actions to support setting the approved amount and similar actions.
- Loading branch information
Showing
65 changed files
with
543 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class ExpensesApprovalsController < ApplicationController | ||
respond_to :html, :json | ||
skip_load_and_authorize_resource | ||
before_filter :load_request_and_authorize | ||
|
||
def update | ||
if p = params[:expenses_approval] | ||
@request.expenses.each do |expense| | ||
expense.approved_amount = p[:"amount_#{expense.id}"] | ||
expense.approved_currency = p[:"currency_#{expense.id}"] | ||
expense.save | ||
end | ||
end | ||
respond_to do |format| | ||
format.html { redirect_to @request, | ||
:notice => I18n.t(:"flash.actions.update.notice", :resource_name => 'request') } | ||
format.json { render :json => {:request => @request} } | ||
end | ||
end | ||
|
||
protected | ||
|
||
def load_request_and_authorize | ||
@request = Request.includes(:expenses).find(params[:request_id]) | ||
authorize! :approve, @request | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class ShipmentsController < InheritedResources::Base | ||
respond_to :html, :js, :json | ||
skip_load_resource :only => [:index, :new] | ||
before_filter :set_states_collection, :only => [:index] | ||
|
||
def show | ||
# We don't want to break the normal process if something goes wrong | ||
resource.user.profile.refresh rescue nil | ||
show! | ||
end | ||
|
||
def create | ||
@shipment ||= Shipment.new(params[:shipment]) | ||
@shipment.user = current_user | ||
create! | ||
end | ||
|
||
def new | ||
@shipment ||= Shipment.new(params[:shipment]) | ||
@shipment.event = Event.find(params[:event_id]) | ||
@shipment.user = current_user | ||
authorize! :create, @shipment | ||
new! | ||
end | ||
|
||
protected | ||
|
||
def collection | ||
@q ||= end_of_association_chain.accessible_by(current_ability).search(params[:q]) | ||
@q.sorts = "id asc" if @q.sorts.empty? | ||
@all_shipments ||= @q.result(:distinct => true) | ||
@shipments ||= @all_shipments.page(params[:page]).per(20) | ||
end | ||
|
||
def set_states_collection | ||
@states_collection = Shipment.state_machines[:state].states.map {|s| [ s.human_name, s.value] } | ||
end | ||
|
||
def permitted_params | ||
params.permit(:shipment => [:event_id, :description, :delivery_address]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.