Fix account suspension

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-08-18 17:21:58 +02:00
parent f8ad3cd8fc
commit 2ea6286d3f
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 29 additions and 21 deletions

View File

@ -80,6 +80,14 @@ export const DELETE_ACCOUNT = gql`
}
`;
export const SUSPEND_USER = gql`
mutation SuspendUser($userId: ID) {
deleteAccount(userId: $userId) {
id
}
}
`;
export const CURRENT_USER_CLIENT = gql`
query {
currentUser @client {

View File

@ -59,7 +59,7 @@
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
import { GET_USER, DELETE_ACCOUNT } from "../../graphql/user";
import { GET_USER, SUSPEND_USER } from "../../graphql/user";
import { usernameWithDomain } from "../../types/actor/actor.model";
import RouteName from "../../router/name";
import { IUser, ICurrentUserRole } from "../../types/current-user.model";
@ -148,7 +148,7 @@ export default class AdminUserProfile extends Vue {
async deleteAccount() {
await this.$apollo.mutate<{ suspendProfile: { id: string } }>({
mutation: DELETE_ACCOUNT,
mutation: SUSPEND_USER,
variables: {
userId: this.id,
},

View File

@ -389,6 +389,25 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
end
end
def delete_account(_parent, %{user_id: user_id}, %{
context: %{current_user: %User{role: role} = moderator_user}
})
when is_moderator(role) do
with {:moderator_actor, %Actor{} = moderator_actor} <-
{:moderator_actor, Users.get_actor_for_user(moderator_user)},
%User{disabled: false} = user <- Users.get_user(user_id),
{:ok, %User{}} <-
do_delete_account(%User{} = user, Relay.get_actor()) do
Admin.log_action(moderator_actor, "delete", user)
else
{:moderator_actor, nil} ->
{:error, "No actor found for the moderator user"}
%User{disabled: true} ->
{:error, "User already disabled"}
end
end
def delete_account(_parent, args, %{
context: %{current_user: %User{email: email} = user}
}) do
@ -411,25 +430,6 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
end
end
def delete_account(_parent, %{user_id: user_id}, %{
context: %{current_user: %User{role: role} = moderator_user}
})
when is_moderator(role) do
with {:moderator_actor, %Actor{} = moderator_actor} <-
{:moderator_actor, Users.get_actor_for_user(moderator_user)},
%User{disabled: false} = user <- Users.get_user(user_id),
{:ok, %User{}} <-
do_delete_account(%User{} = user, Relay.get_actor()) do
Admin.log_action(moderator_actor, "delete", user)
else
{:moderator_actor, nil} ->
{:error, "No actor found for the moderator user"}
%User{disabled: true} ->
{:error, "User already disabled"}
end
end
def delete_account(_parent, _args, _resolution) do
{:error, "You need to be logged-in to delete your account"}
end