2020-01-26 19:34:25 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.UserType do
|
2019-01-14 16:48:08 +00:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for User
|
|
|
|
"""
|
2019-01-14 16:13:17 +00:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2021-03-26 18:01:55 +00:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 2]
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2019-03-08 17:52:27 +00:00
|
|
|
alias Mobilizon.Events
|
2020-11-26 10:41:13 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.{Media, User}
|
2021-06-01 16:08:03 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Users.ActivitySettings
|
2020-01-26 19:34:25 +00:00
|
|
|
alias Mobilizon.GraphQL.Schema
|
2019-01-14 16:13:17 +00:00
|
|
|
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.SortType)
|
2019-03-01 10:41:28 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
@desc "A local user of Mobilizon"
|
|
|
|
object :user do
|
2020-06-15 17:41:11 +00:00
|
|
|
interfaces([:action_log_object])
|
|
|
|
field(:id, :id, description: "The user's ID")
|
2019-01-14 16:13:17 +00:00
|
|
|
field(:email, non_null(:string), description: "The user's email")
|
|
|
|
|
2020-06-11 17:13:21 +00:00
|
|
|
field(:actors, non_null(list_of(:person)),
|
2019-01-14 16:13:17 +00:00
|
|
|
description: "The user's list of profiles (identities)"
|
|
|
|
)
|
|
|
|
|
2019-01-25 12:59:58 +00:00
|
|
|
field(:default_actor, :person, description: "The user's default actor")
|
2019-01-14 16:13:17 +00: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 17:52:27 +00:00
|
|
|
|
|
|
|
field(:feed_tokens, list_of(:feed_token),
|
2021-03-26 18:01:55 +00:00
|
|
|
resolve:
|
|
|
|
dataloader(
|
|
|
|
Events,
|
|
|
|
callback: fn feed_tokens, _parent, _args ->
|
|
|
|
{:ok, Enum.map(feed_tokens, &Map.put(&1, :token, ShortUUID.encode!(&1.token)))}
|
|
|
|
end
|
|
|
|
),
|
2019-03-08 17:52:27 +00:00
|
|
|
description: "A list of the feed tokens for this user"
|
|
|
|
)
|
2019-09-09 07:31:08 +00:00
|
|
|
|
|
|
|
field(:role, :user_role, description: "The role for the user")
|
2019-09-18 15:32:37 +00:00
|
|
|
|
2019-10-01 11:08:09 +00:00
|
|
|
field(:locale, :string, description: "The user's locale")
|
|
|
|
|
2020-06-27 17:12:45 +00:00
|
|
|
field(:provider, :string, description: "The user's login provider")
|
|
|
|
|
2020-06-11 17:13:21 +00:00
|
|
|
field(:disabled, :boolean, description: "Whether the user is disabled")
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
field(:participations, :paginated_participant_list,
|
2019-10-02 15:59:07 +00:00
|
|
|
description: "The list of participations this user has"
|
2019-09-18 15:32:37 +00:00
|
|
|
) do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:after_datetime, :datetime, description: "Filter participations by event start datetime")
|
|
|
|
|
|
|
|
arg(:before_datetime, :datetime, description: "Filter participations by event end datetime")
|
|
|
|
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated participations list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer,
|
|
|
|
default_value: 10,
|
|
|
|
description: "The limit of participations per page"
|
|
|
|
)
|
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
resolve(&User.user_participations/3)
|
|
|
|
end
|
2019-10-02 15:59:07 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
field(:memberships, :paginated_member_list,
|
|
|
|
description: "The list of memberships for this user"
|
|
|
|
) do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated memberships list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of memberships per page")
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&User.user_memberships/3)
|
|
|
|
end
|
|
|
|
|
2019-10-02 15:59:07 +00:00
|
|
|
field(:drafts, list_of(:event), description: "The list of draft events this user has created") do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated drafts events list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of drafts events per page")
|
2019-10-02 15:59:07 +00:00
|
|
|
resolve(&User.user_drafted_events/3)
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
field(:settings, :user_settings, description: "The list of settings for this user") do
|
|
|
|
resolve(&User.user_settings/3)
|
|
|
|
end
|
2020-08-31 14:57:13 +00:00
|
|
|
|
|
|
|
field(:last_sign_in_at, :datetime, description: "When the user previously signed-in")
|
|
|
|
|
|
|
|
field(:last_sign_in_ip, :string, description: "The IP adress the user previously sign-in with")
|
|
|
|
|
|
|
|
field(:current_sign_in_at, :datetime, description: "When the user currenlty signed-in")
|
|
|
|
|
|
|
|
field(:current_sign_in_ip, :string,
|
|
|
|
description: "The IP adress the user's currently signed-in with"
|
|
|
|
)
|
2020-11-23 09:38:01 +00:00
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
field(:media, :paginated_media_list, description: "The user's media objects") do
|
2020-11-23 09:38:01 +00:00
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated user media list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of user media per page")
|
|
|
|
resolve(&User.user_medias/3)
|
|
|
|
end
|
2020-11-23 11:31:15 +00:00
|
|
|
|
|
|
|
field(:media_size, :integer,
|
2020-11-26 10:41:13 +00:00
|
|
|
resolve: &Media.user_size/3,
|
2020-11-23 11:31:15 +00:00
|
|
|
description: "The total size of all the media from this user (from all their actors)"
|
|
|
|
)
|
2021-06-01 16:08:03 +00:00
|
|
|
|
|
|
|
field(:activity_settings, list_of(:activity_setting),
|
|
|
|
resolve: &ActivitySettings.user_activity_settings/3,
|
|
|
|
description: "The user's activity settings"
|
|
|
|
)
|
2019-09-09 07:31:08 +00:00
|
|
|
end
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "The list of roles an user can have"
|
2019-09-09 07:31:08 +00:00
|
|
|
enum :user_role do
|
2020-11-19 16:06:28 +00:00
|
|
|
value(:administrator, description: "Administrator role")
|
|
|
|
value(:moderator, description: "Moderator role")
|
|
|
|
value(:user, description: "User role")
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
|
2019-08-12 14:04:16 +00: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 10:41:28 +00: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
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "The list of sortable fields for an user list"
|
2019-03-01 10:41:28 +00:00
|
|
|
enum :sortable_user_field do
|
2020-11-19 16:06:28 +00:00
|
|
|
value(:id, description: "The user's ID")
|
2019-03-01 10:41:28 +00:00
|
|
|
end
|
|
|
|
|
2020-11-20 14:24:04 +00:00
|
|
|
@desc """
|
|
|
|
A set of user settings
|
|
|
|
"""
|
2020-02-18 07:57:00 +00: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 10:28:19 +00:00
|
|
|
|
2020-11-06 10:34:32 +00:00
|
|
|
field(:notification_pending_participation, :notification_pending_enum,
|
2020-06-08 10:28:19 +00:00
|
|
|
description: "When does the user receives a notification about new pending participations"
|
|
|
|
)
|
2020-11-06 10:34:32 +00:00
|
|
|
|
|
|
|
field(:notification_pending_membership, :notification_pending_enum,
|
|
|
|
description:
|
|
|
|
"When does the user receives a notification about a new pending membership in one of the group they're admin for"
|
|
|
|
)
|
2021-02-12 17:19:49 +00:00
|
|
|
|
|
|
|
field(:location, :location,
|
|
|
|
description: "The user's preferred location, where they want to be suggested events"
|
|
|
|
)
|
2020-06-08 10:28:19 +00:00
|
|
|
end
|
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "The list of values the for pending notification settings"
|
2020-11-06 10:34:32 +00:00
|
|
|
enum :notification_pending_enum do
|
2020-11-19 16:06:28 +00:00
|
|
|
value(:none, as: :none, description: "None. The notification won't be sent.")
|
|
|
|
|
|
|
|
value(:direct,
|
|
|
|
as: :direct,
|
|
|
|
description: "Direct. The notification will be sent right away each time."
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:one_hour,
|
|
|
|
as: :one_hour,
|
|
|
|
description: "One hour. Notifications will be sent at most each hour"
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:one_day,
|
|
|
|
as: :one_day,
|
|
|
|
description: "One day. Notifications will be sent at most each day"
|
|
|
|
)
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
|
|
|
|
2021-02-12 17:19:49 +00:00
|
|
|
object :location do
|
|
|
|
field(:range, :integer, description: "The range in kilometers the user wants to see events")
|
|
|
|
|
|
|
|
field(:geohash, :string, description: "A geohash representing the user's preferred location")
|
|
|
|
|
|
|
|
field(:name, :string, description: "A string describing the user's preferred location")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
The set of parameters needed to input a location
|
|
|
|
"""
|
|
|
|
input_object :location_input do
|
|
|
|
field(:range, :integer, description: "The range in kilometers the user wants to see events")
|
|
|
|
|
|
|
|
field(:geohash, :string, description: "A geohash representing the user's preferred location")
|
|
|
|
|
|
|
|
field(:name, :string, description: "A string describing the user's preferred location")
|
|
|
|
end
|
|
|
|
|
2019-01-25 14:41:10 +00: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 10:41:28 +00:00
|
|
|
|
|
|
|
@desc "List instance users"
|
|
|
|
field :users, :users do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, :string, default_value: "", description: "Filter users by email")
|
|
|
|
arg(:page, :integer, default_value: 1, description: "The page in the paginated users list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of users per page")
|
2019-03-01 10:41:28 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:sort, :sortable_user_field, default_value: :id, description: "Sort column")
|
|
|
|
arg(:direction, :sort_direction, default_value: :desc, description: "Sort direction")
|
2019-03-01 10:41:28 +00:00
|
|
|
|
2020-06-11 17:13:21 +00:00
|
|
|
resolve(&User.list_users/3)
|
2019-03-01 10:41:28 +00:00
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
object :user_mutations do
|
|
|
|
@desc "Create an user"
|
|
|
|
field :create_user, type: :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, non_null(:string), description: "The new user's email")
|
|
|
|
arg(:password, non_null(:string), description: "The new user's password")
|
|
|
|
arg(:locale, :string, description: "The new user's locale")
|
2019-01-25 14:41:10 +00:00
|
|
|
|
2020-10-01 13:07:15 +00:00
|
|
|
resolve(&User.create_user/3)
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Validate an user after registration"
|
|
|
|
field :validate_user, type: :login do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:token, non_null(:string),
|
|
|
|
description: "The token that will be used to validate the user"
|
|
|
|
)
|
|
|
|
|
2019-01-25 14:41:10 +00:00
|
|
|
resolve(&User.validate_user/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Resend registration confirmation token"
|
|
|
|
field :resend_confirmation_email, type: :string do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, non_null(:string), description: "The email used to register")
|
|
|
|
arg(:locale, :string, description: "The user's locale")
|
2019-01-25 14:41:10 +00: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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, non_null(:string), description: "The user's email")
|
|
|
|
arg(:locale, :string, description: "The user's locale")
|
2019-01-25 14:41:10 +00:00
|
|
|
resolve(&User.send_reset_password/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Reset user password"
|
|
|
|
field :reset_password, type: :login do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:token, non_null(:string),
|
|
|
|
description: "The user's token that will be used to reset the password"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:password, non_null(:string), description: "The new password")
|
|
|
|
arg(:locale, :string, default_value: "en", description: "The user's locale")
|
2019-01-25 14:41:10 +00:00
|
|
|
resolve(&User.reset_password/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Login an user"
|
2019-08-12 14:04:16 +00:00
|
|
|
field :login, type: :login do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, non_null(:string), description: "The user's email")
|
|
|
|
arg(:password, non_null(:string), description: "The user's password")
|
2019-01-25 14:41:10 +00:00
|
|
|
resolve(&User.login_user/3)
|
|
|
|
end
|
|
|
|
|
2019-08-12 14:04:16 +00:00
|
|
|
@desc "Refresh a token"
|
|
|
|
field :refresh_token, type: :refreshed_token do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:refresh_token, non_null(:string), description: "A refresh token")
|
2019-08-12 14:04:16 +00:00
|
|
|
resolve(&User.refresh_token/3)
|
|
|
|
end
|
|
|
|
|
2021-05-25 09:00:46 +00:00
|
|
|
@desc "Logout an user, deleting a refresh token"
|
|
|
|
field :logout, :string do
|
|
|
|
arg(:refresh_token, non_null(:string))
|
|
|
|
resolve(&User.logout/3)
|
|
|
|
end
|
|
|
|
|
2019-01-25 14:41:10 +00:00
|
|
|
@desc "Change default actor for user"
|
|
|
|
field :change_default_actor, :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:preferred_username, non_null(:string), description: "The actor preferred_username")
|
2019-01-25 14:41:10 +00:00
|
|
|
resolve(&User.change_default_actor/3)
|
|
|
|
end
|
2019-09-24 16:08:33 +00:00
|
|
|
|
|
|
|
@desc "Change an user password"
|
|
|
|
field :change_password, :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:old_password, non_null(:string), description: "The user's current password")
|
|
|
|
arg(:new_password, non_null(:string), description: "The user's new password")
|
2019-09-24 16:08:33 +00:00
|
|
|
resolve(&User.change_password/3)
|
|
|
|
end
|
2020-02-13 14:48:12 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
@desc "Change an user email"
|
2020-02-13 14:48:12 +00:00
|
|
|
field :change_email, :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:email, non_null(:string), description: "The user's new email")
|
|
|
|
arg(:password, non_null(:string), description: "The user's current password")
|
2020-02-13 14:48:12 +00:00
|
|
|
resolve(&User.change_email/3)
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
@desc "Validate an user email"
|
2020-02-13 14:48:12 +00:00
|
|
|
field :validate_email, :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:token, non_null(:string),
|
|
|
|
description: "The token that will be used to validate the email change"
|
|
|
|
)
|
|
|
|
|
2020-02-13 14:48:12 +00:00
|
|
|
resolve(&User.validate_email/3)
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
@desc "Delete an account"
|
2020-02-13 14:48:12 +00:00
|
|
|
field :delete_account, :deleted_object do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:password, :string, description: "The user's password")
|
|
|
|
arg(:user_id, :id, description: "The user's ID")
|
2020-02-13 14:48:12 +00:00
|
|
|
resolve(&User.delete_account/3)
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "Set user settings"
|
2020-02-18 07:57:00 +00:00
|
|
|
field :set_user_settings, :user_settings do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:timezone, :string, description: "The timezone for this user")
|
|
|
|
|
|
|
|
arg(:notification_on_day, :boolean,
|
|
|
|
description:
|
|
|
|
"Whether this user will receive an email at the start of the day of an event."
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:notification_each_week, :boolean,
|
|
|
|
description: "Whether this user will receive an weekly event recap"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:notification_before_event, :boolean,
|
|
|
|
description: "Whether this user will receive a notification right before event"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:notification_pending_participation, :notification_pending_enum,
|
|
|
|
description: "When does the user receives a notification about new pending participations"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:notification_pending_membership, :notification_pending_enum,
|
|
|
|
description:
|
|
|
|
"When does the user receives a notification about a new pending membership in one of the group they're admin for"
|
|
|
|
)
|
|
|
|
|
2021-02-12 17:19:49 +00:00
|
|
|
arg(:location, :location_input,
|
|
|
|
description: "A geohash of the user's preferred location, where they want to see events"
|
|
|
|
)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&User.set_user_setting/3)
|
|
|
|
end
|
2020-06-16 16:00:27 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "Update the user's locale"
|
2020-06-16 16:00:27 +00:00
|
|
|
field :update_locale, :user do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:locale, :string, description: "The user's new locale")
|
2020-06-16 16:00:27 +00:00
|
|
|
resolve(&User.update_locale/3)
|
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|