diff --git a/lib/atomic/accounts.ex b/lib/atomic/accounts.ex index c79f0ec60..97b67564c 100644 --- a/lib/atomic/accounts.ex +++ b/lib/atomic/accounts.ex @@ -552,7 +552,7 @@ defmodule Atomic.Accounts do """ def has_master_permissions?(user_id) do user = get_user!(user_id) - user.role in [:admin] + user.role == :master end alias Atomic.Organizations diff --git a/lib/atomic/accounts/course.ex b/lib/atomic/accounts/course.ex index a45676811..981dc0984 100644 --- a/lib/atomic/accounts/course.ex +++ b/lib/atomic/accounts/course.ex @@ -1,6 +1,6 @@ defmodule Atomic.Accounts.Course do @moduledoc """ - A course the user is enrolled in + A course the user is enrolled in. """ use Atomic.Schema @@ -12,14 +12,13 @@ defmodule Atomic.Accounts.Course do schema "courses" do field :name, :string field :cycle, Ecto.Enum, values: @cycles + has_many :users, User timestamps() end - @doc """ - A changeset for a course. - """ + @doc false def changeset(course, attrs) do course |> cast(attrs, @required_fields) diff --git a/lib/atomic/accounts/user.ex b/lib/atomic/accounts/user.ex index 248dd3775..f4dcba537 100644 --- a/lib/atomic/accounts/user.ex +++ b/lib/atomic/accounts/user.ex @@ -1,18 +1,22 @@ defmodule Atomic.Accounts.User do @moduledoc """ A user of the application capable of authenticating. + + Types of users: + + * `master` - A user who has full access over the application. + * `student` - A simple user of the application. That can be, for example, owner of an organization. """ use Atomic.Schema alias Atomic.Accounts.Course - alias Atomic.Activities.ActivityEnrollment + alias Atomic.Activities.Enrollment alias Atomic.Organizations.{Collaborator, Membership, Organization} - alias Atomic.Uploaders.ProfilePicture @required_fields ~w(email password)a - @optional_fields ~w(name slug role phone_number confirmed_at course_id current_organization_id)a + @optional_fields ~w(name slug role confirmed_at phone_number course_id current_organization_id)a - @roles ~w(admin student)a + @roles ~w(master student)a @derive {Phoenix.Param, key: :slug} @@ -20,18 +24,19 @@ defmodule Atomic.Accounts.User do field :name, :string field :email, :string field :slug, :string + field :role, Ecto.Enum, values: @roles, default: :student + field :password, :string, virtual: true, redact: true field :hashed_password, :string, redact: true + field :confirmed_at, :naive_datetime field :phone_number, :string - field :profile_picture, ProfilePicture.Type - field :role, Ecto.Enum, values: @roles, default: :student + field :profile_picture, Uploaders.ProfilePicture.Type belongs_to :course, Course belongs_to :current_organization, Organization - has_many :activity_enrollments, ActivityEnrollment - has_many :memberships, Membership + has_many :enrollments, Enrollment has_many :collaborators, Collaborator many_to_many :organizations, Organization, join_through: Membership @@ -226,4 +231,6 @@ defmodule Atomic.Accounts.User do add_error(changeset, :current_password, "is not valid") end end + + def roles, do: @roles end diff --git a/lib/atomic/accounts/user_token.ex b/lib/atomic/accounts/user_token.ex index 605d9fd0c..def47f715 100644 --- a/lib/atomic/accounts/user_token.ex +++ b/lib/atomic/accounts/user_token.ex @@ -20,6 +20,7 @@ defmodule Atomic.Accounts.UserToken do field :token, :binary field :context, :string field :sent_to, :string + belongs_to :user, Atomic.Accounts.User timestamps(updated_at: false) diff --git a/lib/atomic/activities.ex b/lib/atomic/activities.ex index 6933935f8..f6e5704c6 100644 --- a/lib/atomic/activities.ex +++ b/lib/atomic/activities.ex @@ -6,8 +6,7 @@ defmodule Atomic.Activities do alias Atomic.Accounts.User alias Atomic.Activities.Activity - alias Atomic.Activities.ActivityEnrollment - alias Atomic.Activities.Speaker + alias Atomic.Activities.Enrollment alias Atomic.Feed.Post @doc """ @@ -169,7 +168,7 @@ defmodule Atomic.Activities do false """ def participating?(activity_id, user_id) do - ActivityEnrollment + Enrollment |> where(activity_id: ^activity_id, user_id: ^user_id) |> Repo.exists?() end @@ -294,31 +293,31 @@ defmodule Atomic.Activities do ## Examples iex> list_enrollments() - [%ActivityEnrollment{}, ...] + [%Enrollment{}, ...] """ def list_enrollments do - Repo.all(ActivityEnrollment) + Repo.all(Enrollment) end @doc """ Gets a single enrollment. - Raises `Ecto.NoResultsError` if the ActivityEnrollment does not exist. + Raises `Ecto.NoResultsError` if the Enrollment does not exist. ## Examples iex> get_enrollment!(123) - %ActivityEnrollment{} + %Enrollment{} iex> get_enrollment!(456) ** (Ecto.NoResultsError) """ - def get_enrollment!(id), do: Repo.get!(ActivityEnrollment, id) + def get_enrollment!(id), do: Repo.get!(Enrollment, id) def get_enrollment!(activity_id, user_id) do - ActivityEnrollment + Enrollment |> where(activity_id: ^activity_id, user_id: ^user_id) |> Repo.one() end @@ -329,13 +328,13 @@ defmodule Atomic.Activities do ## Examples iex> get_user_enrolled(user, activity_id) - %ActivityEnrollment{} + %Enrollment{} iex> get_user_enrolled(user, activity_id) ** (Ecto.NoResultsError) """ def get_user_enrolled(user, activity_id) do - ActivityEnrollment + Enrollment |> where(user_id: ^user.id, activity_id: ^activity_id) |> Repo.one() |> case do @@ -350,13 +349,13 @@ defmodule Atomic.Activities do ## Examples iex> list_user_enrollments(user) - [%ActivityEnrollment{}, ...] + [%Enrollment{}, ...] iex> list_user_enrollments(user) ** (Ecto.NoResultsError) """ def list_user_enrollments(user_id) do - ActivityEnrollment + Enrollment |> where(user_id: ^user_id) |> Repo.all() end @@ -373,7 +372,7 @@ defmodule Atomic.Activities do def list_user_activities(user_id, opts) when is_list(opts) do from(a in Activity, - join: e in assoc(a, :activity_enrollments), + join: e in assoc(a, :enrollments), where: e.user_id == ^user_id ) |> apply_filters(opts) @@ -382,7 +381,7 @@ defmodule Atomic.Activities do def list_user_activities(user_id, flop) do from(a in Activity, - join: e in assoc(a, :activity_enrollments), + join: e in assoc(a, :enrollments), where: e.user_id == ^user_id ) |> Flop.validate_and_run(flop, for: Activity) @@ -390,7 +389,7 @@ defmodule Atomic.Activities do def list_user_activities(user_id, %{} = flop, opts) when is_list(opts) do from(a in Activity, - join: e in assoc(a, :activity_enrollments), + join: e in assoc(a, :enrollments), where: e.user_id == ^user_id ) |> apply_filters(opts) @@ -403,7 +402,7 @@ defmodule Atomic.Activities do ## Examples iex> create_enrollment(activity_id, %User{} = user) - {:ok, %ActivityEnrollment{}} + {:ok, %Enrollment{}} iex> create_enrollment(activity_id, %User{} = user) {:error, %Ecto.Changeset{}} @@ -411,18 +410,18 @@ defmodule Atomic.Activities do """ def create_enrollment(activity_id, %User{} = user) do Ecto.Multi.new() - |> Ecto.Multi.insert(:activity_enrollments, %ActivityEnrollment{ + |> Ecto.Multi.insert(:enrollments, %Enrollment{ activity_id: activity_id, user_id: user.id }) - |> Multi.update(:activity, fn %{activity_enrollments: enrollment} -> + |> Multi.update(:activity, fn %{enrollments: enrollment} -> activity = get_activity!(enrollment.activity_id) Activity.changeset(activity, %{enrolled: activity.enrolled + 1}) end) |> Repo.transaction() |> case do - {:ok, %{activity_enrollments: enrollment, activity: _activity}} -> + {:ok, %{enrollments: enrollment, activity: _activity}} -> broadcast({:ok, enrollment}, :new_enrollment) {:ok, enrollment} @@ -437,15 +436,15 @@ defmodule Atomic.Activities do ## Examples iex> update_enrollment(enrollment, %{field: new_value}) - {:ok, %ActivityEnrollment{}} + {:ok, %Enrollment{}} iex> update_enrollment(enrollment, %{field: bad_value}) {:error, %Ecto.Changeset{}} """ - def update_enrollment(%ActivityEnrollment{} = enrollment, attrs) do + def update_enrollment(%Enrollment{} = enrollment, attrs) do enrollment - |> ActivityEnrollment.update_changeset(attrs) + |> Enrollment.update_changeset(attrs) |> Repo.update() end @@ -455,7 +454,7 @@ defmodule Atomic.Activities do ## Examples iex> delete_enrollment(activity_id, %User{}) - {:ok, %ActivityEnrollment{}} + {:ok, %Enrollment{}} iex> delete_enrollment(activity_id, %User{}) {:error, %Ecto.Changeset{}} @@ -463,15 +462,15 @@ defmodule Atomic.Activities do """ def delete_enrollment(activity_id, %User{} = user) do Ecto.Multi.new() - |> Ecto.Multi.delete(:activity_enrollments, get_user_enrolled(user, activity_id)) - |> Multi.update(:activity, fn %{activity_enrollments: _enrollment} -> + |> Ecto.Multi.delete(:enrollments, get_user_enrolled(user, activity_id)) + |> Multi.update(:activity, fn %{enrollments: _enrollment} -> activity = get_activity!(activity_id) Activity.changeset(activity, %{enrolled: activity.enrolled - 1}) end) |> Repo.transaction() |> case do - {:ok, %{activity_enrollments: _enrollment, activity: _activity}} -> + {:ok, %{enrollments: _enrollment, activity: _activity}} -> broadcast({1, nil}, :deleted_enrollment) {1, nil} @@ -486,11 +485,11 @@ defmodule Atomic.Activities do ## Examples iex> change_enrollment(enrollment) - %Ecto.Changeset{data: %ActivityEnrollment{}} + %Ecto.Changeset{data: %Enrollment{}} """ - def change_enrollment(%ActivityEnrollment{} = enrollment, attrs \\ %{}) do - ActivityEnrollment.changeset(enrollment, attrs) + def change_enrollment(%Enrollment{} = enrollment, attrs \\ %{}) do + Enrollment.changeset(enrollment, attrs) end @doc """ @@ -499,7 +498,7 @@ defmodule Atomic.Activities do ## Examples iex> broadcast(:new_enrollment, enrollment) - {:ok, %ActivityEnrollment{}} + {:ok, %Enrollment{}} iex> broadcast(:deleted_enrollment, nil) {:ok, nil} @@ -511,7 +510,7 @@ defmodule Atomic.Activities do defp broadcast({:error, _reason} = error, _event), do: error - defp broadcast({:ok, %ActivityEnrollment{} = enrollment}, event) + defp broadcast({:ok, %Enrollment{} = enrollment}, event) when event in [:new_enrollment] do Phoenix.PubSub.broadcast!(Atomic.PubSub, "new_enrollment", {event, enrollment}) {:ok, enrollment} @@ -522,128 +521,4 @@ defmodule Atomic.Activities do Phoenix.PubSub.broadcast!(Atomic.PubSub, "deleted_enrollment", {event, nil}) {number, nil} end - - @doc """ - Returns the list of speakers. - - ## Examples - - iex> list_speakers() - [%Speaker{}, ...] - - """ - def list_speakers do - Repo.all(Speaker) - end - - @doc """ - Returns the list of speakers belonging to an organization. - - ## Examples - - iex> list_speakers_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") - [%Speaker{}, ...] - - """ - def list_speakers_by_organization_id(id) do - Repo.all(from s in Speaker, where: s.organization_id == ^id) - end - - @doc """ - Returns the list of speakers in a list of ids. - - ## Examples - - iex> get_speakers([1, 2, 3]) - [%Speaker{}, ...] - - iex> get_speakers([1, 2, 3]) - [] - """ - def get_speakers(nil), do: [] - - def get_speakers(ids) do - Repo.all(from s in Speaker, where: s.id in ^ids) - end - - @doc """ - Gets a single speaker. - - Raises `Ecto.NoResultsError` if the Speaker does not exist. - - ## Examples - - iex> get_speaker!(123) - %Speaker{} - - iex> get_speaker!(456) - ** (Ecto.NoResultsError) - - """ - def get_speaker!(id), do: Repo.get!(Speaker, id) - - @doc """ - Creates a speaker. - - ## Examples - - iex> create_speaker(%{field: value}) - {:ok, %Speaker{}} - - iex> create_speaker(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_speaker(attrs \\ %{}) do - %Speaker{} - |> Speaker.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a speaker. - - ## Examples - - iex> update_speaker(speaker, %{field: new_value}) - {:ok, %Speaker{}} - - iex> update_speaker(speaker, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_speaker(%Speaker{} = speaker, attrs) do - speaker - |> Speaker.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a speaker. - - ## Examples - - iex> delete_speaker(speaker) - {:ok, %Speaker{}} - - iex> delete_speaker(speaker) - {:error, %Ecto.Changeset{}} - - """ - def delete_speaker(%Speaker{} = speaker) do - Repo.delete(speaker) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking speaker changes. - - ## Examples - - iex> change_speaker(speaker) - %Ecto.Changeset{data: %Speaker{}} - - """ - def change_speaker(%Speaker{} = speaker, attrs \\ %{}) do - Speaker.changeset(speaker, attrs) - end end diff --git a/lib/atomic/activities/activity.ex b/lib/atomic/activities/activity.ex index 8e2d6e256..4735f2e2a 100644 --- a/lib/atomic/activities/activity.ex +++ b/lib/atomic/activities/activity.ex @@ -4,21 +4,13 @@ defmodule Atomic.Activities.Activity do """ use Atomic.Schema - alias Atomic.Activities - - alias Atomic.Activities.{ - ActivityEnrollment, - ActivitySpeaker, - Speaker - } - - alias Atomic.Events.Event + alias Atomic.Activities.Enrollment alias Atomic.Feed.Post alias Atomic.Location alias Atomic.Organizations.Organization - @required_fields ~w(title description start finish minimum_entries maximum_entries organization_id enrolled)a - @optional_fields ~w(event_id image)a + @required_fields ~w(title description start finish minimum_entries maximum_entries enrolled organization_id)a + @optional_fields ~w()a @derive { Flop.Schema, @@ -33,21 +25,21 @@ defmodule Atomic.Activities.Activity do schema "activities" do field :title, :string field :description, :string + field :start, :naive_datetime field :finish, :naive_datetime - field :image, Uploaders.Post.Type + field :maximum_entries, :integer field :minimum_entries, :integer field :enrolled, :integer, default: 0 + field :image, Uploaders.Post.Type embeds_one :location, Location, on_replace: :update belongs_to :organization, Organization - belongs_to :event, Event - belongs_to :post, Post, foreign_key: :post_id + belongs_to :post, Post - many_to_many :speakers, Speaker, on_replace: :delete, join_through: ActivitySpeaker - has_many :activity_enrollments, ActivityEnrollment, foreign_key: :activity_id + has_many :enrollments, Enrollment timestamps() end @@ -56,14 +48,12 @@ defmodule Atomic.Activities.Activity do activity |> cast(attrs, @required_fields ++ @optional_fields) |> cast_embed(:location, with: &Location.changeset/2) - |> cast_attachments(attrs, [:image]) |> validate_required(@required_fields) |> validate_dates() |> validate_entries() |> validate_enrollments() |> check_constraint(:enrolled, name: :enrolled_less_than_max) |> maybe_mark_for_deletion() - |> maybe_put_speakers(attrs) end def image_changeset(activity, attrs) do @@ -157,14 +147,4 @@ defmodule Atomic.Activities.Activity do changeset end end - - defp maybe_put_speakers(changeset, attrs) do - if attrs["speakers"] do - speakers = Activities.get_speakers(attrs["speakers"]) - - Ecto.Changeset.put_assoc(changeset, :speakers, speakers) - else - changeset - end - end end diff --git a/lib/atomic/activities/activity_speaker.ex b/lib/atomic/activities/activity_speaker.ex deleted file mode 100644 index 6b19dc362..000000000 --- a/lib/atomic/activities/activity_speaker.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule Atomic.Activities.ActivitySpeaker do - @moduledoc """ - An activity speaker - """ - use Atomic.Schema - - alias Atomic.Activities.Activity - alias Atomic.Activities.Speaker - - @required_fields ~w(activity_id speaker_id)a - - schema "activity_speakers" do - belongs_to :activity, Activity - belongs_to :speaker, Speaker - - timestamps() - end - - def changeset(activity_speakers, attrs) do - activity_speakers - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/activities/activity_enrollment.ex b/lib/atomic/activities/enrollment.ex similarity index 87% rename from lib/atomic/activities/activity_enrollment.ex rename to lib/atomic/activities/enrollment.ex index af564f325..4284f7f94 100644 --- a/lib/atomic/activities/activity_enrollment.ex +++ b/lib/atomic/activities/enrollment.ex @@ -1,4 +1,4 @@ -defmodule Atomic.Activities.ActivityEnrollment do +defmodule Atomic.Activities.Enrollment do @moduledoc """ An activity enrollment. """ @@ -11,7 +11,7 @@ defmodule Atomic.Activities.ActivityEnrollment do @required_fields ~w(activity_id user_id)a @optional_fields ~w(present)a - schema "activity_enrollments" do + schema "enrollments" do field :present, :boolean, default: false belongs_to :activity, Activity @@ -33,7 +33,6 @@ defmodule Atomic.Activities.ActivityEnrollment do |> validate_required(@required_fields) end - # Validates if the maximum number of enrollments has been reached. defp validate_maximum_entries(changeset) do activity_id = get_field(changeset, :activity_id) activity = Activities.get_activity!(activity_id) diff --git a/lib/atomic/activities/speaker.ex b/lib/atomic/activities/speaker.ex deleted file mode 100644 index 7dd3877b8..000000000 --- a/lib/atomic/activities/speaker.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Atomic.Activities.Speaker do - @moduledoc """ - The person who speaks and provides the activity - """ - use Atomic.Schema - - alias Atomic.Activities.Activity - alias Atomic.Activities.ActivitySpeaker - alias Atomic.Organizations.Organization - - @required_fields ~w(name bio organization_id)a - - schema "speakers" do - field :name, :string - field :bio, :string - - many_to_many :activities, Activity, join_through: ActivitySpeaker - belongs_to :organization, Organization, on_replace: :delete_if_exists - - timestamps() - end - - def changeset(speaker, attrs) do - speaker - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/board.ex b/lib/atomic/board.ex deleted file mode 100644 index b37cf65c6..000000000 --- a/lib/atomic/board.ex +++ /dev/null @@ -1,289 +0,0 @@ -defmodule Atomic.Board do - @moduledoc """ - The Boards context. - """ - use Atomic.Context - - alias Atomic.Organizations.Board - alias Atomic.Organizations.BoardDepartments - alias Atomic.Organizations.UserOrganization - - @doc """ - Returns the list of boards. - - ## Examples - - iex> list_boards() - [%Board{}, ...] - - """ - def list_boards do - Repo.all(Board) - end - - @doc """ - Returns the list of boards belonging to an organization. - - ## Examples - - iex> list_boards_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") - [%Board{}, ...] - - """ - def list_boards_by_organization_id(id) do - Repo.all(from d in Board, where: d.organization_id == ^id) - end - - @doc """ - Returns the list of boards in a list of given ids. - - ## Examples - - iex> get_boards([ - ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621", - ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621" - ...> ]) - [%Board{}, ...] - - iex> get_boards(nil) - [] - """ - def get_boards(nil), do: [] - - def get_boards(ids) do - Repo.all(from d in Board, where: d.id in ^ids) - end - - @doc """ - Gets a single board. - - Raises `Ecto.NoResultsError` if the Board does not exist. - - ## Examples - - iex> get_board!(123) - %Board{} - - iex> get_board!(456) - ** (Ecto.NoResultsError) - - """ - def get_board!(id, opts \\ []) do - Board - |> apply_filters(opts) - |> Repo.get!(id) - end - - @doc """ - Creates a board. - - ## Examples - - iex> create_board(%{field: value}) - {:ok, %Board{}} - - iex> create_board(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_board(attrs \\ %{}) do - %Board{} - |> Board.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a board. - - ## Examples - - iex> update_board(board, %{field: new_value}) - {:ok, %Board{}} - - iex> update_board(board, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_board(%Board{} = board, attrs) do - board - |> Board.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a board. - - ## Examples - - iex> delete_board(board) - {:ok, %Board{}} - - iex> delete_board(board) - {:error, %Ecto.Changeset{}} - - """ - def delete_board(%Board{} = board) do - Repo.delete(board) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking board changes. - - ## Examples - - iex> change_board(board) - %Ecto.Changeset{data: %Board{}} - - """ - def change_board(%Board{} = board, attrs \\ %{}) do - Board.changeset(board, attrs) - end - - def get_organization_board_by_year(year, organization_id) do - Repo.get_by(Board, year: year, organization_id: organization_id) - end - - @doc """ - Returns the list of board_departments. - - ## Examples - - iex> list_board_departments() - [%BoardDepartments{}, ...] - - """ - def list_board_departments do - Repo.all(BoardDepartments) - end - - @doc """ - Returns the list of board_departments belonging to an organization. - - ## Examples - - iex> list_board_departments_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") - [%BoardDepartments{}, ...] - - """ - def list_board_departments_by_organization_id(id) do - Repo.all(from d in BoardDepartments, where: d.organization_id == ^id) - end - - @doc """ - Returns the list of board_departments in a list of given ids. - - ## Examples - - iex> get_board_departments([ - ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621", - ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621" - ...> ]) - [%BoardDepartments{}, ...] - - iex> get_board_departments(nil) - [] - """ - def get_board_departments(nil), do: [] - - def get_board_departments(ids) do - Repo.all(from d in BoardDepartments, where: d.id in ^ids) - end - - def get_board_departments_by_board_id(board_id, _preloads \\ []) do - Repo.all(from d in BoardDepartments, where: d.board_id == ^board_id) - |> Enum.sort_by(& &1.priority) - end - - def get_board_department_users(board_departments_id, opts \\ []) do - UserOrganization - |> where([u], u.board_departments_id == ^board_departments_id) - |> order_by([u], u.priority) - |> apply_filters(opts) - |> Repo.all() - end - - @doc """ - Gets a single board_departments. - - Raises `Ecto.NoResultsError` if the BoardDepartments does not exist. - - ## Examples - - iex> get_board_department!(123) - %BoardDepartments{} - - iex> get_board_department!(456) - ** (Ecto.NoResultsError) - - """ - def get_board_department!(id, opts \\ []) do - BoardDepartments - |> apply_filters(opts) - |> Repo.get!(id) - end - - @doc """ - Creates a board_departments. - - ## Examples - - iex> create_board_department(%{field: value}) - {:ok, %BoardDepartments{}} - - iex> create_board_department(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_board_department(attrs \\ %{}) do - %BoardDepartments{} - |> BoardDepartments.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a board_departments. - - ## Examples - - iex> update_board_department(board_departments, %{field: new_value}) - {:ok, %BoardDepartments{}} - - iex> update_board_department(board_departments, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_board_department(%BoardDepartments{} = board_departments, attrs) do - board_departments - |> BoardDepartments.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a board_departments. - - ## Examples - - iex> delete_board_department(board_departments) - {:ok, %BoardDepartments{}} - - iex> delete_board_department(board_departments) - {:error, %Ecto.Changeset{}} - - """ - def delete_board_department(%BoardDepartments{} = board_departments) do - Repo.delete(board_departments) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking board_departments changes. - - ## Examples - - iex> change_board_department(board_departments) - %Ecto.Changeset{data: %BoardDepartments{}} - - """ - def change_board_department(%BoardDepartments{} = board_departments, attrs \\ %{}) do - BoardDepartments.changeset(board_departments, attrs) - end -end diff --git a/lib/atomic/ecto/year.ex b/lib/atomic/ecto/year.ex deleted file mode 100644 index ab135b060..000000000 --- a/lib/atomic/ecto/year.ex +++ /dev/null @@ -1,157 +0,0 @@ -defmodule Atomic.Ecto.Year do - @moduledoc """ - Type for storing school years (2019/2020 e.g.) - """ - use Ecto.Type - - @spec type :: :string - def type, do: :string - - @doc """ - Transforms external data into a runtime format. - - ## Parameters - - year: valid year in a string format (yyyy/yyyy) - - ## Examples - - iex> Year.cast("2019/2020") - {:ok, "2019/2020"} - - iex> Year.cast("2019-2020") - {:error, [message: "Invalid string format"]} - - iex> Year.cast("2019-2021") - {:error, [message: gettext("Second year is not the first + 1")]} - - """ - def cast(year), do: format(year) - - @doc """ - Transforms the data into a specific format to be stored - - ## Parameters - - year: valid year in a string format (yyyy/yyyy) - """ - def dump(year), do: format(year) |> parse_result() - - @doc """ - Transforms the data back to a runtime format - - ## Parameters - - year: valid year in a string format - """ - def load(year), do: format(year) |> parse_result() - - def format(year) when not is_binary(year), do: {:error, :invalid_input} - - def format(year) do - case Regex.named_captures(~r/\A(?\d{4})\/(?\d{4})\z/, year) do - %{"first" => first_str, "second" => second_str} -> - {first, _} = Integer.parse(first_str) - {second, _} = Integer.parse(second_str) - - case second - first do - 1 -> {:ok, year} - _ -> {:error, :year_mismatch} - end - - nil -> - {:error, :invalid_format} - end - end - - @doc """ - Returns the current academic year - - ## Examples - - iex> current_year() - "2022/2023" - """ - @spec current_year() :: String.t() - def current_year do - now = Date.utc_today() - start_year = calculate_academic_start_year(now) - - "#{start_year}/#{start_year + 1}" - end - - @doc """ - Returns the start year of the academic year of a given date - - ## Examples - - iex> calculate_academic_start_year(~D[2020-01-01]) - 2019 - - iex> calculate_academic_start_year(~D[2020-09-01]) - 2020 - - iex> calculate_academic_start_year(~D[2022-05-31]) - 2021 - - iex> calculate_academic_start_year(~D[2022-08-31]) - 2021 - - iex> calculate_academic_start_year(~D[2023-12-05]) - 2023 - """ - @spec calculate_academic_start_year(Date.t()) :: integer() - def calculate_academic_start_year(date) do - current_year = date.year - next_year = current_year + 1 - - academic_year_start = Timex.parse!("01-09-#{current_year}", "{0D}-{0M}-{YYYY}") - academic_year_end = Timex.parse!("31-08-#{next_year}", "{0D}-{0M}-{YYYY}") - - if Timex.between?(date, academic_year_start, academic_year_end, inclusive: true) do - current_year - else - current_year - 1 - end - end - - @doc """ - Returns the next academic year - - ## Examples - - iex> next_year("2020/2021") - "2021/2022" - - iex> next_year("2021/2022") - "2022/2023" - """ - @spec next_year(String.t()) :: String.t() - def next_year(year) do - year - |> String.split("/") - |> Enum.map(fn x -> String.to_integer(x) end) - |> Enum.map(fn x -> x + 1 end) - |> Enum.map_join("/", fn x -> Integer.to_string(x) end) - end - - @doc """ - Returns the previous academic year - - ## Examples - - iex> previous_year("2020/2021") - "2019/2020" - - iex> previous_year("2021/2022") - "2020/2021" - """ - @spec previous_year(String.t()) :: String.t() - def previous_year(year) do - year - |> String.split("/") - |> Enum.map(fn x -> String.to_integer(x) end) - |> Enum.map(fn x -> x - 1 end) - |> Enum.map_join("/", fn x -> Integer.to_string(x) end) - end - - defp parse_result({:ok, _year} = result), do: result - defp parse_result({:error, _errors}), do: :error -end diff --git a/lib/atomic/events/event.ex b/lib/atomic/events/event.ex deleted file mode 100644 index 6c9da7363..000000000 --- a/lib/atomic/events/event.ex +++ /dev/null @@ -1,31 +0,0 @@ -defmodule Atomic.Events.Event do - @moduledoc false - use Atomic.Schema - - alias Atomic.Activities.Activity - alias Atomic.Events.EventEnrollment - alias Atomic.Events.EventOrganization - alias Atomic.Location - - @required_fields ~w(name location_id)a - @optional_fields ~w(description event_organization_id)a - - schema "events" do - field :name, :string - field :description, :string - - belongs_to :event_organization, EventOrganization - embeds_one :location, Location, on_replace: :delete - - has_many :activities, Activity - has_many :enrollments, EventEnrollment - - timestamps() - end - - def changeset(events, attrs) do - events - |> cast(attrs, @required_fields ++ @optional_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/events/event_enrollment.ex b/lib/atomic/events/event_enrollment.ex deleted file mode 100644 index bf563733f..000000000 --- a/lib/atomic/events/event_enrollment.ex +++ /dev/null @@ -1,27 +0,0 @@ -defmodule Atomic.Events.EventEnrollment do - @moduledoc """ - An event enrollment. - """ - use Atomic.Schema - - alias Atomic.Accounts.User - alias Atomic.Events.Event - - @required_fields ~w(event_id user_id) - @optional_fields ~w(present) - - schema "event_enrollments" do - field :present, :boolean - - belongs_to :event, Event - belongs_to :user, User - - timestamps() - end - - def changeset(enrollment, attrs) do - enrollment - |> cast(attrs, @required_fields ++ @optional_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/events/event_organization.ex b/lib/atomic/events/event_organization.ex deleted file mode 100644 index 377288995..000000000 --- a/lib/atomic/events/event_organization.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule Atomic.Events.EventOrganization do - @moduledoc false - use Atomic.Schema - - alias Atomic.Events.Event - alias Atomic.Organizations.Organization - - @required_fields ~w(event_id organization_id)a - - schema "event_organizations" do - belongs_to :event, Event - belongs_to :organization, Organization - - timestamps() - end - - def changeset(event_organization, attrs) do - event_organization - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/exporter.ex b/lib/atomic/exporter.ex deleted file mode 100644 index 750ab0ace..000000000 --- a/lib/atomic/exporter.ex +++ /dev/null @@ -1,122 +0,0 @@ -defmodule Atomic.Exporter do - @moduledoc """ - - Utilities for tabular data exporting. - Supports csv and xlsx formats. - - """ - - alias Elixlsx.{Sheet, Workbook} - - @doc """ - Builds a csv formatted string with the data in the entities list. - - ## Examples - - iex> entities_to_csv([%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], [ - ...> [:name], - ...> [:age] - ...> ]) - "name,age\\nJohn Doe,23\\nJane Doe,25" - - iex> entities_to_csv([%{name: "John Doe", age: 23, dog: %{name: "Cooper", breed: "Beagle"}}], [ - ...> [:name], - ...> [:dog, :breed] - ...> ]) - "name,breed\\nJohn Doe,Beagle" - """ - def entities_to_csv(entities, columns) do - data = - ([Enum.map_join(columns, ",", fn col -> List.last(col) end)] ++ - (entities - |> Enum.map(fn entity -> - extract_entity_values(entity, columns) - |> Enum.join(",") - end))) - |> Enum.intersperse("\n") - |> to_string() - - data - end - - @doc """ - Builds an xlsx workbook containing a sheet with the data in the entities list. - - ## Examples - - iex> entities_to_xlsx_workbook( - ...> [%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], - ...> [[[:name], 20], [[:age], 10]], - ...> [], - ...> "People" - ...> ) - %Elixlsx.Workbook{ - sheets: [ - %Elixlsx.Sheet{ - name: "People", - rows: [[["Name"], ["Age"]], ["John Doe", 23], ["Jane Doe", 25]], - col_widths: %{1 => 20, 2 => 10}, - row_heights: %{}, - group_cols: [], - group_rows: [], - merge_cells: [], - pane_freeze: {1, 2}, - show_grid_lines: true - } - ], - datetime: nil - } - """ - def entities_to_xlsx_workbook(entities, columns, header_styles, sheet_name) do - paths = columns |> Enum.map(fn column -> List.first(column) end) - sizes = columns |> Enum.map(fn column -> List.last(column) end) - - column_widths = - 1..length(sizes) - |> Enum.zip(sizes) - |> Map.new() - - sheet = - %Sheet{ - name: sheet_name, - rows: - [ - Enum.map(paths, fn column -> - [column |> List.last() |> format_atom() | header_styles] - end) - ] ++ - Enum.map(entities, fn entity -> - Enum.map(extract_entity_values(entity, paths), &value_to_excel/1) - end) - } - |> Sheet.set_pane_freeze(1, length(columns)) - |> Map.replace(:col_widths, column_widths) - - %Workbook{sheets: [sheet]} - end - - defp extract_entity_values(entity, columns) do - Enum.map(columns, fn col -> - List.foldl(col, entity, fn key, object -> Map.get(object, key) end) - end) - end - - defp format_atom(key) do - key - |> to_string() - |> String.split("_") - |> Enum.map_join(" ", &String.capitalize/1) - end - - defp value_to_excel(%NaiveDateTime{} = date) do - [datetime_to_excel(date), datetime: true] - end - - defp value_to_excel(value) do - value - end - - defp datetime_to_excel(date) do - {{date.year, date.month, date.day}, {date.hour, date.minute, date.second}} - end -end diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index ce2db2e13..98f23f588 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -6,7 +6,9 @@ defmodule Atomic.Organizations do alias Atomic.Accounts.User alias Atomic.Feed.Post - alias Atomic.Organizations.{Announcement, Membership, Organization, UserOrganization} + alias Atomic.Organizations.{Announcement, Membership, Organization} + + ## Organizations @doc """ Returns the list of organizations. @@ -204,24 +206,6 @@ defmodule Atomic.Organizations do |> Repo.update() end - @doc """ - Updates an organization card image. - - ## Examples - - iex> update_card_image(organization, %{card_image: new_value}) - {:ok, %Organization{}} - - iex> update_card_image(organization, %{card_image: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_card_image(%Organization{} = organization, attrs) do - organization - |> Organization.card_changeset(attrs) - |> Repo.update() - end - @doc """ Deletes a organization. @@ -251,6 +235,8 @@ defmodule Atomic.Organizations do Organization.changeset(organization, attrs) end + ## Memberships + @doc """ Creates a membership. @@ -297,14 +283,6 @@ defmodule Atomic.Organizations do |> Repo.all() end - def list_display_memberships(%{} = flop, opts \\ []) do - Membership - |> join(:left, [o], p in assoc(o, :user), as: :user) - |> where([a], a.role != :follower) - |> apply_filters(opts) - |> Flop.validate_and_run(flop, for: Membership) - end - @doc """ Verifies if an user is a member of an organization. @@ -331,9 +309,6 @@ defmodule Atomic.Organizations do iex> get_role(user_id, organization_id) :follower - iex> get_role(user_id, organization_id) - :member - iex> get_role(user_id, organization_id) :admin @@ -447,33 +422,17 @@ defmodule Atomic.Organizations do Membership.changeset(membership, attrs) end - @doc """ - Returns all roles lower or equal to the given role. - - Follower is not considered a role for the purposes of this function - - ## Examples - - iex> roles_less_than_or_equal(:member) - [:member] - - """ - def roles_less_than_or_equal(role) do - [:follower, :member, :admin, :owner] - |> Enum.drop_while(fn elem -> elem != role end) - end - @doc """ Returns all roles bigger or equal to the given role. ## Examples - iex> roles_bigger_than_or_equal(:member) - [:member, :admin, :owner] + iex> roles_bigger_than_or_equal(:follower) + [:follower, :admin, :owner] """ def roles_bigger_than_or_equal(role) do - [:follower, :member, :admin, :owner] + Membership.roles() |> Enum.drop_while(fn elem -> elem != role end) end @@ -494,109 +453,6 @@ defmodule Atomic.Organizations do |> Repo.aggregate(:count, :id) end - @doc """ - Returns the list of users organizations. - - ## Examples - - iex> list_users_organizations() - [%UserOrganization{}, ...] - - iex> list_users_organizations() - [%UserOrganization{}, ...] - - """ - def list_users_organizations(opts \\ [], preloads \\ []) do - UserOrganization - |> apply_filters(opts) - |> Repo.all() - |> Repo.preload(preloads) - end - - @doc """ - Gets a single user organization. - - Raises `Ecto.NoResultsError` if the user organization does not exist. - - ## Examples - - iex> get_user_organization!(123) - %UserOrganization{} - - iex> get_user_organization!(456) - ** (Ecto.NoResultsError) - - """ - def get_user_organization!(id, preloads \\ []) do - Repo.get!(UserOrganization, id) - |> Repo.preload(preloads) - end - - @doc """ - Creates an user organization. - - ## Examples - - iex> create_user_organization(%{field: value}) - {:ok, %UserOrganization{}} - - iex> create_user_organization(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_user_organization(attrs) do - %UserOrganization{} - |> UserOrganization.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates an user organization. - - ## Examples - - iex> update_user_organization(user_organization, %{field: new_value}) - {:ok, %UserOrganization{}} - - iex> update_user_organization(user_organization, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_user_organization(%UserOrganization{} = user_organization, attrs) do - user_organization - |> UserOrganization.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes an user organization. - - ## Examples - - iex> delete_user_organization(user_organization) - {:ok, %UserOrganization{}} - - iex> delete_user_organization(user_organization) - {:error, %Ecto.Changeset{}} - - """ - def delete_user_organization(%UserOrganization{} = user_organization) do - Repo.delete(user_organization) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking user_organization changes. - - ## Examples - - iex> change_user_organization(user_organization) - %Ecto.Changeset{data: %UserOrganization{}} - - """ - def change_user_organization(%UserOrganization{} = user_organization, attrs \\ %{}) do - UserOrganization.changeset(user_organization, attrs) - end - @doc """ Returns the amount of members in an organization. diff --git a/lib/atomic/organizations/announcement.ex b/lib/atomic/organizations/announcement.ex index f0162fde2..e9068b7d9 100644 --- a/lib/atomic/organizations/announcement.ex +++ b/lib/atomic/organizations/announcement.ex @@ -8,7 +8,7 @@ defmodule Atomic.Organizations.Announcement do alias Atomic.Organizations.Organization @required_fields ~w(title description organization_id)a - @optional_fields ~w(image)a + @optional_fields ~w()a @derive { Flop.Schema, diff --git a/lib/atomic/organizations/board.ex b/lib/atomic/organizations/board.ex deleted file mode 100644 index a62179c26..000000000 --- a/lib/atomic/organizations/board.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Atomic.Organizations.Board do - @moduledoc false - use Atomic.Schema - - alias Atomic.Ecto.Year - alias Atomic.Organizations.BoardDepartments - alias Atomic.Organizations.Organization - - @required_fields ~w(year organization_id)a - - schema "boards" do - field :year, Year - has_many :board_departments, BoardDepartments - - belongs_to :organization, Organization - - timestamps() - end - - def changeset(board, attrs) do - board - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/organizations/board_departments.ex b/lib/atomic/organizations/board_departments.ex deleted file mode 100644 index 3a1a3de5d..000000000 --- a/lib/atomic/organizations/board_departments.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Atomic.Organizations.BoardDepartments do - @moduledoc false - use Atomic.Schema - - alias Atomic.Organizations.Board - alias Atomic.Organizations.UserOrganization - - @required_fields ~w(name board_id priority)a - - schema "board_departments" do - field :name, :string - field :priority, :integer - - belongs_to :board, Board - has_many :user_organization, UserOrganization - - timestamps() - end - - def changeset(board_departments, attrs) do - board_departments - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/organizations/card.ex b/lib/atomic/organizations/card.ex deleted file mode 100644 index 98a5ea5b3..000000000 --- a/lib/atomic/organizations/card.ex +++ /dev/null @@ -1,36 +0,0 @@ -defmodule Atomic.Organizations.Card do - @moduledoc """ - The membership card for an organization - """ - use Atomic.Schema - import Ecto.Changeset - - @optional_fields ~w( - name_size - name_color - name_x - name_y - number_size - number_color - number_x - number_y - )a - - @derive Jason.Encoder - @primary_key false - embedded_schema do - field :name_size, :float - field :name_color, :string - field :name_x, :float - field :name_y, :float - field :number_size, :float - field :number_color, :string - field :number_x, :float - field :number_y, :float - end - - def changeset(card, attrs) do - card - |> cast(attrs, @optional_fields) - end -end diff --git a/lib/atomic/organizations/department.ex b/lib/atomic/organizations/department.ex index 831e7d012..6bc379e0a 100644 --- a/lib/atomic/organizations/department.ex +++ b/lib/atomic/organizations/department.ex @@ -1,8 +1,9 @@ defmodule Atomic.Organizations.Department do @moduledoc """ - A department of an organization + A department of an organization. """ use Atomic.Schema + alias Atomic.Organizations.Organization @required_fields ~w(name organization_id)a @@ -11,10 +12,12 @@ defmodule Atomic.Organizations.Department do schema "departments" do field :name, :string field :description, :string - field :banner, Atomic.Uploaders.Banner.Type + field :collaborator_applications, :boolean, default: false field :archived, :boolean, default: false + field :banner, Atomic.Uploaders.Banner.Type + belongs_to :organization, Organization, on_replace: :delete_if_exists timestamps() diff --git a/lib/atomic/organizations/membership.ex b/lib/atomic/organizations/membership.ex index 05f4eaab3..192e86f83 100644 --- a/lib/atomic/organizations/membership.ex +++ b/lib/atomic/organizations/membership.ex @@ -1,41 +1,29 @@ defmodule Atomic.Organizations.Membership do - @moduledoc false + @moduledoc """ + Schema representing a user's membership in an organization. + + Memberships are used to track the relationship between a user and an organization. + + Types of memberships: + * `owner` - The user has full control over the organization. + * `admin` - The user can only control the organization's departments. + * `follower` - The user is following the organization. + + This schema can be further extended to include additional roles, such as `member`. + """ use Atomic.Schema alias Atomic.Accounts.User alias Atomic.Organizations.Organization - @required_fields ~w(user_id organization_id created_by_id role)a - @optional_fields ~w(number)a - - @roles ~w(follower member admin owner)a - - @export_fields [ - [[:number], 10], - [[:user, :name], 40], - [[:user, :phone_number], 20], - [[:user, :email], 30], - [[:user, :inserted_at], 30] - ] - - @derive { - Flop.Schema, - filterable: [:member_name, :inserted_at], - sortable: [:member_name, :inserted_at, :updated_at, :number], - default_order: %{ - order_by: [:inserted_at], - order_directions: [:desc] - }, - join_fields: [ - member_name: [binding: :user, field: :name, path: [:user, :name]] - ] - } + @required_fields ~w(user_id organization_id role)a + @optional_fields ~w()a + + @roles ~w(follower admin owner)a schema "memberships" do - field :number, :integer, read_after_writes: true field :role, Ecto.Enum, values: @roles - belongs_to :created_by, User belongs_to :user, User belongs_to :organization, Organization @@ -48,5 +36,5 @@ defmodule Atomic.Organizations.Membership do |> validate_required(@required_fields) end - def export_fields, do: @export_fields + def roles, do: @roles end diff --git a/lib/atomic/organizations/organization.ex b/lib/atomic/organizations/organization.ex index 0114e0507..9db7602bb 100644 --- a/lib/atomic/organizations/organization.ex +++ b/lib/atomic/organizations/organization.ex @@ -4,11 +4,11 @@ defmodule Atomic.Organizations.Organization do alias Atomic.Accounts.User alias Atomic.Location - alias Atomic.Organizations.{Announcement, Board, Card, Department, Membership, Partner} + alias Atomic.Organizations.{Announcement, Department, Membership, Partner} alias Atomic.Uploaders @required_fields ~w(name long_name description)a - @optional_fields ~w(card_image logo)a + @optional_fields ~w()a @derive { Flop.Schema, @@ -25,35 +25,25 @@ defmodule Atomic.Organizations.Organization do field :name, :string field :long_name, :string field :description, :string - field :card_image, Uploaders.Card.Type + field :logo, Uploaders.Logo.Type + embeds_one :location, Location, on_replace: :delete has_many :departments, Department, on_replace: :delete_if_exists, on_delete: :delete_all, - foreign_key: :organization_id, preload_order: [asc: :name] - many_to_many :users, User, join_through: Membership - has_many :partners, Partner, on_replace: :delete_if_exists, on_delete: :delete_all, - foreign_key: :organization_id, preload_order: [asc: :name] - embeds_one :location, Location, on_replace: :delete - embeds_one :card, Card, on_replace: :delete - has_many :announcements, Announcement, on_replace: :delete, preload_order: [asc: :inserted_at] - has_many :boards, Board, - on_replace: :delete_if_exists, - on_delete: :delete_all, - foreign_key: :organization_id, - preload_order: [asc: :year] + many_to_many :users, User, join_through: Membership timestamps() end @@ -62,18 +52,10 @@ defmodule Atomic.Organizations.Organization do organization |> cast(attrs, @required_fields ++ @optional_fields) |> cast_embed(:location, with: &Location.changeset/2) - |> cast_embed(:card, with: &Card.changeset/2) - |> cast_attachments(attrs, [:card_image, :logo]) |> validate_required(@required_fields) |> unique_constraint(:name) end - def card_changeset(organization, attrs) do - organization - |> cast_attachments(attrs, [:card_image]) - |> cast_embed(:card, with: &Card.changeset/2) - end - def logo_changeset(organization, attrs) do organization |> cast_attachments(attrs, [:logo]) diff --git a/lib/atomic/organizations/partner.ex b/lib/atomic/organizations/partner.ex index a99474278..1da523918 100644 --- a/lib/atomic/organizations/partner.ex +++ b/lib/atomic/organizations/partner.ex @@ -1,6 +1,6 @@ defmodule Atomic.Organizations.Partner do @moduledoc """ - A partnership between an organization and a partner. + Schema representing a partner of an organization. """ use Atomic.Schema @@ -25,14 +25,16 @@ defmodule Atomic.Organizations.Partner do schema "partners" do field :name, :string field :description, :string + field :notes, :string + field :benefits, :string field :archived, :boolean, default: false field :image, Uploaders.PartnerImage.Type + embeds_one :location, Location, on_replace: :update embeds_one :socials, Socials, on_replace: :update - belongs_to :organization, Organization - field :notes, :string + belongs_to :organization, Organization timestamps() end @@ -42,7 +44,6 @@ defmodule Atomic.Organizations.Partner do |> cast(attrs, @required_fields ++ @optional_fields) |> cast_embed(:location, with: &Location.changeset/2) |> cast_embed(:socials, with: &Socials.changeset/2) - |> cast_attachments(attrs, [:image]) |> validate_required(@required_fields) |> unique_constraint(:name) end diff --git a/lib/atomic/organizations/users_organizations.ex b/lib/atomic/organizations/users_organizations.ex deleted file mode 100644 index 55b6939af..000000000 --- a/lib/atomic/organizations/users_organizations.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Atomic.Organizations.UserOrganization do - @moduledoc false - use Atomic.Schema - - alias Atomic.Accounts.User - alias Atomic.Organizations.BoardDepartments - - @required_fields ~w(role priority user_id board_departments_id)a - - schema "users_organizations" do - field :role, :string - field :priority, :integer - - belongs_to :user, User - belongs_to :board_departments, BoardDepartments - - timestamps() - end - - def changeset(user_organization, attrs) do - user_organization - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - end -end diff --git a/lib/atomic/quantum/certificate_delivery.ex b/lib/atomic/quantum/certificate_delivery.ex index 726a6d47a..373f7d621 100644 --- a/lib/atomic/quantum/certificate_delivery.ex +++ b/lib/atomic/quantum/certificate_delivery.ex @@ -16,7 +16,7 @@ defmodule Atomic.Quantum.CertificateDelivery do alias Atomic.Mailer alias Atomic.Repo - alias Atomic.Activities.{Activity, ActivityEnrollment} + alias Atomic.Activities.{Activity, Enrollment} alias Atomic.Organizations.Organization alias AtomicWeb.ActivityEmails @@ -66,7 +66,7 @@ defmodule Atomic.Quantum.CertificateDelivery do # It uses `wkhtmltopdf` to build it from an HTML template, which # is rendered beforehand. defp generate_certificate( - %ActivityEnrollment{} = enrollment, + %Enrollment{} = enrollment, %Activity{} = activity, %Organization{} = organization ) do @@ -127,7 +127,7 @@ defmodule Atomic.Quantum.CertificateDelivery do defp included_enrollments do enrollments = from s in subquery(last_activities_query()), - inner_join: e in ActivityEnrollment, + inner_join: e in Enrollment, on: e.activity_id == s.activity_id, where: e.present, select: e diff --git a/lib/atomic/uploaders/card.ex b/lib/atomic/uploaders/card.ex deleted file mode 100644 index 2023ff8e8..000000000 --- a/lib/atomic/uploaders/card.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule Atomic.Uploaders.Card do - @moduledoc """ - Uploader for organization membership cards. - """ - use Atomic.Uploader - alias Atomic.Organizations.Organization - - def storage_dir(_version, {_file, %Organization{} = scope}) do - "uploads/atomic/cards/#{scope.id}" - end -end diff --git a/lib/atomic_web/components/board.ex b/lib/atomic_web/components/board.ex deleted file mode 100644 index c60064ec2..000000000 --- a/lib/atomic_web/components/board.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule AtomicWeb.Components.Board do - @moduledoc false - use AtomicWeb, :component - - import AtomicWeb.Components.Avatar - - attr :user_organization, :map, required: true - - def member_bubble(assigns) do - ~H""" -
- <.avatar class="mx-auto" color={:light_gray} name={@user_organization.user.name} size={:xl} src={Uploaders.ProfilePicture.url({@user_organization.user.profile_picture, @user_organization.user}, :original)} /> -
-

