@@ -6,6 +6,7 @@ class SourceUsersController < ApplicationController
6
6
7
7
before_action :source_user
8
8
before_action :check_current_user_matches_invite!
9
+ before_action :check_source_user_status!
9
10
10
11
respond_to :html
11
12
feature_category :importers
@@ -14,28 +15,37 @@ def accept
14
15
if source_user . accept
15
16
# TODO: This is where we enqueue the job to assign the contributions.
16
17
17
- redirect_to ( root_path , notice : format ( mapping_decision_notice ( 'approved' ) , invite_details ) )
18
+ flash [ :raw ] = banner ( 'accept_invite' )
19
+ redirect_to ( dashboard_groups_path )
18
20
else
19
- redirect_to ( root_path , alert : _ ( ' The invitation could not be accepted.') )
21
+ redirect_to ( dashboard_groups_path , alert : s_ ( 'UserMapping| The invitation could not be accepted.') )
20
22
end
21
23
end
22
24
23
25
def decline
24
26
if source_user . reject
25
- redirect_to ( root_path , notice : format ( mapping_decision_notice ( 'rejected' ) , invite_details ) )
27
+ flash [ :raw ] = banner ( 'reject_invite' )
28
+ redirect_to ( dashboard_groups_path )
26
29
else
27
- redirect_to ( root_path , alert : _ ( ' The invitation could not be declined.') )
30
+ redirect_to ( dashboard_groups_path , alert : s_ ( 'UserMapping| The invitation could not be declined.') )
28
31
end
29
32
end
30
33
31
- def show
32
- redirect_to ( root_path , alert : _ ( 'The invitation is not valid' ) ) unless source_user . awaiting_approval?
33
- end
34
+ def show ; end
34
35
35
36
private
36
37
38
+ def check_source_user_status!
39
+ return if source_user . awaiting_approval?
40
+
41
+ redirect_to ( dashboard_groups_path , alert : s_ ( 'UserMapping|The invitation is not valid' ) )
42
+ end
43
+
37
44
def check_current_user_matches_invite!
38
- not_found unless current_user_matches_invite?
45
+ return if current_user_matches_invite?
46
+
47
+ flash [ :raw ] = banner ( 'cancel_invite' )
48
+ redirect_to ( dashboard_groups_path )
39
49
end
40
50
41
51
def current_user_matches_invite?
@@ -47,24 +57,19 @@ def source_user
47
57
end
48
58
strong_memoize_attr :source_user
49
59
50
- def invite_details
51
- {
52
- source_username : source_user . source_username ,
53
- source_hostname : source_user . source_hostname ,
54
- destination_group : source_user . namespace . name
55
- }
56
- end
57
-
58
60
def check_feature_flag!
59
61
not_found unless Feature . enabled? ( :importer_user_mapping , current_user )
60
62
end
61
63
62
- # TODO: This is a placeholder for the proper UI to be provided
63
- # in a follow-up MR.
64
- def mapping_decision_notice ( decision )
65
- "You have #{ decision } the reassignment of contributions from " \
66
- "%{source_username} on %{source_hostname} " \
67
- "to yourself on %{destination_group}."
64
+ def banner ( partial )
65
+ render_to_string (
66
+ partial : partial ,
67
+ layout : false ,
68
+ formats : :html ,
69
+ locals : {
70
+ source_user : source_user
71
+ }
72
+ ) . html_safe # rubocop: disable Rails/OutputSafety -- render_to_string already makes the string safe
68
73
end
69
74
end
70
75
end
0 commit comments