2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Member
|
|
|
|
"""
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.{Group, Member}
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
@desc """
|
|
|
|
Represents a member of a group
|
|
|
|
"""
|
|
|
|
object :member do
|
2023-03-17 18:10:59 +01:00
|
|
|
meta(:authorize, :user)
|
2021-02-24 19:06:48 +01:00
|
|
|
interfaces([:activity_object])
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:id, :id, description: "The member's ID")
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:parent, :group, description: "Of which the profile is member")
|
2019-04-03 17:29:03 +02:00
|
|
|
field(:actor, :person, description: "Which profile is member of")
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:role, :member_role_enum, description: "The role of this membership")
|
|
|
|
field(:invited_by, :person, description: "Who invited this member")
|
2020-07-09 17:24:28 +02:00
|
|
|
field(:inserted_at, :naive_datetime, description: "When was this member created")
|
2020-08-14 11:32:23 +02:00
|
|
|
field(:updated_at, :naive_datetime, description: "When was this member updated")
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
Values for a member role
|
|
|
|
"""
|
2020-02-18 08:57:00 +01:00
|
|
|
enum :member_role_enum do
|
2020-11-19 17:06:28 +01:00
|
|
|
value(:not_approved, description: "The member needs to be approved by the group admins")
|
|
|
|
value(:invited, description: "The member has been invited")
|
|
|
|
value(:member, description: "Regular member")
|
|
|
|
value(:moderator, description: "The member is a moderator")
|
|
|
|
value(:administrator, description: "The member is an administrator")
|
|
|
|
value(:creator, description: "The member was the creator of the group. Shouldn't be used.")
|
|
|
|
value(:rejected, description: "The member has been rejected or excluded from the group")
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
A paginated list of members
|
|
|
|
"""
|
2020-02-18 08:57:00 +01:00
|
|
|
object :paginated_member_list do
|
2023-03-17 18:10:59 +01:00
|
|
|
meta(:authorize, :user)
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:elements, list_of(:member), description: "A list of members")
|
|
|
|
field(:total, :integer, description: "The total number of elements in the list")
|
|
|
|
end
|
|
|
|
|
2019-03-01 17:11:28 +01:00
|
|
|
object :member_mutations do
|
|
|
|
@desc "Join a group"
|
|
|
|
field :join_group, :member do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:group_id, non_null(:id), description: "The group ID")
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group_membership",
|
|
|
|
args: %{parent_id: :group_id}
|
|
|
|
)
|
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
resolve(&Group.join_group/3)
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@desc "Leave a group"
|
2020-08-14 11:32:23 +02:00
|
|
|
field :leave_group, :deleted_object do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:group_id, non_null(:id), description: "The group ID")
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group_membership",
|
|
|
|
args: %{parent_id: :group_id}
|
2020-11-19 17:06:28 +01:00
|
|
|
)
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
resolve(&Group.leave_group/3)
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Accept an invitation to a group"
|
|
|
|
field :accept_invitation, :member do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The member ID")
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group_membership"
|
|
|
|
)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
resolve(&Member.accept_invitation/3)
|
|
|
|
end
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
@desc "Reject an invitation to a group"
|
|
|
|
field :reject_invitation, :member do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The member ID")
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group_membership"
|
|
|
|
)
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
resolve(&Member.reject_invitation/3)
|
|
|
|
end
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
@desc "Invite an actor to join the group"
|
|
|
|
field :invite_member, :member do
|
|
|
|
arg(:group_id, non_null(:id), description: "The group ID")
|
|
|
|
|
|
|
|
arg(:target_actor_username, non_null(:string),
|
|
|
|
description: "The targeted person's federated username"
|
|
|
|
)
|
|
|
|
|
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group:members",
|
|
|
|
args: %{parent_id: :group_id}
|
|
|
|
)
|
|
|
|
|
|
|
|
resolve(&Member.invite_member/3)
|
|
|
|
end
|
|
|
|
|
2021-11-12 15:42:52 +01:00
|
|
|
@desc """
|
|
|
|
Approve a membership request
|
|
|
|
"""
|
|
|
|
field :approve_member, :member do
|
|
|
|
arg(:member_id, non_null(:id), description: "The member ID")
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group:members",
|
|
|
|
args: %{parent_id: :member_id}
|
|
|
|
)
|
|
|
|
|
2021-11-12 15:42:52 +01:00
|
|
|
resolve(&Member.approve_member/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
Reject a membership request
|
|
|
|
"""
|
|
|
|
field :reject_member, :member do
|
|
|
|
arg(:member_id, non_null(:id), description: "The member ID")
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group:members",
|
|
|
|
args: %{parent_id: :member_id}
|
|
|
|
)
|
|
|
|
|
2021-11-12 15:42:52 +01:00
|
|
|
resolve(&Member.reject_member/3)
|
|
|
|
end
|
|
|
|
|
2020-11-20 15:24:04 +01:00
|
|
|
@desc """
|
|
|
|
Update a member's role
|
|
|
|
"""
|
2020-08-20 10:54:58 +02:00
|
|
|
field :update_member, :member do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:member_id, non_null(:id), description: "The member ID")
|
|
|
|
arg(:role, non_null(:member_role_enum), description: "The new member role")
|
2020-08-20 10:54:58 +02:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group:members",
|
|
|
|
args: %{parent_id: :member_id}
|
|
|
|
)
|
|
|
|
|
2020-08-20 10:54:58 +02:00
|
|
|
resolve(&Member.update_member/3)
|
|
|
|
end
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
@desc "Remove a member from a group"
|
|
|
|
field :remove_member, :member do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:member_id, non_null(:id), description: "The member ID")
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2021-11-12 15:42:52 +01:00
|
|
|
arg(:exclude, :boolean,
|
|
|
|
default_value: false,
|
|
|
|
description: "Whether the member should be excluded from the group"
|
|
|
|
)
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Actors.Member,
|
|
|
|
rule: :"write:group:members",
|
|
|
|
args: %{parent_id: :member_id}
|
|
|
|
)
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
resolve(&Member.remove_member/3)
|
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
|
|
|
end
|