<%= @user_organization.user.name %>

-

- <%= @user_organization.role %> -

-
-
- """ - end -end diff --git a/lib/atomic_web/components/calendar/month.ex b/lib/atomic_web/components/calendar/month.ex index 099035708..6717e6ba5 100644 --- a/lib/atomic_web/components/calendar/month.ex +++ b/lib/atomic_web/components/calendar/month.ex @@ -137,7 +137,7 @@ defmodule AtomicWeb.Components.CalendarMonth do <%= @text %> <%= if (activities = get_date_activities(@activities, @date)) != [] do %> - Enum.count(activities) events + <%= Enum.count(activities) %> events <%= for activity <- activities do %> <%= if activity do %> diff --git a/lib/atomic_web/components/multi_select.ex b/lib/atomic_web/components/multi_select.ex deleted file mode 100644 index 97e19960e..000000000 --- a/lib/atomic_web/components/multi_select.ex +++ /dev/null @@ -1,83 +0,0 @@ -defmodule AtomicWeb.Components.MultiSelect do - @moduledoc """ - A multi-select component that allows you to select multiple items from a list. - The component attributes are: - @items - a list of items to be displayed in the dropdown in the format of %{id: id, label: label, selected: selected} - @selected_items - the number of items selected - @target - the target to send the event to - - The component events are: - toggle-option - toggles the selected state of an item. This event should be defined in the component that you passed in the @target attribute. - """ - - use AtomicWeb, :live_component - alias Phoenix.LiveView.JS - - def render(assigns) do - ~H""" -
-
- - Speakers - -
- - - -
-
-
- """ - end -end diff --git a/lib/atomic_web/config.ex b/lib/atomic_web/config.ex index 07970498f..72503fd54 100644 --- a/lib/atomic_web/config.ex +++ b/lib/atomic_web/config.ex @@ -53,14 +53,7 @@ defmodule AtomicWeb.Config do key: :memberships, title: "Memberships", icon: :user_plus, - url: Routes.membership_index_path(conn, :index, current_organization.id), - tabs: [] - }, - %{ - key: :board, - title: "Board", - icon: :users, - url: Routes.board_index_path(conn, :index, current_organization.id), + url: Routes.home_index_path(conn, :index), tabs: [] }, %{ diff --git a/lib/atomic_web/controllers/data_export_controller.ex b/lib/atomic_web/controllers/data_export_controller.ex deleted file mode 100644 index 800d55a08..000000000 --- a/lib/atomic_web/controllers/data_export_controller.ex +++ /dev/null @@ -1,79 +0,0 @@ -defmodule AtomicWeb.DataExportController do - use AtomicWeb, :controller - - alias Atomic.Exporter - alias Atomic.Organizations - alias Atomic.Organizations.Membership - - # Generic excel header styling - @header_styles [ - align_horizontal: :center, - bold: true, - size: 12, - color: "#ffffff", - bg_color: "#ff9900" - ] - - @doc """ - Returns an organization's memberships as a csv file. - """ - def export_memberships_csv(conn, %{"organization_id" => organization_id}) do - case write_memberships_csv(organization_id) do - {:ok, data} -> - conn - |> put_resp_content_type("text/csv") - |> put_resp_header("content-disposition", "attachment; filename=\"memberships.csv\"") - |> put_root_layout(false) - |> send_resp(200, data) - end - end - - @doc """ - Returns an organization's memberships as a formatted - xlsx workbook. - - The generated workbook only contains one sheet displaying - the organization's memberships. - In the occurence of an error when writing the document - to memory it returns a 500 response with an explanation. - """ - def export_memberships_xlsx(conn, %{"organization_id" => organization_id}) do - case write_memberships_xlsx(organization_id) do - {:ok, data} -> - conn - |> put_resp_content_type("text/xlsx") - |> put_resp_header("content-disposition", "attachment; filename=\"memberships.xlsx\"") - |> put_root_layout(false) - |> send_resp(200, data) - - {:error, reason} -> - conn |> send_resp(500, "Internal Server Error: #{reason}") - end - end - - defp write_memberships_csv(organization_id) do - {:ok, - Organizations.list_memberships(%{"organization_id" => organization_id}, [:user]) - |> Exporter.entities_to_csv( - Membership.export_fields() - |> Enum.map(fn column -> List.first(column) end) - )} - end - - defp write_memberships_xlsx(organization_id) do - memberships = Organizations.list_memberships(%{"organization_id" => organization_id}, [:user]) - organization = Organizations.get_organization!(organization_id) - sheet_name = String.slice(organization.name, 0..15) <> "'s Memberships" - - case Exporter.entities_to_xlsx_workbook( - memberships, - Membership.export_fields(), - @header_styles, - sheet_name - ) - |> Elixlsx.write_to_memory("memberships-#{organization_id}.xlsx") do - {:ok, {_, data}} -> {:ok, data} - {:error, reason} -> {:error, to_string(reason)} - end - end -end diff --git a/lib/atomic_web/controllers/user_registration_controller.ex b/lib/atomic_web/controllers/user_registration_controller.ex index 6e2595410..b12615add 100644 --- a/lib/atomic_web/controllers/user_registration_controller.ex +++ b/lib/atomic_web/controllers/user_registration_controller.ex @@ -9,7 +9,7 @@ defmodule AtomicWeb.UserRegistrationController do conn = conn - |> assign(:roles, ~w(admin student)a) + |> assign(:roles, User.roles()) render(conn, "new.html", changeset: changeset) end diff --git a/lib/atomic_web/live/activity_live/edit.ex b/lib/atomic_web/live/activity_live/edit.ex index fa1f7160c..0105362d9 100644 --- a/lib/atomic_web/live/activity_live/edit.ex +++ b/lib/atomic_web/live/activity_live/edit.ex @@ -11,7 +11,7 @@ defmodule AtomicWeb.ActivityLive.Edit do @impl true def handle_params(%{"id" => id}, _, socket) do - activity = Activities.get_activity!(id, [:speakers, :organization]) + activity = Activities.get_activity!(id, [:organization]) {:noreply, socket diff --git a/lib/atomic_web/live/activity_live/form_component.ex b/lib/atomic_web/live/activity_live/form_component.ex index 96237f659..1afeef7db 100644 --- a/lib/atomic_web/live/activity_live/form_component.ex +++ b/lib/atomic_web/live/activity_live/form_component.ex @@ -3,21 +3,18 @@ defmodule AtomicWeb.ActivityLive.FormComponent do alias Atomic.Activities alias Atomic.Uploader - alias AtomicWeb.Components.{ImageUploader, MultiSelect} + alias AtomicWeb.Components.ImageUploader import AtomicWeb.Components.Forms @impl true def update(%{activity: activity} = assigns, socket) do changeset = Activities.change_activity(activity) - speakers = list_speakers(assigns) {:ok, socket |> assign(assigns) |> assign_form(changeset) - |> assign(:speakers, speakers) - |> assign(:selected_speakers, Enum.count(speakers, & &1.selected)) |> allow_upload(:image, accept: Uploader.extensions_whitelist(), max_entries: 1)} end @@ -33,40 +30,13 @@ defmodule AtomicWeb.ActivityLive.FormComponent do @impl true def handle_event("save", %{"activity" => activity_params}, socket) do - speakers = - List.foldl(socket.assigns.speakers, [], fn speaker, acc -> - if speaker.selected do - [speaker.id | acc] - else - acc - end - end) - activity_params = activity_params - |> Map.put("speakers", speakers) |> Map.put("organization_id", socket.assigns.current_organization.id) save_activity(socket, socket.assigns.action, activity_params) end - @impl true - def handle_event("toggle-option", %{"id" => id}, socket) do - updated_speakers = - Enum.map(socket.assigns.speakers, fn option -> - if option.id == id do - %{option | selected: !option.selected} - else - option - end - end) - - {:noreply, - socket - |> assign(:speakers, updated_speakers) - |> assign(:selected_speakers, Enum.count(updated_speakers, & &1.selected))} - end - @impl true def handle_event("cancel-image", %{"ref" => ref}, socket) do {:noreply, cancel_upload(socket, :image, ref)} @@ -121,24 +91,6 @@ defmodule AtomicWeb.ActivityLive.FormComponent do end end - defp list_speakers(assigns) do - activity = assigns.activity - - organization_speakers = - Activities.list_speakers_by_organization_id(assigns.current_organization.id) - - Enum.map(organization_speakers, fn s -> - selected = - if(is_list(activity.speakers), do: Enum.member?(activity.speakers, s), else: false) - - %{ - id: s.id, - label: s.name, - selected: selected - } - end) - end - defp assign_form(socket, %Ecto.Changeset{} = changeset) do assign(socket, :form, to_form(changeset)) end diff --git a/lib/atomic_web/live/activity_live/form_component.html.heex b/lib/atomic_web/live/activity_live/form_component.html.heex index a11e8c9ed..6ba98a7b4 100644 --- a/lib/atomic_web/live/activity_live/form_component.html.heex +++ b/lib/atomic_web/live/activity_live/form_component.html.heex @@ -46,10 +46,6 @@ -
- <.live_component module={MultiSelect} id="speakers" items={@speakers} selected_items={@selected_speakers} target={@myself} /> -
-
<.field type="textarea" field={@form[:description]} label="Description" placeholder="Choose description" rows={15} required />
diff --git a/lib/atomic_web/live/activity_live/index.ex b/lib/atomic_web/live/activity_live/index.ex index 6e2bf0e18..3362306e8 100644 --- a/lib/atomic_web/live/activity_live/index.ex +++ b/lib/atomic_web/live/activity_live/index.ex @@ -1,7 +1,7 @@ defmodule AtomicWeb.ActivityLive.Index do use AtomicWeb, :live_view - import AtomicWeb.Components.{Avatar, Button, Empty, Pagination, Tabs} + import AtomicWeb.Components.{Button, Empty, Pagination, Tabs} alias Atomic.Accounts alias Atomic.Activities @@ -39,7 +39,7 @@ defmodule AtomicWeb.ActivityLive.Index do end defp list_all_activities(_socket, params) do - case Activities.list_activities(params, preloads: [:speakers, :activity_enrollments]) do + case Activities.list_activities(params, preloads: [:enrollments]) do {:ok, {activities, meta}} -> %{activities: activities, meta: meta} @@ -52,9 +52,7 @@ defmodule AtomicWeb.ActivityLive.Index do organizations = Organizations.list_organizations_followed_by_user(socket.assigns.current_user.id) - case Activities.list_organizations_activities(organizations, params, - preloads: [:speakers, :activity_enrollments] - ) do + case Activities.list_organizations_activities(organizations, params, preloads: [:enrollments]) do {:ok, {activities, meta}} -> %{activities: activities, meta: meta} @@ -64,7 +62,7 @@ defmodule AtomicWeb.ActivityLive.Index do end defp list_upcoming_activities(_socket, params) do - case Activities.list_upcoming_activities(params, preloads: [:speakers, :activity_enrollments]) do + case Activities.list_upcoming_activities(params, preloads: [:enrollments]) do {:ok, {activities, meta}} -> %{activities: activities, meta: meta} @@ -75,7 +73,7 @@ defmodule AtomicWeb.ActivityLive.Index do defp list_enrolled_activities(socket, params) do case Activities.list_user_activities(socket.assigns.current_user.id, params, - preloads: [:speakers, :activity_enrollments] + preloads: [:enrollments] ) do {:ok, {activities, meta}} -> %{activities: activities, meta: meta} diff --git a/lib/atomic_web/live/activity_live/index.html.heex b/lib/atomic_web/live/activity_live/index.html.heex index a582348ef..174c4f853 100644 --- a/lib/atomic_web/live/activity_live/index.html.heex +++ b/lib/atomic_web/live/activity_live/index.html.heex @@ -51,7 +51,7 @@

<.icon name={:users} solid class="flex-shrink-0 mr-1.5 w-5 h-5 text-zinc-400" /> - <%= Enum.count(activity.activity_enrollments) %> / <%= activity.maximum_entries %> + <%= Enum.count(activity.enrollments) %> / <%= activity.maximum_entries %>

<.icon name={:calendar} solid class="flex-shrink-0 mr-1.5 w-5 h-5 text-zinc-400" /> @@ -77,16 +77,6 @@ <.icon name={:bell} solid class="flex-shrink-0 mr-1.5 w-5 h-5 text-zinc-400" /> Closed

<% end %> -
- <%= for speaker <- activity.speakers do %> -
- <.avatar name={speaker.name} size={:xs} color={:light_gray} class="!w-6 !h-6 mr-1.5" /> -

- <%= extract_first_last_name(speaker.name) %> -

-
- <% end %> -
diff --git a/lib/atomic_web/live/activity_live/show.ex b/lib/atomic_web/live/activity_live/show.ex index 621040c28..6deb235e8 100644 --- a/lib/atomic_web/live/activity_live/show.ex +++ b/lib/atomic_web/live/activity_live/show.ex @@ -1,11 +1,9 @@ defmodule AtomicWeb.ActivityLive.Show do use AtomicWeb, :live_view - import AtomicWeb.Components.Avatar - alias Atomic.Accounts alias Atomic.Activities - alias Atomic.Activities.ActivityEnrollment + alias Atomic.Activities.Enrollment @impl true def mount(%{"id" => id}, _session, socket) do @@ -19,7 +17,7 @@ defmodule AtomicWeb.ActivityLive.Show do @impl true def handle_params(%{"id" => id}, _, socket) do - activity = Activities.get_activity!(id, [:speakers, :organization]) + activity = Activities.get_activity!(id, [:organization]) {:noreply, socket @@ -37,7 +35,7 @@ defmodule AtomicWeb.ActivityLive.Show do @impl true def handle_event("enroll", _payload, socket) do case Activities.create_enrollment(socket.assigns.id, socket.assigns.current_user) do - {:ok, %ActivityEnrollment{}} -> + {:ok, %Enrollment{}} -> {:noreply, socket |> put_flash(:success, "Enrolled successufully!") diff --git a/lib/atomic_web/live/activity_live/show.html.heex b/lib/atomic_web/live/activity_live/show.html.heex index dcfd5eefe..e99933c41 100644 --- a/lib/atomic_web/live/activity_live/show.html.heex +++ b/lib/atomic_web/live/activity_live/show.html.heex @@ -89,24 +89,6 @@ <%= @activity.description %> -
-
- <%= if @activity.speakers != [] do %> - <%= gettext("Speaker") %> - <%= for speaker <- @activity.speakers do %> -
-
-
- <.avatar name={speaker.name} size={:xs} color={:light_gray} class="mr-2 inline-flex" /> - <.link navigate={Routes.speaker_show_path(@socket, :show, @activity.organization_id, speaker)} class="text-md text-blue-500"> - <%= extract_first_last_name(speaker.name) %> - -
-
- <% end %> - <% end %> -
-
<%= if @enrolled? do %>
diff --git a/lib/atomic_web/live/board_live/edit.ex b/lib/atomic_web/live/board_live/edit.ex deleted file mode 100644 index 2e95fbf9e..000000000 --- a/lib/atomic_web/live/board_live/edit.ex +++ /dev/null @@ -1,29 +0,0 @@ -defmodule AtomicWeb.BoardLive.Edit do - use AtomicWeb, :live_view - - alias Atomic.Accounts - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, assign(socket, :users, Accounts.list_users())} - end - - @impl true - def handle_params(%{"organization_id" => _organization_id, "id" => id}, _, 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) - organization = user_organization.organization - - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action, organization)) - |> assign(:user_organization, user_organization) - |> assign(:users, users) - |> assign(:current_user, socket.assigns.current_user)} - end - - defp page_title(:index, organization), do: "#{organization.name}'s board" - defp page_title(:show, organization), do: "#{organization.name}'s board" - defp page_title(:edit, _), do: "Edit board" -end diff --git a/lib/atomic_web/live/board_live/edit.html.heex b/lib/atomic_web/live/board_live/edit.html.heex deleted file mode 100644 index e6d1c2228..000000000 --- a/lib/atomic_web/live/board_live/edit.html.heex +++ /dev/null @@ -1 +0,0 @@ -<.live_component module={AtomicWeb.BoardLive.FormComponent} users={@users} id={@user_organization.id} title={@page_title} action={@live_action} user_organization={@user_organization} return_to={Routes.board_show_path(@socket, :show, @user_organization.organization_id, @user_organization.id)} /> diff --git a/lib/atomic_web/live/board_live/form_component.ex b/lib/atomic_web/live/board_live/form_component.ex deleted file mode 100644 index 967aae4ee..000000000 --- a/lib/atomic_web/live/board_live/form_component.ex +++ /dev/null @@ -1,70 +0,0 @@ -defmodule AtomicWeb.BoardLive.FormComponent do - use AtomicWeb, :live_component - - alias Atomic.Organizations - - @impl true - def mount(socket) do - {:ok, socket} - end - - @impl true - def update(%{user_organization: user_organization} = assigns, socket) do - changeset = Organizations.change_user_organization(user_organization) - - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} - end - - @impl true - def handle_event("validate", %{"user_organization" => user_organization_params}, socket) do - changeset = - socket.assigns.user_organization - |> Organizations.change_user_organization(user_organization_params) - |> Map.put(:action, :validate) - - {:noreply, assign(socket, :changeset, changeset)} - end - - def handle_event("save", %{"user_organization" => user_organization_params}, socket) do - save_user_organization(socket, socket.assigns.action, user_organization_params) - end - - defp save_user_organization(socket, :edit, user_organization_params) do - case Organizations.update_user_organization( - socket.assigns.user_organization, - user_organization_params - ) do - {:ok, _organization} -> - {:noreply, - socket - |> put_flash(:info, "Board updated successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end - end - - defp save_user_organization(socket, :new, user_organization_params) do - attrs = - Map.put( - user_organization_params, - "organization_id", - socket.assigns.user_organization.organization_id - ) - - case Organizations.create_user_organization(attrs) do - {:ok, _organization} -> - {:noreply, - socket - |> put_flash(:info, "Board created successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, changeset: changeset)} - end - end -end diff --git a/lib/atomic_web/live/board_live/form_component.html.heex b/lib/atomic_web/live/board_live/form_component.html.heex deleted file mode 100644 index 9537729f4..000000000 --- a/lib/atomic_web/live/board_live/form_component.html.heex +++ /dev/null @@ -1,13 +0,0 @@ -
-

