Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 464
- Log:
Canvass version 1.0.2.
- Author:
- rool
- Date:
- Sat May 03 09:48:48 +0100 2014
- Size:
- 3824 Bytes
1 | ######################################################################## |
2 | # File:: donations_controller.rb |
3 | # (C):: Hipposoft 2011 |
4 | # |
5 | # Purpose:: Handle creating and displaying donations. |
6 | # ---------------------------------------------------------------------- |
7 | # 30-Jan-2011 (ADH): Created. |
8 | ######################################################################## |
9 | |
10 | class DonationsController < ApplicationController |
11 | |
12 | uses_prototype() |
13 | uses_leightbox( :only => :index ) |
14 | |
15 | @@hubssolib_permissions = HubSsoLib::Permissions.new( { |
16 | :index => [ :admin, :webmaster, :privileged, :normal ], |
17 | :show => [ :admin, :webmaster, :privileged, :normal ], |
18 | :new => [ :admin, :webmaster, :privileged, :normal ], |
19 | :create => [ :admin, :webmaster, :privileged, :normal ] |
20 | } ) |
21 | |
22 | def self.hubssolib_permissions |
23 | @@hubssolib_permissions |
24 | end |
25 | |
26 | def skip_main_heading? |
27 | action_name.to_sym == :index |
28 | end |
29 | |
30 | # GET /donations |
31 | # GET /users/<n>/donations |
32 | def index |
33 | |
34 | # The Donation model takes care of permissions for users trying to view |
35 | # the donations of other users and so-forth within its "conditions_for" |
36 | # class method. If the user hacks around with URLs they might get an odd |
37 | # title such as "All Donations", but the list will only contain things |
38 | # they're allowed to see (e.g. for non-admins, only their donations). |
39 | |
40 | appctrl_search_sort_and_paginate( |
41 | Donation, |
42 | :default_sorting => Donation.default_sort_hash(), |
43 | :extra_conditions => Donation.conditions_for( params, current_user ) |
44 | ) |
45 | end |
46 | |
47 | # GET /donations/<n> |
48 | # GET /users/<u>/donations/<n> |
49 | def show |
50 | @donation = Donation.find_by_id( |
51 | params[ :id ], |
52 | :conditions => Donation.conditions_for( params, current_user ) |
53 | ) |
54 | |
55 | redirect_to polls_path and return if @donation.nil? |
56 | end |
57 | |
58 | # GET /polls/<n>/donations/new |
59 | def new |
60 | @poll = Poll.find_by_id( params[ :poll_id ] ) |
61 | @donation = Donation.generate_for( @poll, current_user, '0', '0' ) |
62 | params[ :payment_method ] = current_user.admin? ? 'none' : 'onsite' |
63 | end |
64 | |
65 | # POST /polls/<n>/donations |
66 | def create |
67 | |
68 | payment_method = params[ :payment_method ] |
69 | |
70 | redirect_to root_path() and return if ( |
71 | %w{ none onsite offsite }.include?( payment_method ) == false || |
72 | ( payment_method == 'none' && current_user.admin? == false ) |
73 | ) |
74 | |
75 | # Here, we know that the payment method parameter is valid and the |
76 | # current user has permission to use whatever method was specified. |
77 | |
78 | begin |
79 | options = {} |
80 | |
81 | if ( payment_method == 'none' ) |
82 | options[ :external ] = true |
83 | options[ :name ] = params[ :payment_none_donor_name ] |
84 | options[ :email ] = params[ :payment_none_donor_email ] |
85 | end |
86 | |
87 | @poll = Poll.find_by_id( params[ :poll_id ] ) |
88 | @donation = Donation.generate_for( |
89 | @poll, |
90 | current_user, |
91 | params[ :donation ][ :amount_integer ], |
92 | params[ :donation ][ :amount_fraction ], |
93 | options |
94 | ) |
95 | |
96 | rescue => error |
97 | appctrl_report_error( error ) |
98 | redirect_to root_path() |
99 | |
100 | end |
101 | |
102 | saved = @donation.save |
103 | |
104 | if ( saved && payment_method == 'none' ) |
105 | saved = Donation.transaction do |
106 | @donation.notes = t( :'uk.org.pond.canvass.controllers.donations.view_external_note' ) |
107 | @donation.invoice_number = InvoiceNumber.next! |
108 | @donation.paid! # See Workflow state machine definitions in donation.rb |
109 | @donation.save |
110 | end |
111 | end |
112 | |
113 | if saved |
114 | redirect_to( case payment_method |
115 | when 'onsite' |
116 | new_poll_payment_gateway_onsite_path( @poll ) |
117 | when 'offsite' |
118 | new_poll_payment_gateway_offsite_path( @poll ) |
119 | when 'none' |
120 | poll_path( @poll ) |
121 | end ) |
122 | else |
123 | render :action => 'new' |
124 | end |
125 | end |
126 | end |