diff --git a/lib/atomic_web/live/activity_live/new.ex b/lib/atomic_web/live/activity_live/new.ex
index c7fcb823c..fc45b2a0e 100644
--- a/lib/atomic_web/live/activity_live/new.ex
+++ b/lib/atomic_web/live/activity_live/new.ex
@@ -11,15 +11,15 @@ defmodule AtomicWeb.ActivityLive.New do
end
@impl true
- def handle_params(_params, _url, socket) do
+ def handle_params(params, _url, socket) do
entries = [
%{
name: gettext("Activities"),
- route: Routes.activity_index_path(socket, :index)
+ route: Routes.activity_index_path(socket, :index, params["organization_id"])
},
%{
name: gettext("New Activity"),
- route: Routes.activity_new_path(socket, :new)
+ route: Routes.activity_new_path(socket, :new, params["organization_id"])
}
]
diff --git a/lib/atomic_web/live/activity_live/new.html.heex b/lib/atomic_web/live/activity_live/new.html.heex
index b6676be95..0cd31fb2a 100644
--- a/lib/atomic_web/live/activity_live/new.html.heex
+++ b/lib/atomic_web/live/activity_live/new.html.heex
@@ -1,3 +1,3 @@
- <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={:new} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_index_path(@socket, :index)} />
+ <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_index_path(@socket, :index, @current_organization)} />
diff --git a/lib/atomic_web/live/activity_live/show.ex b/lib/atomic_web/live/activity_live/show.ex
index 48c2e1b49..b8840e485 100644
--- a/lib/atomic_web/live/activity_live/show.ex
+++ b/lib/atomic_web/live/activity_live/show.ex
@@ -4,6 +4,7 @@ defmodule AtomicWeb.ActivityLive.Show do
alias Atomic.Accounts
alias Atomic.Activities
alias Atomic.Organizations
+ alias AtomicWeb.MismatchError
@impl true
def mount(%{"id" => id}, _session, socket) do
@@ -16,27 +17,32 @@ defmodule AtomicWeb.ActivityLive.Show do
end
@impl true
- def handle_params(%{"id" => id}, _, socket) do
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
activity = Activities.get_activity!(id, [:activity_sessions, :departments, :speakers])
+ organizations = Activities.get_activity_organizations!(activity)
entries = [
%{
name: gettext("Activities"),
- route: Routes.activity_index_path(socket, :index)
+ route: Routes.activity_index_path(socket, :index, organization_id)
},
%{
name: activity.title,
- route: Routes.activity_show_path(socket, :show, activity)
+ route: Routes.activity_show_path(socket, :show, organization_id, activity.id)
}
]
- {:noreply,
- socket
- |> assign(:enrolled?, Activities.is_user_enrolled?(activity, socket.assigns.current_user))
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:breadcrumb_entries, entries)
- |> assign(:current_page, :activities)
- |> assign(:activity, %{activity | enrolled: Activities.get_total_enrolled(activity)})}
+ if organization_id in organizations do
+ {:noreply,
+ socket
+ |> assign(:enrolled?, Activities.is_user_enrolled?(activity, socket.assigns.current_user))
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:current_page, :activities)
+ |> assign(:activity, %{activity | enrolled: Activities.get_total_enrolled(activity)})}
+ else
+ raise MismatchError
+ end
end
@impl true
@@ -82,7 +88,10 @@ defmodule AtomicWeb.ActivityLive.Show do
def handle_event("delete", _payload, socket) do
{:ok, _} = Activities.delete_activity(socket.assigns.activity)
- {:noreply, push_redirect(socket, to: Routes.activity_index_path(socket, :index))}
+ {:noreply,
+ push_redirect(socket,
+ to: Routes.activity_index_path(socket, :index, socket.assigns.current_organization)
+ )}
end
@impl true
diff --git a/lib/atomic_web/live/activity_live/show.html.heex b/lib/atomic_web/live/activity_live/show.html.heex
index 21647815a..8221d35c8 100644
--- a/lib/atomic_web/live/activity_live/show.html.heex
+++ b/lib/atomic_web/live/activity_live/show.html.heex
@@ -1,12 +1,12 @@
<%= if @live_action in [:edit] do %>
- <.modal return_to={Routes.activity_show_path(@socket, :show, @activity)}>
- <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_show_path(@socket, :show, @activity)} />
+ <.modal return_to={Routes.activity_show_path(@socket, :show, @current_organization, @activity)}>
+ <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_show_path(@socket, :show, @current_organization, @activity)} />
<% end %>
<%= if @live_action in [:edit] do %>
- <.modal return_to={Routes.activity_show_path(@socket, :show, @activity)}>
- <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_show_path(@socket, :show, @activity)} />
+ <.modal return_to={Routes.activity_show_path(@socket, :show, @current_organization, @activity)}>
+ <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} organization={@current_organization} title={@page_title} action={@live_action} activity={@activity} return_to={Routes.activity_show_path(@socket, :show, @current_organization, @activity)} />
<% end %>
@@ -128,7 +128,7 @@
<%= Accounts.extract_initials(speaker.name) %>
- <%= live_redirect to: Routes.speaker_show_path(@socket, :show, speaker), class: "text-md text-blue-500" do %>
+ <%= live_redirect to: Routes.speaker_show_path(@socket, :show, @current_organization, speaker), class: "text-md text-blue-500" do %>
<%= Accounts.extract_first_last_name(speaker.name) %>
<% end %>
@@ -179,13 +179,13 @@
<%= if @current_user.role in [:admin] or is_admin?(@current_user, @activity) do %>
- <%= live_patch("Edit", to: Routes.activity_edit_path(@socket, :edit, @activity), class: "button") %>
+ <%= live_patch("Edit", to: Routes.activity_edit_path(@socket, :edit, @activity, @current_organization), class: "button") %>
<%= link("Delete", to: "#", phx_click: "delete", phx_value_id: @activity.id, data: [confirm: "Are you sure?"]) %>
<% end %>
- <%= live_redirect("Back", to: Routes.activity_index_path(@socket, :index)) %>
+ <%= live_redirect("Back", to: Routes.activity_index_path(@socket, :index, @current_organization)) %>
diff --git a/lib/atomic_web/live/board_live/edit.ex b/lib/atomic_web/live/board_live/edit.ex
index 748a7543f..dfe1c3282 100644
--- a/lib/atomic_web/live/board_live/edit.ex
+++ b/lib/atomic_web/live/board_live/edit.ex
@@ -10,16 +10,20 @@ defmodule AtomicWeb.BoardLive.Edit do
end
@impl true
- def handle_params(%{"org" => _org, "id" => id}, _url, socket) do
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _url, socket) do
user_organization = Organizations.get_user_organization!(id, [:user, :organization])
users = Enum.map(Accounts.list_users(), fn u -> [key: u.email, value: u.id] end)
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:user_organization, user_organization)
- |> assign(:users, users)
- |> assign(:current_user, socket.assigns.current_user)}
+ if user_organization.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:user_organization, user_organization)
+ |> assign(:users, users)
+ |> assign(:current_user, socket.assigns.current_user)}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:index), do: "List board"
diff --git a/lib/atomic_web/live/board_live/index.ex b/lib/atomic_web/live/board_live/index.ex
index d56a8df80..665e773e1 100644
--- a/lib/atomic_web/live/board_live/index.ex
+++ b/lib/atomic_web/live/board_live/index.ex
@@ -9,11 +9,20 @@ defmodule AtomicWeb.BoardLive.Index do
end
@impl true
- def handle_params(%{"org" => id}, _, socket) do
+ def handle_params(%{"organization_id" => id}, _, socket) do
users_organizations = list_users_organizations(id)
+ entries = [
+ %{
+ name: gettext("Users Organizations"),
+ route: Routes.board_index_path(socket, :index, id)
+ }
+ ]
+
{:noreply,
socket
+ |> assign(:current_page, :board)
+ |> assign(:breadcrumb_entries, entries)
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:users_organizations, users_organizations)
|> assign(:id, id)}
diff --git a/lib/atomic_web/live/board_live/new.ex b/lib/atomic_web/live/board_live/new.ex
index bf42259aa..e7aee6840 100644
--- a/lib/atomic_web/live/board_live/new.ex
+++ b/lib/atomic_web/live/board_live/new.ex
@@ -11,12 +11,12 @@ defmodule AtomicWeb.BoardLive.New do
end
@impl true
- def handle_params(%{"org" => org_id}, _url, socket) do
+ def handle_params(%{"organization_id" => organization_id}, _url, socket) do
{:noreply,
socket
|> assign(:page_title, gettext("New Board"))
|> assign(:user_organization, %UserOrganization{
- organization_id: org_id
+ organization_id: organization_id
})
|> assign(:users, Enum.map(Accounts.list_users(), fn u -> [key: u.email, value: u.id] end))
|> assign(:current_user, socket.assigns.current_user)}
diff --git a/lib/atomic_web/live/board_live/show.ex b/lib/atomic_web/live/board_live/show.ex
index 3e0d43d2d..e9c860d27 100644
--- a/lib/atomic_web/live/board_live/show.ex
+++ b/lib/atomic_web/live/board_live/show.ex
@@ -9,13 +9,17 @@ defmodule AtomicWeb.BoardLive.Show do
end
@impl true
- def handle_params(%{"id" => id}, _, socket) do
- user_org = Organizations.get_user_organization!(id, [:user, :organization])
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
+ user_organization = Organizations.get_user_organization!(id, [:user, :organization])
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:user_organization, user_org)}
+ if user_organization.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:user_organization, user_organization)}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:show), do: "Show Board"
diff --git a/lib/atomic_web/live/department_live/index.ex b/lib/atomic_web/live/department_live/index.ex
index c95dcbdaf..f4621e5b8 100644
--- a/lib/atomic_web/live/department_live/index.ex
+++ b/lib/atomic_web/live/department_live/index.ex
@@ -3,35 +3,49 @@ defmodule AtomicWeb.DepartmentLive.Index do
alias Atomic.Departments
alias Atomic.Departments.Department
- alias Atomic.Organizations
@impl true
- def mount(_params, _session, socket) do
- {:ok, assign(socket, :departments, list_departments())}
+ def mount(%{"organization_id" => organization_id}, _session, socket) do
+ {:ok, assign(socket, :departments, list_departments(organization_id))}
end
@impl true
- def handle_params(%{"org" => _id} = params, _url, socket) do
- {:noreply, apply_action(socket, socket.assigns.live_action, params)}
+ def handle_params(params, _url, socket) do
+ entries = [
+ %{
+ name: gettext("Departments"),
+ route: Routes.department_index_path(socket, :index, params["organization_id"])
+ }
+ ]
+
+ {:noreply,
+ socket
+ |> assign(:current_page, :departments)
+ |> assign(:breadcrumb_entries, entries)
+ |> apply_action(socket.assigns.live_action, params)}
end
- defp apply_action(socket, :edit, %{"id" => id}) do
- socket
- |> assign(:page_title, "Edit Department")
- |> assign(:department, Departments.get_department!(id))
+ defp apply_action(socket, :edit, %{"organization_id" => organization_id, "id" => id}) do
+ department = Departments.get_department!(id)
+
+ if department.organization_id == organization_id do
+ socket
+ |> assign(:page_title, "Edit Department")
+ |> assign(:department, Departments.get_department!(id))
+ else
+ raise AtomicWeb.MismatchError
+ end
end
- defp apply_action(socket, :new, %{"org" => id}) do
+ defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Department")
- |> assign(:organization, Organizations.get_organization!(id))
|> assign(:department, %Department{})
end
- defp apply_action(socket, :index, %{"org" => id}) do
+ defp apply_action(socket, :index, _params) do
socket
|> assign(:page_title, "Listing Departments")
- |> assign(:organization, Organizations.get_organization!(id))
|> assign(:department, nil)
end
@@ -40,10 +54,11 @@ defmodule AtomicWeb.DepartmentLive.Index do
department = Departments.get_department!(id)
{:ok, _} = Departments.delete_department(department)
- {:noreply, assign(socket, :departments, list_departments())}
+ {:noreply,
+ assign(socket, :departments, list_departments(socket.assigns.current_organization.id))}
end
- defp list_departments do
- Departments.list_departments()
+ defp list_departments(id) do
+ Departments.list_departments_by_organization_id(id)
end
end
diff --git a/lib/atomic_web/live/department_live/index.html.heex b/lib/atomic_web/live/department_live/index.html.heex
index abc44402d..580ac0fe4 100644
--- a/lib/atomic_web/live/department_live/index.html.heex
+++ b/lib/atomic_web/live/department_live/index.html.heex
@@ -1,8 +1,8 @@
Listing Departments
<%= if @live_action in [:new, :edit] do %>
- <.modal return_to={Routes.department_index_path(@socket, :index, @organization)}>
- <.live_component module={AtomicWeb.DepartmentLive.FormComponent} organization={@organization} id={@department.id || :new} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_index_path(@socket, :index, @organization)} />
+ <.modal return_to={Routes.department_index_path(@socket, :index, @current_organization)}>
+ <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id || :new} organization={@current_organization} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_index_path(@socket, :index, @current_organization)} />
<% end %>
@@ -20,8 +20,8 @@
<%= department.name %> |
- <%= live_redirect("Show", to: Routes.department_show_path(@socket, :show, department.organization_id, department)) %>
- <%= live_patch("Edit", to: Routes.department_index_path(@socket, :edit, department.organization_id, department)) %>
+ <%= live_redirect("Show", to: Routes.department_show_path(@socket, :show, @current_organization, department)) %>
+ <%= live_patch("Edit", to: Routes.department_index_path(@socket, :edit, @current_organization, department)) %>
<%= link("Delete", to: "#", phx_click: "delete", phx_value_id: department.id, data: [confirm: "Are you sure?"]) %>
|
@@ -29,4 +29,4 @@
-
<%= live_patch("New Department", to: Routes.department_index_path(@socket, :new, @organization)) %>
+
<%= live_patch("New Department", to: Routes.department_index_path(@socket, :new, @current_organization)) %>
diff --git a/lib/atomic_web/live/department_live/show.ex b/lib/atomic_web/live/department_live/show.ex
index e8ff68123..6124a4e02 100644
--- a/lib/atomic_web/live/department_live/show.ex
+++ b/lib/atomic_web/live/department_live/show.ex
@@ -2,7 +2,6 @@ defmodule AtomicWeb.DepartmentLive.Show do
use AtomicWeb, :live_view
alias Atomic.Departments
- alias Atomic.Organizations
@impl true
def mount(_params, _session, socket) do
@@ -10,12 +9,30 @@ defmodule AtomicWeb.DepartmentLive.Show do
end
@impl true
- def handle_params(%{"org" => org, "id" => id}, _, socket) do
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:organization, Organizations.get_organization!(org))
- |> assign(:department, Departments.get_department!(id, preloads: :activities))}
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
+ department = Departments.get_department!(id, preloads: [:activities])
+
+ entries = [
+ %{
+ name: gettext("Departments"),
+ route: Routes.department_index_path(socket, :index, organization_id)
+ },
+ %{
+ name: gettext("Department"),
+ route: Routes.department_show_path(socket, :show, organization_id, id)
+ }
+ ]
+
+ if department.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:current_page, :departments)
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:department, department)}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:show), do: "Show Department"
diff --git a/lib/atomic_web/live/department_live/show.html.heex b/lib/atomic_web/live/department_live/show.html.heex
index 430a0c233..a48601716 100644
--- a/lib/atomic_web/live/department_live/show.html.heex
+++ b/lib/atomic_web/live/department_live/show.html.heex
@@ -1,8 +1,8 @@
Show Department
<%= if @live_action in [:edit] do %>
- <.modal return_to={Routes.department_show_path(@socket, :show, @organization, @department)}>
- <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_show_path(@socket, :show, @organization, @department)} />
+ <.modal return_to={Routes.department_show_path(@socket, :show, @current_organization, @department)}>
+ <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_show_path(@socket, :show, @current_organization, @department)} />
<% end %>
@@ -17,12 +17,12 @@
<%= for activity <- @department.activities do %>
-
- <%= live_redirect(activity.title, to: Routes.activity_show_path(@socket, :show, activity)) %>
+ <%= live_redirect(activity.title, to: Routes.activity_show_path(@socket, :show, @current_organization, activity)) %>
<% end %>
-
<%= live_patch("Edit", to: Routes.department_show_path(@socket, :edit, @organization, @department), class: "button") %> |
-
<%= live_redirect("Back", to: Routes.department_index_path(@socket, :index, @organization)) %>
+
<%= live_patch("Edit", to: Routes.department_show_path(@socket, :edit, @current_organization, @department), class: "button") %> |
+
<%= live_redirect("Back", to: Routes.department_index_path(@socket, :index, @current_organization)) %>
diff --git a/lib/atomic_web/live/home_live/index.ex b/lib/atomic_web/live/home_live/index.ex
new file mode 100644
index 000000000..f282e43b5
--- /dev/null
+++ b/lib/atomic_web/live/home_live/index.ex
@@ -0,0 +1,25 @@
+defmodule AtomicWeb.HomeLive.Index do
+ @moduledoc false
+ use AtomicWeb, :live_view
+
+ @impl true
+ def mount(_params, _session, socket) do
+ {:ok, socket}
+ end
+
+ @impl true
+ def handle_params(_params, _url, socket) do
+ entries = [
+ %{
+ name: gettext("Home"),
+ route: Routes.home_index_path(socket, :index)
+ }
+ ]
+
+ {:noreply,
+ socket
+ |> assign(:page_title, "Home")
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:current_page, :home)}
+ end
+end
diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex
new file mode 100644
index 000000000..719de6cd4
--- /dev/null
+++ b/lib/atomic_web/live/home_live/index.html.heex
@@ -0,0 +1,3 @@
+
+
Atomic Home
+
diff --git a/lib/atomic_web/live/hooks.ex b/lib/atomic_web/live/hooks.ex
index b9add6517..5a7548ec4 100644
--- a/lib/atomic_web/live/hooks.ex
+++ b/lib/atomic_web/live/hooks.ex
@@ -5,15 +5,74 @@ defmodule AtomicWeb.Hooks do
import Phoenix.LiveView
alias Atomic.Accounts
+ alias Atomic.Organizations
def on_mount(:default, _params, _session, socket) do
{:cont, assign(socket, :page_title, "Atomic")}
end
- def on_mount(:current_user, _params, %{"user_token" => user_token}, socket) do
+ def on_mount(
+ :authenticated_user_state,
+ _params,
+ %{"user_token" => user_token, "current_organization" => _},
+ socket
+ ) do
current_user = Accounts.get_user_by_session_token(user_token)
- {:cont, assign(socket, current_user: current_user)}
+ if current_user.default_organization_id != nil do
+ socket =
+ socket
+ |> assign(:current_user, current_user)
+ |> assign(
+ :current_organization,
+ Organizations.get_organization!(current_user.default_organization_id)
+ )
+
+ {:cont, socket}
+ else
+ socket =
+ socket
+ |> assign(:current_user, current_user)
+
+ {:cont, socket}
+ end
+ end
+
+ def on_mount(:general_user_state, _params, session, socket) do
+ current_organization = session["current_organization"]
+ current_user = session["user_token"]
+
+ case {current_organization, current_user} do
+ {nil, nil} ->
+ {:cont, socket}
+
+ {nil, _} ->
+ user = Accounts.get_user_by_session_token(current_user)
+
+ {:cont,
+ socket
+ |> assign(:current_user, user)
+ |> assign(
+ :current_organization,
+ Organizations.get_organization!(user.default_organization_id)
+ )}
+
+ {_, nil} ->
+ {:cont,
+ socket
+ |> assign(:current_organization, current_organization)}
+
+ {_, _} ->
+ user = Accounts.get_user_by_session_token(current_user)
+
+ {:cont,
+ socket
+ |> assign(:current_user, user)
+ |> assign(
+ :current_organization,
+ Organizations.get_organization!(user.default_organization_id)
+ )}
+ end
end
def on_mount(:current_user, _params, _session, socket) do
diff --git a/lib/atomic_web/live/membership_live/edit.ex b/lib/atomic_web/live/membership_live/edit.ex
index b12c0edf0..bb418b48e 100644
--- a/lib/atomic_web/live/membership_live/edit.ex
+++ b/lib/atomic_web/live/membership_live/edit.ex
@@ -9,19 +9,23 @@ defmodule AtomicWeb.MembershipLive.Edit do
end
@impl true
- def handle_params(%{"org" => org, "id" => id}, _, socket) do
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
membership = Organizations.get_membership!(id, [:user, :organization, :created_by])
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:organization, org)
- |> assign(:membership, membership)
- |> assign(:current_user, socket.assigns.current_user)
- |> assign(
- :allowed_roles,
- Organizations.roles_less_than_or_equal(socket.assigns.current_user.role)
- )}
+ if membership.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:organization, organization_id)
+ |> assign(:membership, membership)
+ |> assign(:current_user, socket.assigns.current_user)
+ |> assign(
+ :allowed_roles,
+ Organizations.roles_less_than_or_equal(socket.assigns.current_user.role)
+ )}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:index), do: "List memberships"
diff --git a/lib/atomic_web/live/membership_live/index.ex b/lib/atomic_web/live/membership_live/index.ex
index 454c68208..a7d9a79b5 100644
--- a/lib/atomic_web/live/membership_live/index.ex
+++ b/lib/atomic_web/live/membership_live/index.ex
@@ -9,13 +9,22 @@ defmodule AtomicWeb.MembershipLive.Index do
end
@impl true
- def handle_params(%{"org" => id}, _, socket) do
+ def handle_params(%{"organization_id" => id}, _, socket) do
memberships =
Organizations.list_memberships(%{"organization_id" => id}, [:user])
|> Enum.filter(fn m -> m.role != :follower end)
+ entries = [
+ %{
+ name: gettext("Memberships"),
+ route: Routes.membership_index_path(socket, :index, id)
+ }
+ ]
+
{:noreply,
socket
+ |> assign(:current_page, :memberships)
+ |> assign(:breadcrumb_entries, entries)
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:memberships, memberships)}
end
diff --git a/lib/atomic_web/live/membership_live/new.ex b/lib/atomic_web/live/membership_live/new.ex
index 020fe7df3..bbe906dd5 100644
--- a/lib/atomic_web/live/membership_live/new.ex
+++ b/lib/atomic_web/live/membership_live/new.ex
@@ -12,12 +12,12 @@ defmodule AtomicWeb.MembershipLive.New do
end
@impl true
- def handle_params(%{"org" => org_id}, _url, socket) do
+ def handle_params(%{"organization_id" => organization_id}, _url, socket) do
{:noreply,
socket
|> assign(:page_title, gettext("New Membership"))
|> assign(:membership, %Membership{
- organization_id: org_id
+ organization_id: organization_id
})
|> assign(:users, Enum.map(Accounts.list_users(), fn u -> [key: u.email, value: u.id] end))
|> assign(
diff --git a/lib/atomic_web/live/membership_live/show.ex b/lib/atomic_web/live/membership_live/show.ex
index fab8a6238..9b2e1c42b 100644
--- a/lib/atomic_web/live/membership_live/show.ex
+++ b/lib/atomic_web/live/membership_live/show.ex
@@ -9,13 +9,17 @@ defmodule AtomicWeb.MembershipLive.Show do
end
@impl true
- def handle_params(%{"org" => _org, "id" => id}, _, socket) do
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
membership = Organizations.get_membership!(id, [:user, :organization, :created_by])
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:membership, membership)}
+ if membership.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:membership, membership)}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:index), do: "List memberships"
diff --git a/lib/atomic_web/live/organization_live/index.ex b/lib/atomic_web/live/organization_live/index.ex
index 8ecb9635f..09278a785 100644
--- a/lib/atomic_web/live/organization_live/index.ex
+++ b/lib/atomic_web/live/organization_live/index.ex
@@ -1,20 +1,43 @@
defmodule AtomicWeb.OrganizationLive.Index do
use AtomicWeb, :live_view
+ alias Atomic.Accounts
alias Atomic.Organizations
alias Atomic.Organizations.Organization
@impl true
- def mount(_params, _session, socket) do
- {:ok, assign(socket, :organizations, list_organizations())}
+ def mount(_params, session, socket) do
+ user = Accounts.get_user_by_session_token(session["user_token"])
+
+ {:ok,
+ socket
+ |> assign(:organizations, list_organizations())
+ |> assign(:current_user, user)}
end
@impl true
def handle_params(params, _url, socket) do
- {:noreply, apply_action(socket, socket.assigns.live_action, params)}
+ entries = [
+ %{
+ name: gettext("Organizations"),
+ route: Routes.organization_index_path(socket, :index)
+ }
+ ]
+
+ {:noreply,
+ socket
+ |> apply_action(socket.assigns.live_action, params)
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:current_page, :organizations)}
+ end
+
+ defp apply_action(socket, :show, %{"organization_id" => id}) do
+ socket
+ |> assign(:page_title, "Show Organization")
+ |> assign(:organization, Organizations.get_organization!(id))
end
- defp apply_action(socket, :edit, %{"id" => id}) do
+ defp apply_action(socket, :edit, %{"organization_id" => id}) do
socket
|> assign(:page_title, "Edit Organization")
|> assign(:organization, Organizations.get_organization!(id))
@@ -33,7 +56,7 @@ defmodule AtomicWeb.OrganizationLive.Index do
end
@impl true
- def handle_event("delete", %{"id" => id}, socket) do
+ def handle_event("delete", %{"organization_id" => id}, socket) do
organization = Organizations.get_organization!(id)
{:ok, _} = Organizations.delete_organization(organization)
@@ -43,4 +66,8 @@ defmodule AtomicWeb.OrganizationLive.Index do
defp list_organizations do
Organizations.list_organizations()
end
+
+ def update_default_organization(user, organization) do
+ Accounts.update_user(user, %{default_organization_id: organization.id})
+ end
end
diff --git a/lib/atomic_web/live/organization_live/index.html.heex b/lib/atomic_web/live/organization_live/index.html.heex
index 7f68e2ac1..1c8bd7711 100644
--- a/lib/atomic_web/live/organization_live/index.html.heex
+++ b/lib/atomic_web/live/organization_live/index.html.heex
@@ -22,8 +22,8 @@
<%= organization.description %> |
- <%= live_redirect("Show", to: Routes.organization_show_path(@socket, :show, organization)) %>
- <%= live_patch("Edit", to: Routes.organization_index_path(@socket, :edit, organization)) %>
+ <%= live_patch("Show", to: Routes.organization_show_path(@socket, :show, organization.id)) %>
+ <%= live_patch("Edit", to: Routes.organization_index_path(@socket, :edit, organization.id)) %>
<%= link("Delete", to: "#", phx_click: "delete", phx_value_id: organization.id, data: [confirm: "Are you sure?"]) %>
|
diff --git a/lib/atomic_web/live/organization_live/show.ex b/lib/atomic_web/live/organization_live/show.ex
index 4b5122e24..af09ebae3 100644
--- a/lib/atomic_web/live/organization_live/show.ex
+++ b/lib/atomic_web/live/organization_live/show.ex
@@ -1,21 +1,42 @@
defmodule AtomicWeb.OrganizationLive.Show do
use AtomicWeb, :live_view
+ alias Atomic.Accounts
alias Atomic.Organizations
@impl true
- def mount(_params, _session, socket) do
- {:ok, socket}
+ def mount(_params, session, socket) do
+ user = Accounts.get_user_by_session_token(session["user_token"])
+
+ {:ok, socket |> assign(:current_user, user)}
end
@impl true
- def handle_params(%{"id" => id}, _, socket) do
+ def handle_params(%{"organization_id" => id}, _, socket) do
org = Organizations.get_organization!(id, [:departments])
+ user = socket.assigns.current_user
+
+ if user.default_organization_id != id do
+ Accounts.update_user(user, %{"default_organization_id" => id})
+ end
+
+ entries = [
+ %{
+ name: gettext("Organizations"),
+ route: Routes.organization_index_path(socket, :index)
+ },
+ %{
+ name: gettext("Show Organization"),
+ route: Routes.organization_show_path(socket, :show, id)
+ }
+ ]
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:organization, org)
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:current_page, :organizations)
|> assign(:following, Organizations.is_member_of?(socket.assigns.current_user, org))}
end
diff --git a/lib/atomic_web/live/partner_live/form_component.ex b/lib/atomic_web/live/partner_live/form_component.ex
index 64fb33643..6ee1d0d97 100644
--- a/lib/atomic_web/live/partner_live/form_component.ex
+++ b/lib/atomic_web/live/partner_live/form_component.ex
@@ -57,6 +57,8 @@ defmodule AtomicWeb.PartnerLive.FormComponent do
end
defp save_partner(socket, :new, partner_params) do
+ partner_params = Map.put(partner_params, "organization_id", socket.assigns.organization.id)
+
case Partnerships.create_partner(partner_params, &consume_image_data(socket, &1)) do
{:ok, _partner} ->
{:noreply,
diff --git a/lib/atomic_web/live/partner_live/form_component.html.heex b/lib/atomic_web/live/partner_live/form_component.html.heex
index 26d70a1d7..731c5b1fe 100644
--- a/lib/atomic_web/live/partner_live/form_component.html.heex
+++ b/lib/atomic_web/live/partner_live/form_component.html.heex
@@ -72,7 +72,7 @@
<%= submit do %>
-
+
Save
<% end %>
diff --git a/lib/atomic_web/live/partner_live/index.ex b/lib/atomic_web/live/partner_live/index.ex
index 01b517731..9a4a72fd9 100644
--- a/lib/atomic_web/live/partner_live/index.ex
+++ b/lib/atomic_web/live/partner_live/index.ex
@@ -5,19 +5,36 @@ defmodule AtomicWeb.PartnerLive.Index do
alias Atomic.Partnerships.Partner
@impl true
- def mount(_params, _session, socket) do
- {:ok, assign(socket, :partnerships, list_partnerships())}
+ def mount(%{"organization_id" => organization_id}, _session, socket) do
+ {:ok, assign(socket, :partnerships, list_partnerships(organization_id))}
end
@impl true
def handle_params(params, _url, socket) do
- {:noreply, apply_action(socket, socket.assigns.live_action, params)}
+ entries = [
+ %{
+ name: gettext("Partnerships"),
+ route: Routes.partner_index_path(socket, :index, params["organization_id"])
+ }
+ ]
+
+ {:noreply,
+ socket
+ |> assign(:current_page, :partners)
+ |> assign(:breadcrumb_entries, entries)
+ |> apply_action(socket.assigns.live_action, params)}
end
- defp apply_action(socket, :edit, %{"id" => id}) do
- socket
- |> assign(:page_title, "Edit Partner")
- |> assign(:partner, Partnerships.get_partner!(id))
+ defp apply_action(socket, :edit, %{"organization_id" => organization_id, "id" => id}) do
+ partner = Partnerships.get_partner!(id)
+
+ if partner.organization_id == organization_id do
+ socket
+ |> assign(:page_title, "Edit Partner")
+ |> assign(:partner, Partnerships.get_partner!(id))
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp apply_action(socket, :new, _params) do
@@ -37,10 +54,11 @@ defmodule AtomicWeb.PartnerLive.Index do
partner = Partnerships.get_partner!(id)
{:ok, _} = Partnerships.delete_partner(partner)
- {:noreply, assign(socket, :partnerships, list_partnerships())}
+ {:noreply,
+ assign(socket, :partnerships, list_partnerships(socket.assigns.current_organization.id))}
end
- defp list_partnerships do
- Partnerships.list_partnerships()
+ defp list_partnerships(id) do
+ Partnerships.list_partnerships_by_organization_id(id)
end
end
diff --git a/lib/atomic_web/live/partner_live/index.html.heex b/lib/atomic_web/live/partner_live/index.html.heex
index 7ab2cf743..7f892ded7 100644
--- a/lib/atomic_web/live/partner_live/index.html.heex
+++ b/lib/atomic_web/live/partner_live/index.html.heex
@@ -1,8 +1,8 @@
Listing Partnerships
<%= if @live_action in [:new, :edit] do %>
- <.modal return_to={Routes.partner_index_path(@socket, :index)}>
- <.live_component module={AtomicWeb.PartnerLive.FormComponent} id={@partner.id || :new} title={@page_title} action={@live_action} partner={@partner} return_to={Routes.partner_index_path(@socket, :index)} />
+ <.modal return_to={Routes.partner_index_path(@socket, :index, @current_organization)}>
+ <.live_component module={AtomicWeb.PartnerLive.FormComponent} id={@partner.id || :new} organization={@current_organization} title={@page_title} action={@live_action} partner={@partner} return_to={Routes.partner_index_path(@socket, :index, @current_organization)} />
<% end %>
@@ -22,8 +22,8 @@
<%= partner.description %> |
- <%= live_redirect("Show", to: Routes.partner_show_path(@socket, :show, partner)) %>
- <%= live_patch("Edit", to: Routes.partner_index_path(@socket, :edit, partner)) %>
+ <%= live_redirect("Show", to: Routes.partner_show_path(@socket, :show, @current_organization, partner)) %>
+ <%= live_patch("Edit", to: Routes.partner_index_path(@socket, :edit, @current_organization, partner)) %>
<%= link("Delete", to: "#", phx_click: "delete", phx_value_id: partner.id, data: [confirm: "Are you sure?"]) %>
|
@@ -31,4 +31,4 @@
-
<%= live_patch("New Partner", to: Routes.partner_index_path(@socket, :new)) %>
+
<%= live_patch("New Partner", to: Routes.partner_index_path(@socket, :new, @current_organization)) %>
diff --git a/lib/atomic_web/live/partner_live/show.ex b/lib/atomic_web/live/partner_live/show.ex
index 182ad97b5..b8a4701f9 100644
--- a/lib/atomic_web/live/partner_live/show.ex
+++ b/lib/atomic_web/live/partner_live/show.ex
@@ -10,11 +10,17 @@ defmodule AtomicWeb.PartnerLive.Show do
end
@impl true
- def handle_params(%{"id" => id}, _, socket) do
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:partner, Partnerships.get_partner!(id))}
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
+ partner = Partnerships.get_partner!(id)
+
+ if partner.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:partner, partner)}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:show), do: "Show Partner"
diff --git a/lib/atomic_web/live/partner_live/show.html.heex b/lib/atomic_web/live/partner_live/show.html.heex
index 4f5f51268..daff0ce2e 100644
--- a/lib/atomic_web/live/partner_live/show.html.heex
+++ b/lib/atomic_web/live/partner_live/show.html.heex
@@ -1,8 +1,8 @@
Show Partner
<%= if @live_action in [:edit] do %>
- <.modal return_to={Routes.partner_show_path(@socket, :show, @partner)}>
- <.live_component module={AtomicWeb.PartnerLive.FormComponent} id={@partner.id} title={@page_title} action={@live_action} partner={@partner} return_to={Routes.partner_show_path(@socket, :show, @partner)} />
+ <.modal return_to={Routes.partner_show_path(@socket, :show, @current_organization, @partner)}>
+ <.live_component module={AtomicWeb.PartnerLive.FormComponent} id={@partner.id} title={@page_title} action={@live_action} partner={@partner} return_to={Routes.partner_show_path(@socket, :show, @current_organization, @partner)} />
<% end %>
@@ -24,5 +24,5 @@
<% end %>
-
<%= live_patch("Edit", to: Routes.partner_show_path(@socket, :edit, @partner), class: "button") %> |
-
<%= live_redirect("Back", to: Routes.partner_index_path(@socket, :index)) %>
+
<%= live_patch("Edit", to: Routes.partner_show_path(@socket, :edit, @current_organization, @partner), class: "button") %> |
+
<%= live_redirect("Back", to: Routes.partner_index_path(@socket, :index, @current_organization)) %>
diff --git a/lib/atomic_web/live/scanner_live/index.ex b/lib/atomic_web/live/scanner_live/index.ex
index ad2bd3e0e..2498b9e0d 100644
--- a/lib/atomic_web/live/scanner_live/index.ex
+++ b/lib/atomic_web/live/scanner_live/index.ex
@@ -12,10 +12,18 @@ defmodule AtomicWeb.ScannerLive.Index do
@impl true
def handle_params(_params, _url, socket) do
+ entries = [
+ %{
+ name: gettext("Scanner"),
+ route: Routes.scanner_index_path(socket, :index)
+ }
+ ]
+
{:noreply,
socket
|> assign(:current_page, :scanner)
- |> assign(:title, "Scanner")}
+ |> assign(:title, "Scanner")
+ |> assign(:breadcrumb_entries, entries)}
end
@impl true
diff --git a/lib/atomic_web/live/speaker_live/form_component.ex b/lib/atomic_web/live/speaker_live/form_component.ex
index ef8bdeab0..144e7a59d 100644
--- a/lib/atomic_web/live/speaker_live/form_component.ex
+++ b/lib/atomic_web/live/speaker_live/form_component.ex
@@ -41,6 +41,8 @@ defmodule AtomicWeb.SpeakerLive.FormComponent do
end
defp save_speaker(socket, :new, speaker_params) do
+ speaker_params = Map.put(speaker_params, "organization_id", socket.assigns.organization.id)
+
case Activities.create_speaker(speaker_params) do
{:ok, _speaker} ->
{:noreply,
diff --git a/lib/atomic_web/live/speaker_live/index.ex b/lib/atomic_web/live/speaker_live/index.ex
index 85bc39238..e0956eb58 100644
--- a/lib/atomic_web/live/speaker_live/index.ex
+++ b/lib/atomic_web/live/speaker_live/index.ex
@@ -5,8 +5,8 @@ defmodule AtomicWeb.SpeakerLive.Index do
alias Atomic.Activities.Speaker
@impl true
- def mount(_params, _session, socket) do
- {:ok, assign(socket, :speakers, list_speakers())}
+ def mount(%{"organization_id" => organization_id}, _session, socket) do
+ {:ok, assign(socket, :speakers, list_speakers(organization_id))}
end
@impl true
@@ -14,7 +14,7 @@ defmodule AtomicWeb.SpeakerLive.Index do
entries = [
%{
name: gettext("Speakers"),
- route: Routes.speaker_index_path(socket, :index)
+ route: Routes.speaker_index_path(socket, :index, params["organization_id"])
}
]
@@ -25,10 +25,16 @@ defmodule AtomicWeb.SpeakerLive.Index do
|> apply_action(socket.assigns.live_action, params)}
end
- defp apply_action(socket, :edit, %{"id" => id}) do
- socket
- |> assign(:page_title, "Edit Speaker")
- |> assign(:speaker, Activities.get_speaker!(id))
+ defp apply_action(socket, :edit, %{"organization_id" => organization_id, "id" => id}) do
+ speaker = Activities.get_speaker!(id)
+
+ if speaker.organization_id == organization_id do
+ socket
+ |> assign(:page_title, "Edit Speaker")
+ |> assign(:speaker, speaker)
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp apply_action(socket, :new, _params) do
@@ -48,10 +54,10 @@ defmodule AtomicWeb.SpeakerLive.Index do
speaker = Activities.get_speaker!(id)
{:ok, _} = Activities.delete_speaker(speaker)
- {:noreply, assign(socket, :speakers, list_speakers())}
+ {:noreply, assign(socket, :speakers, list_speakers(socket.assigns.current_organization.id))}
end
- defp list_speakers do
- Activities.list_speakers()
+ defp list_speakers(organization_id) do
+ Activities.list_speakers_by_organization_id(organization_id)
end
end
diff --git a/lib/atomic_web/live/speaker_live/index.html.heex b/lib/atomic_web/live/speaker_live/index.html.heex
index 17ffbc9c9..ed87b8f1b 100644
--- a/lib/atomic_web/live/speaker_live/index.html.heex
+++ b/lib/atomic_web/live/speaker_live/index.html.heex
@@ -1,8 +1,8 @@
Listing Speakers
<%= if @live_action in [:new, :edit] do %>
- <.modal return_to={Routes.speaker_index_path(@socket, :index)}>
- <.live_component module={AtomicWeb.SpeakerLive.FormComponent} id={@speaker.id || :new} title={@page_title} action={@live_action} speaker={@speaker} return_to={Routes.speaker_index_path(@socket, :index)} />
+ <.modal return_to={Routes.speaker_index_path(@socket, :index, @current_organization)}>
+ <.live_component module={AtomicWeb.SpeakerLive.FormComponent} id={@speaker.id || :new} organization={@current_organization} title={@page_title} action={@live_action} speaker={@speaker} return_to={Routes.speaker_index_path(@socket, :index, @current_organization)} />
<% end %>
@@ -22,8 +22,8 @@
<%= speaker.bio %> |
- <%= live_redirect("Show", to: Routes.speaker_show_path(@socket, :show, speaker)) %>
- <%= live_patch("Edit", to: Routes.speaker_index_path(@socket, :edit, speaker)) %>
+ <%= live_redirect("Show", to: Routes.speaker_show_path(@socket, :show, @current_organization, speaker)) %>
+ <%= live_patch("Edit", to: Routes.speaker_index_path(@socket, :edit, @current_organization, speaker)) %>
<%= link("Delete", to: "#", phx_click: "delete", phx_value_id: speaker.id, data: [confirm: "Are you sure?"]) %>
|
@@ -31,4 +31,4 @@
-
<%= live_patch("New Speaker", to: Routes.speaker_index_path(@socket, :new)) %>
+
<%= live_patch("New Speaker", to: Routes.speaker_index_path(@socket, :new, @current_organization)) %>
diff --git a/lib/atomic_web/live/speaker_live/show.ex b/lib/atomic_web/live/speaker_live/show.ex
index eb5b4b47d..49a3818b4 100644
--- a/lib/atomic_web/live/speaker_live/show.ex
+++ b/lib/atomic_web/live/speaker_live/show.ex
@@ -9,24 +9,30 @@ defmodule AtomicWeb.SpeakerLive.Show do
end
@impl true
- def handle_params(%{"id" => id}, _, socket) do
+ def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do
+ speaker = Activities.get_speaker!(id)
+
entries = [
%{
name: gettext("Speakers"),
- route: Routes.speaker_index_path(socket, :index)
+ route: Routes.speaker_index_path(socket, :index, organization_id)
},
%{
name: gettext("Show"),
- route: Routes.speaker_show_path(socket, :show, id)
+ route: Routes.speaker_show_path(socket, :show, organization_id, id)
}
]
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:current_page, :speakers)
- |> assign(:breadcrumb_entries, entries)
- |> assign(:speaker, Activities.get_speaker!(id))}
+ if speaker.organization_id == organization_id do
+ {:noreply,
+ socket
+ |> assign(:page_title, page_title(socket.assigns.live_action))
+ |> assign(:current_page, :speakers)
+ |> assign(:breadcrumb_entries, entries)
+ |> assign(:speaker, Activities.get_speaker!(id))}
+ else
+ raise AtomicWeb.MismatchError
+ end
end
defp page_title(:show), do: "Show Speaker"
diff --git a/lib/atomic_web/live/speaker_live/show.html.heex b/lib/atomic_web/live/speaker_live/show.html.heex
index 73999d02c..b108acb76 100644
--- a/lib/atomic_web/live/speaker_live/show.html.heex
+++ b/lib/atomic_web/live/speaker_live/show.html.heex
@@ -1,8 +1,8 @@
Show Speaker
<%= if @live_action in [:edit] do %>
- <.modal return_to={Routes.speaker_show_path(@socket, :show, @speaker)}>
- <.live_component module={AtomicWeb.SpeakerLive.FormComponent} id={@speaker.id} title={@page_title} action={@live_action} speaker={@speaker} return_to={Routes.speaker_show_path(@socket, :show, @speaker)} />
+ <.modal return_to={Routes.speaker_show_path(@socket, :show, @current_organization, @speaker)}>
+ <.live_component module={AtomicWeb.SpeakerLive.FormComponent} id={@speaker.id} organization={@current_organization} title={@page_title} action={@live_action} speaker={@speaker} return_to={Routes.speaker_show_path(@socket, :show, @current_organization, @speaker)} />
<% end %>
@@ -18,5 +18,5 @@
-
<%= live_patch("Edit", to: Routes.speaker_show_path(@socket, :edit, @speaker), class: "button") %> |
-
<%= live_redirect("Back", to: Routes.speaker_index_path(@socket, :index)) %>
+
<%= live_patch("Edit", to: Routes.speaker_show_path(@socket, :edit, @current_organization, @speaker), class: "button") %> |
+
<%= live_redirect("Back", to: Routes.speaker_index_path(@socket, :index, @current_organization)) %>
diff --git a/lib/atomic_web/live/user_live/edit.html.heex b/lib/atomic_web/live/user_live/edit.html.heex
index dffb93cee..4896ca8b5 100644
--- a/lib/atomic_web/live/user_live/edit.html.heex
+++ b/lib/atomic_web/live/user_live/edit.html.heex
@@ -1 +1 @@
-<.live_component module={AtomicWeb.UserLive.FormComponent} user={@user} id={@current_user.id} courses={@courses} title={@page_title} action={@live_action} return_to={Routes.activity_index_path(@socket, :index)} />
+<.live_component module={AtomicWeb.UserLive.FormComponent} user={@user} id={@current_user.id} courses={@courses} title={@page_title} action={@live_action} return_to={Routes.home_index_path(@conn, :index)} />
diff --git a/lib/atomic_web/plugs/authorize.ex b/lib/atomic_web/plugs/authorize.ex
new file mode 100644
index 000000000..62492fa4c
--- /dev/null
+++ b/lib/atomic_web/plugs/authorize.ex
@@ -0,0 +1,48 @@
+defmodule AtomicWeb.Plugs.Authorize do
+ @moduledoc false
+ import Plug.Conn
+
+ alias Atomic.Organizations
+
+ def init(opts), do: opts
+
+ def call(conn, minimum_authorized_role) do
+ if authorized?(conn, minimum_authorized_role) do
+ conn
+ else
+ conn
+ |> send_resp(:not_found, "")
+ |> halt()
+ end
+ end
+
+ defp authorized?(conn, minimum_authorized_role) do
+ organization_id = get_organization_id(conn)
+
+ case {organization_id, conn.assigns.current_user} do
+ {nil, _} ->
+ false
+
+ {id, user} ->
+ user_authorized?(user, id, minimum_authorized_role)
+ end
+ end
+
+ defp get_organization_id(conn) do
+ case conn.params["organization_id"] do
+ organization_id when is_binary(organization_id) ->
+ organization_id
+
+ _ ->
+ nil
+ end
+ end
+
+ defp user_authorized?(user, organization_id, minimum_authorized_role) do
+ user_organizations = Enum.map(user.organizations, & &1.id)
+ role = Organizations.get_role(user.id, organization_id)
+ allowed_roles = Organizations.roles_bigger_than_or_equal(minimum_authorized_role)
+
+ organization_id in user_organizations && role in allowed_roles
+ end
+end
diff --git a/lib/atomic_web/router.ex b/lib/atomic_web/router.ex
index 04f31502e..9de88ed12 100644
--- a/lib/atomic_web/router.ex
+++ b/lib/atomic_web/router.ex
@@ -17,62 +17,90 @@ defmodule AtomicWeb.Router do
plug :accepts, ["json"]
end
+ pipeline :admin do
+ plug AtomicWeb.Plugs.Authorize, :admin
+ end
+
+ pipeline :member do
+ plug AtomicWeb.Plugs.Authorize, :member
+ end
+
+ pipeline :follower do
+ plug AtomicWeb.Plugs.Authorize, :follower
+ end
+
scope "/", AtomicWeb do
pipe_through :browser
+
+ live_session :general, on_mount: [{AtomicWeb.Hooks, :general_user_state}] do
+ live "/", HomeLive.Index, :index
+
+ live "/organizations", OrganizationLive.Index, :index
+ live "/organizations/:organization_id", OrganizationLive.Show, :show
+
+ scope "/organizations/:organization_id" do
+ live "/board/", BoardLive.Index, :index
+ live "/board/:id", BoardLive.Show, :show
+ end
+ end
end
scope "/", AtomicWeb do
pipe_through [:browser, :require_authenticated_user]
- live_session :logged_in, on_mount: [{AtomicWeb.Hooks, :current_user}] do
- live "/", ActivityLive.Index, :index
+ live_session :logged_in, on_mount: [{AtomicWeb.Hooks, :authenticated_user_state}] do
live "/scanner", ScannerLive.Index, :index
- live "/activities", ActivityLive.Index, :index
- live "/activities/new", ActivityLive.New, :new
- live "/activities/:id/edit", ActivityLive.Edit, :edit
- live "/activities/:id", ActivityLive.Show, :show
-
- live "/departments/:org", DepartmentLive.Index, :index
- live "/departments/:org/new", DepartmentLive.Index, :new
- live "/departments/:org/:id/edit", DepartmentLive.Index, :edit
- live "/departments/:org/:id", DepartmentLive.Show, :show
- live "/departments/:org/:id/show/edit", DepartmentLive.Show, :edit
-
- live "/partners", PartnerLive.Index, :index
- live "/partners/new", PartnerLive.Index, :new
- live "/partners/:id/edit", PartnerLive.Index, :edit
- live "/partners/:id", PartnerLive.Show, :show
- live "/partners/:id/show/edit", PartnerLive.Show, :edit
-
- live "/speakers", SpeakerLive.Index, :index
- live "/speakers/new", SpeakerLive.Index, :new
- live "/speakers/:id/edit", SpeakerLive.Index, :edit
- live "/speakers/:id", SpeakerLive.Show, :show
- live "/speakers/:id/show/edit", SpeakerLive.Show, :edit
- live "/organizations", OrganizationLive.Index, :index
- live "/organizations/new", OrganizationLive.Index, :new
- live "/organizations/:id/edit", OrganizationLive.Index, :edit
- live "/organizations/:id", OrganizationLive.Show, :show
- live "/organizations/:id/show/edit", OrganizationLive.Show, :edit
+ scope "/organizations/:organization_id" do
+ pipe_through :admin
+ live "/edit", OrganizationLive.Index, :edit
+ live "/show/edit", OrganizationLive.Show, :edit
- live "/membership/:org", MembershipLive.Index, :index
- live "/membership/:org/new", MembershipLive.New, :new
- live "/membership/:org/:id", MembershipLive.Show, :show
- live "/membership/:org/:id/edit", MembershipLive.Edit, :edit
+ live "/activities/new", ActivityLive.New, :new
+ live "/activities/:id/edit", ActivityLive.Edit, :edit
- live "/card/:membership_id", CardLive.Show, :show
+ live "/departments/new", DepartmentLive.Index, :new
+ live "/departments/:id/edit", DepartmentLive.Index, :edit
+ live "/departments/:id/show/edit", DepartmentLive.Show, :edit
+
+ live "/partners/new", PartnerLive.Index, :new
+ live "/partners/:id/edit", PartnerLive.Index, :edit
+ live "/partners/:id/show/edit", PartnerLive.Show, :edit
+
+ live "/speakers/new", SpeakerLive.Index, :new
+ live "/speakers/:id/edit", SpeakerLive.Index, :edit
+ live "/speakers/:id/show/edit", SpeakerLive.Show, :edit
+
+ live "/board/new", BoardLive.New, :new
+ live "/board/:id/edit", BoardLive.Edit, :edit
+
+ live "/memberships", MembershipLive.Index, :index
+ live "/memberships/new", MembershipLive.New, :new
+ live "/memberships/:id", MembershipLive.Show, :show
+ live "/memberships/:id/edit", MembershipLive.Edit, :edit
+ end
+
+ scope "/organizations/:organization_id" do
+ pipe_through :follower
+ live "/activities", ActivityLive.Index, :index
+ live "/activities/:id", ActivityLive.Show, :show
- live "/board/:org", BoardLive.Index, :index
- live "/board/:org/new", BoardLive.New, :new
- live "/board/:org/:id", BoardLive.Show, :show
- live "/board/:org/:id/edit", BoardLive.Edit, :edit
- live "/memberships/:org", MembershipLive.Index, :index
- live "/memberships/:org/new", MembershipLive.New, :new
- live "/memberships/:org/:id", MembershipLive.Show, :show
- live "/memberships/:org/:id/edit", MembershipLive.Edit, :edit
+ live "/departments", DepartmentLive.Index, :index
+ live "/departments/:id", DepartmentLive.Show, :show
+
+ live "/partners", PartnerLive.Index, :index
+ live "/partners/:id", PartnerLive.Show, :show
+
+ live "/speakers", SpeakerLive.Index, :index
+ live "/speakers/:id", SpeakerLive.Show, :show
+ end
+
+ live "/organizations/new", OrganizationLive.Index, :new
live "/user/edit", UserLive.Edit, :edit
+
+ pipe_through :member
+ live "/card/:membership_id", CardLive.Show, :show
end
end
diff --git a/lib/atomic_web/templates/error/404.html.heex b/lib/atomic_web/templates/error/404.html.heex
new file mode 100644
index 000000000..3678ddf7d
--- /dev/null
+++ b/lib/atomic_web/templates/error/404.html.heex
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+ <%= live_title_tag(assigns[:page_title] || "Store", suffix: " · 404") %>
+
+
+
+
+
+
+
+
+
+
+
+ We can't seem to find the page you're looking for.
The link you followed may be broken, or the page may have been removed.
+
+
+
+
+
+
diff --git a/lib/atomic_web/templates/layout/live.html.heex b/lib/atomic_web/templates/layout/live.html.heex
index e810c6c0e..8b6bf1b49 100644
--- a/lib/atomic_web/templates/layout/live.html.heex
+++ b/lib/atomic_web/templates/layout/live.html.heex
@@ -18,15 +18,15 @@
- <%= Atomic.Accounts.extract_initials("CeSIUM") %>
+ <%= Atomic.Accounts.extract_initials(@current_organization.name) %>
- CeSIUM
+ <%= @current_organization.name %>
- Role
+ <%= AtomicWeb.ViewUtils.capitalize_first_letter(Atomic.Organizations.get_role(@current_user.id, @current_organization.id)) %>
@@ -54,34 +54,36 @@
aria-labelledby="options-menu-button"
tabindex="-1"
>
-
-
+
+ <% end %>