<%= @title %>

- - <.form :let={f} for={@changeset} id="board-form" phx-target={@myself} phx-submit="save"> - <%= label(f, :user_id) %> - <%= select(f, :user_id, @users) %> - <%= label(f, :title) %> - <%= text_input(f, :title) %> - <%= label(f, :year) %> - <%= text_input(f, :year, pattern: "\\d{4}/\\d{4}") %> - <%= submit("Save", phx_disable_with: "Saving...") %> - -
diff --git a/lib/atomic_web/live/board_live/index.ex b/lib/atomic_web/live/board_live/index.ex deleted file mode 100644 index 3e2a2c6b8..000000000 --- a/lib/atomic_web/live/board_live/index.ex +++ /dev/null @@ -1,102 +0,0 @@ -defmodule AtomicWeb.BoardLive.Index do - use AtomicWeb, :live_view - - import AtomicWeb.Components.Empty - import AtomicWeb.Components.Board - import AtomicWeb.Components.Button - - alias Atomic.Accounts - alias Atomic.Board - alias Atomic.Ecto.Year - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => organization_id}, _, socket) do - current_year = Year.current_year() - board = Board.get_organization_board_by_year(current_year, organization_id) - - board_departments = - case board do - nil -> [] - _ -> Board.get_board_departments_by_board_id(board.id) - end - - organization = Organizations.get_organization!(organization_id) - role = Organizations.get_role(socket.assigns.current_user.id, organization_id) - - {:noreply, - socket - |> assign(:current_page, :board) - |> assign(:page_title, "#{organization.name}'s #{gettext("Board")}") - |> assign(:board_departments, board_departments) - |> assign(:empty?, Enum.empty?(board_departments)) - |> assign(:has_permissions?, has_permissions?(socket, organization_id)) - |> assign(:organization, organization) - |> assign(:role, role) - |> assign(:year, current_year)} - end - - @impl true - def handle_event("previous-year", %{"organization-id" => organization_id}, socket) do - year = Year.previous_year(socket.assigns.year) - board = Board.get_organization_board_by_year(year, organization_id) - - board_departments = - case board do - nil -> [] - _ -> Board.get_board_departments_by_board_id(board.id) - end - - {:noreply, - socket - |> assign(:board_departments, board_departments) - |> assign(:empty?, Enum.empty?(board_departments)) - |> assign(:year, year)} - end - - @impl true - def handle_event("next-year", %{"organization-id" => organization_id}, socket) do - year = Year.next_year(socket.assigns.year) - board = Board.get_organization_board_by_year(year, organization_id) - - board_departments = - case board do - nil -> [] - _ -> Board.get_board_departments_by_board_id(board.id) - end - - {:noreply, - socket - |> assign(:board_departments, board_departments) - |> assign(:empty?, Enum.empty?(board_departments)) - |> assign(:year, year)} - end - - @impl true - def handle_event("update-sorting", %{"ids" => ids}, socket) do - ids = Enum.filter(ids, fn id -> String.length(id) > 0 end) - - ids - |> Enum.with_index(0) - |> Enum.each(fn {"board-department-" <> id, priority} -> - id - |> Board.get_board_department!() - |> Board.update_board_department(%{priority: priority}) - end) - - {:noreply, socket} - end - - defp has_permissions?(socket, organization_id) do - Accounts.has_master_permissions?(socket.assigns.current_user.id) || - Accounts.has_permissions_inside_organization?( - socket.assigns.current_user.id, - organization_id - ) - end -end diff --git a/lib/atomic_web/live/board_live/index.html.heex b/lib/atomic_web/live/board_live/index.html.heex deleted file mode 100644 index 84226c333..000000000 --- a/lib/atomic_web/live/board_live/index.html.heex +++ /dev/null @@ -1,47 +0,0 @@ -
-
    -
    -
    - <.icon name={:arrow_small_left} solid class="cursor-pointer mb-2 mr-2 w-8 h-8 text-zinc-400" phx-click="previous-year" phx-value-organization_id={@organization.id} /> -

    - <%= gettext("Board") %> <%= @year %> -

    - <.icon name={:arrow_small_right} solid class="cursor-pointer mb-2 ml-2 w-8 h-8 text-zinc-400" phx-click="next-year" phx-value-organization_id={@organization.id} /> -
    - <%= if not @empty? and @has_permissions? do %> - - <% end %> -
    - <%= if @empty? and @has_permissions? do %> -
    - <.empty_state url={Routes.board_new_path(@socket, :new, @organization)} placeholder="board member" /> -
    - <% else %> - <%= for board_department <- @board_departments do %> -
  • -
    - <%= if @role in [:owner, :admin] do %> - - <.icon name={:bars_3} solid class="w-5 h-5 text-zinc-400" /> - - <% end %> -

    <%= board_department.name %>

    -
    -
    -
    -
    - <%= for user_organization <- Board.get_board_department_users(board_department.id, preloads: [:user]) do %> - <.member_bubble user_organization={user_organization} /> - <% end %> -
    -
    -
    -
  • - <% end %> - <% end %> -
-
diff --git a/lib/atomic_web/live/board_live/new.ex b/lib/atomic_web/live/board_live/new.ex deleted file mode 100644 index bda0bf760..000000000 --- a/lib/atomic_web/live/board_live/new.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule AtomicWeb.BoardLive.New do - @moduledoc false - use AtomicWeb, :live_view - - alias Atomic.Accounts - alias Atomic.Organizations.UserOrganization - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => _organization_id}, _, socket) do - {:noreply, - socket - |> assign(:current_page, :board) - |> assign(:page_title, gettext("New Board")) - |> assign(:user_organization, %UserOrganization{}) - |> assign(:users, Enum.map(Accounts.list_users(), fn u -> [key: u.email, value: u.id] end))} - end -end diff --git a/lib/atomic_web/live/board_live/new.html.heex b/lib/atomic_web/live/board_live/new.html.heex deleted file mode 100644 index 36b75b43c..000000000 --- a/lib/atomic_web/live/board_live/new.html.heex +++ /dev/null @@ -1 +0,0 @@ -<.live_component module={AtomicWeb.BoardLive.FormComponent} organization_id={@current_organization.id} users={@users} id={:new} title={@page_title} action={@live_action} user_organization={@user_organization} return_to={Routes.board_index_path(@socket, :index, @current_organization.id)} /> diff --git a/lib/atomic_web/live/board_live/show.ex b/lib/atomic_web/live/board_live/show.ex deleted file mode 100644 index 1d321efb1..000000000 --- a/lib/atomic_web/live/board_live/show.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule AtomicWeb.BoardLive.Show do - use AtomicWeb, :live_view - - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - 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_organization)} - end - - defp page_title(:show), do: "Show Board" - defp page_title(:edit), do: "Edit Board" -end diff --git a/lib/atomic_web/live/board_live/show.html.heex b/lib/atomic_web/live/board_live/show.html.heex deleted file mode 100644 index 76cbbaf9a..000000000 --- a/lib/atomic_web/live/board_live/show.html.heex +++ /dev/null @@ -1,16 +0,0 @@ -

Show Board

- -
    -
  • - Name: Nome -
  • - -
  • - Title: - <%= @user_organization.title %> -
  • -
  • - Year: - <%= @user_organization.year %> -
  • -
diff --git a/lib/atomic_web/live/card_live/show.ex b/lib/atomic_web/live/card_live/show.ex deleted file mode 100644 index 8b2ce2614..000000000 --- a/lib/atomic_web/live/card_live/show.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule AtomicWeb.CardLive.Show do - use AtomicWeb, :live_view - - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"membership_id" => id}, _, socket) do - membership = Organizations.get_membership!(id, [:user, :organization]) - - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:membership, membership)} - end - - defp page_title(:show), do: "Membership Card" -end diff --git a/lib/atomic_web/live/card_live/show.html.heex b/lib/atomic_web/live/card_live/show.html.heex deleted file mode 100644 index 3dedf9161..000000000 --- a/lib/atomic_web/live/card_live/show.html.heex +++ /dev/null @@ -1,24 +0,0 @@ -<%= if @membership.organization.card_image != nil do %> -
-
Uploaders.Card.url({@membership.organization.card_image, @membership.organization}, :original) <> ")"} - > -

to_string(@membership.organization.card.name_size) <> "vw; color: " <> @membership.organization.card.name_color <> "; transform: translate(" <> to_string(@membership.organization.card.name_x) <> "%, " <> to_string(@membership.organization.card.name_y) <> "%);"} - > - <%= @membership.user.name %> -

-

to_string(@membership.organization.card.number_size) <> "vw; color: " <> @membership.organization.card.number_color <> "; transform: translate(" <> to_string(@membership.organization.card.number_x) <> "%, " <> to_string(@membership.organization.card.number_y) <> "%);"} - > - <%= @membership.number %> -

-
-<% else %> -
-

This organization does not have a membership card

-
-<% end %> diff --git a/lib/atomic_web/live/home_live/components/follow_suggestions.ex b/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex similarity index 94% rename from lib/atomic_web/live/home_live/components/follow_suggestions.ex rename to lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex index 94d0e02d3..f1b3d5260 100644 --- a/lib/atomic_web/live/home_live/components/follow_suggestions.ex +++ b/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex @@ -2,7 +2,7 @@ defmodule AtomicWeb.HomeLive.Components.FollowSuggestions do @moduledoc false use AtomicWeb, :component - alias AtomicWeb.HomeLive.Components.FollowSuggestions.Suggestion + alias __MODULE__.Suggestion attr :current_user, :map, required: true, diff --git a/lib/atomic_web/live/home_live/components/suggestion.ex b/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex similarity index 99% rename from lib/atomic_web/live/home_live/components/suggestion.ex rename to lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex index cff7ba9a6..b29697dc2 100644 --- a/lib/atomic_web/live/home_live/components/suggestion.ex +++ b/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex @@ -1,6 +1,7 @@ defmodule AtomicWeb.HomeLive.Components.FollowSuggestions.Suggestion do @moduledoc false use AtomicWeb, :live_component + import AtomicWeb.Components.Avatar alias Atomic.Organizations diff --git a/lib/atomic_web/live/membership_live/edit.ex b/lib/atomic_web/live/membership_live/edit.ex deleted file mode 100644 index 13f6112bf..000000000 --- a/lib/atomic_web/live/membership_live/edit.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule AtomicWeb.MembershipLive.Edit do - use AtomicWeb, :live_view - - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, assign(socket, :current_user, socket.assigns.current_user)} - end - - @impl true - def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do - membership = Organizations.get_membership!(id, [:user, :organization, :created_by]) - organization = Organizations.get_organization!(organization_id) - - {:noreply, - socket - |> assign(:page_title, "Edit Membership") - |> assign(:current_page, :memberships) - |> assign(:organization, organization) - |> assign(:membership, membership) - |> assign(:current_user, socket.assigns.current_user) - |> assign( - :allowed_roles, - Organizations.roles_less_than_or_equal(socket.assigns.current_user.role) - )} - end -end diff --git a/lib/atomic_web/live/membership_live/edit.html.heex b/lib/atomic_web/live/membership_live/edit.html.heex deleted file mode 100644 index 9ce671ad1..000000000 --- a/lib/atomic_web/live/membership_live/edit.html.heex +++ /dev/null @@ -1 +0,0 @@ -<.live_component module={AtomicWeb.MembershipLive.FormComponent} id={@membership.id} membership={@membership} action={@live_action} allowed_roles={@allowed_roles} return_to={Routes.membership_index_path(@socket, :index, @organization)} /> diff --git a/lib/atomic_web/live/membership_live/form_component.ex b/lib/atomic_web/live/membership_live/form_component.ex deleted file mode 100644 index 773698ad1..000000000 --- a/lib/atomic_web/live/membership_live/form_component.ex +++ /dev/null @@ -1,86 +0,0 @@ -defmodule AtomicWeb.MembershipLive.FormComponent do - use AtomicWeb, :live_component - - alias Atomic.Organizations - - @impl true - def update(%{membership: membership} = assigns, socket) do - changeset = Organizations.change_membership(membership) - - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} - end - - @impl true - def handle_event("validate", %{"membership" => membership_params}, socket) do - changeset = - socket.assigns.membership - |> Organizations.change_membership(membership_params) - |> Map.put(:action, :validate) - - {:noreply, assign(socket, :changeset, changeset)} - end - - @impl true - def handle_event("save", %{"membership" => membership_params}, socket) do - membership_params = Map.put(membership_params, "current_user", socket.assigns.current_user) - - update_membership( - socket, - socket.assigns.action, - membership_params - ) - end - - defp update_membership(socket, :edit, membership_params) do - membership = socket.assigns.membership - current_user = membership_params["current_user"] - number = membership_params["number"] - role = membership_params["role"] - - case Organizations.update_membership( - membership, - %{ - created_by_id: current_user.id, - number: number, - role: role - } - ) do - {:ok, _membership} -> - {:noreply, - socket - |> put_flash(:success, "membership updated successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end - end - - defp update_membership(socket, :new, membership_params) do - org_id = socket.assigns.membership.organization_id - current_user = membership_params["current_user"] - number = membership_params["number"] - role = membership_params["role"] - user_id = membership_params["user_id"] - - case Organizations.create_membership(%{ - created_by_id: current_user.id, - number: number, - role: role, - organization_id: org_id, - user_id: user_id - }) do - {:ok, _membership} -> - {:noreply, - socket - |> put_flash(:success, "membership created successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end - end -end diff --git a/lib/atomic_web/live/membership_live/form_component.html.heex b/lib/atomic_web/live/membership_live/form_component.html.heex deleted file mode 100644 index 4761dcc21..000000000 --- a/lib/atomic_web/live/membership_live/form_component.html.heex +++ /dev/null @@ -1,15 +0,0 @@ -
- <.form :let={f} for={@changeset} id="membership-form" phx-target={@myself} phx-submit="save"> - <%= if @action == :new do %> - <%= label(f, :user_id) %> - <%= select(f, :user_id, @users) %> - <% else %> -

<%= @membership.user.email %>

- <% end %> - <%= label(f, :number) %> - <%= number_input(f, :number) %> - <%= label(f, :role) %> - <%= select(f, :role, @allowed_roles) %> - <%= submit("Save", phx_disable_with: "Saving...") %> - -
diff --git a/lib/atomic_web/live/membership_live/index.ex b/lib/atomic_web/live/membership_live/index.ex deleted file mode 100644 index 57fbe457b..000000000 --- a/lib/atomic_web/live/membership_live/index.ex +++ /dev/null @@ -1,40 +0,0 @@ -defmodule AtomicWeb.MembershipLive.Index do - use AtomicWeb, :live_view - - import AtomicWeb.Helpers - import AtomicWeb.Components.Pagination - import AtomicWeb.Components.Table - import AtomicWeb.Components.Dropdown - - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => organization_id} = params, _, socket) do - organization = Organizations.get_organization!(organization_id) - - {:noreply, - socket - |> assign(:page_title, "#{organization.name}'s #{gettext("Memberships")}") - |> assign(:current_page, :memberships) - |> assign(:params, params) - |> assign(list_memberships(organization_id, params))} - end - - defp list_memberships(id, params) do - case Organizations.list_display_memberships(Map.put(params, "page_size", 9), - where: [organization_id: id], - preloads: [:user, :created_by] - ) do - {:ok, {memberships, meta}} -> - %{memberships: memberships, meta: meta} - - {:error, flop} -> - %{memberships: [], meta: flop} - end - end -end diff --git a/lib/atomic_web/live/membership_live/index.html.heex b/lib/atomic_web/live/membership_live/index.html.heex deleted file mode 100644 index 8aae94bb1..000000000 --- a/lib/atomic_web/live/membership_live/index.html.heex +++ /dev/null @@ -1,92 +0,0 @@ -
-
-
-

- <%= gettext("Memberships") %> -

-
-
- -
- -
- <.dropdown - orientation={:down} - id="export-menu-button" - icon_variant={:solid} - items={[ - %{name: "Export to CSV", link: Routes.data_export_path(@socket, :export_memberships_csv, @params["organization_id"]), icon: :queue_list}, - %{name: "Export to Excel", link: Routes.data_export_path(@socket, :export_memberships_xlsx, @params["organization_id"]), icon: :table_cells} - ]} - > - <:wrapper> - <.button color={:primary} variant={:inverted} class="group"> - <.icon name={:cloud_arrow_down} solid class="mr-2 -ml-1 w-5 h-5 text-orange-500 group-hover:text-white" /> Export Memberships - - - - -
-
- -
-
-
-
- <.table items={@memberships} meta={@meta} filter={[member_name: [op: :ilike_and]]}> - <:col :let={membership} label="Number" field={:number}><%= membership.number %> - <:col :let={membership} label="Name" field={:member_name}> - <.link navigate={Routes.profile_show_path(@socket, :show, membership.user)}> - <%= membership.user.name %> - - - <:col :let={membership} label="Email" field={:member_email}><%= membership.user.email %> - <:col :let={membership} label="Role" field={:role}> -

<%= membership.role %>

- - <:col :let={_membership} label="Phone Number" field={:phone_number}>Phone number - <:col :let={membership} label="Requested At" field={:inserted_at}><%= display_date(membership.inserted_at) %> <%= display_time(membership.inserted_at) %> - <:col :let={membership} label="Created By" field={:created_by_name}><%= membership.created_by.name %> - <:col :let={membership} label="Last Update" field={:updated_at}><%= display_date(membership.updated_at) %> <%= display_time(membership.updated_at) %> - <:col :let={membership}> - <%= link to: Routes.membership_edit_path(@socket, :edit, membership.organization_id, membership), class: "text-orange-500 hover:text-orange-900" do %> - - <% end %> - - - <.pagination items={@memberships} meta={@meta} params={@params} class="mt-2 flex w-full items-center justify-between border-r-[1px]" /> -
-
-
-
-
diff --git a/lib/atomic_web/live/membership_live/new.ex b/lib/atomic_web/live/membership_live/new.ex deleted file mode 100644 index f92b9292c..000000000 --- a/lib/atomic_web/live/membership_live/new.ex +++ /dev/null @@ -1,29 +0,0 @@ -defmodule AtomicWeb.MembershipLive.New do - @moduledoc false - use AtomicWeb, :live_view - - alias Atomic.Accounts - alias Atomic.Organizations - alias Atomic.Organizations.Membership - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => organization_id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, gettext("New Membership")) - |> assign(:membership, %Membership{ - organization_id: organization_id - }) - |> assign(:users, Enum.map(Accounts.list_users(), fn u -> [key: u.email, value: u.id] end)) - |> assign( - :allowed_roles, - Organizations.roles_less_than_or_equal(socket.assigns.current_user.role) - ) - |> assign(:current_user, socket.assigns.current_user)} - end -end diff --git a/lib/atomic_web/live/membership_live/new.html.heex b/lib/atomic_web/live/membership_live/new.html.heex deleted file mode 100644 index 5b20dd9b2..000000000 --- a/lib/atomic_web/live/membership_live/new.html.heex +++ /dev/null @@ -1,11 +0,0 @@ -<.live_component - module={AtomicWeb.MembershipLive.FormComponent} - current_user={@current_user} - id={:new} - title={@page_title} - action={@live_action} - allowed_roles={@allowed_roles} - users={@users} - membership={@membership} - return_to={Routes.membership_index_path(@socket, :index, @membership.organization_id)} -/> diff --git a/lib/atomic_web/live/membership_live/show.ex b/lib/atomic_web/live/membership_live/show.ex deleted file mode 100644 index d9046c101..000000000 --- a/lib/atomic_web/live/membership_live/show.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule AtomicWeb.MembershipLive.Show do - use AtomicWeb, :live_view - - alias Atomic.Organizations - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => organization_id, "id" => id}, _, socket) do - membership = Organizations.get_membership!(id, [:user, :organization, :created_by]) - organization = Organizations.get_organization!(organization_id) - - {:noreply, - socket - |> assign(:page_title, "#{organization.name} - #{membership.user.name}") - |> assign(:membership, membership)} - end -end diff --git a/lib/atomic_web/live/membership_live/show.html.heex b/lib/atomic_web/live/membership_live/show.html.heex deleted file mode 100644 index 07fa61390..000000000 --- a/lib/atomic_web/live/membership_live/show.html.heex +++ /dev/null @@ -1,11 +0,0 @@ -
-

Temporary Name

-

Associate Number <%= @membership.number %>

-
-

Email: <%= @membership.user.email %>

-

Phone Number: Temporary Number

-

Created At: <%= @membership.inserted_at %>

-

Created By: <%= @membership.created_by.email %>

-

Updated At: <%= @membership.updated_at %>

-
-
diff --git a/lib/atomic_web/live/organization_live/form_component.ex b/lib/atomic_web/live/organization_live/form_component.ex index f578f0d8c..50b492388 100644 --- a/lib/atomic_web/live/organization_live/form_component.ex +++ b/lib/atomic_web/live/organization_live/form_component.ex @@ -1,17 +1,11 @@ defmodule AtomicWeb.OrganizationLive.FormComponent do use AtomicWeb, :live_component - alias Atomic.Activities alias Atomic.Organizations @impl true def mount(socket) do - speakers = Activities.list_speakers() - - {:ok, - socket - |> allow_upload(:card, accept: Atomic.Uploader.extensions_whitelist(), max_entries: 1) - |> assign(:speakers, speakers)} + {:ok, socket} end @impl true @@ -39,8 +33,6 @@ defmodule AtomicWeb.OrganizationLive.FormComponent do end defp save_organization(socket, :edit, organization_params) do - consume_card_data(socket, socket.assigns.organization) - case Organizations.update_organization(socket.assigns.organization, organization_params) do {:ok, _organization} -> {:noreply, @@ -65,23 +57,4 @@ defmodule AtomicWeb.OrganizationLive.FormComponent do {:noreply, assign(socket, changeset: changeset)} end end - - defp consume_card_data(socket, organization) do - consume_uploaded_entries(socket, :card, fn %{path: path}, entry -> - Organizations.update_card_image(organization, %{ - "card_image" => %Plug.Upload{ - content_type: entry.client_type, - filename: entry.client_name, - path: path - } - }) - end) - |> case do - [{:ok, organization}] -> - {:ok, organization} - - _errors -> - {:ok, organization} - end - end end diff --git a/lib/atomic_web/live/organization_live/form_component.html.heex b/lib/atomic_web/live/organization_live/form_component.html.heex index 3b174cf45..d2340bef1 100644 --- a/lib/atomic_web/live/organization_live/form_component.html.heex +++ b/lib/atomic_web/live/organization_live/form_component.html.heex @@ -10,77 +10,6 @@ <%= text_input(f, :description) %> <%= error_tag(f, :description) %> -
- <.live_file_input upload={@uploads.card} class="hidden" /> -
-
-
-
-
- -

or drag and drop

-
- -

- PNG, JPG, GIF up to 10MB -

-
-
-
-
-
- <%= for entry <- @uploads.card.entries do %> - <%= for err <- upload_errors(@uploads.card, entry) do %> -

<%= Phoenix.Naming.humanize(err) %>

- <% end %> -
-
- <.live_img_preview entry={entry} /> -
-
- <%= if String.length(entry.client_name) < 30 do - entry.client_name - else - String.slice(entry.client_name, 0..30) <> "... " - end %> -
- -
-
-
- <% end %> -
-
- <%= inputs_for f, :card, fn ff -> %> - <%= label(ff, :number_x) %> - <%= number_input(ff, :number_x) %> - <%= label(ff, :number_y) %> - <%= number_input(ff, :number_y) %> - <%= label(ff, :number_size) %> - <%= number_input(ff, :number_size) %> - <%= label(ff, :number_color) %> - <%= text_input(ff, :number_color) %> - <%= label(ff, :name_x) %> - <%= number_input(ff, :name_x) %> - <%= label(ff, :name_y) %> - <%= number_input(ff, :name_y) %> - <%= label(ff, :name_size) %> - <%= number_input(ff, :name_size) %> - <%= label(ff, :name_color) %> - <%= text_input(ff, :name_color) %> - <% end %> - <%= error_tag(f, :departments) %> -
<%= submit("Save", phx_disable_with: "Saving...") %>
diff --git a/lib/atomic_web/live/organization_live/new.ex b/lib/atomic_web/live/organization_live/new.ex index 47cb1f730..f206143b6 100644 --- a/lib/atomic_web/live/organization_live/new.ex +++ b/lib/atomic_web/live/organization_live/new.ex @@ -1,7 +1,6 @@ defmodule AtomicWeb.OrganizationLive.New do use AtomicWeb, :live_view - alias Atomic.Organizations alias Atomic.Organizations.Organization @impl true @@ -15,10 +14,6 @@ defmodule AtomicWeb.OrganizationLive.New do socket |> assign(:page_title, "New Organization") |> assign(:organization, %Organization{}) - |> assign( - :allowed_roles, - Organizations.roles_less_than_or_equal(socket.assigns.current_user.role) - ) |> assign(:current_page, :organization)} end end diff --git a/lib/atomic_web/live/organization_live/new.html.heex b/lib/atomic_web/live/organization_live/new.html.heex index edff8ee8b..48a9c7a7a 100644 --- a/lib/atomic_web/live/organization_live/new.html.heex +++ b/lib/atomic_web/live/organization_live/new.html.heex @@ -1 +1 @@ -<.live_component module={AtomicWeb.OrganizationLive.FormComponent} current_user={@current_user} organization={@current_organization} id={:new} title={@page_title} action={@live_action} allowed_roles={@allowed_roles} return_to={Routes.organization_index_path(@socket, :index)} /> +<.live_component module={AtomicWeb.OrganizationLive.FormComponent} current_user={@current_user} organization={@current_organization} id={:new} title={@page_title} action={@live_action} return_to={Routes.organization_index_path(@socket, :index)} /> diff --git a/lib/atomic_web/live/organization_live/show.html.heex b/lib/atomic_web/live/organization_live/show.html.heex index fc855a810..44e8a5c73 100644 --- a/lib/atomic_web/live/organization_live/show.html.heex +++ b/lib/atomic_web/live/organization_live/show.html.heex @@ -105,8 +105,6 @@ <.avatar name={person.name} size={:sm} color={:light_gray} /> <% end %>
- <.link navigate={Routes.board_index_path(@socket, :index, @organization.id)} class="hover:underline text-blue-500"> - <%= gettext("View all") %> - + <%= gettext("View all") %> diff --git a/lib/atomic_web/live/scanner_live/index.ex b/lib/atomic_web/live/scanner_live/index.ex index b66b16e10..392fe516c 100644 --- a/lib/atomic_web/live/scanner_live/index.ex +++ b/lib/atomic_web/live/scanner_live/index.ex @@ -1,9 +1,9 @@ defmodule AtomicWeb.ScannerLive.Index do @moduledoc false - use AtomicWeb, :live_view + + alias Atomic.Accounts alias Atomic.Activities - alias Atomic.Organizations @impl true def mount(_params, _session, socket) do @@ -20,24 +20,17 @@ defmodule AtomicWeb.ScannerLive.Index do @doc """ Handles the scan event. - Basically it does two checks: - 1) Verifies if current_organization is in organizations that are related to the session of the activity. - 2) Verifies if current_user is admin or owner of the organization, or , if current_user is admin of the system. - - If 1) and 2) are true, then confirm_participation is called. - Else a flash message is shown and the user is redirected to the scanner index. """ @impl true def handle_event("scan", pathname, socket) do [_, activity_id, user_id | _] = String.split(pathname, "/") - activity = Activities.get_activity!(activity_id) if (socket.assigns.current_organization.id == activity.organization_id && - Organizations.get_role( + Accounts.has_permissions_inside_organization?( socket.assigns.current_user.id, socket.assigns.current_organization.id - ) in [:admin, :owner]) or socket.assigns.current_user.role in [:admin] do + )) || Accounts.has_master_permissions?(socket.assigns.current_user) do confirm_participation(socket, activity_id, user_id) else {:noreply, @@ -47,9 +40,6 @@ defmodule AtomicWeb.ScannerLive.Index do end end - # Updates the enrollment of the user in the session, setting present to true. - # If the update is successful, a flash message is shown and the user is redirected to the scanner index. - # Else a flash message is shown and the user is redirected to the scanner index. defp confirm_participation(socket, session_id, user_id) do case Activities.update_enrollment(Activities.get_enrollment!(session_id, user_id), %{ present: true diff --git a/lib/atomic_web/live/speaker_live/form_component.ex b/lib/atomic_web/live/speaker_live/form_component.ex deleted file mode 100644 index a2f452cef..000000000 --- a/lib/atomic_web/live/speaker_live/form_component.ex +++ /dev/null @@ -1,57 +0,0 @@ -defmodule AtomicWeb.SpeakerLive.FormComponent do - use AtomicWeb, :live_component - - alias Atomic.Activities - - @impl true - def update(%{speaker: speaker} = assigns, socket) do - changeset = Activities.change_speaker(speaker) - - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} - end - - @impl true - def handle_event("validate", %{"speaker" => speaker_params}, socket) do - changeset = - socket.assigns.speaker - |> Activities.change_speaker(speaker_params) - |> Map.put(:action, :validate) - - {:noreply, assign(socket, :changeset, changeset)} - end - - def handle_event("save", %{"speaker" => speaker_params}, socket) do - save_speaker(socket, socket.assigns.action, speaker_params) - end - - defp save_speaker(socket, :edit, speaker_params) do - case Activities.update_speaker(socket.assigns.speaker, speaker_params) do - {:ok, _speaker} -> - {:noreply, - socket - |> put_flash(:info, "Speaker updated successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end - 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, - socket - |> put_flash(:info, "Speaker created successfully") - |> push_navigate(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, changeset: changeset)} - end - end -end diff --git a/lib/atomic_web/live/speaker_live/form_component.html.heex b/lib/atomic_web/live/speaker_live/form_component.html.heex deleted file mode 100644 index a7f747251..000000000 --- a/lib/atomic_web/live/speaker_live/form_component.html.heex +++ /dev/null @@ -1,17 +0,0 @@ -
-

<%= @title %>

- - <.form :let={f} for={@changeset} id="speaker-form" phx-target={@myself} phx-change="validate" phx-submit="save"> - <%= label(f, :name) %> - <%= text_input(f, :name) %> - <%= error_tag(f, :name) %> - - <%= label(f, :bio) %> - <%= textarea(f, :bio) %> - <%= error_tag(f, :bio) %> - -
- <%= submit("Save", phx_disable_with: "Saving...") %> -
- -
diff --git a/lib/atomic_web/live/speaker_live/index.ex b/lib/atomic_web/live/speaker_live/index.ex deleted file mode 100644 index 44d975848..000000000 --- a/lib/atomic_web/live/speaker_live/index.ex +++ /dev/null @@ -1,52 +0,0 @@ -defmodule AtomicWeb.SpeakerLive.Index do - use AtomicWeb, :live_view - - import AtomicWeb.Components.Modal - - alias Atomic.Activities - alias Atomic.Activities.Speaker - alias Phoenix.LiveView.JS - - @impl true - def mount(%{"organization_id" => organization_id}, _session, socket) do - {:ok, assign(socket, :speakers, list_speakers(organization_id))} - end - - @impl true - def handle_params(params, _, socket) do - {:noreply, - socket - |> assign(:current_page, :speakers) - |> apply_action(socket.assigns.live_action, params)} - end - - defp apply_action(socket, :edit, %{"organization_id" => _organization_id, "id" => id}) do - socket - |> assign(:page_title, "Edit Speaker") - |> assign(:speaker, Activities.get_speaker!(id)) - end - - defp apply_action(socket, :new, _params) do - socket - |> assign(:page_title, "New Speaker") - |> assign(:speaker, %Speaker{}) - end - - defp apply_action(socket, :index, _params) do - socket - |> assign(:page_title, "Listing Speakers") - |> assign(:speaker, nil) - end - - @impl true - def handle_event("delete", %{"id" => id}, socket) do - speaker = Activities.get_speaker!(id) - {:ok, _} = Activities.delete_speaker(speaker) - - {:noreply, assign(socket, :speakers, list_speakers(socket.assigns.current_organization.id))} - end - - 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 deleted file mode 100644 index cd15f6ede..000000000 --- a/lib/atomic_web/live/speaker_live/index.html.heex +++ /dev/null @@ -1,34 +0,0 @@ -

Listing Speakers

- -<%= if @live_action in [:new, :edit] do %> - <.modal id="speaker-edit" on_cancel={JS.push(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 %> - - - - - - - - - - - - <%= for speaker <- @speakers do %> - - - - - - - <% end %> - -
NameBio
<%= speaker.name %><%= speaker.bio %> - <.link navigate={Routes.speaker_show_path(@socket, :show, @current_organization, speaker)}><%= gettext("Show") %> - <.link patch={Routes.speaker_index_path(@socket, :edit, @current_organization, speaker)}><%= gettext("Edit") %> - <%= link("Delete", to: "#", phx_click: "delete", phx_value_id: speaker.id, data: [confirm: "Are you sure?"]) %> -
- -<.link patch={Routes.speaker_index_path(@socket, :new, @current_organization)}><%= gettext("New Speaker") %> diff --git a/lib/atomic_web/live/speaker_live/show.ex b/lib/atomic_web/live/speaker_live/show.ex deleted file mode 100644 index 04caef12a..000000000 --- a/lib/atomic_web/live/speaker_live/show.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule AtomicWeb.SpeakerLive.Show do - use AtomicWeb, :live_view - - import AtomicWeb.Components.Modal - - alias Atomic.Activities - alias Phoenix.LiveView.JS - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"organization_id" => _organization_id, "id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:current_page, :speakers) - |> assign(:speaker, Activities.get_speaker!(id))} - end - - defp page_title(:show), do: "Show Speaker" - defp page_title(:edit), do: "Edit Speaker" -end diff --git a/lib/atomic_web/live/speaker_live/show.html.heex b/lib/atomic_web/live/speaker_live/show.html.heex deleted file mode 100644 index 3bf5b02f6..000000000 --- a/lib/atomic_web/live/speaker_live/show.html.heex +++ /dev/null @@ -1,22 +0,0 @@ -

Show Speaker

- -<%= if @live_action in [:edit] do %> - <.modal id="speaker-edit" on_cancel={JS.push(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 %> - -
    -
  • - Name: - <%= @speaker.name %> -
  • - -
  • - Bio: - <%= @speaker.bio %> -
  • -
- -<.link patch={Routes.speaker_show_path(@socket, :edit, @current_organization, @speaker)} class="button"><%= gettext("Edit") %> -| <.link navigate={Routes.speaker_index_path(@socket, :index, @current_organization)}><%= gettext("Back") %> diff --git a/lib/atomic_web/plugs/authorize.ex b/lib/atomic_web/plugs/authorize.ex index ea47d8576..19177344f 100644 --- a/lib/atomic_web/plugs/authorize.ex +++ b/lib/atomic_web/plugs/authorize.ex @@ -45,7 +45,7 @@ defmodule AtomicWeb.Plugs.Authorize do 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) || user.role == :admin + organization_id in user_organizations && role in allowed_roles end defp get_organization_id(conn) do diff --git a/lib/atomic_web/router.ex b/lib/atomic_web/router.ex index d9795feec..9843a8c8d 100644 --- a/lib/atomic_web/router.ex +++ b/lib/atomic_web/router.ex @@ -14,20 +14,12 @@ defmodule AtomicWeb.Router do plug :fetch_current_user end - pipeline :api do - plug :accepts, ["json"] - end - # Authorization pipelines pipeline :admin do plug AtomicWeb.Plugs.Authorize, :admin end - pipeline :member do - plug AtomicWeb.Plugs.Authorize, :member - end - pipeline :master do plug AtomicWeb.Plugs.Authorize, :master end @@ -42,27 +34,16 @@ defmodule AtomicWeb.Router do plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Organizations.get_announcement!/1 end - pipeline :confirm_board_association do - plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Board.get_board!/1 - end - pipeline :confirm_department_association do plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Departments.get_department!/1 end - pipeline :confirm_membership_association do - plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Organizations.get_membership!/1 - end - pipeline :confirm_partner_association do plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Partners.get_partner!/1 end - pipeline :confirm_speaker_association do - plug AtomicWeb.Plugs.VerifyAssociation, &Atomic.Activities.get_speaker!/1 - end - ## Admin routes + scope "/", AtomicWeb do pipe_through [ :browser, @@ -102,35 +83,14 @@ defmodule AtomicWeb.Router do live "/new", PartnerLive.Edit, :new live "/:id/edit", PartnerLive.Edit, :edit end - - scope "/speakers" do - pipe_through :confirm_speaker_association - live "/new", SpeakerLive.New, :new - live "/:id/edit", SpeakerLive.Edit, :edit - end - - scope "/board" do - pipe_through :confirm_board_association - live "/new", BoardLive.New, :new - live "/:id/edit", BoardLive.Edit, :edit - end - - scope "/memberships" do - pipe_through :confirm_membership_association - live "/", MembershipLive.Index, :index - live "/new", MembershipLive.New, :new - live "/:id", MembershipLive.Show, :show - live "/:id/edit", MembershipLive.Edit, :edit - get "/export/csv", DataExportController, :export_memberships_csv - get "/export/xlsx", DataExportController, :export_memberships_xlsx - end end end end ## Normal user routes + scope "/", AtomicWeb do - pipe_through [:browser] + pipe_through :browser live_session :user, on_mount: [{AtomicWeb.Hooks, :current_user_state}] do live "/", HomeLive.Index, :index @@ -144,7 +104,6 @@ defmodule AtomicWeb.Router do live "/announcements/:id", AnnouncementLive.Show, :show live "/profile/:slug", ProfileLive.Show, :show - live "/profile/:slug/edit", ProfileLive.Edit, :edit pipe_through [ :require_authenticated_user, @@ -152,6 +111,8 @@ defmodule AtomicWeb.Router do :require_finished_user_setup ] + live "/profile/:slug/edit", ProfileLive.Edit, :edit + live "/scanner", ScannerLive.Index, :index get "/users/change_password", UserChangePasswordController, :edit @@ -166,28 +127,13 @@ defmodule AtomicWeb.Router do live "/:id", DepartmentLive.Show, :show end - scope "/board" do - pipe_through :confirm_board_association - live "/", BoardLive.Index, :index - live "/:id", BoardLive.Show, :show - end - scope "/partners" do pipe_through :confirm_partner_association live "/", PartnerLive.Index, :index live "/:id", PartnerLive.Show, :show end - - scope "/speakers" do - pipe_through :confirm_speaker_association - live "/", SpeakerLive.Index, :index - live "/:id", SpeakerLive.Show, :show - end end - pipe_through [:member] - live "/card/:membership_id", CardLive.Show, :show - # Only masters can create organizations pipe_through [:master] live "/organizations/new", OrganizationLive.New, :new @@ -195,14 +141,17 @@ defmodule AtomicWeb.Router do end ## Authentication routes + scope "/", AtomicWeb do pipe_through [:browser, :redirect_if_user_is_authenticated] scope "/users" do get "/register", UserRegistrationController, :new post "/register", UserRegistrationController, :create + get "/log_in", UserSessionController, :new post "/log_in", UserSessionController, :create + get "/reset_password", UserResetPasswordController, :new post "/reset_password", UserResetPasswordController, :create get "/reset_password/:token", UserResetPasswordController, :edit @@ -222,10 +171,11 @@ defmodule AtomicWeb.Router do end scope "/", AtomicWeb do - pipe_through [:browser] + pipe_through :browser scope "/users" do delete "/log_out", UserSessionController, :delete + get "/confirm", UserConfirmationController, :new post "/confirm", UserConfirmationController, :create get "/confirm/:token", UserConfirmationController, :edit @@ -243,22 +193,23 @@ defmodule AtomicWeb.Router do forward "/mailbox", Plug.Swoosh.MailboxPreview end + end + # Enables the Storybook components collection in development. + # + # Check the PhoenixStorybook documentation for more information. + if Mix.env() == :dev do scope "/" do storybook_assets() end scope "/", AtomicWeb do - pipe_through [:browser] + pipe_through :browser + live_storybook("/storybook", backend_module: AtomicWeb.Storybook) end end - # Other scopes may use custom stacks. - # scope "/api", AtomicWeb do - # pipe_through :api - # end - # Enables LiveDashboard only for development # # If you want to use the LiveDashboard in production, you should put diff --git a/priv/fake/admins.txt b/priv/fake/masters.txt similarity index 100% rename from priv/fake/admins.txt rename to priv/fake/masters.txt diff --git a/priv/repo/migrations/2022000000000_create_organizations.exs b/priv/repo/migrations/2022000000000_create_organizations.exs index 71e9a5378..d725bdd89 100644 --- a/priv/repo/migrations/2022000000000_create_organizations.exs +++ b/priv/repo/migrations/2022000000000_create_organizations.exs @@ -4,11 +4,13 @@ defmodule Atomic.Repo.Migrations.CreateOrganizations do def change do create table(:organizations, primary_key: false) do add :id, :binary_id, primary_key: true + add :name, :string, null: false add :long_name, :string, null: false add :description, :text, null: false - add :location, :map + add :logo, :string + add :location, :map timestamps() end diff --git a/priv/repo/migrations/20220922010100_create_events.exs b/priv/repo/migrations/20220922010100_create_events.exs deleted file mode 100644 index 6a6f38f2e..000000000 --- a/priv/repo/migrations/20220922010100_create_events.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateEvents do - use Ecto.Migration - - def change do - create table(:events, primary_key: false) do - add :id, :binary_id, primary_key: true - add :name, :string, null: false - add :description, :text - add :location, :map - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20221000000000_create_departments.exs b/priv/repo/migrations/20221000000000_create_departments.exs index 641873234..cb0eec220 100644 --- a/priv/repo/migrations/20221000000000_create_departments.exs +++ b/priv/repo/migrations/20221000000000_create_departments.exs @@ -4,12 +4,15 @@ defmodule Atomic.Repo.Migrations.CreateDepartments do def change do create table(:departments, primary_key: false) do add :id, :binary_id, primary_key: true + add :name, :string, null: false add :description, :text - add :banner, :string + add :collaborator_applications, :boolean, default: false, null: false add :archived, :boolean, default: false, null: false + add :banner, :string + add :organization_id, references(:organizations, on_delete: :delete_all, type: :binary_id), null: false diff --git a/priv/repo/migrations/20221014155230_create_users_auth_tables.exs b/priv/repo/migrations/20221014155230_create_users_auth_tables.exs index 645fcd55e..dc00ab854 100644 --- a/priv/repo/migrations/20221014155230_create_users_auth_tables.exs +++ b/priv/repo/migrations/20221014155230_create_users_auth_tables.exs @@ -6,14 +6,17 @@ defmodule Atomic.Repo.Migrations.CreateUsersAuthTables do create table(:users, primary_key: false) do add :id, :binary_id, primary_key: true + add :name, :string add :email, :citext, null: false add :slug, :citext - add :phone_number, :string + add :role, :string, null: false, default: "student" + add :hashed_password, :string, null: false + add :confirmed_at, :naive_datetime + add :phone_number, :string add :profile_picture, :string - add :role, :string, null: false, default: "student" add :current_organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all) @@ -26,11 +29,13 @@ defmodule Atomic.Repo.Migrations.CreateUsersAuthTables do create table(:users_tokens, primary_key: false) do add :id, :binary_id, primary_key: true - add :user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false + add :token, :binary, null: false add :context, :string, null: false add :sent_to, :string + add :user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false + timestamps(updated_at: false) end diff --git a/priv/repo/migrations/20221022010100_create_activities.exs b/priv/repo/migrations/20221022010100_create_activities.exs index cf4838639..10ae6829d 100644 --- a/priv/repo/migrations/20221022010100_create_activities.exs +++ b/priv/repo/migrations/20221022010100_create_activities.exs @@ -4,17 +4,20 @@ defmodule Atomic.Repo.Migrations.CreateActivities do def change do create table(:activities, primary_key: false) do add :id, :binary_id, primary_key: true + add :title, :string, null: false add :description, :text, null: false + add :start, :naive_datetime, null: false add :finish, :naive_datetime, null: false - add :location, :map + add :minimum_entries, :integer, null: false add :maximum_entries, :integer, null: false - add :image, :string add :enrolled, :integer, default: 0, null: false - add :event_id, references(:events, type: :binary_id) + add :image, :string + add :location, :map + add :organization_id, references(:organizations, type: :binary_id), null: false timestamps() diff --git a/priv/repo/migrations/20221104160002_create_activity_enrollments.exs b/priv/repo/migrations/20221104160002_create_enrollments.exs similarity index 56% rename from priv/repo/migrations/20221104160002_create_activity_enrollments.exs rename to priv/repo/migrations/20221104160002_create_enrollments.exs index 1edd9cd8a..c1133b7ef 100644 --- a/priv/repo/migrations/20221104160002_create_activity_enrollments.exs +++ b/priv/repo/migrations/20221104160002_create_enrollments.exs @@ -1,13 +1,14 @@ -defmodule Atomic.Repo.Migrations.CreateActivityEnrollments do +defmodule Atomic.Repo.Migrations.CreateEnrollments do use Ecto.Migration def change do - create table(:activity_enrollments, primary_key: false) do + create table(:enrollments, primary_key: false) do add :id, :binary_id, primary_key: true + add :present, :boolean, null: false, default: false add :activity_id, references(:activities, on_delete: :delete_all, type: :binary_id) - add :user_id, references(:users, on_delete: :delete_all, type: :binary_id) + add :user_id, references(:users, type: :binary_id) timestamps() end diff --git a/priv/repo/migrations/20221123000537_create_partnerships.exs b/priv/repo/migrations/20221123000537_create_partners.exs similarity index 99% rename from priv/repo/migrations/20221123000537_create_partnerships.exs rename to priv/repo/migrations/20221123000537_create_partners.exs index edf7e571c..68470bf55 100644 --- a/priv/repo/migrations/20221123000537_create_partnerships.exs +++ b/priv/repo/migrations/20221123000537_create_partners.exs @@ -4,14 +4,17 @@ defmodule Atomic.Repo.Migrations.CreatePartners do def change do create table(:partners, primary_key: false) do add :id, :binary_id, primary_key: true + add :name, :string, null: false add :description, :text + add :notes, :text + add :benefits, :text + add :archived, :boolean, default: false add :image, :string + add :location, :map add :socials, :map - add :archived, :boolean, default: false - add :notes, :text add :organization_id, references(:organizations, on_delete: :delete_all, type: :binary_id) diff --git a/priv/repo/migrations/20221129000955_create_speakers.exs b/priv/repo/migrations/20221129000955_create_speakers.exs deleted file mode 100644 index d5a0210f6..000000000 --- a/priv/repo/migrations/20221129000955_create_speakers.exs +++ /dev/null @@ -1,15 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateSpeakers do - use Ecto.Migration - - def change do - create table(:speakers, primary_key: false) do - add :id, :binary_id, primary_key: true - add :name, :string, null: false - add :bio, :text - - add :organization_id, references(:organizations, on_delete: :delete_all, type: :binary_id) - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20221129000958_create_activity_speakers.exs b/priv/repo/migrations/20221129000958_create_activity_speakers.exs deleted file mode 100644 index f92bece26..000000000 --- a/priv/repo/migrations/20221129000958_create_activity_speakers.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateActivitySpeakers do - use Ecto.Migration - - def change do - create table(:activity_speakers, primary_key: false) do - add :id, :binary_id, primary_key: true - - add :activity_id, references(:activities, on_delete: :nothing, type: :binary_id) - add :speaker_id, references(:speakers, on_delete: :nothing, type: :binary_id) - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20221129000961_create_event_organization.exs b/priv/repo/migrations/20221129000961_create_event_organization.exs deleted file mode 100644 index ef04a60b0..000000000 --- a/priv/repo/migrations/20221129000961_create_event_organization.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateEventOrganization do - use Ecto.Migration - - def change do - create table(:event_organization, primary_key: false) do - add :id, :binary_id, primary_key: true - - add :organization_id, references(:organizations, on_delete: :nothing, type: :binary_id) - add :event_id, references(:events, on_delete: :nothing, type: :binary_id) - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20230313102641_create_memberships.exs b/priv/repo/migrations/20230313102641_create_memberships.exs index 530345532..93bb1db84 100644 --- a/priv/repo/migrations/20230313102641_create_memberships.exs +++ b/priv/repo/migrations/20230313102641_create_memberships.exs @@ -4,19 +4,15 @@ defmodule Atomic.Repo.Migrations.CreateMemberships do def change do create table(:memberships, primary_key: false) do add :id, :binary_id, primary_key: true - add :number, :integer - add :role, :string, null: false - add :created_by_id, references(:users, on_delete: :nothing, type: :binary_id), null: false - add :user_id, references(:users, on_delete: :nothing, type: :binary_id), null: false + add :role, :string, null: false - add :organization_id, references(:organizations, on_delete: :nothing, type: :binary_id), - null: false + add :user_id, references(:users, type: :binary_id), null: false + add :organization_id, references(:organizations, type: :binary_id), null: false timestamps() end create unique_index(:memberships, [:user_id, :organization_id]) - create unique_index(:memberships, [:number, :organization_id]) end end diff --git a/priv/repo/migrations/20230325151547_create_courses.exs b/priv/repo/migrations/20230325151547_create_courses.exs index cdcc9cdbf..c8298199a 100644 --- a/priv/repo/migrations/20230325151547_create_courses.exs +++ b/priv/repo/migrations/20230325151547_create_courses.exs @@ -4,6 +4,7 @@ defmodule Atomic.Repo.Migrations.CreateCourses do def change do create table(:courses, primary_key: false) do add :id, :binary_id, primary_key: true + add :name, :string, null: false add :cycle, :string, null: false @@ -11,7 +12,7 @@ defmodule Atomic.Repo.Migrations.CreateCourses do end alter table(:users) do - add :course_id, references(:courses, on_delete: :nothing, type: :binary_id) + add :course_id, references(:courses, type: :binary_id) end end end diff --git a/priv/repo/migrations/20230430092354_create_cards.exs b/priv/repo/migrations/20230430092354_create_cards.exs deleted file mode 100644 index fddbea7ff..000000000 --- a/priv/repo/migrations/20230430092354_create_cards.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateCards do - use Ecto.Migration - - def change do - alter table(:organizations) do - add :card_image, :string - add :card, :map, default: %{}, null: true - end - end -end diff --git a/priv/repo/migrations/20230914180406_create_event_enrollments.exs b/priv/repo/migrations/20230914180406_create_event_enrollments.exs deleted file mode 100644 index 18c69683d..000000000 --- a/priv/repo/migrations/20230914180406_create_event_enrollments.exs +++ /dev/null @@ -1,15 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateEventEnrollments do - use Ecto.Migration - - def change do - create table(:event_enrollments, primary_key: false) do - add :id, :binary_id, primary_key: true - add :present, :boolean, null: false, default: false - - add :event_id, references(:events, on_delete: :delete_all, type: :binary_id) - add :user_id, references(:users, on_delete: :delete_all, type: :binary_id) - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20230980102641_create_boards.exs b/priv/repo/migrations/20230980102641_create_boards.exs deleted file mode 100644 index 2a1d9e3e5..000000000 --- a/priv/repo/migrations/20230980102641_create_boards.exs +++ /dev/null @@ -1,16 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateBoards do - use Ecto.Migration - - def change do - create table(:boards, primary_key: false) do - add :id, :binary_id, primary_key: true - add :year, :string, null: false - - add :organization_id, references(:organizations, type: :binary_id), null: false - - timestamps() - end - - create unique_index(:boards, [:year, :organization_id]) - end -end diff --git a/priv/repo/migrations/20230980102645_create_board_departments.exs b/priv/repo/migrations/20230980102645_create_board_departments.exs deleted file mode 100644 index 673ff52d2..000000000 --- a/priv/repo/migrations/20230980102645_create_board_departments.exs +++ /dev/null @@ -1,15 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateBoardDepartments do - use Ecto.Migration - - def change do - create table(:board_departments, primary_key: false) do - add :id, :binary_id, primary_key: true - add :name, :string, null: false - add :priority, :integer, null: false - - add :board_id, references(:boards, type: :binary_id), null: false - - timestamps() - end - end -end diff --git a/priv/repo/migrations/20231030141755_create_users_organizations.exs b/priv/repo/migrations/20231030141755_create_users_organizations.exs deleted file mode 100644 index 519f949e9..000000000 --- a/priv/repo/migrations/20231030141755_create_users_organizations.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Atomic.Repo.Migrations.CreateUsersOrganizations do - use Ecto.Migration - - def change do - create table(:users_organizations, primary_key: false) do - add :id, :binary_id, primary_key: true - add :role, :string, null: false - add :priority, :integer, null: false - - add :user_id, references(:users, on_delete: :nothing, type: :binary_id), null: false - - add :board_departments_id, - references(:board_departments, on_delete: :nothing, type: :binary_id) - - timestamps() - end - end -end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index c7eb8290a..10c4efd54 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -15,8 +15,7 @@ defmodule Atomic.Repo.Seeds do "enrollments.exs", "departments.exs", "memberships.exs", - "partners.exs", - "speakers.exs" + "partners.exs" ] |> Enum.each(fn file -> Code.require_file("#{@seeds_dir}/#{file}") diff --git a/priv/repo/seeds/accounts.exs b/priv/repo/seeds/accounts.exs index 6aaa90760..55bff19d9 100644 --- a/priv/repo/seeds/accounts.exs +++ b/priv/repo/seeds/accounts.exs @@ -7,13 +7,13 @@ defmodule Atomic.Repo.Seeds.Accounts do alias Atomic.Organizations.Organization alias Atomic.Repo - @admins File.read!("priv/fake/admins.txt") |> String.split("\n") + @masters File.read!("priv/fake/masters.txt") |> String.split("\n") @students File.read!("priv/fake/students.txt") |> String.split("\n") def run do case Repo.all(User) do [] -> - seed_users(@admins, :admin) + seed_users(@masters, :master) seed_users(@students, :student) _ -> diff --git a/priv/repo/seeds/enrollments.exs b/priv/repo/seeds/enrollments.exs index b7cfc802b..9a8f37abf 100644 --- a/priv/repo/seeds/enrollments.exs +++ b/priv/repo/seeds/enrollments.exs @@ -4,8 +4,7 @@ defmodule Atomic.Repo.Seeds.Enrollments do """ alias Atomic.Accounts.User alias Atomic.Activities - alias Atomic.Activities.{Activity, ActivityEnrollment} - alias Atomic.Organizations.Organization + alias Atomic.Activities.{Activity, Enrollment} alias Atomic.Repo def run do @@ -13,7 +12,7 @@ defmodule Atomic.Repo.Seeds.Enrollments do end def seed_enrollments do - case Repo.all(ActivityEnrollment) do + case Repo.all(Enrollment) do [] -> users = Repo.all(User) activities = Repo.all(Activity) diff --git a/priv/repo/seeds/memberships.exs b/priv/repo/seeds/memberships.exs index 97cd004c5..89c9806f3 100644 --- a/priv/repo/seeds/memberships.exs +++ b/priv/repo/seeds/memberships.exs @@ -3,40 +3,14 @@ defmodule Atomic.Repo.Seeds.Memberships do Seeds the database with memberships. """ alias Atomic.Accounts.User - alias Atomic.Ecto.Year alias Atomic.Organization - alias Atomic.Organizations.{Board, BoardDepartments, Membership, Organization, UserOrganization} + alias Atomic.Organizations.{Membership, Organization} alias Atomic.Repo - @roles ~w(follower member admin owner)a - - @board_department_names [ - "Presidência", - "CAOS", - "Marketing e Conteúdo", - "Relações Externas e Parcerias", - "Pegadógico", - "Recreativo", - "Vogais", - "Mesa da Assembleia Geral", - "Conselho Fiscal" - ] - - @roles_inside_organization [ - "Presidente", - "Vice-Presidente", - "Secretário", - "Tesoureiro", - "Vogal", - "Diretor", - "Codiretor" - ] + @roles Membership.roles() def run do seed_memberships() - seed_boards() - seed_board_departments() - seed_user_organizations() end def seed_memberships do @@ -54,7 +28,6 @@ defmodule Atomic.Repo.Seeds.Memberships do |> Membership.changeset(%{ "user_id" => user.id, "organization_id" => Enum.random(organizations).id, - "created_by_id" => Enum.random(users).id, "role" => Enum.random(@roles) }) |> Repo.insert!() @@ -65,71 +38,6 @@ defmodule Atomic.Repo.Seeds.Memberships do Mix.shell().error("Found memberships, aborting seeding memberships.") end end - - def seed_boards do - case Repo.all(Board) do - [] -> - organizations = Repo.all(Organization) - - for organization <- organizations do - %Board{} - |> Board.changeset(%{ - "organization_id" => organization.id, - "year" => Year.current_year() - }) - |> Repo.insert!() - end - - _ -> - Mix.shell().error("Found boards, aborting seeding boards.") - end - end - - def seed_board_departments do - case Repo.all(BoardDepartments) do - [] -> - boards = Repo.all(Board) - - for board <- boards do - for i <- 0..(length(@board_department_names) - 1) do - %BoardDepartments{} - |> BoardDepartments.changeset(%{ - "board_id" => board.id, - "name" => Enum.at(@board_department_names, i), - "priority" => i - }) - |> Repo.insert!() - end - end - - _ -> - Mix.shell().error("Found board departments, aborting seeding board departments.") - end - end - - def seed_user_organizations do - case Repo.all(UserOrganization) do - [] -> - users = Repo.all(User) - board_departments = Repo.all(BoardDepartments) - - for board_department <- board_departments do - for i <- 0..(length(@roles_inside_organization) - 1) do - %UserOrganization{} - |> UserOrganization.changeset(%{ - "user_id" => Enum.random(users).id, - "board_departments_id" => board_department.id, - "role" => Enum.at(@roles_inside_organization, i), - "priority" => i - }) - |> Repo.insert!() - end - end - - _ -> - Mix.shell().error("Found user organizations, aborting seeding user organizations.") - end - end end Atomic.Repo.Seeds.Memberships.run() diff --git a/priv/repo/seeds/organizations.exs b/priv/repo/seeds/organizations.exs index dd2b42744..2aaf5fea8 100644 --- a/priv/repo/seeds/organizations.exs +++ b/priv/repo/seeds/organizations.exs @@ -19,6 +19,7 @@ defmodule Atomic.Repo.Seeds.Organizations do end def seed_organizations do + # Seed CeSIUM %Organization{ name: "CeSIUM", long_name: @@ -31,24 +32,6 @@ defmodule Atomic.Repo.Seeds.Organizations do } } |> Repo.insert!() - # TODO: Update to CeSIUM actual card - |> Organization.card_changeset(%{ - card: %{ - name_size: 2, - name_color: "#ff00ff", - name_x: -10, - name_y: -100, - number_size: 2, - number_color: "#00ff00", - number_x: 100, - number_y: 100 - }, - card_image: %Plug.Upload{ - path: "priv/static/images/card.png", - content_type: "image/png", - filename: "card.png" - } - }) |> Organization.logo_changeset(%{ logo: %Plug.Upload{ path: "priv/static/images/cesium-ORANGE.svg", @@ -58,6 +41,7 @@ defmodule Atomic.Repo.Seeds.Organizations do }) |> Repo.update!() + # Seed other organizations @organizations |> Enum.each(fn organization -> %{ diff --git a/priv/repo/seeds/speakers.exs b/priv/repo/seeds/speakers.exs deleted file mode 100644 index 52c2eb904..000000000 --- a/priv/repo/seeds/speakers.exs +++ /dev/null @@ -1,37 +0,0 @@ -defmodule Atomic.Repo.Seeds.Speakers do - @moduledoc """ - Seeds the database with speakers. - """ - alias Atomic.Activities - alias Atomic.Activities.Speaker - alias Atomic.Organizations.Organization - alias Atomic.Repo - - @organizations Repo.all(Organization) - - def run do - case Repo.all(Speaker) do - [] -> - seed_speakers() - - _ -> - Mix.shell().error("Found speakers, aborting seeding speakers.") - end - end - - def seed_speakers do - for _ <- 0..30 do - organization = Enum.random(@organizations) - - attrs = %{ - "name" => Faker.Person.name(), - "bio" => Faker.Lorem.sentence(), - "organization_id" => organization.id - } - - Activities.create_speaker(attrs) - end - end -end - -Atomic.Repo.Seeds.Speakers.run() diff --git a/test/atomic/activities_test.exs b/test/atomic/activities_test.exs index 0dfdb5186..1d3ab1749 100644 --- a/test/atomic/activities_test.exs +++ b/test/atomic/activities_test.exs @@ -3,9 +3,8 @@ defmodule Atomic.ActivitiesTest do use Atomic.DataCase alias Atomic.Activities + import Atomic.Factory - import Atomic.ActivitiesFixtures - alias Atomic.OrganizationsFixtures describe "activities" do alias Atomic.Activities.Activity @@ -77,9 +76,7 @@ defmodule Atomic.ActivitiesTest do end describe "enrollments" do - alias Atomic.Activities.ActivityEnrollment - - @invalid_attrs %{} + alias Atomic.Activities.Enrollment test "list_enrollments/0 returns all enrollments" do enrollment = insert(:enrollment) @@ -96,7 +93,7 @@ defmodule Atomic.ActivitiesTest do user = insert(:user) activity = insert(:activity) - assert {:ok, %ActivityEnrollment{}} = Activities.create_enrollment(activity.id, user) + assert {:ok, %Enrollment{}} = Activities.create_enrollment(activity.id, user) assert Activities.get_activity!(activity.id).enrolled == 1 end @@ -104,7 +101,7 @@ defmodule Atomic.ActivitiesTest do enrollment = insert(:enrollment) update_attrs = %{present: true} - assert {:ok, %ActivityEnrollment{}} = Activities.update_enrollment(enrollment, update_attrs) + assert {:ok, %Enrollment{}} = Activities.update_enrollment(enrollment, update_attrs) end test "delete_enrollment/1 deletes the enrollment" do @@ -118,62 +115,4 @@ defmodule Atomic.ActivitiesTest do assert %Ecto.Changeset{} = Activities.change_enrollment(enrollment) end end - - describe "speakers" do - alias Atomic.Activities.Speaker - - @invalid_attrs %{bio: nil, name: nil} - - test "list_speakers/0 returns all speakers" do - speaker = speaker_fixture() - assert Activities.list_speakers() == [speaker] - end - - test "get_speaker!/1 returns the speaker with given id" do - speaker = speaker_fixture() - assert Activities.get_speaker!(speaker.id) == speaker - end - - test "create_speaker/1 with valid data creates a speaker" do - valid_attrs = %{ - bio: "some bio", - name: "some name", - organization_id: OrganizationsFixtures.organization_fixture().id - } - - assert {:ok, %Speaker{} = speaker} = Activities.create_speaker(valid_attrs) - assert speaker.bio == "some bio" - assert speaker.name == "some name" - end - - test "create_speaker/1 with invalid data returns error changeset" do - assert {:error, %Ecto.Changeset{}} = Activities.create_speaker(@invalid_attrs) - end - - test "update_speaker/2 with valid data updates the speaker" do - speaker = speaker_fixture() - update_attrs = %{bio: "some updated bio", name: "some updated name"} - - assert {:ok, %Speaker{} = speaker} = Activities.update_speaker(speaker, update_attrs) - assert speaker.bio == "some updated bio" - assert speaker.name == "some updated name" - end - - test "update_speaker/2 with invalid data returns error changeset" do - speaker = speaker_fixture() - assert {:error, %Ecto.Changeset{}} = Activities.update_speaker(speaker, @invalid_attrs) - assert speaker == Activities.get_speaker!(speaker.id) - end - - test "delete_speaker/1 deletes the speaker" do - speaker = speaker_fixture() - assert {:ok, %Speaker{}} = Activities.delete_speaker(speaker) - assert_raise Ecto.NoResultsError, fn -> Activities.get_speaker!(speaker.id) end - end - - test "change_speaker/1 returns a speaker changeset" do - speaker = speaker_fixture() - assert %Ecto.Changeset{} = Activities.change_speaker(speaker) - end - end end diff --git a/test/atomic/exporter_test.exs b/test/atomic/exporter_test.exs deleted file mode 100644 index 1b3e1446c..000000000 --- a/test/atomic/exporter_test.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule Atomic.ExporterTest do - @moduledoc """ - Tests for the Atomic.Exporter module - """ - use ExUnit.Case, async: true - - import Atomic.Exporter - - doctest Atomic.Exporter -end diff --git a/test/atomic/organizations_test.exs b/test/atomic/organizations_test.exs index bbe3465d3..a116ba5a0 100644 --- a/test/atomic/organizations_test.exs +++ b/test/atomic/organizations_test.exs @@ -75,7 +75,7 @@ defmodule Atomic.OrganizationsTest do alias Atomic.Organizations.Membership test "list_memberships/1 returns all memberships of organization" do - membership = insert(:membership, role: :member) + membership = insert(:membership, role: :admin) memberships = Organizations.list_memberships(%{"organization_id" => membership.organization_id}) @@ -111,21 +111,20 @@ defmodule Atomic.OrganizationsTest do membership = insert(:membership) attrs = %{ - number: 42 + role: :admin } assert {:ok, %Membership{} = membership} = Organizations.update_membership(membership, attrs) - assert membership.number == 42 + assert membership.role == :admin end test "update_membership/2 with invalid data updates the membership" do membership = insert(:membership) attrs = %{ - user_id: nil, - number: 42 + user_id: nil } assert {:error, %Ecto.Changeset{}} = Organizations.update_membership(membership, attrs) @@ -144,62 +143,6 @@ defmodule Atomic.OrganizationsTest do end end - describe "board" do - test "list_users_organizations/2 returns none users organizations" do - assert Organizations.list_users_organizations() == [] - end - - test "list_users_organizations/2 returns all users organizations" do - user_organization = insert(:user_organization) - organizations = Organizations.list_users_organizations() |> Enum.map(& &1.id) - - assert organizations == [user_organization.id] - end - - test "get_user_organization!/2 raises Ecto.NoResultsError" do - insert(:user_organization) - - assert_raise Ecto.NoResultsError, - fn -> Organizations.get_user_organization!(Ecto.UUID.generate()) end - end - - test "get_user_organization!/2 returns existing user organization" do - user_organization = insert(:user_organization) - - assert Organizations.get_user_organization!(user_organization.id).id == - user_organization.id - end - - test "update_user_organization/2 updates existing user_organization" do - user_organization = insert(:user_organization) - board_department = insert(:board_department) - - {:ok, new_user_organization} = - Organizations.update_user_organization(user_organization, %{ - role: "Vice-Presidente", - board_departments_id: board_department.id - }) - - assert new_user_organization.role == "Vice-Presidente" - end - - test "delete_user_organization/1 deletes existing user organization" do - user_organization = insert(:user_organization) - - assert {:ok, _} = Organizations.delete_user_organization(user_organization) - assert Organizations.list_users_organizations() == [] - end - - test "change_user_organization/2 returns a changeset" do - user_organization = insert(:user_organization) - - assert %Ecto.Changeset{} = - Organizations.change_user_organization(user_organization, %{ - role: "Vice-Presidente" - }) - end - end - describe "announcements" do alias Atomic.Organizations.Announcement diff --git a/test/support/factories/accounts_factory.ex b/test/support/factories/accounts_factory.ex index b303a8751..bdfc44c78 100644 --- a/test/support/factories/accounts_factory.ex +++ b/test/support/factories/accounts_factory.ex @@ -7,7 +7,7 @@ defmodule Atomic.Factories.AccountFactory do defmacro __using__(_opts) do quote do - @roles ~w(admin student)a + @roles User.roles() def user_factory do %User{ diff --git a/test/support/factories/activities_factory.ex b/test/support/factories/activities_factory.ex index 880e4352c..a8e59e395 100644 --- a/test/support/factories/activities_factory.ex +++ b/test/support/factories/activities_factory.ex @@ -2,7 +2,7 @@ defmodule Atomic.Factories.ActivityFactory do @moduledoc """ A factory to generate account related structs """ - alias Atomic.Activities.{Activity, ActivityEnrollment} + alias Atomic.Activities.{Activity, Enrollment} defmacro __using__(_opts) do quote do @@ -23,7 +23,7 @@ defmodule Atomic.Factories.ActivityFactory do end def enrollment_factory do - %ActivityEnrollment{ + %Enrollment{ present: Enum.random([true, false]), activity: build(:activity), user: build(:user) diff --git a/test/support/factories/organizations_factory.ex b/test/support/factories/organizations_factory.ex index c8a66ad0a..33455426e 100644 --- a/test/support/factories/organizations_factory.ex +++ b/test/support/factories/organizations_factory.ex @@ -1,21 +1,16 @@ defmodule Atomic.Factories.OrganizationFactory do @moduledoc """ - A factory to generate organization related structs + A factory to generate organization related structs. """ - alias Atomic.Ecto.Year - alias Atomic.Organizations.{ Announcement, - Board, - BoardDepartments, Membership, - Organization, - UserOrganization + Organization } defmacro __using__(_opts) do quote do - @roles ~w(member admin owner)a + @roles Membership.roles() def organization_factory do %Organization{ @@ -28,36 +23,11 @@ defmodule Atomic.Factories.OrganizationFactory do def membership_factory do %Membership{ user: build(:user), - created_by: build(:user, role: "admin"), organization: build(:organization), role: Enum.random(@roles) } end - def board_factory do - %Board{ - year: Year.current_year(), - organization: build(:organization) - } - end - - def board_department_factory do - %BoardDepartments{ - name: Faker.Company.buzzword(), - priority: Enum.random(0..4), - board: build(:board) - } - end - - def user_organization_factory do - %UserOrganization{ - user: build(:user), - role: Faker.Company.bullshit(), - board_departments_id: build(:board_department).id, - priority: Enum.random(0..4) - } - end - def announcement_factory do organization = insert(:organization) diff --git a/test/support/fixtures/activities_fixtures.ex b/test/support/fixtures/activities_fixtures.ex index 9308bbf20..53d583351 100644 --- a/test/support/fixtures/activities_fixtures.ex +++ b/test/support/fixtures/activities_fixtures.ex @@ -25,20 +25,4 @@ defmodule Atomic.ActivitiesFixtures do activity end - - @doc """ - Generate a speaker. - """ - def speaker_fixture(attrs \\ %{}) do - {:ok, speaker} = - attrs - |> Enum.into(%{ - bio: "some bio", - name: "some name", - organization_id: OrganizationsFixtures.organization_fixture().id - }) - |> Atomic.Activities.create_speaker() - - speaker - end end diff --git a/test/support/fixtures/organizations_fixtures.ex b/test/support/fixtures/organizations_fixtures.ex index 8b0102c8e..c53be5495 100644 --- a/test/support/fixtures/organizations_fixtures.ex +++ b/test/support/fixtures/organizations_fixtures.ex @@ -19,129 +19,4 @@ defmodule Atomic.OrganizationsFixtures do organization end - - @doc """ - Generate an membership - """ - def membership_fixture(attrs \\ %{}) do - {:ok, organization} = - %{} - |> Enum.into(%{ - description: "some description", - name: "SN", - long_name: "some name" - }) - |> Atomic.Organizations.create_organization() - - {:ok, user} = - %{} - |> Enum.into(%{ - email: "test@mail.pt", - password: "password1234", - role: :student - }) - |> Atomic.Accounts.register_user() - - {:ok, membership} = - attrs - |> Enum.into(%{ - role: :member, - created_by_id: user.id, - user_id: user.id, - organization_id: organization.id - }) - |> Atomic.Organizations.create_membership() - - membership - end - - def board_fixture do - {:ok, organization} = - %{ - description: "some description", - name: "SN", - long_name: "some name" - } - |> Atomic.Organizations.create_organization() - - {:ok, board} = - %{ - year: "2022/2023", - organization_id: organization.id - } - |> Atomic.Board.create_board() - - board - end - - def board_department_fixture do - {:ok, organization} = - %{ - description: "some description", - name: "SN", - long_name: "some name" - } - |> Atomic.Organizations.create_organization() - - {:ok, board} = - %{ - year: "2022/2023", - organization_id: organization.id - } - |> Atomic.Board.create_board() - - {:ok, board_department} = - %{ - name: "SN", - board_id: board.id, - priority: 1 - } - |> Atomic.Board.create_board_department() - - board_department - end - - def user_organization_fixture do - {:ok, organization} = - %{ - description: "some description", - name: "SN", - long_name: "some name" - } - |> Atomic.Organizations.create_organization() - - {:ok, board} = - %{ - year: "2022/2023", - organization_id: organization.id - } - |> Atomic.Board.create_board() - - {:ok, board_department} = - %{ - name: "some name", - board_id: board.id, - priority: 1 - } - |> Atomic.Board.create_board_department() - - {:ok, user} = - %{ - email: "test@mail.com", - password: "password1234", - role: :student - } - |> Atomic.Accounts.register_user() - - {:ok, user_organization} = - %{ - user_id: user.id, - board_departments_id: board_department.id, - role: "some role", - priority: 1 - } - |> Atomic.Organizations.create_user_organization() - - user_organization - end end