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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cb7317f716d9074645b160bbbb03c2ad4b35a6e
4
- data.tar.gz: a4352f39986625f4148ddc8696bf007f8bae8956
3
+ metadata.gz: 0b7d3e76866d073fc15d237fb08ede032a3fa5c6
4
+ data.tar.gz: 9c8e0ff9164d5c89b4e31b0666eafe5bf67e6db9
5
5
  SHA512:
6
- metadata.gz: cac357585717cc0a38b2122b5cee94222c9e1995ea1aa55e2b42a23becffc9f48bb6b6f2de7af92baab08fdfe75509080f313047f9dd3ee4e0a60562ee5efac2
7
- data.tar.gz: bf90f5df27a2fa31a799bee3dbc98a248c0411f4fc059a4557678c05b4db24f1363d4f89843d23e750d4751579389a4ba36331029226c370af0a87912e9820a8
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
- inherit_resources
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
- edit! { authorize resource }
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
- respond_to do |format|
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
- respond_to do |format|
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 the resource, 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
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 resource
69
- @initiative = resource.initiative
70
- @user = resource.user
68
+ authorize @contribution
69
+ @initiative = @contribution.initiative
70
+ @user = @contribution.user
71
71
  state = state.to_sym
72
- transition = resource.transition_by_state(state)
73
- initial_state = resource.state_name
74
- if resource.send("can_#{transition}?")
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 resource.state_on_gateway != state
77
- if resource.update_state_on_gateway!(state)
78
- resource.send("#{transition}!")
77
+ if @contribution.state_on_gateway != state
78
+ if @contribution.update_state_on_gateway!(state)
79
+ @contribution.send("#{transition}!")
79
80
  else
80
- flash[:failure] = "Não foi possível alterar o status de seu apoio."
81
+ flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
81
82
  end
82
83
  else
83
- resource.send("#{transition}!")
84
+ @contribution.send("#{transition}!")
84
85
  end
85
86
  rescue
86
- flash[:failure] = "Ooops, ocorreu um erro ao alterar o status de seu apoio."
87
+ flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
87
88
  end
88
89
  else
89
- flash[:failure] = "Não foi permitido alterar o status deste apoio."
90
+ flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
90
91
  end
91
- if flash[:failure].present?
92
+ if flash[:alert].present?
92
93
  render 'initiatives/contributions/show'
93
94
  else
94
95
  if initial_state == :pending
95
- flash[:success] = "Apoio realizado com sucesso!"
96
+ flash[:notice] = t('flash.actions.create.notice', resource_name: resource_name)
96
97
  else
97
- flash[:success] = "Status do apoio alterado com sucesso!"
98
+ flash[:notice] = t('flash.actions.update.notice', resource_name: resource_name)
98
99
  end
99
- redirect_to initiative_contribution_path(resource.initiative.id, resource)
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)
@@ -1,3 +1,3 @@
1
1
  module UnlockGateway
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-09 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails