-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create organizations slug #393
Conversation
AI-Generated Summary: This pull request involves many changes across the AtomicWeb Elixir application relating to the handling of organizations. The primary change is a structural shift in the routing system. It moves from using organization IDs ( Other notable changes include:
The overall aim appears to increase the readability of the URLs, possibly by making identifiers within the URL more user-friendly, and to enforce unique handles for each organization to avoid routing issues. These alterations would significantly affect the functionality and performance of the application, and thorough tests should be conducted to ensure the routing works as expected without negatively impacting the user experience or system performance. |
defp validate_slug(changeset) do | ||
changeset | ||
|> validate_required([:slug]) | ||
|> validate_format(:slug, ~r/^[a-zA-Z0-9_.]+$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to allow case sensitive slugs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree they should be case insensitive. Meaning "cesium" and "CeSIUM" both stand for the same slug.
|
||
## Examples | ||
iex> get_organization_by_slug("foo_bar") | ||
%Organization{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%Organization{} | |
%Organization{} | |
@@ -213,7 +238,7 @@ defmodule Atomic.Organizations do | |||
nil | |||
|
|||
""" | |||
def get_role(user_id, organization_id) do | |||
def get_role(user_id, organization_id) when is_binary(user_id) and is_binary(organization_id) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
@@ -10,7 +10,7 @@ | |||
<%= if not @empty and @has_permissions do %> | |||
<div class="hidden lg:border-orange-500 lg:block"> | |||
<%= live_patch("+ New Activity", | |||
to: Routes.activity_new_path(@socket, :new, @current_organization), | |||
to: Routes.activity_new_path(@socket, :new, @current_organization.slug), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, interpolated ~p values are encoded via the Phoenix.Param protocol. For example, a %Post{} struct in your application may derive the Phoenix.Param protocol to generate slug-based paths rather than ID based ones. This allows you to use ~p"/posts/#{post}" rather than ~p"/posts/#{post.slug}" throughout your application. See the Phoenix.Param documentation for more details.
What about implementing this? Then we would only need to write @current_organization
instead of @current_organization.slug
💡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to implement this 🙏🏼
|> assign(:id, id) | ||
|> assign(:slug, slug)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these assigns needed?
@@ -13,5 +14,6 @@ defmodule Atomic.Repo.Migrations.CreateOrganizations do | |||
end | |||
|
|||
create unique_index(:organizations, [:name]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need an index by name. I know it was not added now, but, please, remove it 🙏🏼
def get_activity_organizations!(activity, preloads \\ [:departments]) do | ||
Repo.preload(activity, preloads) | ||
|> Map.get(:departments, []) | ||
|> Enum.map(& &1.organization_id) | ||
|> Enum.map(fn id -> | ||
Organizations.get_organization!(id).slug | ||
end) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this anymore, since an activity is, for now, associated to only one organization.
%{ | ||
key: :departments, | ||
title: "Departments", | ||
icon: :cube, | ||
url: Routes.department_index_path(conn, :index, current_organization.slug), | ||
tabs: [] | ||
}, | ||
%{ | ||
key: :partners, | ||
title: "Partners", | ||
icon: :user_group, | ||
url: Routes.partner_index_path(conn, :index, current_organization.slug), | ||
tabs: [] | ||
}, | ||
%{ | ||
key: :memberships, | ||
title: "Memberships", | ||
icon: :user_add, | ||
url: Routes.membership_index_path(conn, :index, current_organization.slug), | ||
tabs: [] | ||
}, | ||
%{ | ||
key: :board, | ||
title: "Board", | ||
icon: :users, | ||
url: Routes.board_index_path(conn, :index, current_organization), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are admin pages. Why are you adding them here?
@@ -10,7 +10,7 @@ | |||
<%= if not @empty and @has_permissions do %> | |||
<div class="hidden lg:border-orange-500 lg:block"> | |||
<%= live_patch("+ New Activity", | |||
to: Routes.activity_new_path(@socket, :new, @current_organization), | |||
to: Routes.activity_new_path(@socket, :new, @current_organization.slug), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to implement this 🙏🏼
1 similar comment
Will be done in the future |
No description provided.