File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -30,18 +30,21 @@ defmodule Algora.Organizations do
30
30
def onboard_organization ( params ) do
31
31
user = Repo . get_by ( User , email: params . user . email )
32
32
33
+ domain = params . user . email |> String . split ( "@" ) |> List . last ( )
34
+
33
35
org =
34
36
case user do
35
37
nil ->
36
- nil
38
+ Repo . one ( from o in User , where: o . domain == ^ domain , limit: 1 )
37
39
38
40
user ->
39
41
Repo . one (
40
42
from o in User ,
41
- join: m in assoc ( o , :members ) ,
42
- join: u in assoc ( m , :user ) ,
43
- where: o . handle in ^ generate_unique_org_handle_candidates ( params . organization . handle ) ,
44
- where: u . id == ^ user . id ,
43
+ left_join: m in assoc ( o , :members ) ,
44
+ left_join: u in assoc ( m , :user ) ,
45
+ where:
46
+ o . domain == ^ domain or
47
+ ( o . handle in ^ generate_unique_org_handle_candidates ( params . organization . handle ) and u . id == ^ user . id ) ,
45
48
limit: 1
46
49
)
47
50
end
You can’t perform that action at this time.
0 commit comments