Allow to join an open group
Also: * Refactor interacting with a remote event so that you can interact with a remote group as well * Add a setting for group admins to pick between an open and invite-only group * Fix new groups without posts/todos/resources/events/conversations URL set * Repair local groups that haven't got their posts/todos/resources/events/conversations URL set * Add a scheduled job to refresh remote groups every hour * Add a user setting to pick when to receive notifications when there's new members to approve (will be used when this feature is available) * Fix pagination for members Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -84,7 +84,14 @@ defmodule Mobilizon.Actors.Actor do
|
||||
@attrs @required_attrs ++ @optional_attrs
|
||||
|
||||
@update_required_attrs @required_attrs -- [:url]
|
||||
@update_optional_attrs [:name, :summary, :manually_approves_followers, :user_id, :visibility]
|
||||
@update_optional_attrs [
|
||||
:name,
|
||||
:summary,
|
||||
:manually_approves_followers,
|
||||
:user_id,
|
||||
:visibility,
|
||||
:openness
|
||||
]
|
||||
@update_attrs @update_required_attrs ++ @update_optional_attrs
|
||||
|
||||
@registration_required_attrs [:preferred_username, :keys, :suspended, :url, :type]
|
||||
@@ -113,7 +120,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||
:name,
|
||||
:summary,
|
||||
:manually_approves_followers,
|
||||
:visibility
|
||||
:visibility,
|
||||
:openness
|
||||
]
|
||||
@remote_actor_creation_attrs @remote_actor_creation_required_attrs ++
|
||||
@remote_actor_creation_optional_attrs
|
||||
@@ -349,6 +357,17 @@ defmodule Mobilizon.Actors.Actor do
|
||||
|> put_change(:inbox_url, build_url(username, :inbox))
|
||||
|> put_change(:shared_inbox_url, "#{Endpoint.url()}/inbox")
|
||||
|> put_change(:members_url, if(type == :Group, do: build_url(username, :members), else: nil))
|
||||
|> put_change(
|
||||
:resources_url,
|
||||
if(type == :Group, do: build_url(username, :resources), else: nil)
|
||||
)
|
||||
|> put_change(:todos_url, if(type == :Group, do: build_url(username, :todos), else: nil))
|
||||
|> put_change(:posts_url, if(type == :Group, do: build_url(username, :posts), else: nil))
|
||||
|> put_change(:events_url, if(type == :Group, do: build_url(username, :events), else: nil))
|
||||
|> put_change(
|
||||
:discussions_url,
|
||||
if(type == :Group, do: build_url(username, :discussions), else: nil)
|
||||
)
|
||||
|> put_change(:url, build_url(username, :page))
|
||||
end
|
||||
|
||||
|
||||
@@ -640,6 +640,15 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Lists the groups.
|
||||
"""
|
||||
@spec list_groups_for_stream :: Enum.t()
|
||||
def list_external_groups_for_stream do
|
||||
external_groups_query()
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of groups an actor is member of.
|
||||
"""
|
||||
@@ -720,6 +729,13 @@ defmodule Mobilizon.Actors do
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets the default member role depending on the event join options.
|
||||
"""
|
||||
@spec get_default_member_role(Actor.t()) :: :member | :not_approved
|
||||
def get_default_member_role(%Actor{openness: :open}), do: :member
|
||||
def get_default_member_role(%Actor{openness: _}), do: :not_approved
|
||||
|
||||
@doc """
|
||||
Gets a single member of an actor (for example a group).
|
||||
"""
|
||||
@@ -859,7 +875,7 @@ defmodule Mobilizon.Actors do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of administrator members for a group.
|
||||
Returns a paginated list of administrator members for a group.
|
||||
"""
|
||||
@spec list_administrator_members_for_group(integer | String.t(), integer | nil, integer | nil) ::
|
||||
Page.t()
|
||||
@@ -869,6 +885,16 @@ defmodule Mobilizon.Actors do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the complete list of administrator members for a group.
|
||||
"""
|
||||
@spec list_all_administrator_members_for_group(integer | String.t()) :: [Member.t()]
|
||||
def list_all_administrator_members_for_group(id) do
|
||||
id
|
||||
|> administrator_members_for_group_query()
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of all group ids where the actor_id is the last administrator.
|
||||
"""
|
||||
@@ -1400,6 +1426,11 @@ defmodule Mobilizon.Actors do
|
||||
)
|
||||
end
|
||||
|
||||
@spec external_groups_query :: Ecto.Query.t()
|
||||
defp external_groups_query do
|
||||
where(Actor, [a], a.type == ^:Group and not is_nil(a.domain))
|
||||
end
|
||||
|
||||
@spec list_members_for_user_query(integer()) :: Ecto.Query.t()
|
||||
defp list_members_for_user_query(user_id) do
|
||||
from(
|
||||
@@ -1422,11 +1453,10 @@ defmodule Mobilizon.Actors do
|
||||
|
||||
@spec members_for_group_query(integer | String.t()) :: Ecto.Query.t()
|
||||
defp members_for_group_query(group_id) do
|
||||
from(
|
||||
m in Member,
|
||||
where: m.parent_id == ^group_id,
|
||||
preload: [:parent, :actor]
|
||||
)
|
||||
Member
|
||||
|> where(parent_id: ^group_id)
|
||||
|> order_by(desc: :updated_at)
|
||||
|> preload([:parent, :actor])
|
||||
end
|
||||
|
||||
@spec group_external_member_actor_query(integer()) :: Ecto.Query.t()
|
||||
|
||||
@@ -13,6 +13,7 @@ defmodule Mobilizon.Users.Setting do
|
||||
notification_each_week: boolean,
|
||||
notification_before_event: boolean,
|
||||
notification_pending_participation: NotificationPendingNotificationDelay.t(),
|
||||
notification_pending_membership: NotificationPendingNotificationDelay.t(),
|
||||
user: User.t()
|
||||
}
|
||||
|
||||
@@ -23,7 +24,8 @@ defmodule Mobilizon.Users.Setting do
|
||||
:notification_on_day,
|
||||
:notification_each_week,
|
||||
:notification_before_event,
|
||||
:notification_pending_participation
|
||||
:notification_pending_participation,
|
||||
:notification_pending_membership
|
||||
]
|
||||
|
||||
@attrs @required_attrs ++ @optional_attrs
|
||||
@@ -39,6 +41,10 @@ defmodule Mobilizon.Users.Setting do
|
||||
default: :one_day
|
||||
)
|
||||
|
||||
field(:notification_pending_membership, NotificationPendingNotificationDelay,
|
||||
default: :one_day
|
||||
)
|
||||
|
||||
belongs_to(:user, User, primary_key: true, type: :id, foreign_key: :id, define_field: false)
|
||||
|
||||
timestamps()
|
||||
|
||||
Reference in New Issue
Block a user