unlock_gateway 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/unlock_gateway/controller.rb +28 -32
- data/lib/unlock_gateway/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b7d3e76866d073fc15d237fb08ede032a3fa5c6
|
4
|
+
data.tar.gz: 9c8e0ff9164d5c89b4e31b0666eafe5bf67e6db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10b84ad2e9cda745ea085785ce2a195f57872484c57f3d3bd6f3c48fb871d113fb0166a2a65dfe41d5bab165bcd1275604050c00780c9b2b4b0f05daf9a26eb7
|
7
|
+
data.tar.gz: 07035e0ebb9daa53ccd713f0fef5e4fa784871a5a3c4d79df5dea72fd3eb7efe2b43210dae25f5bbb2333ce8056e13487c872dd77c5a30429667188a43dc6c58
|
@@ -9,9 +9,8 @@ module UnlockGateway
|
|
9
9
|
def self.extended(base)
|
10
10
|
base.class_eval do
|
11
11
|
|
12
|
-
|
12
|
+
before_action :set_contribution, only: %i[edit activate suspend]
|
13
13
|
|
14
|
-
actions :create, :edit
|
15
14
|
respond_to :html
|
16
15
|
|
17
16
|
after_action :verify_authorized
|
@@ -25,25 +24,26 @@ module UnlockGateway
|
|
25
24
|
|
26
25
|
# A second step or final checkout should use this action
|
27
26
|
def edit
|
28
|
-
|
27
|
+
authorize @contribution
|
29
28
|
end
|
30
29
|
|
31
30
|
# This action will be used when the user requests to activate/reactivate a contribution
|
32
31
|
def activate
|
33
|
-
|
34
|
-
format.html { transition_state(:active) }
|
35
|
-
end
|
32
|
+
transition_state(:active)
|
36
33
|
end
|
37
34
|
|
38
35
|
# This action will be used when the user requests to suspend a contribution
|
39
36
|
def suspend
|
40
|
-
|
41
|
-
format.html { transition_state(:suspended) }
|
42
|
-
end
|
37
|
+
transition_state(:suspended)
|
43
38
|
end
|
44
39
|
|
45
40
|
private
|
46
41
|
|
42
|
+
# Sets @contribution
|
43
|
+
def set_contribution
|
44
|
+
@contribution = Contribution.find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
47
|
# Creates the contribution, sets session[:gateway_id], returns true if successful and renders new action if not
|
48
48
|
def create_contribution
|
49
49
|
|
@@ -63,48 +63,44 @@ module UnlockGateway
|
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
-
# This method authorizes
|
66
|
+
# This method authorizes @contribution, checks if the contribution can be transitioned to the desired state, calls Contribution#update_state_on_gateway!, transition the contribution's state, and return the proper JSON for Unlock's AJAX calls
|
67
67
|
def transition_state(state)
|
68
|
-
authorize
|
69
|
-
@initiative =
|
70
|
-
@user =
|
68
|
+
authorize @contribution
|
69
|
+
@initiative = @contribution.initiative
|
70
|
+
@user = @contribution.user
|
71
71
|
state = state.to_sym
|
72
|
-
transition =
|
73
|
-
initial_state =
|
74
|
-
|
72
|
+
transition = @contribution.transition_by_state(state)
|
73
|
+
initial_state = @contribution.state_name
|
74
|
+
resource_name = @contribution.class.model_name.human
|
75
|
+
if @contribution.send("can_#{transition}?")
|
75
76
|
begin
|
76
|
-
if
|
77
|
-
if
|
78
|
-
|
77
|
+
if @contribution.state_on_gateway != state
|
78
|
+
if @contribution.update_state_on_gateway!(state)
|
79
|
+
@contribution.send("#{transition}!")
|
79
80
|
else
|
80
|
-
flash[:
|
81
|
+
flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
|
81
82
|
end
|
82
83
|
else
|
83
|
-
|
84
|
+
@contribution.send("#{transition}!")
|
84
85
|
end
|
85
86
|
rescue
|
86
|
-
flash[:
|
87
|
+
flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
|
87
88
|
end
|
88
89
|
else
|
89
|
-
flash[:
|
90
|
+
flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
|
90
91
|
end
|
91
|
-
if flash[:
|
92
|
+
if flash[:alert].present?
|
92
93
|
render 'initiatives/contributions/show'
|
93
94
|
else
|
94
95
|
if initial_state == :pending
|
95
|
-
flash[:
|
96
|
+
flash[:notice] = t('flash.actions.create.notice', resource_name: resource_name)
|
96
97
|
else
|
97
|
-
flash[:
|
98
|
+
flash[:notice] = t('flash.actions.update.notice', resource_name: resource_name)
|
98
99
|
end
|
99
|
-
redirect_to initiative_contribution_path(
|
100
|
+
redirect_to initiative_contribution_path(@contribution.initiative.id, @contribution)
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
# Strong parameters for Contribution. This duplication is due to a inherited_resources problem that requires both
|
104
|
-
def permitted_params
|
105
|
-
params.permit(contribution: policy(@contribution || Contribution.new).permitted_attributes)
|
106
|
-
end
|
107
|
-
|
108
104
|
# Strong parameters for Contribution
|
109
105
|
def contribution_params
|
110
106
|
params.require(:contribution).permit(*policy(@contribution || Contribution.new).permitted_attributes)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unlock_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Weinmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|