2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-15 12:00:08 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-11-14 10:50:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
2018-11-26 10:47:23 +00:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
2019-03-26 15:56:16 +00:00
|
|
|
"go.uber.org/zap"
|
2018-11-14 10:50:15 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/internal/post"
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Mutation is graphql request that modifies data
|
|
|
|
Mutation = "mutation"
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
// CreateUserMutation is a user creation mutation name
|
|
|
|
CreateUserMutation = "createUser"
|
|
|
|
// UpdateAccountMutation is a mutation name for account updating
|
|
|
|
UpdateAccountMutation = "updateAccount"
|
|
|
|
// DeleteAccountMutation is a mutation name for account deletion
|
|
|
|
DeleteAccountMutation = "deleteAccount"
|
|
|
|
// ChangePasswordMutation is a mutation name for password changing
|
|
|
|
ChangePasswordMutation = "changePassword"
|
|
|
|
// CreateProjectMutation is a mutation name for project creation
|
|
|
|
CreateProjectMutation = "createProject"
|
|
|
|
// DeleteProjectMutation is a mutation name for project deletion
|
|
|
|
DeleteProjectMutation = "deleteProject"
|
|
|
|
// UpdateProjectDescriptionMutation is a mutation name for project updating
|
|
|
|
UpdateProjectDescriptionMutation = "updateProjectDescription"
|
|
|
|
|
|
|
|
// AddProjectMembersMutation is a mutation name for adding new project members
|
|
|
|
AddProjectMembersMutation = "addProjectMembers"
|
|
|
|
// DeleteProjectMembersMutation is a mutation name for deleting project members
|
|
|
|
DeleteProjectMembersMutation = "deleteProjectMembers"
|
|
|
|
|
|
|
|
// CreateAPIKeyMutation is a mutation name for api key creation
|
|
|
|
CreateAPIKeyMutation = "createAPIKey"
|
2019-02-13 11:34:40 +00:00
|
|
|
// DeleteAPIKeysMutation is a mutation name for api key deleting
|
|
|
|
DeleteAPIKeysMutation = "deleteAPIKeys"
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-07-10 21:29:26 +01:00
|
|
|
// AddPaymentMethodMutation is mutation name for adding new payment method
|
|
|
|
AddPaymentMethodMutation = "addPaymentMethod"
|
|
|
|
// DeletePaymentMethodMutation is mutation name for deleting payment method
|
|
|
|
DeletePaymentMethodMutation = "deletePaymentMethod"
|
|
|
|
// SetDefaultPaymentMethodMutation is mutation name setting payment method as default payment method
|
|
|
|
SetDefaultPaymentMethodMutation = "setDefaultPaymentMethod"
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
// InputArg is argument name for all input types
|
|
|
|
InputArg = "input"
|
|
|
|
// FieldProjectID is field name for projectID
|
|
|
|
FieldProjectID = "projectID"
|
|
|
|
// FieldNewPassword is a field name for new password
|
|
|
|
FieldNewPassword = "newPassword"
|
2019-03-19 17:55:43 +00:00
|
|
|
// Secret is a field name for registration token for user creation during Vanguard release
|
|
|
|
Secret = "secret"
|
2019-07-23 17:08:07 +01:00
|
|
|
// ReferrerUserID is a field name for passing referrer's user id
|
2019-07-26 18:58:17 +01:00
|
|
|
ReferrerUserID = "referrerUserId"
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// rootMutation creates mutation for graphql populated by AccountsClient
|
2019-04-04 15:56:20 +01:00
|
|
|
func rootMutation(log *zap.Logger, service *console.Service, mailService *mailservice.Service, types *TypeCreator) *graphql.Object {
|
2018-11-14 10:50:15 +00:00
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: Mutation,
|
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
CreateUserMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.user,
|
2018-11-14 10:50:15 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
InputArg: &graphql.ArgumentConfig{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: graphql.NewNonNull(types.userInput),
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
2019-03-19 17:55:43 +00:00
|
|
|
Secret: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2019-07-23 17:08:07 +01:00
|
|
|
ReferrerUserID: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
2018-11-21 15:51:43 +00:00
|
|
|
// creates user and company from input params and returns userID if succeed
|
2018-11-14 10:50:15 +00:00
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
input, _ := p.Args[InputArg].(map[string]interface{})
|
2019-03-19 17:55:43 +00:00
|
|
|
secretInput, _ := p.Args[Secret].(string)
|
2019-07-23 17:08:07 +01:00
|
|
|
refUserID, _ := p.Args[ReferrerUserID].(string)
|
2019-07-19 19:22:10 +01:00
|
|
|
|
2018-12-10 15:57:06 +00:00
|
|
|
createUser := fromMapCreateUser(input)
|
2018-11-14 10:50:15 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
secret, err := console.RegistrationSecretFromBase64(secretInput)
|
|
|
|
if err != nil {
|
2019-07-30 14:21:00 +01:00
|
|
|
log.Error("register: failed to create account",
|
2019-05-23 18:20:01 +01:00
|
|
|
zap.Error(err))
|
2019-07-30 14:21:00 +01:00
|
|
|
log.Debug("register: ", zap.String("rawSecret", secretInput))
|
2019-05-23 18:20:01 +01:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-07-23 17:08:07 +01:00
|
|
|
user, err := service.CreateUser(p.Context, createUser, secret, refUserID)
|
2018-11-14 10:50:15 +00:00
|
|
|
if err != nil {
|
2019-05-23 18:20:01 +01:00
|
|
|
log.Error("register: failed to create account",
|
|
|
|
zap.Error(err))
|
2019-07-30 14:21:00 +01:00
|
|
|
log.Debug("register: ", zap.String("rawSecret", secretInput))
|
2019-05-23 18:20:01 +01:00
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2019-03-02 15:22:20 +00:00
|
|
|
}
|
2019-04-09 13:20:29 +01:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
token, err := service.GenerateActivationToken(p.Context, user.ID, user.Email)
|
|
|
|
if err != nil {
|
2019-03-26 15:56:16 +00:00
|
|
|
log.Error("register: failed to generate activation token",
|
2019-06-18 00:37:44 +01:00
|
|
|
zap.Stringer("id", user.ID),
|
2019-03-26 15:56:16 +00:00
|
|
|
zap.String("email", user.Email),
|
|
|
|
zap.Error(err))
|
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
return user, HandleError(err)
|
2019-03-02 15:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rootObject := p.Info.RootValue.(map[string]interface{})
|
2019-03-26 15:56:16 +00:00
|
|
|
origin := rootObject["origin"].(string)
|
|
|
|
link := origin + rootObject[ActivationPath].(string) + token
|
2019-03-27 12:33:32 +00:00
|
|
|
userName := user.ShortName
|
|
|
|
if user.ShortName == "" {
|
|
|
|
userName = user.FullName
|
|
|
|
}
|
2019-03-26 15:56:16 +00:00
|
|
|
|
2019-05-17 13:29:35 +01:00
|
|
|
mailService.SendRenderedAsync(
|
|
|
|
p.Context,
|
|
|
|
[]post.Address{{Address: user.Email, Name: userName}},
|
|
|
|
&AccountActivationEmail{
|
|
|
|
Origin: origin,
|
|
|
|
ActivationLink: link,
|
|
|
|
},
|
|
|
|
)
|
2018-11-14 10:50:15 +00:00
|
|
|
|
2019-02-11 10:33:56 +00:00
|
|
|
return user, nil
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
UpdateAccountMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.user,
|
2018-11-28 10:31:15 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
InputArg: &graphql.ArgumentConfig{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: graphql.NewNonNull(types.userInput),
|
2018-11-28 10:31:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
input, _ := p.Args[InputArg].(map[string]interface{})
|
2018-12-11 15:54:45 +00:00
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
auth, err := console.GetAuth(p.Context)
|
2018-11-28 10:31:15 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-11-28 10:31:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
info := fillUserInfo(&auth.User, input)
|
2018-11-28 10:31:15 +00:00
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
err = service.UpdateAccount(p.Context, info)
|
2018-11-28 12:30:38 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-11-28 10:31:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return auth.User, nil
|
2018-11-28 10:31:15 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
ChangePasswordMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.user,
|
2018-12-10 15:57:06 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldPassword: &graphql.ArgumentConfig{
|
2018-12-10 15:57:06 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldNewPassword: &graphql.ArgumentConfig{
|
2018-12-10 15:57:06 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
pass, _ := p.Args[FieldPassword].(string)
|
|
|
|
newPass, _ := p.Args[FieldNewPassword].(string)
|
2018-12-24 12:52:52 +00:00
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
auth, err := console.GetAuth(p.Context)
|
2018-12-10 15:57:06 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-12-10 15:57:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
err = service.ChangePassword(p.Context, pass, newPass)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-12-24 12:52:52 +00:00
|
|
|
}
|
2018-12-11 15:54:45 +00:00
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return auth.User, nil
|
2018-12-10 15:57:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
DeleteAccountMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.user,
|
2018-11-27 14:20:58 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldPassword: &graphql.ArgumentConfig{
|
2018-12-14 16:14:17 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2018-11-27 14:20:58 +00:00
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
password, _ := p.Args[FieldPassword].(string)
|
2018-12-24 12:52:52 +00:00
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
auth, err := console.GetAuth(p.Context)
|
2018-11-27 14:20:58 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-11-27 14:20:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
err = service.DeleteAccount(p.Context, password)
|
2018-11-27 14:20:58 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-11-27 14:20:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return auth.User, nil
|
2018-11-27 14:20:58 +00:00
|
|
|
},
|
|
|
|
},
|
2018-11-26 10:47:23 +00:00
|
|
|
// creates project from input params
|
2019-01-24 16:26:36 +00:00
|
|
|
CreateProjectMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.project,
|
2018-11-26 10:47:23 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
InputArg: &graphql.ArgumentConfig{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: graphql.NewNonNull(types.projectInput),
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
var projectInput = fromMapProjectInfo(p.Args[InputArg].(map[string]interface{}))
|
2018-11-26 10:47:23 +00:00
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
project, err := service.CreateProject(p.Context, projectInput)
|
|
|
|
if err != nil {
|
|
|
|
return nil, HandleError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return project, nil
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
// deletes project by id, taken from input params
|
2019-01-24 16:26:36 +00:00
|
|
|
DeleteProjectMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.project,
|
2018-11-26 10:47:23 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.ArgumentConfig{
|
2018-11-28 16:20:23 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
inputID := p.Args[FieldID].(string)
|
2018-11-26 10:47:23 +00:00
|
|
|
projectID, err := uuid.Parse(inputID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-08 14:54:35 +00:00
|
|
|
project, err := service.GetProject(p.Context, *projectID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = service.DeleteProject(p.Context, project.ID); err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return project, nil
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
2018-11-28 16:20:23 +00:00
|
|
|
// updates project description
|
2019-01-24 16:26:36 +00:00
|
|
|
UpdateProjectDescriptionMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.project,
|
2018-11-26 10:47:23 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.ArgumentConfig{
|
2018-11-28 16:20:23 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldDescription: &graphql.ArgumentConfig{
|
2018-11-28 16:20:23 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
description := p.Args[FieldDescription].(string)
|
2018-11-26 10:47:23 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
inputID := p.Args[FieldID].(string)
|
2018-11-26 10:47:23 +00:00
|
|
|
projectID, err := uuid.Parse(inputID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
project, err := service.UpdateProject(p.Context, *projectID, description)
|
|
|
|
if err != nil {
|
|
|
|
return nil, HandleError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return project, nil
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-06 14:40:32 +00:00
|
|
|
// add user as member of given project
|
2019-01-24 16:26:36 +00:00
|
|
|
AddProjectMembersMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.project,
|
2018-12-06 14:40:32 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldProjectID: &graphql.ArgumentConfig{
|
2018-12-06 14:40:32 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldEmail: &graphql.ArgumentConfig{
|
2018-12-20 15:36:32 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
|
2018-12-06 14:40:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
pID, _ := p.Args[FieldProjectID].(string)
|
|
|
|
emails, _ := p.Args[FieldEmail].([]interface{})
|
2018-12-06 14:40:32 +00:00
|
|
|
|
2018-12-21 15:41:53 +00:00
|
|
|
projectID, err := uuid.Parse(pID)
|
2018-12-06 14:40:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-12-21 15:41:53 +00:00
|
|
|
var userEmails []string
|
|
|
|
for _, email := range emails {
|
|
|
|
userEmails = append(userEmails, email.(string))
|
2018-12-20 15:36:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 15:42:19 +00:00
|
|
|
project, err := service.GetProject(p.Context, *projectID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2019-03-06 15:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
users, err := service.AddProjectMembers(p.Context, *projectID, userEmails)
|
2018-12-21 15:41:53 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-12-20 15:36:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:56:16 +00:00
|
|
|
rootObject := p.Info.RootValue.(map[string]interface{})
|
|
|
|
origin := rootObject["origin"].(string)
|
|
|
|
signIn := origin + rootObject[SignInPath].(string)
|
|
|
|
|
2019-05-17 13:29:35 +01:00
|
|
|
for _, user := range users {
|
|
|
|
userName := user.ShortName
|
|
|
|
if user.ShortName == "" {
|
|
|
|
userName = user.FullName
|
2019-03-06 15:42:19 +00:00
|
|
|
}
|
2019-05-17 13:29:35 +01:00
|
|
|
|
|
|
|
mailService.SendRenderedAsync(
|
|
|
|
p.Context,
|
|
|
|
[]post.Address{{Address: user.Email, Name: userName}},
|
|
|
|
&ProjectInvitationEmail{
|
|
|
|
Origin: origin,
|
|
|
|
UserName: userName,
|
|
|
|
ProjectName: project.Name,
|
|
|
|
SignInLink: signIn,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2019-03-06 15:42:19 +00:00
|
|
|
|
2019-03-26 15:56:16 +00:00
|
|
|
return project, nil
|
2018-12-06 14:40:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
// delete user membership for given project
|
2019-01-24 16:26:36 +00:00
|
|
|
DeleteProjectMembersMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.project,
|
2018-12-06 14:40:32 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldProjectID: &graphql.ArgumentConfig{
|
2018-12-06 14:40:32 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldEmail: &graphql.ArgumentConfig{
|
2018-12-20 15:36:32 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
|
2018-12-06 14:40:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
pID, _ := p.Args[FieldProjectID].(string)
|
|
|
|
emails, _ := p.Args[FieldEmail].([]interface{})
|
2018-12-06 14:40:32 +00:00
|
|
|
|
2018-12-21 15:41:53 +00:00
|
|
|
projectID, err := uuid.Parse(pID)
|
2018-12-06 14:40:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-12-21 15:41:53 +00:00
|
|
|
var userEmails []string
|
|
|
|
for _, email := range emails {
|
|
|
|
userEmails = append(userEmails, email.(string))
|
2018-12-20 15:36:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 15:41:53 +00:00
|
|
|
err = service.DeleteProjectMembers(p.Context, *projectID, userEmails)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
project, err := service.GetProject(p.Context, *projectID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, HandleError(err)
|
2018-12-20 15:36:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
return project, nil
|
2018-12-06 14:40:32 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-27 15:30:15 +00:00
|
|
|
// creates new api key
|
2019-01-24 16:26:36 +00:00
|
|
|
CreateAPIKeyMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.createAPIKey,
|
2018-12-27 15:30:15 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldProjectID: &graphql.ArgumentConfig{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldName: &graphql.ArgumentConfig{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
projectID, _ := p.Args[FieldProjectID].(string)
|
|
|
|
name, _ := p.Args[FieldName].(string)
|
2018-12-27 15:30:15 +00:00
|
|
|
|
|
|
|
pID, err := uuid.Parse(projectID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
info, key, err := service.CreateAPIKey(p.Context, *pID, name)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-12-27 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return createAPIKey{
|
2019-05-24 17:51:27 +01:00
|
|
|
Key: key.Serialize(),
|
2018-12-27 15:30:15 +00:00
|
|
|
KeyInfo: info,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// deletes api key
|
2019-02-13 11:34:40 +00:00
|
|
|
DeleteAPIKeysMutation: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: graphql.NewList(types.apiKeyInfo),
|
2018-12-27 15:30:15 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.ArgumentConfig{
|
2019-02-13 11:34:40 +00:00
|
|
|
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
|
2018-12-27 15:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-02-13 11:34:40 +00:00
|
|
|
paramKeysID, _ := p.Args[FieldID].([]interface{})
|
|
|
|
|
|
|
|
var keyIds []uuid.UUID
|
|
|
|
var keys []console.APIKeyInfo
|
|
|
|
for _, id := range paramKeysID {
|
|
|
|
keyID, err := uuid.Parse(id.(string))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := service.GetAPIKeyInfo(p.Context, *keyID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2019-02-13 11:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keyIds = append(keyIds, *keyID)
|
|
|
|
keys = append(keys, *key)
|
2018-12-27 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 11:34:40 +00:00
|
|
|
err := service.DeleteAPIKeys(p.Context, keyIds)
|
2018-12-27 15:30:15 +00:00
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return nil, HandleError(err)
|
2018-12-27 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 11:34:40 +00:00
|
|
|
return keys, nil
|
2018-12-27 15:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-10 21:29:26 +01:00
|
|
|
AddPaymentMethodMutation: &graphql.Field{
|
|
|
|
Type: graphql.Boolean,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
FieldProjectID: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
FieldCardToken: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
FieldIsDefault: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Boolean),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
projectID, _ := p.Args[FieldProjectID].(string)
|
|
|
|
cardToken, _ := p.Args[FieldCardToken].(string)
|
|
|
|
isDefault, _ := p.Args[FieldIsDefault].(bool)
|
|
|
|
|
|
|
|
projID, err := uuid.Parse(projectID)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = service.AddNewPaymentMethod(p.Context, cardToken, isDefault, *projID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return false, HandleError(err)
|
2019-07-10 21:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DeletePaymentMethodMutation: &graphql.Field{
|
|
|
|
Type: graphql.Boolean,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
FieldID: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
fieldProjectPaymentID, _ := p.Args[FieldID].(string)
|
|
|
|
|
|
|
|
paymentID, err := uuid.Parse(fieldProjectPaymentID)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = service.DeleteProjectPaymentMethod(p.Context, *paymentID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return false, HandleError(err)
|
2019-07-10 21:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SetDefaultPaymentMethodMutation: &graphql.Field{
|
|
|
|
Type: graphql.Boolean,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
FieldProjectID: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
FieldID: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
fieldProjectID, _ := p.Args[FieldProjectID].(string)
|
|
|
|
fieldProjectPaymentID, _ := p.Args[FieldID].(string)
|
|
|
|
|
|
|
|
paymentID, err := uuid.Parse(fieldProjectPaymentID)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
projectID, err := uuid.Parse(fieldProjectID)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = service.SetDefaultPaymentMethod(p.Context, *paymentID, *projectID)
|
|
|
|
if err != nil {
|
2019-09-04 16:02:39 +01:00
|
|
|
return false, HandleError(err)
|
2019-07-10 21:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
},
|
|
|
|
},
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|