Fix api token flash and revoke mutation

This commit is contained in:
Simon Prévost 2023-12-22 09:35:36 -05:00
parent 5bbe9ba0ac
commit 959a83afd8
6 changed files with 26 additions and 15 deletions

View File

@ -16,7 +16,7 @@ defmodule Accent.GraphQL.Mutations.APIToken do
resolve(project_authorize(:create_project_api_token, &APITokenResolver.create/3, :project_id))
end
field :revoke_api_token, :boolean do
field :revoke_api_token, :mutated_api_token do
arg(:id, non_null(:id))
resolve(api_token_authorize(:revoke_project_api_token, &APITokenResolver.revoke/3))

View File

@ -5,21 +5,22 @@ defmodule Accent.GraphQL.Resolvers.APIToken do
alias Accent.Plugs.GraphQLContext
alias Accent.Project
@spec create(Project.t(), any(), GraphQLContext.t()) :: {:ok, AccessToken.t() | nil}
@spec create(Project.t(), any(), GraphQLContext.t()) ::
{:ok, %{api_token: AccessToken.t() | nil, errors: list(String.t()) | nil}}
def create(project, args, info) do
case APITokenManager.create(project, info.context[:conn].assigns[:current_user], args) do
{:ok, %{access_token: api_token}} ->
{:ok, %{api_token: api_token, errors: nil}}
{:error, _reason, _, _} ->
{:ok, %{access_token: nil, errors: ["unprocessable_entity"]}}
{:ok, %{api_token: nil, errors: ["unprocessable_entity"]}}
end
end
@spec revoke(Project.t(), any(), GraphQLContext.t()) :: {:ok, AccessToken.t() | nil}
@spec revoke(Project.t(), any(), GraphQLContext.t()) :: {:ok, AccessToken.t()}
def revoke(access_token, _args, _) do
APITokenManager.revoke(access_token)
{:ok, true}
{:ok, access_token}
end
@spec list_project(Project.t(), any(), GraphQLContext.t()) :: {:ok, AccessToken.t() | nil}

View File

@ -1091,10 +1091,12 @@
},
"api_token": {
"loading_content": "Fetching projects API settings…",
"api_token_add_success": "API token has been created with success",
"api_token_add_error": "API token could not be created",
"api_token_revoke_success": "API token has been revoked with success",
"api_token_revoke_error": "API token could not be revoked"
"flash_messages": {
"api_token_add_success": "API token has been created with success",
"api_token_add_error": "API token could not be created",
"api_token_revoke_success": "API token has been revoked with success",
"api_token_revoke_error": "API token could not be revoked"
}
},
"jipt": {
"loading_content": "Fetching projects Just In Place Translations settings…"

View File

@ -1094,10 +1094,12 @@
},
"api_token": {
"loading_content": "Récupération des paramètres dAPI du projet…",
"api_token_add_success": "Le jeton dAPI a été créé avec succès",
"api_token_add_error": "Le jeton dAPI na pas pu être créé",
"api_token_revoke_success": "Le jeton dAPI a été révoqué avec succès",
"api_token_revoke_error": "Le jeton dAPI na pas pu être révoqué"
"flash_messages": {
"api_token_add_success": "Le jeton dAPI a été créé avec succès",
"api_token_add_error": "Le jeton dAPI na pas pu être créé",
"api_token_revoke_success": "Le jeton dAPI a été révoqué avec succès",
"api_token_revoke_error": "Le jeton dAPI na pas pu être révoqué"
}
},
"jipt": {
"loading_content": "Récupération des paramètres de traduction JIPT du projet…"

View File

@ -10,7 +10,7 @@ import ApolloMutate from 'accent-webapp/services/apollo-mutate';
import apiTokenCreateQuery from 'accent-webapp/queries/create-api-token';
import apiTokenRevokeQuery from 'accent-webapp/queries/revoke-api-token';
const FLASH_MESSAGE_PREFIX = 'pods.project.edit.flash_messages.';
const FLASH_MESSAGE_PREFIX = 'pods.project.edit.api_token.flash_messages.';
const FLASH_MESSAGE_API_TOKEN_ADD_SUCCESS = `${FLASH_MESSAGE_PREFIX}api_token_add_success`;
const FLASH_MESSAGE_API_TOKEN_ADD_ERROR = `${FLASH_MESSAGE_PREFIX}api_token_add_error`;
const FLASH_MESSAGE_API_TOKEN_REVOKE_SUCCESS = `${FLASH_MESSAGE_PREFIX}api_token_revoke_success`;

View File

@ -6,6 +6,12 @@ export interface RevokeApiTokenVariables {
export default gql`
mutation ApiTokenRevoke($id: ID!) {
revokeApiToken(id: $id)
revokeApiToken(id: $id) {
apiToken {
id
}
errors
}
}
`;