mirror of
https://github.com/mirego/accent.git
synced 2024-09-11 18:58:14 +03:00
Fix api token flash and revoke mutation
This commit is contained in:
parent
5bbe9ba0ac
commit
959a83afd8
@ -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))
|
||||
|
@ -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}
|
||||
|
@ -1091,10 +1091,12 @@
|
||||
},
|
||||
"api_token": {
|
||||
"loading_content": "Fetching project’s 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 project’s Just In Place Translations settings…"
|
||||
|
@ -1094,10 +1094,12 @@
|
||||
},
|
||||
"api_token": {
|
||||
"loading_content": "Récupération des paramètres d’API du projet…",
|
||||
"api_token_add_success": "Le jeton d’API a été créé avec succès",
|
||||
"api_token_add_error": "Le jeton d’API n’a pas pu être créé",
|
||||
"api_token_revoke_success": "Le jeton d’API a été révoqué avec succès",
|
||||
"api_token_revoke_error": "Le jeton d’API n’a pas pu être révoqué"
|
||||
"flash_messages": {
|
||||
"api_token_add_success": "Le jeton d’API a été créé avec succès",
|
||||
"api_token_add_error": "Le jeton d’API n’a pas pu être créé",
|
||||
"api_token_revoke_success": "Le jeton d’API a été révoqué avec succès",
|
||||
"api_token_revoke_error": "Le jeton d’API n’a pas pu être révoqué"
|
||||
}
|
||||
},
|
||||
"jipt": {
|
||||
"loading_content": "Récupération des paramètres de traduction JIPT du projet…"
|
||||
|
@ -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`;
|
||||
|
@ -6,6 +6,12 @@ export interface RevokeApiTokenVariables {
|
||||
|
||||
export default gql`
|
||||
mutation ApiTokenRevoke($id: ID!) {
|
||||
revokeApiToken(id: $id)
|
||||
revokeApiToken(id: $id) {
|
||||
apiToken {
|
||||
id
|
||||
}
|
||||
|
||||
errors
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
Loading…
Reference in New Issue
Block a user