diff --git a/.tool-versions b/.tool-versions index 72e53aa9..39c1949f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ elixir 1.14.1-otp-25 -erlang 25.1.2 +erlang 25.2.3 nodejs 18.12.0 diff --git a/assets/package-lock.json b/assets/package-lock.json index 2d4e9ad7..161efb24 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -4,7 +4,6 @@ "requires": true, "packages": { "": { - "name": "assets", "license": "MIT", "dependencies": { "phoenix": "file:../deps/phoenix", @@ -24,11 +23,11 @@ } }, "../deps/phoenix": { - "version": "1.6.15", + "version": "1.7.7", "license": "MIT" }, "../deps/phoenix_html": { - "version": "3.2.0" + "version": "3.3.2" }, "node_modules/@babel/code-frame": { "version": "7.8.3", diff --git a/config/config.exs b/config/config.exs index 0b4f676f..9bc80908 100644 --- a/config/config.exs +++ b/config/config.exs @@ -14,7 +14,7 @@ config :safira, staff_code: System.get_env("DISCORD_STAFF_CODE"), from_email: System.get_env("FROM_EMAIL") || "test@seium.com", from_email_name: System.get_env("FROM_EMAIL_NAME") || "SEI", - roulette_cost: String.to_integer(System.get_env("ROULETTE_COST") || "10"), + roulette_cost: String.to_integer(System.get_env("ROULETTE_COST") || "20"), roulette_tokens_min: String.to_integer(System.get_env("ROULETTE_TOKENS_MIN") || "5"), roulette_tokens_max: String.to_integer(System.get_env("ROULETTE_TOKENS_MAX") || "20"), token_bonus: String.to_integer(System.get_env("TOKEN_BONUS") || "10"), diff --git a/lib/mix/tasks/gen.managers.ex b/lib/mix/tasks/gen.staffs.ex similarity index 83% rename from lib/mix/tasks/gen.managers.ex rename to lib/mix/tasks/gen.staffs.ex index cdb37645..b7cf5708 100644 --- a/lib/mix/tasks/gen.managers.ex +++ b/lib/mix/tasks/gen.staffs.ex @@ -1,6 +1,6 @@ -defmodule Mix.Tasks.Gen.Managers do +defmodule Mix.Tasks.Gen.Staffs do @moduledoc """ - Task to generate managers + Task to generate staffs """ use Mix.Task @@ -25,7 +25,7 @@ defmodule Mix.Tasks.Gen.Managers do Mix.Task.run("app.start") Enum.each(1..n, fn _n -> - email = Enum.join(["manager#{man_num() + 1}", @domain], "@") + email = Enum.join(["staff#{man_num() + 1}", @domain], "@") password = random_string(8) user = %{ @@ -34,14 +34,14 @@ defmodule Mix.Tasks.Gen.Managers do "password_confirmation" => password } - Accounts.create_manager(%{"user" => user}) + Accounts.create_staff(%{"user" => user}) IO.puts("#{email}:#{password}") end) end defp man_num do - Accounts.list_managers() + Accounts.list_staff() |> List.last() |> give_num end diff --git a/lib/mix/tasks/gen.managers_from_csv.ex b/lib/mix/tasks/gen.staffs_from_csv.ex similarity index 87% rename from lib/mix/tasks/gen.managers_from_csv.ex rename to lib/mix/tasks/gen.staffs_from_csv.ex index af38f9dd..76517523 100644 --- a/lib/mix/tasks/gen.managers_from_csv.ex +++ b/lib/mix/tasks/gen.staffs_from_csv.ex @@ -1,4 +1,4 @@ -defmodule Mix.Tasks.Gen.ManagersFromCsv do +defmodule Mix.Tasks.Gen.StaffsFromCsv do @shortdoc "Generates the mangers from a CSV" @moduledoc """ @@ -7,8 +7,8 @@ defmodule Mix.Tasks.Gen.ManagersFromCsv do and a flag ("Local"/"Remote") indicating if the file is local or remote ## Examples - $ mix gen.managers_from_csv "assets/managers_sei_exemplo.csv" "Local" - $ mix gen.managers_from_csv "https://sample.url.managers_sei_exemplo.csv" "Remote" + $ mix gen.staffs_from_csv "assets/staffs_sei_exemplo.csv" "Local" + $ mix gen.staffs_from_csv "https://sample.url.staffs_sei_exemplo.csv" "Remote" """ use Mix.Task @@ -90,7 +90,7 @@ defmodule Mix.Tasks.Gen.ManagersFromCsv do "password_confirmation" => password } - Accounts.create_manager(%{"user" => user, "is_admin" => convert!(user_csv_entry.admin)}) + Accounts.create_staff(%{"user" => user, "is_admin" => convert!(user_csv_entry.admin)}) IO.puts("#{email}:#{password}") end) diff --git a/lib/mix/tasks/gift.all.attendees.badge.ex b/lib/mix/tasks/gift.all.attendees.badge.ex index 88fb5389..7ee52785 100644 --- a/lib/mix/tasks/gift.all.attendees.badge.ex +++ b/lib/mix/tasks/gift.all.attendees.badge.ex @@ -24,7 +24,7 @@ defmodule Mix.Tasks.Gift.All.Attendees.Badge do |> Enum.each(fn a -> Contest.create_redeem(%{ attendee_id: a.id, - manager_id: 1, + staff_id: 1, badge_id: badge_id }) end) diff --git a/lib/mix/tasks/gift.all.badges.ex b/lib/mix/tasks/gift.all.badges.ex index 4105a625..9a762d04 100644 --- a/lib/mix/tasks/gift.all.badges.ex +++ b/lib/mix/tasks/gift.all.badges.ex @@ -17,7 +17,7 @@ defmodule Mix.Tasks.Gift.All.Badges do Safira.Contest.list_badges() |> Enum.map( - &Safira.Contest.create_redeem(%{attendee_id: attendee_id, manager_id: 1, badge_id: &1.id}) + &Safira.Contest.create_redeem(%{attendee_id: attendee_id, staff_id: 1, badge_id: &1.id}) ) end end diff --git a/lib/mix/tasks/gift.all_gold.badge.ex b/lib/mix/tasks/gift.all_gold.badge.ex index 1640a345..08b16dc6 100644 --- a/lib/mix/tasks/gift.all_gold.badge.ex +++ b/lib/mix/tasks/gift.all_gold.badge.ex @@ -47,7 +47,7 @@ defmodule Mix.Tasks.Gift.AllGold.Badge do attendees |> Enum.each(fn id -> - Contest.create_redeem(%{attendee_id: id, badge_id: badge_id, manager_id: 1}, :admin) + Contest.create_redeem(%{attendee_id: id, badge_id: badge_id, staff_id: 1}, :admin) end) end end diff --git a/lib/mix/tasks/gift.badge.ex b/lib/mix/tasks/gift.badge.ex index b7552a7a..cc23d56a 100644 --- a/lib/mix/tasks/gift.badge.ex +++ b/lib/mix/tasks/gift.badge.ex @@ -141,7 +141,7 @@ defmodule Mix.Tasks.Gift.Badge do defp give(attendee_id, badge_id) do Contest.create_redeem( - %{attendee_id: attendee_id, manager_id: 1, badge_id: badge_id}, + %{attendee_id: attendee_id, staff_id: 1, badge_id: badge_id}, :admin ) end diff --git a/lib/mix/tasks/gift.badge.full.participation.ex b/lib/mix/tasks/gift.badge.full.participation.ex index a375913c..2abf2874 100644 --- a/lib/mix/tasks/gift.badge.full.participation.ex +++ b/lib/mix/tasks/gift.badge.full.participation.ex @@ -43,7 +43,7 @@ defmodule Mix.Tasks.Gift.Badge.Full.Participation do Contest.create_redeem( %{ attendee_id: attendee_id, - manager_id: 1, + staff_id: 1, badge_id: badge_id }, :admin diff --git a/lib/mix/tasks/gift.badge.participation.ex b/lib/mix/tasks/gift.badge.participation.ex index 0a56eea1..e55fc4ad 100644 --- a/lib/mix/tasks/gift.badge.participation.ex +++ b/lib/mix/tasks/gift.badge.participation.ex @@ -46,7 +46,7 @@ defmodule Mix.Tasks.Gift.Badge.Participation do Contest.create_redeem( %{ attendee_id: attendee_id, - manager_id: 1, + staff_id: 1, badge_id: badge_id }, :admin diff --git a/lib/mix/tasks/gift.checkpoint.badge.ex b/lib/mix/tasks/gift.checkpoint.badge.ex index 431c0e75..91b4893f 100644 --- a/lib/mix/tasks/gift.checkpoint.badge.ex +++ b/lib/mix/tasks/gift.checkpoint.badge.ex @@ -88,7 +88,7 @@ defmodule Mix.Tasks.Gift.Company.Checkpoint.Badge do %{ attendee_id: a.id, badge_id: Map.get(args, :badge_id), - manager_id: 1 + staff_id: 1 } |> create_redeem(args, a, Map.get(args, :badge)) end) diff --git a/lib/mix/tasks/gift.checkpoint.badge.quantity.ex b/lib/mix/tasks/gift.checkpoint.badge.quantity.ex index 77506a29..5f5586d8 100644 --- a/lib/mix/tasks/gift.checkpoint.badge.quantity.ex +++ b/lib/mix/tasks/gift.checkpoint.badge.quantity.ex @@ -85,7 +85,7 @@ defmodule Mix.Tasks.Gift.Quantity.Checkpoint.Badge do %{ attendee_id: a.id, badge_id: Map.get(args, :badge_id), - manager_id: 1 + staff_id: 1 } |> create_redeem(args, a, Map.get(args, :badge)) end) diff --git a/lib/mix/tasks/gift.checkpoint.badge.with.redeemable.ex b/lib/mix/tasks/gift.checkpoint.badge.with.redeemable.ex index 8488d374..cd976dd6 100644 --- a/lib/mix/tasks/gift.checkpoint.badge.with.redeemable.ex +++ b/lib/mix/tasks/gift.checkpoint.badge.with.redeemable.ex @@ -94,7 +94,7 @@ defmodule Mix.Tasks.Gift.Company.Checkpoint.Badge.With.Redeemable do %{ attendee_id: a.id, badge_id: Map.get(args, :badge_id), - manager_id: 1 + staff_id: 1 } |> create_redeem(args, a, Map.get(args, :badge)) end) diff --git a/lib/mix/tasks/gift.daily.badge.ex b/lib/mix/tasks/gift.daily.badge.ex index 64dbfb92..cda277b5 100644 --- a/lib/mix/tasks/gift.daily.badge.ex +++ b/lib/mix/tasks/gift.daily.badge.ex @@ -43,7 +43,7 @@ defmodule Mix.Tasks.Gift.Daily.Badge do Contest.create_redeem( %{ attendee_id: a.id, - manager_id: 1, + staff_id: 1, badge_id: badge_id }, :admin diff --git a/lib/mix/tasks/govern.managers.ex b/lib/mix/tasks/govern.staffs.ex similarity index 73% rename from lib/mix/tasks/govern.managers.ex rename to lib/mix/tasks/govern.staffs.ex index a3f794e4..3f7cf91b 100644 --- a/lib/mix/tasks/govern.managers.ex +++ b/lib/mix/tasks/govern.staffs.ex @@ -1,6 +1,6 @@ -defmodule Mix.Tasks.Govern.Managers do +defmodule Mix.Tasks.Govern.Staffs do @moduledoc """ - Task to activate all manager accounts + Task to activate all staff accounts """ use Mix.Task @@ -20,8 +20,8 @@ defmodule Mix.Tasks.Govern.Managers do defp create(email, value) do Mix.Task.run("app.start") - Safira.Accounts.get_manager_by_email(email) + Safira.Accounts.get_staff_by_email(email) |> List.first() - |> Safira.Accounts.update_manager(%{active: value}) + |> Safira.Accounts.update_staff(%{active: value}) end end diff --git a/lib/safira/accounts/accounts.ex b/lib/safira/accounts/accounts.ex index a4ee13e8..af0260b7 100644 --- a/lib/safira/accounts/accounts.ex +++ b/lib/safira/accounts/accounts.ex @@ -7,7 +7,7 @@ defmodule Safira.Accounts do alias Safira.Accounts.Attendee alias Safira.Accounts.Company - alias Safira.Accounts.Manager + alias Safira.Accounts.Staff alias Safira.Accounts.User alias Safira.Repo @@ -22,7 +22,7 @@ defmodule Safira.Accounts do Repo.get!(User, id) |> Repo.preload(:attendee) |> Repo.preload(:company) - |> Repo.preload(:manager) + |> Repo.preload(:staff) end def get_user_email(email) do @@ -33,14 +33,14 @@ defmodule Safira.Accounts do Repo.get_by!(User, email: email) |> Repo.preload(:attendee) |> Repo.preload(:company) - |> Repo.preload(:manager) + |> Repo.preload(:staff) end def get_user_preload_email(email) do Repo.get_by(User, email: email) |> Repo.preload(:attendee) |> Repo.preload(:company) - |> Repo.preload(:manager) + |> Repo.preload(:staff) end def get_user_token(token) do @@ -151,39 +151,39 @@ defmodule Safira.Accounts do Attendee.changeset(attendee, %{}) end - def list_managers do - Repo.all(Manager) + def list_staff do + Repo.all(Staff) end - def get_manager!(id), do: Repo.get!(Manager, id) + def get_staff!(id), do: Repo.get!(Staff, id) - def get_manager_by_email(email) do + def get_staff_by_email(email) do Repo.all( - from m in Manager, + from m in Staff, join: u in assoc(m, :user), where: u.email == ^email, preload: [user: u] ) end - def create_manager(attrs \\ %{}) do - %Manager{} - |> Manager.changeset(attrs) + def create_staff(attrs \\ %{}) do + %Staff{} + |> Staff.changeset(attrs) |> Repo.insert() end - def update_manager(%Manager{} = manager, attrs) do - manager - |> Manager.changeset(attrs) + def update_staff(%Staff{} = staff, attrs) do + staff + |> Staff.changeset(attrs) |> Repo.update() end - def delete_manager(%Manager{} = manager) do - Repo.delete(manager) + def delete_staff(%Staff{} = staff) do + Repo.delete(staff) end - def change_manager(%Manager{} = manager) do - Manager.changeset(manager, %{}) + def change_staff(%Staff{} = staff) do + Staff.changeset(staff, %{}) end def list_companies do @@ -233,19 +233,19 @@ defmodule Safira.Accounts do |> Kernel.not() end - def is_manager(conn) do + def is_staff(conn) do get_user(conn) - |> Map.fetch!(:manager) + |> Map.fetch!(:staff) |> is_nil |> Kernel.not() end def is_admin(conn) do - manager = + staff = get_user(conn) - |> Map.fetch(:manager) + |> Map.fetch(:staff) - case manager do + case staff do {:error} -> false diff --git a/lib/safira/accounts/manager.ex b/lib/safira/accounts/staff.ex similarity index 73% rename from lib/safira/accounts/manager.ex rename to lib/safira/accounts/staff.ex index b18bfbdb..0ded08a4 100644 --- a/lib/safira/accounts/manager.ex +++ b/lib/safira/accounts/staff.ex @@ -1,6 +1,6 @@ -defmodule Safira.Accounts.Manager do +defmodule Safira.Accounts.Staff do @moduledoc """ - A manager is a staff member who can give attendees badges and + A staff is a staff member who can give attendees badges and deliver them prizes they win throughout the event """ use Ecto.Schema @@ -9,7 +9,7 @@ defmodule Safira.Accounts.Manager do alias Safira.Accounts.User alias Safira.Contest.Redeem - schema "managers" do + schema "staffs" do field :active, :boolean, default: true field :is_admin, :boolean, default: false @@ -19,8 +19,8 @@ defmodule Safira.Accounts.Manager do timestamps() end - def changeset(manager, attrs) do - manager + def changeset(staff, attrs) do + staff |> cast(attrs, [:active, :is_admin]) |> cast_assoc(:user) |> validate_required([:active, :is_admin]) diff --git a/lib/safira/accounts/user.ex b/lib/safira/accounts/user.ex index 65cd7b9a..fa567fd5 100644 --- a/lib/safira/accounts/user.ex +++ b/lib/safira/accounts/user.ex @@ -7,7 +7,7 @@ defmodule Safira.Accounts.User do alias Safira.Accounts.Attendee alias Safira.Accounts.Company - alias Safira.Accounts.Manager + alias Safira.Accounts.Staff schema "users" do field :email, :string @@ -15,7 +15,7 @@ defmodule Safira.Accounts.User do field :ban, :boolean, default: false has_one :attendee, Attendee, on_delete: :delete_all - has_one :manager, Manager, on_delete: :delete_all + has_one :staff, Staff, on_delete: :delete_all has_one :company, Company, on_delete: :delete_all field :reset_password_token, :string diff --git a/lib/safira/admin/accounts.ex b/lib/safira/admin/accounts.ex index 9dd06fc3..5a6f47fc 100644 --- a/lib/safira/admin/accounts.ex +++ b/lib/safira/admin/accounts.ex @@ -10,7 +10,7 @@ defmodule Safira.Admin.Accounts do alias Safira.Accounts.Attendee alias Safira.Accounts.Company - alias Safira.Accounts.Manager + alias Safira.Accounts.Staff alias Safira.Admin.Accounts.AdminUser @@ -170,16 +170,16 @@ defmodule Safira.Admin.Accounts do end @doc """ - Paginate the list of managers using filtrex + Paginate the list of staffs using filtrex filters. ## Examples - iex> list_managers(%{}) - %{managers: [%Manager{}], ...} + iex> list_staffs(%{}) + %{staffs: [%Staff{}], ...} """ - @spec paginate_managers(map) :: {:ok, map} | {:error, any} - def paginate_managers(params \\ %{}) do + @spec paginate_staffs(map) :: {:ok, map} | {:error, any} + def paginate_staffs(params \\ %{}) do params = params |> Map.put_new("sort_direction", "desc") @@ -189,11 +189,11 @@ defmodule Safira.Admin.Accounts do {:ok, sort_field} = Map.fetch(params, "sort_field") with {:ok, filter} <- - Filtrex.parse_params(filter_config(:managers), params["manager"] || %{}), - %Scrivener.Page{} = page <- do_paginate_managers(filter, params) do + Filtrex.parse_params(filter_config(:staffs), params["staff"] || %{}), + %Scrivener.Page{} = page <- do_paginate_staffs(filter, params) do {:ok, %{ - managers: page.entries, + staffs: page.entries, page_number: page.page_number, page_size: page.page_size, total_pages: page.total_pages, @@ -208,8 +208,8 @@ defmodule Safira.Admin.Accounts do end end - defp do_paginate_managers(filter, params) do - Manager + defp do_paginate_staffs(filter, params) do + Staff |> Filtrex.query(filter) |> where([m], not is_nil(m.user_id)) |> preload(:user) @@ -218,100 +218,100 @@ defmodule Safira.Admin.Accounts do end @doc """ - Returns the list of managers. + Returns the list of staffs. ## Examples - iex> list_managers() - [%Manager{}, ...] + iex> list_staffs() + [%Staff{}, ...] """ - def list_managers do - Repo.all(Manager) + def list_staffs do + Repo.all(Staff) end @doc """ - Gets a single manager. + Gets a single staff. - Raises `Ecto.NoResultsError` if the Manager does not exist. + Raises `Ecto.NoResultsError` if the Staff does not exist. ## Examples - iex> get_manager!(123) - %Manager{} + iex> get_staff!(123) + %Staff{} - iex> get_manager!(456) + iex> get_staff!(456) ** (Ecto.NoResultsError) """ - def get_manager!(id) do - Repo.get!(Manager, id) + def get_staff!(id) do + Repo.get!(Staff, id) |> Repo.preload(:user) end @doc """ - Creates a manager. + Creates a staff. ## Examples - iex> create_manager(%{field: value}) - {:ok, %Manager{}} + iex> create_staff(%{field: value}) + {:ok, %Staff{}} - iex> create_manager(%{field: bad_value}) + iex> create_staff(%{field: bad_value}) {:error, %Ecto.Changeset{}} """ - def create_manager(attrs \\ %{}) do - %Manager{} - |> Manager.changeset(attrs) + def create_staff(attrs \\ %{}) do + %Staff{} + |> Staff.changeset(attrs) |> Repo.insert() end @doc """ - Updates a manager. + Updates a staff. ## Examples - iex> update_manager(manager, %{field: new_value}) - {:ok, %Manager{}} + iex> update_staff(staff, %{field: new_value}) + {:ok, %Staff{}} - iex> update_manager(manager, %{field: bad_value}) + iex> update_staff(staff, %{field: bad_value}) {:error, %Ecto.Changeset{}} """ - def update_manager(%Manager{} = manager, attrs) do - manager - |> Manager.changeset(attrs) + def update_staff(%Staff{} = staff, attrs) do + staff + |> Staff.changeset(attrs) |> Repo.update() end @doc """ - Deletes a Manager. + Deletes a Staff. ## Examples - iex> delete_manager(manager) - {:ok, %Manager{}} + iex> delete_staff(staff) + {:ok, %Staff{}} - iex> delete_manager(manager) + iex> delete_staff(staff) {:error, %Ecto.Changeset{}} """ - def delete_manager(%Manager{} = manager) do - Repo.delete(manager) + def delete_staff(%Staff{} = staff) do + Repo.delete(staff) end @doc """ - Returns an `%Ecto.Changeset{}` for tracking manager changes. + Returns an `%Ecto.Changeset{}` for tracking staff changes. ## Examples - iex> change_manager(manager) - %Ecto.Changeset{source: %Manager{}} + iex> change_staff(staff) + %Ecto.Changeset{source: %Staff{}} """ - def change_manager(%Manager{} = manager) do - Manager.changeset(manager, %{}) + def change_staff(%Staff{} = staff) do + Staff.changeset(staff, %{}) end @doc """ @@ -465,7 +465,7 @@ defmodule Safira.Admin.Accounts do end end - defp filter_config(:managers) do + defp filter_config(:staffs) do defconfig do boolean(:active) end diff --git a/lib/safira/admin/contest.ex b/lib/safira/admin/contest.ex index d2780fdf..823e4321 100644 --- a/lib/safira/admin/contest.ex +++ b/lib/safira/admin/contest.ex @@ -195,7 +195,7 @@ defmodule Safira.Admin.Contest do defp do_paginate_redeems(filter, params) do Redeem |> Filtrex.query(filter) - |> preload([:badge, manager: :user, attendee: :user]) + |> preload([:badge, staff: :user, attendee: :user]) |> order_by(^sort(params)) |> paginate(Repo, params, @pagination) end @@ -229,7 +229,7 @@ defmodule Safira.Admin.Contest do """ def get_redeem!(id) do Repo.get!(Redeem, id) - |> Repo.preload([:badge, manager: :user, attendee: :user]) + |> Repo.preload([:badge, staff: :user, attendee: :user]) end @doc """ @@ -453,7 +453,7 @@ defmodule Safira.Admin.Contest do defp filter_config(:redeems) do defconfig do - number(:manager_id) + number(:staff_id) number(:badge_id) end end diff --git a/lib/safira/contest/contest.ex b/lib/safira/contest/contest.ex index 0cf71c53..c3119bde 100644 --- a/lib/safira/contest/contest.ex +++ b/lib/safira/contest/contest.ex @@ -168,7 +168,7 @@ defmodule Safira.Contest do Repo.get_by(DailyToken, attendee_id: attendee_id, day: day) end - def create_redeem(attrs \\ %{}, user_type \\ :manager) do + def create_redeem(attrs \\ %{}, user_type \\ :staff) do Multi.new() |> Multi.insert(:redeem, Redeem.changeset(%Redeem{}, attrs, user_type)) |> Multi.update(:attendee, fn %{redeem: redeem} -> diff --git a/lib/safira/contest/redeem.ex b/lib/safira/contest/redeem.ex index ae1729e0..d5009e9a 100644 --- a/lib/safira/contest/redeem.ex +++ b/lib/safira/contest/redeem.ex @@ -1,6 +1,6 @@ defmodule Safira.Contest.Redeem do @moduledoc """ - A redeem happens when a manager / company + A redeem happens when a staff / company gives a badge to an attendee """ use Ecto.Schema @@ -8,25 +8,25 @@ defmodule Safira.Contest.Redeem do alias Safira.Accounts alias Safira.Accounts.Attendee - alias Safira.Accounts.Manager + alias Safira.Accounts.Staff alias Safira.Contest alias Safira.Contest.Badge schema "redeems" do belongs_to(:attendee, Attendee, foreign_key: :attendee_id, type: :binary_id) - belongs_to(:manager, Manager) + belongs_to(:staff, Staff) belongs_to(:badge, Badge) timestamps() end @doc false - def changeset(redeem, attrs, user_type \\ :manager) do + def changeset(redeem, attrs, user_type \\ :staff) do redeem - |> cast(attrs, [:attendee_id, :manager_id, :badge_id]) + |> cast(attrs, [:attendee_id, :staff_id, :badge_id]) |> foreign_key_constraint(:attendee_id) - |> foreign_key_constraint(:manager_id) + |> foreign_key_constraint(:staff_id) |> validate_required([:attendee_id, :badge_id]) |> unique_constraint(:unique_attendee_badge, name: :unique_attendee_badge, diff --git a/lib/safira/roulette/roulette.ex b/lib/safira/roulette/roulette.ex index 7b0454ab..cede5872 100644 --- a/lib/safira/roulette/roulette.ex +++ b/lib/safira/roulette/roulette.ex @@ -393,7 +393,7 @@ defmodule Safira.Roulette do %{ attendee_id: attendee.id, badge_id: badge.id, - manager_id: 1 + staff_id: 1 }, :admin ) @@ -545,7 +545,7 @@ defmodule Safira.Roulette do end end - # redeems an item for an atendee, should only be used by managers + # redeems an item for an atendee, should only be used by staffs def redeem_prize(prize_id, attendee, quantity) do Multi.new() |> Multi.run(:attendee_prize, fn _repo, _changes -> diff --git a/lib/safira/store/store.ex b/lib/safira/store/store.ex index 08f9f2bb..031bcff7 100644 --- a/lib/safira/store/store.ex +++ b/lib/safira/store/store.ex @@ -135,7 +135,7 @@ defmodule Safira.Store do |> Repo.transaction() end - # redeems an item for an atendee, should only be used by managers + # redeems an item for an atendee, should only be used by staffs def redeem_redeemable(redeemable_id, attendee, quantity) do Multi.new() |> Multi.run(:buy, fn _repo, _changes -> diff --git a/lib/safira_web/authorize.ex b/lib/safira_web/authorize.ex index cc1e6b00..36354fdc 100644 --- a/lib/safira_web/authorize.ex +++ b/lib/safira_web/authorize.ex @@ -7,7 +7,7 @@ defmodule Safira.Authorize do alias Safira.Repo - @user_types [:attendee, :company, :manager] + @user_types [:attendee, :company, :staff] def init(default) do default diff --git a/lib/safira_web/controllers/admin/manager_controller.ex b/lib/safira_web/controllers/admin/manager_controller.ex deleted file mode 100644 index e23d1f8f..00000000 --- a/lib/safira_web/controllers/admin/manager_controller.ex +++ /dev/null @@ -1,71 +0,0 @@ -defmodule SafiraWeb.Admin.ManagerController do - use SafiraWeb, controller: "1.6" - - alias Safira.Accounts.Manager - alias Safira.Admin.Accounts - - plug(:put_layout, {SafiraWeb.LayoutView, "torch.html"}) - - def index(conn, params) do - case Accounts.paginate_managers(params) do - {:ok, assigns} -> - render(conn, "index.html", assigns) - - error -> - conn - |> put_flash(:error, "There was an error rendering Managers. #{inspect(error)}") - |> redirect(to: Routes.admin_manager_path(conn, :index)) - end - end - - def new(conn, _params) do - changeset = Accounts.change_manager(%Manager{}) - render(conn, "new.html", changeset: changeset) - end - - def create(conn, %{"manager" => manager_params}) do - case Accounts.create_manager(manager_params) do - {:ok, manager} -> - conn - |> put_flash(:info, "Manager created successfully.") - |> redirect(to: Routes.admin_manager_path(conn, :show, manager)) - - {:error, %Ecto.Changeset{} = changeset} -> - render(conn, "new.html", changeset: changeset) - end - end - - def show(conn, %{"id" => id}) do - manager = Accounts.get_manager!(id) - render(conn, "show.html", manager: manager) - end - - def edit(conn, %{"id" => id}) do - manager = Accounts.get_manager!(id) - changeset = Accounts.change_manager(manager) - render(conn, "edit.html", manager: manager, changeset: changeset) - end - - def update(conn, %{"id" => id, "manager" => manager_params}) do - manager = Accounts.get_manager!(id) - - case Accounts.update_manager(manager, manager_params) do - {:ok, manager} -> - conn - |> put_flash(:info, "Manager updated successfully.") - |> redirect(to: Routes.admin_manager_path(conn, :show, manager)) - - {:error, %Ecto.Changeset{} = changeset} -> - render(conn, "edit.html", manager: manager, changeset: changeset) - end - end - - def delete(conn, %{"id" => id}) do - manager = Accounts.get_manager!(id) - {:ok, _manager} = Accounts.delete_manager(manager) - - conn - |> put_flash(:info, "Manager deleted successfully.") - |> redirect(to: Routes.admin_manager_path(conn, :index)) - end -end diff --git a/lib/safira_web/controllers/admin/staff_controller.ex b/lib/safira_web/controllers/admin/staff_controller.ex new file mode 100644 index 00000000..f1a6789e --- /dev/null +++ b/lib/safira_web/controllers/admin/staff_controller.ex @@ -0,0 +1,71 @@ +defmodule SafiraWeb.Admin.StaffController do + use SafiraWeb, controller: "1.6" + + alias Safira.Accounts.Staff + alias Safira.Admin.Accounts + + plug(:put_layout, {SafiraWeb.LayoutView, "torch.html"}) + + def index(conn, params) do + case Accounts.paginate_staffs(params) do + {:ok, assigns} -> + render(conn, "index.html", assigns) + + error -> + conn + |> put_flash(:error, "There was an error rendering Staffs. #{inspect(error)}") + |> redirect(to: Routes.admin_staff_path(conn, :index)) + end + end + + def new(conn, _params) do + changeset = Accounts.change_staff(%Staff{}) + render(conn, "new.html", changeset: changeset) + end + + def create(conn, %{"staff" => staff_params}) do + case Accounts.create_staff(staff_params) do + {:ok, staff} -> + conn + |> put_flash(:info, "Staff created successfully.") + |> redirect(to: Routes.admin_staff_path(conn, :show, staff)) + + {:error, %Ecto.Changeset{} = changeset} -> + render(conn, "new.html", changeset: changeset) + end + end + + def show(conn, %{"id" => id}) do + staff = Accounts.get_staff!(id) + render(conn, "show.html", staff: staff) + end + + def edit(conn, %{"id" => id}) do + staff = Accounts.get_staff!(id) + changeset = Accounts.change_staff(staff) + render(conn, "edit.html", staff: staff, changeset: changeset) + end + + def update(conn, %{"id" => id, "staff" => staff_params}) do + staff = Accounts.get_staff!(id) + + case Accounts.update_staff(staff, staff_params) do + {:ok, staff} -> + conn + |> put_flash(:info, "Staff updated successfully.") + |> redirect(to: Routes.admin_staff_path(conn, :show, staff)) + + {:error, %Ecto.Changeset{} = changeset} -> + render(conn, "edit.html", staff: staff, changeset: changeset) + end + end + + def delete(conn, %{"id" => id}) do + staff = Accounts.get_staff!(id) + {:ok, _staff} = Accounts.delete_staff(staff) + + conn + |> put_flash(:info, "Staff deleted successfully.") + |> redirect(to: Routes.admin_staff_path(conn, :index)) + end +end diff --git a/lib/safira_web/controllers/attendee_controller.ex b/lib/safira_web/controllers/attendee_controller.ex index 9d9106fa..dc372b2a 100644 --- a/lib/safira_web/controllers/attendee_controller.ex +++ b/lib/safira_web/controllers/attendee_controller.ex @@ -26,8 +26,8 @@ defmodule SafiraWeb.AttendeeController do is_nil(attendee.user_id) -> {:error, :not_registered} - Accounts.is_manager(conn) -> - render(conn, "manager_show.json", attendee: attendee) + Accounts.is_staff(conn) -> + render(conn, "staff_show.json", attendee: attendee) true -> attendee = diff --git a/lib/safira_web/controllers/auth_controller.ex b/lib/safira_web/controllers/auth_controller.ex index a56a5ff3..70680b74 100644 --- a/lib/safira_web/controllers/auth_controller.ex +++ b/lib/safira_web/controllers/auth_controller.ex @@ -32,10 +32,10 @@ defmodule SafiraWeb.AuthController do |> Map.put(:id, user_preload.id) |> Map.put(:type, "company") - not is_nil(user_preload.manager) -> + not is_nil(user_preload.staff) -> user |> Map.put(:id, user_preload.id) - |> Map.put(:type, "manager") + |> Map.put(:type, "staff") end render(conn, :data, user: user) diff --git a/lib/safira_web/controllers/badge_controller.ex b/lib/safira_web/controllers/badge_controller.ex index 0a71ed5f..339ebcc8 100644 --- a/lib/safira_web/controllers/badge_controller.ex +++ b/lib/safira_web/controllers/badge_controller.ex @@ -12,7 +12,7 @@ defmodule SafiraWeb.BadgeController do badges = Contest.list_badges() render(conn, "index.json", badges: badges) - Accounts.is_manager(conn) -> + Accounts.is_staff(conn) -> badges = Contest.list_available_badges() render(conn, "index.json", badges: badges) diff --git a/lib/safira_web/controllers/deliver_prize_controller.ex b/lib/safira_web/controllers/deliver_prize_controller.ex index 703064f9..814c8722 100644 --- a/lib/safira_web/controllers/deliver_prize_controller.ex +++ b/lib/safira_web/controllers/deliver_prize_controller.ex @@ -22,13 +22,13 @@ defmodule SafiraWeb.DeliverPrizeController do " def create(conn, %{"redeem" => redeem_params}) do - # checks the user token to see if its a manager - if Accounts.is_manager(conn) do + # checks the user token to see if its a staff + if Accounts.is_staff(conn) do validate_redeem(conn, redeem_params) else conn |> put_status(:unauthorized) - |> json(%{error: "Only managers can give prizes"}) + |> json(%{error: "Only staffs can give prizes"}) end end diff --git a/lib/safira_web/controllers/deliver_redeemable_controller.ex b/lib/safira_web/controllers/deliver_redeemable_controller.ex index 7442a760..dda3185c 100644 --- a/lib/safira_web/controllers/deliver_redeemable_controller.ex +++ b/lib/safira_web/controllers/deliver_redeemable_controller.ex @@ -20,13 +20,13 @@ defmodule SafiraWeb.DeliverRedeemableController do " def create(conn, %{"redeem" => redeem_params}) do - # checks the user token to see if its a manager - if Accounts.is_manager(conn) do + # checks the user token to see if its a staff + if Accounts.is_staff(conn) do validate_redeem(conn, redeem_params) else conn |> put_status(:unauthorized) - |> json(%{error: "Only managers can deliver redeemables"}) + |> json(%{error: "Only staffs can deliver redeemables"}) end end @@ -38,7 +38,7 @@ defmodule SafiraWeb.DeliverRedeemableController do |> put_status(:bad_request) |> json(%{Error: "Wrong attendee"}) else - if Accounts.is_manager(conn) do + if Accounts.is_staff(conn) do redeemables = Store.get_attendee_not_redemed(attendee) render(conn, "index.json", delivers: redeemables) else diff --git a/lib/safira_web/controllers/discord_association_controller.ex b/lib/safira_web/controllers/discord_association_controller.ex index 618beafd..f8446a57 100644 --- a/lib/safira_web/controllers/discord_association_controller.ex +++ b/lib/safira_web/controllers/discord_association_controller.ex @@ -6,7 +6,7 @@ defmodule SafiraWeb.DiscordAssociationController do action_fallback SafiraWeb.FallbackController def show(conn, %{"id" => discord_id}) do - if Accounts.is_company(conn) || Accounts.is_manager(conn) do + if Accounts.is_company(conn) || Accounts.is_staff(conn) do show_aux(conn, discord_id) else conn @@ -18,7 +18,7 @@ defmodule SafiraWeb.DiscordAssociationController do # association_params= %{"discord_association_code" => discord_association_code, "discord_id" => discord_id} def create(conn, association_params) do - if Accounts.is_manager(conn) do + if Accounts.is_staff(conn) do association_aux(conn, association_params) else conn diff --git a/lib/safira_web/controllers/redeem_controller.ex b/lib/safira_web/controllers/redeem_controller.ex index 8c9a69ee..9e4c6cca 100644 --- a/lib/safira_web/controllers/redeem_controller.ex +++ b/lib/safira_web/controllers/redeem_controller.ex @@ -16,10 +16,10 @@ defmodule SafiraWeb.RedeemController do company_aux(conn, redeem_params, user) Accounts.is_admin(conn) -> - manager_aux(conn, redeem_params, user, :admin) + staff_aux(conn, redeem_params, user, :admin) - Accounts.is_manager(conn) -> - manager_aux(conn, redeem_params, user, :manager) + Accounts.is_staff(conn) -> + staff_aux(conn, redeem_params, user, :staff) true -> conn @@ -39,11 +39,11 @@ defmodule SafiraWeb.RedeemController do end end - defp manager_aux(conn, redeem_params, user, user_type) do + defp staff_aux(conn, redeem_params, user, user_type) do case Map.fetch(redeem_params, "badge_id") do {:ok, id} -> Contest.get_badge!(id) - redeem_params = Map.put(redeem_params, "manager_id", user.manager.id) + redeem_params = Map.put(redeem_params, "staff_id", user.staff.id) with {:ok, %Redeem{} = _redeem} <- Contest.create_redeem(redeem_params, user_type) do conn diff --git a/lib/safira_web/cors.ex b/lib/safira_web/cors.ex index f92b4937..cadb1ec2 100644 --- a/lib/safira_web/cors.ex +++ b/lib/safira_web/cors.ex @@ -3,7 +3,7 @@ defmodule SafiraWeb.CORS do @domain System.get_env("CORS_DOMAIN") use Corsica.Router, - origins: ~r{^https?://#{@domain}}, + origins: ["http://localhost:3000"], log: [rejected: :error, invalid: :warn, accepted: :debug], allow_headers: :all, allow_credentials: true, diff --git a/lib/safira_web/router.ex b/lib/safira_web/router.ex index 4c96d26d..35e01c6e 100644 --- a/lib/safira_web/router.ex +++ b/lib/safira_web/router.ex @@ -95,7 +95,7 @@ defmodule SafiraWeb.Router do resources "/badges", BadgeController resources "/attendees", AttendeeController - resources "/managers", ManagerController + resources "/staffs", StaffController resources "/companies", CompanyController resources "/redeems", RedeemController resources "/referrals", ReferralController diff --git a/lib/safira_web/templates/admin/redeem/index.html.eex b/lib/safira_web/templates/admin/redeem/index.html.eex index 66c9640c..c176acbe 100644 --- a/lib/safira_web/templates/admin/redeem/index.html.eex +++ b/lib/safira_web/templates/admin/redeem/index.html.eex @@ -10,9 +10,9 @@ <%= form_tag @conn.request_path, method: :get, id: "torch-filters-form" do %>
<%= manager.user.email %> | +<%= staf.user.email %> | -<%= manager.active %> | +<%= staff.active %> | - <%= link "Show", to: Routes.admin_manager_path(@conn, :show, manager) %> - <%= link "Edit", to: Routes.admin_manager_path(@conn, :edit, manager) %> - <%= link "Delete", to: Routes.admin_manager_path(@conn, :delete, manager), method: :delete, data: [confirm: "Are you sure?"] %> + <%= link "Show", to: Routes.admin_staff_path(@conn, :show, staff) %> + <%= link "Edit", to: Routes.admin_staff_path(@conn, :edit, staff) %> + <%= link "Delete", to: Routes.admin_staff_path(@conn, :delete, staff), method: :delete, data: [confirm: "Are you sure?"] %> |
No Managers match your search.
+No Staffs match your search.
<% end %>