Skip to content

Commit

Permalink
Implement an async GraphQL endpoint for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Oct 17, 2022
1 parent 45d1624 commit ec47878
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions big_tests/tests/graphql_domain_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ domain_tests() ->
get_domains_by_host_type,
get_domain_details,
delete_domain,
request_delete_domain,
get_domains_after_deletion,
set_domain_password,
set_nonexistent_domain_password,
Expand Down Expand Up @@ -177,6 +178,21 @@ delete_domain(Config) ->
<<"domain">> := #{<<"domain">> := ?SECOND_EXAMPLE_DOMAIN}},
ParsedResult2).

request_delete_domain(Config) ->
Domain = <<"exampleDomain">>,
Result1 = request_remove_domain(Domain, ?HOST_TYPE, Config),
ParsedResult1 = get_ok_value([data, domain, requestRemoveDomain], Result1),
ct:pal("Value ~p~n", [ParsedResult1]),
?assertMatch(#{<<"msg">> := <<"Domain disabled and enqueued for deletion">>,
<<"domain">> := #{<<"domain">> := Domain,
<<"status">> := <<"DELETING">>}},
ParsedResult1),
F = fun() ->
Result = get_domain_details(Domain, Config),
domain_not_found_error_formatting(Result)
end,
mongoose_helper:wait_until(F, ok, #{time_left => timer:seconds(5)}).

get_domains_after_deletion(Config) ->
Result = get_domains_by_host_type(?HOST_TYPE, Config),
ParsedResult = get_ok_value([data, domain, domainsByHostType], Result),
Expand Down Expand Up @@ -263,6 +279,10 @@ remove_domain(Domain, HostType, Config) ->
Vars = #{domain => Domain, hostType => HostType},
execute_command(<<"domain">>, <<"removeDomain">>, Vars, Config).

request_remove_domain(Domain, HostType, Config) ->
Vars = #{domain => Domain, hostType => HostType},
execute_command(<<"domain">>, <<"requestRemoveDomain">>, Vars, Config).

get_domains_by_host_type(HostType, Config) ->
Vars = #{hostType => HostType},
execute_command(<<"domain">>, <<"domainsByHostType">>, Vars, Config).
Expand Down
3 changes: 3 additions & 0 deletions priv/graphql/schemas/admin/domain.gql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type DomainAdminMutation @protected{
"Remove domain. Only for global admin"
removeDomain(domain: String!, hostType: String!): RemoveDomainPayload
@protected(type: GLOBAL)
"Remove domain. Only for global admin"
requestRemoveDomain(domain: String!, hostType: String!): RemoveDomainPayload
@protected(type: GLOBAL)
"Enable domain. Only for global admin"
enableDomain(domain: String!): Domain
@protected(type: GLOBAL)
Expand Down
8 changes: 8 additions & 0 deletions src/graphql/admin/mongoose_graphql_domain_admin_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ execute(_Ctx, admin, <<"removeDomain">>, #{<<"domain">> := Domain, <<"hostType">
{error, Error} ->
error_handler(Error, Domain, HostType)
end;
execute(_Ctx, admin, <<"requestRemoveDomain">>, #{<<"domain">> := Domain, <<"hostType">> := HostType}) ->
case mongoose_domain_api:request_delete_domain(Domain, HostType) of
ok ->
DomainObj = #domain{domain = Domain, host_type = HostType, status = deleting},
{ok, #{<<"domain">> => DomainObj, <<"msg">> => <<"Domain disabled and enqueued for deletion">>}};
{error, Error} ->
error_handler(Error, Domain, HostType)
end;
execute(_Ctx, admin, <<"enableDomain">>, #{<<"domain">> := Domain}) ->
case mongoose_domain_api:enable_domain(Domain) of
ok ->
Expand Down

0 comments on commit ec47878

Please sign in to comment.