diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 1c6396bd5..96e5e3b0d 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -136,17 +136,25 @@ defmodule Atomic.Organizations do end @doc """ - Returns the list of organizations where an user is an admin or owner. + Returns the list of organizations which are connected with the user. + By default, it returns the organizations where the user is an admin or owner. ## Examples - iex> list_user_organizations(user_id) + iex> list_user_organizations(123) [%Organization{}, ...] + + iex> list_user_organizations(456) + [] + + iex> list_user_organizations(123, [:follower]) + [%Organization{}, ...] + """ - def list_user_organizations(user_id, opts \\ []) do + def list_user_organizations(user_id, roles \\ [:admin, :owner], opts \\ []) do Organization |> join(:inner, [o], m in Membership, on: m.organization_id == o.id) - |> where([o, m], m.user_id == ^user_id and m.role in [:admin, :owner]) + |> where([o, m], m.user_id == ^user_id and m.role in ^roles) |> apply_filters(opts) |> Repo.all() end @@ -256,30 +264,19 @@ defmodule Atomic.Organizations do end @doc """ - Returns the list of memberships. + Returns the list of members in an organization. + A member is someone who is connected to the organization with a role other than `:follower`. ## Examples - iex> list_memberships(%{"organization_id" => id}) - [%Organization{}, ...] - - iex> list_memberships(%{"user_id" => id}) + iex> list_memberships(123) [%Organization{}, ...] """ - def list_memberships(params, preloads \\ []) - - def list_memberships(%{"organization_id" => organization_id}, preloads) do + def list_memberships(organization_id, opts \\ []) do Membership - |> where([a], a.organization_id == ^organization_id and a.role != :follower) - |> Repo.all() - |> Repo.preload(preloads) - end - - def list_memberships(%{"user_id" => user_id}, preloads) do - Membership - |> where([a], a.user_id == ^user_id) - |> Repo.preload(preloads) + |> where([m], m.organization_id == ^organization_id and m.role != :follower) + |> apply_filters(opts) |> Repo.all() end diff --git a/lib/atomic_web/live/home_live/index.ex b/lib/atomic_web/live/home_live/index.ex index f4ebf82a5..a30dab65a 100644 --- a/lib/atomic_web/live/home_live/index.ex +++ b/lib/atomic_web/live/home_live/index.ex @@ -75,8 +75,8 @@ defmodule AtomicWeb.HomeLive.Index do current_user = socket.assigns.current_user %{entries: entries, metadata: metadata} = - Organizations.list_memberships(%{"user_id" => current_user.id}) - |> Enum.map(& &1.organization_id) + Organizations.list_user_organizations(current_user.id, [:follower]) + |> Enum.map(& &1.id) |> Feed.list_posts_following_paginated([]) {:noreply, diff --git a/lib/atomic_web/live/organization_live/components/organization_about.ex b/lib/atomic_web/live/organization_live/components/about.ex similarity index 96% rename from lib/atomic_web/live/organization_live/components/organization_about.ex rename to lib/atomic_web/live/organization_live/components/about.ex index bd186fb85..27400dcba 100644 --- a/lib/atomic_web/live/organization_live/components/organization_about.ex +++ b/lib/atomic_web/live/organization_live/components/about.ex @@ -1,4 +1,4 @@ -defmodule AtomicWeb.OrganizationLive.Components.OrganizationAbout do +defmodule AtomicWeb.OrganizationLive.Components.About do @moduledoc false use AtomicWeb, :component @@ -7,7 +7,7 @@ defmodule AtomicWeb.OrganizationLive.Components.OrganizationAbout do attr :organization, Organization, required: true, doc: "the organization which about to display" - def organization_about(assigns) do + def about(assigns) do ~H"""
Access to our room facilities
+Free access to all activities
+Official member t-shirt
+<%= gettext("Pay once, be a member forever") %>
++ 10€ + EUR +
+ <.button icon={:banknotes} class="mt-10 text-sm"><%= gettext("Request your membership") %> +<%= gettext("Payments should be made within our location.") %> <%= @organization.location %>
+<%= gettext("Name") %> | +<%= gettext("Role") %> | +<%= gettext("Joined At") %> | +
---|---|---|
+
+ <.avatar name={member.user.name} size={:sm} color={:light_gray} class="ring-1 ring-white" />
+
+
+
+ <%= member.user.name %>
+ <%= member.user.email %>
+ |
+ <%= capitalize_first_letter(member.role) %> | +<%= relative_datetime(member.inserted_at) %> | +