2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.UserType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for User
|
|
|
|
"""
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2019-03-08 18:52:27 +01:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2020-01-26 20:34:25 +01:00
|
|
|
import Mobilizon.GraphQL.Helpers.Error
|
|
|
|
|
2019-03-08 18:52:27 +01:00
|
|
|
alias Mobilizon.Events
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.User
|
|
|
|
alias Mobilizon.GraphQL.Schema
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
import_types(Schema.SortType)
|
2019-03-01 11:41:28 +01:00
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
@desc "A local user of Mobilizon"
|
|
|
|
object :user do
|
2020-06-15 19:41:11 +02:00
|
|
|
interfaces([:action_log_object])
|
|
|
|
field(:id, :id, description: "The user's ID")
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:email, non_null(:string), description: "The user's email")
|
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
field(:actors, non_null(list_of(:person)),
|
2019-01-14 17:13:17 +01:00
|
|
|
description: "The user's list of profiles (identities)"
|
|
|
|
)
|
|
|
|
|
2019-01-25 13:59:58 +01:00
|
|
|
field(:default_actor, :person, description: "The user's default actor")
|
2019-01-14 17:13:17 +01:00
|
|
|
|
|
|
|
field(:confirmed_at, :datetime,
|
|
|
|
description: "The datetime when the user was confirmed/activated"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:confirmation_sent_at, :datetime,
|
|
|
|
description: "The datetime the last activation/confirmation token was sent"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:confirmation_token, :string, description: "The account activation/confirmation token")
|
|
|
|
|
|
|
|
field(:reset_password_sent_at, :datetime,
|
|
|
|
description: "The datetime last reset password email was sent"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:reset_password_token, :string,
|
|
|
|
description: "The token sent when requesting password token"
|
|
|
|
)
|
2019-03-08 18:52:27 +01:00
|
|
|
|
|
|
|
field(:feed_tokens, list_of(:feed_token),
|
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "A list of the feed tokens for this user"
|
|
|
|
)
|
2019-09-09 09:31:08 +02:00
|
|
|
|
|
|
|
field(:role, :user_role, description: "The role for the user")
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2019-10-01 13:08:09 +02:00
|
|
|
field(:locale, :string, description: "The user's locale")
|
|
|
|
|
2020-06-27 19:12:45 +02:00
|
|
|
field(:provider, :string, description: "The user's login provider")
|
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
field(:disabled, :boolean, description: "Whether the user is disabled")
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:participations, :paginated_participant_list,
|
2019-10-02 17:59:07 +02:00
|
|
|
description: "The list of participations this user has"
|
2019-09-18 17:32:37 +02:00
|
|
|
) do
|
|
|
|
arg(:after_datetime, :datetime)
|
|
|
|
arg(:before_datetime, :datetime)
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&User.user_participations/3)
|
|
|
|
end
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:memberships, :paginated_member_list,
|
|
|
|
description: "The list of memberships for this user"
|
|
|
|
) do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&User.user_memberships/3)
|
|
|
|
end
|
|
|
|
|
2019-10-02 17:59:07 +02:00
|
|
|
field(:drafts, list_of(:event), description: "The list of draft events this user has created") do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&User.user_drafted_events/3)
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
field(:settings, :user_settings, description: "The list of settings for this user") do
|
|
|
|
resolve(&User.user_settings/3)
|
|
|
|
end
|
2019-09-09 09:31:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
enum :user_role do
|
|
|
|
value(:administrator)
|
|
|
|
value(:moderator)
|
|
|
|
value(:user)
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
|
2019-08-12 16:04:16 +02:00
|
|
|
@desc "Token"
|
|
|
|
object :refreshed_token do
|
|
|
|
field(:access_token, non_null(:string), description: "Generated access token")
|
|
|
|
field(:refresh_token, non_null(:string), description: "Generated refreshed token")
|
|
|
|
end
|
|
|
|
|
2019-03-01 11:41:28 +01:00
|
|
|
@desc "Users list"
|
|
|
|
object :users do
|
|
|
|
field(:total, non_null(:integer), description: "Total elements")
|
|
|
|
field(:elements, non_null(list_of(:user)), description: "User elements")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "The list of possible options for the event's status"
|
|
|
|
enum :sortable_user_field do
|
|
|
|
value(:id)
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
object :user_settings do
|
|
|
|
field(:timezone, :string, description: "The timezone for this user")
|
|
|
|
|
|
|
|
field(:notification_on_day, :boolean,
|
|
|
|
description: "Whether this user will receive an email at the start of the day of an event."
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:notification_each_week, :boolean,
|
|
|
|
description: "Whether this user will receive an weekly event recap"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:notification_before_event, :boolean,
|
|
|
|
description: "Whether this user will receive a notification right before event"
|
|
|
|
)
|
2020-06-08 12:28:19 +02:00
|
|
|
|
|
|
|
field(:notification_pending_participation, :notification_pending_participation_enum,
|
|
|
|
description: "When does the user receives a notification about new pending participations"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
enum :notification_pending_participation_enum do
|
|
|
|
value(:none, as: :none)
|
|
|
|
value(:direct, as: :direct)
|
|
|
|
value(:one_hour, as: :one_hour)
|
|
|
|
value(:one_day, as: :one_day)
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
object :user_queries do
|
|
|
|
@desc "Get an user"
|
|
|
|
field :user, :user do
|
|
|
|
arg(:id, non_null(:id))
|
|
|
|
resolve(&User.find_user/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Get the current user"
|
|
|
|
field :logged_user, :user do
|
|
|
|
resolve(&User.get_current_user/3)
|
|
|
|
end
|
2019-03-01 11:41:28 +01:00
|
|
|
|
|
|
|
@desc "List instance users"
|
|
|
|
field :users, :users do
|
2020-06-11 19:13:21 +02:00
|
|
|
arg(:email, :string, default_value: "")
|
2019-03-01 11:41:28 +01:00
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
|
|
|
|
arg(:sort, :sortable_user_field, default_value: :id)
|
2019-03-05 12:14:31 +01:00
|
|
|
arg(:direction, :sort_direction, default_value: :desc)
|
2019-03-01 11:41:28 +01:00
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
resolve(&User.list_users/3)
|
2019-03-01 11:41:28 +01:00
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
object :user_mutations do
|
|
|
|
@desc "Create an user"
|
|
|
|
field :create_user, type: :user do
|
|
|
|
arg(:email, non_null(:string))
|
|
|
|
arg(:password, non_null(:string))
|
2019-10-01 13:08:09 +02:00
|
|
|
arg(:locale, :string)
|
2019-01-25 15:41:10 +01:00
|
|
|
|
|
|
|
resolve(handle_errors(&User.create_user/3))
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Validate an user after registration"
|
|
|
|
field :validate_user, type: :login do
|
|
|
|
arg(:token, non_null(:string))
|
|
|
|
resolve(&User.validate_user/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Resend registration confirmation token"
|
|
|
|
field :resend_confirmation_email, type: :string do
|
|
|
|
arg(:email, non_null(:string))
|
2019-10-01 13:08:09 +02:00
|
|
|
arg(:locale, :string)
|
2019-01-25 15:41:10 +01:00
|
|
|
resolve(&User.resend_confirmation_email/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Send a link through email to reset user password"
|
|
|
|
field :send_reset_password, type: :string do
|
|
|
|
arg(:email, non_null(:string))
|
2019-10-01 13:08:09 +02:00
|
|
|
arg(:locale, :string)
|
2019-01-25 15:41:10 +01:00
|
|
|
resolve(&User.send_reset_password/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Reset user password"
|
|
|
|
field :reset_password, type: :login do
|
|
|
|
arg(:token, non_null(:string))
|
|
|
|
arg(:password, non_null(:string))
|
|
|
|
arg(:locale, :string, default_value: "en")
|
|
|
|
resolve(&User.reset_password/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Login an user"
|
2019-08-12 16:04:16 +02:00
|
|
|
field :login, type: :login do
|
2019-01-25 15:41:10 +01:00
|
|
|
arg(:email, non_null(:string))
|
|
|
|
arg(:password, non_null(:string))
|
|
|
|
resolve(&User.login_user/3)
|
|
|
|
end
|
|
|
|
|
2019-08-12 16:04:16 +02:00
|
|
|
@desc "Refresh a token"
|
|
|
|
field :refresh_token, type: :refreshed_token do
|
|
|
|
arg(:refresh_token, non_null(:string))
|
|
|
|
resolve(&User.refresh_token/3)
|
|
|
|
end
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
@desc "Change default actor for user"
|
|
|
|
field :change_default_actor, :user do
|
|
|
|
arg(:preferred_username, non_null(:string))
|
|
|
|
resolve(&User.change_default_actor/3)
|
|
|
|
end
|
2019-09-24 18:08:33 +02:00
|
|
|
|
|
|
|
@desc "Change an user password"
|
|
|
|
field :change_password, :user do
|
|
|
|
arg(:old_password, non_null(:string))
|
|
|
|
arg(:new_password, non_null(:string))
|
|
|
|
resolve(&User.change_password/3)
|
|
|
|
end
|
2020-02-13 15:48:12 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@desc "Change an user email"
|
2020-02-13 15:48:12 +01:00
|
|
|
field :change_email, :user do
|
|
|
|
arg(:email, non_null(:string))
|
|
|
|
arg(:password, non_null(:string))
|
|
|
|
resolve(&User.change_email/3)
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@desc "Validate an user email"
|
2020-02-13 15:48:12 +01:00
|
|
|
field :validate_email, :user do
|
|
|
|
arg(:token, non_null(:string))
|
|
|
|
resolve(&User.validate_email/3)
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@desc "Delete an account"
|
2020-02-13 15:48:12 +01:00
|
|
|
field :delete_account, :deleted_object do
|
2020-06-11 19:13:21 +02:00
|
|
|
arg(:password, :string)
|
|
|
|
arg(:user_id, :id)
|
2020-02-13 15:48:12 +01:00
|
|
|
resolve(&User.delete_account/3)
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
field :set_user_settings, :user_settings do
|
|
|
|
arg(:timezone, :string)
|
|
|
|
arg(:notification_on_day, :boolean)
|
|
|
|
arg(:notification_each_week, :boolean)
|
|
|
|
arg(:notification_before_event, :boolean)
|
2020-06-08 12:28:19 +02:00
|
|
|
arg(:notification_pending_participation, :notification_pending_participation_enum)
|
2020-02-18 08:57:00 +01:00
|
|
|
resolve(&User.set_user_setting/3)
|
|
|
|
end
|
2020-06-16 18:00:27 +02:00
|
|
|
|
|
|
|
field :update_locale, :user do
|
|
|
|
arg(:locale, :string)
|
|
|
|
resolve(&User.update_locale/3)
|
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|