Skip to content

Commit 24abdfd

Browse files
author
Pietro
committed
feat(wallet): same as previous, but also for already logged in commoners
1 parent 2c3118e commit 24abdfd

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

app/controllers/groups_controller.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class GroupsController < ApplicationController
22
before_action :set_group, only: [:show, :edit, :update, :destroy, :leave, :affiliation, :affiliate]
3-
before_action :set_commoner, only: [:new, :create, :leave]
3+
before_action :set_commoner, only: [:new, :create, :leave, :join_and_associate_qr_wallet]
44

55
# GET /groups
66
# GET /groups.json
@@ -78,6 +78,20 @@ def affiliate
7878
end
7979
end
8080

81+
def join_and_associate_qr_wallet
82+
if params[:hash_id].present?
83+
wallet = Wallet.find_by(hash_id: params[:hash_id])
84+
respond_to do |format|
85+
if wallet.present? && !@commoner.member_of?(wallet.currency.group)
86+
associate_commoner_to_wallet(@commoner, wallet)
87+
format.html { redirect_to wallet_short_path(wallet.hash_id), notice: _('Good! This wallet has been associated to your account') }
88+
else
89+
format.html { redirect_to wallet_short_path(wallet.hash_id), alert: _('Oh no, an error occurred') }
90+
end
91+
end
92+
end
93+
end
94+
8195
# POST /groups
8296
# POST /groups.json
8397
def create

app/models/ability.rb

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def initialize(user)
4949
can :join, Group do |group|
5050
!commoner.member_of? group
5151
end
52+
can :join_and_associate_qr_wallet, Group do |group|
53+
!commoner.member_of? group
54+
end
5255
cannot [:affiliation, :affiliate], Group
5356
can :create, JoinRequest do |join_request|
5457
# commoner must not be a member and there must be no pending requests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Modal -->
2+
<div class="modal fade" id="joinAndAssociateQrWalletModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
3+
<div class="modal-dialog" role="document">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<h5 class="modal-title red-title" id="exampleModalLabel"><%= s_('Title|Please read before proceeding') %></h5>
7+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
8+
<span aria-hidden="true">&times;</span>
9+
</button>
10+
</div>
11+
<div class="modal-body">
12+
<div class="row">
13+
<div class="col">
14+
<%= _("After having associated this wallet to this Commonfare account, you will also become a member of the group <strong>#{@wallet.currency.group.name}</strong>. Click the button below to proceed.").html_safe %>
15+
</div>
16+
</div>
17+
</div>
18+
<div class="modal-footer">
19+
<%= link_to s_('Title|Associate to this Commonfare account'), group_join_and_associate_qr_wallet_path(@wallet.currency.group, @wallet.hash_id), class: 'btn btn-cf btn-block' %>
20+
</div>
21+
</div>
22+
</div>
23+
</div>

app/views/wallets/view.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<%= link_to(s_('Button|Daily takings'), daily_takings_commoner_wallet_path(@commoner, @wallet, {day_start: get_day_start_for_wallet(@wallet)}), class: 'btn btn-outline-secondary btn-block') if can? :daily_takings, @wallet %>
1919
<%= link_to s_('Button|Activate account'), affiliation_group_path(@wallet.currency.group, { commoner_name: @wallet.holder.name}), class: 'btn btn-cf btn-block' if can_activate_account_for_group?(@wallet.currency.group, @wallet.holder) %>
2020
<%= link_to s_('Button|Associate to your Commonfare account'), new_user_session_path({ hash_id: @wallet.hash_id}), class: 'btn btn-cf btn-block' if can_activate_account_for_group?(@wallet.currency.group, @wallet.holder) %>
21+
<%= link_to s_('Button|Associate to this Commonfare account'), '#', class: 'btn btn-cf btn-block', data: { toggle: "modal", target: "#joinAndAssociateQrWalletModal" } if can? :join_and_associate_qr_wallet, @wallet.currency.group %>
2122

2223
<% if can_top_up_wallet? %>
2324
<%= link_to(s_('Button|Withdraw'), withdraw_commoner_transactions_path(@wallet.walletable, { from_wallet_id: @wallet.id, currency: @wallet.currency.id }), class: 'btn btn btn-cf btn-block') %>
@@ -48,3 +49,4 @@
4849
</div>
4950

5051
<%= render 'wallets/qr_modal' if can_view_qr_code? %>
52+
<%= render 'wallets/join_and_associate_qr_wallet_modal' if can? :join_and_associate_qr_wallet, @wallet.currency.group %>

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
get 'transaction_confirm', to: 'transactions#confirm'
107107
resources :transactions, except: [:edit, :update, :destroy]
108108
end
109+
match 'join_and_associate_qr_wallet/:hash_id', to: 'groups#join_and_associate_qr_wallet', via: :get, as: 'join_and_associate_qr_wallet'
109110
end
110111
resources :conversations, except: [:edit, :update, :destroy] do
111112
resources :messages, only: [:create, :destroy]

0 commit comments

Comments
 (0)