@@ -116,31 +116,41 @@ defmodule AlgoraWeb.ClaimLive do
116
116
end
117
117
118
118
@ impl true
119
- def handle_event ( "reward_bounty" , _params , socket ) do
120
- claim = socket . assigns . primary_claim
119
+ def handle_event ( "reward_bounty" , _params , % { assigns: % { current_user: nil } } = socket ) do
120
+ { :noreply ,
121
+ redirect ( socket , to: ~p" /auth/login?#{ % { return_to: ~p" /claims/#{ socket . assigns . primary_claim . group_id } " } } " ) }
122
+ end
123
+
124
+ def handle_event ( "reward_bounty" , _params , % { assigns: % { current_user: current_user , target: target } } = socket ) do
125
+ user_org_ids = MapSet . new ( [ current_user | Algora.Organizations . get_user_orgs ( current_user ) ] , & & 1 . id )
121
126
122
- # TODO: use the correct bounty
123
- bounty = hd ( claim . target . bounties )
127
+ # TODO: allow user to choose if multiple bounties are available
128
+ case Enum . find ( target . bounties , & MapSet . member? ( user_org_ids , & 1 . owner_id ) ) do
129
+ nil ->
130
+ # TODO: allow user to add a bounty
131
+ { :noreply , put_flash ( socket , :error , "You are not authorized to reward this bounty" ) }
124
132
125
- case Algora.Bounties . reward_bounty (
126
- % {
127
- # TODO: handle unauthenticated user
128
- creator: socket . assigns . current_user ,
129
- amount: bounty . amount ,
130
- bounty_id: bounty . id ,
131
- claims: socket . assigns . claims
132
- } ,
133
- ticket_ref: % {
134
- owner: claim . target . repository . user . provider_login ,
135
- repo: claim . target . repository . name ,
136
- number: claim . target . number
137
- }
138
- ) do
139
- { :ok , session_url } ->
140
- { :noreply , redirect ( socket , external: session_url ) }
133
+ bounty ->
134
+ case Algora.Bounties . reward_bounty (
135
+ % {
136
+ creator: current_user ,
137
+ # TODO: allow user to choose amount
138
+ amount: bounty . amount ,
139
+ bounty_id: bounty . id ,
140
+ claims: socket . assigns . claims
141
+ } ,
142
+ ticket_ref: % {
143
+ owner: target . repository . user . provider_login ,
144
+ repo: target . repository . name ,
145
+ number: target . number
146
+ }
147
+ ) do
148
+ { :ok , session_url } ->
149
+ { :noreply , redirect ( socket , external: session_url ) }
141
150
142
- { :error , _reason } ->
143
- { :noreply , put_flash ( socket , :error , "Failed to create payment session. Please try again later." ) }
151
+ { :error , _reason } ->
152
+ { :noreply , put_flash ( socket , :error , "Failed to create payment session. Please try again later." ) }
153
+ end
144
154
end
145
155
end
146
156
0 commit comments