Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/atlas/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Atlas.Accounts.User do
field :hashed_password, :string, redact: true
field :current_password, :string, virtual: true, redact: true
field :confirmed_at, :utc_datetime
field :type, Ecto.Enum, values: [:student, :admin, :professor]
field :type, Ecto.Enum, values: [:student, :admin, :professor, :department]

has_one :student, University.Student, on_delete: :delete_all

Expand Down
6 changes: 5 additions & 1 deletion lib/atlas_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ defmodule AtlasWeb.Router do
plug AtlasWeb.Plugs.UserRequires, user_types: [:professor, :admin]
end

pipeline :is_at_least_department do
plug AtlasWeb.Plugs.UserRequires, user_types: [:professor, :admin, :department]
end

scope "/", AtlasWeb do
get "/", PageController, :index
end
Expand Down Expand Up @@ -93,7 +97,7 @@ defmodule AtlasWeb.Router do
get "/selected", EventController, :selected_index
resources "/", EventController, only: [:index, :show]

pipe_through :is_at_least_professor
pipe_through :is_at_least_department

resources "/", EventController, only: [:create, :update, :delete]
end
Expand Down
5 changes: 5 additions & 0 deletions priv/fake/department_names.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CAOS
DMC
DSP
REC
PED
21 changes: 20 additions & 1 deletion priv/repo/seeds/users.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Atlas.Repo.Seeds.Accounts do

@first_names File.read!("priv/fake/first_names.txt") |> String.split("\n", trim: true)
@last_names File.read!("priv/fake/last_names.txt") |> String.split("\n", trim: true)
@department_names File.read!("priv/fake/department_names.txt") |> String.split("\n", trim: true)

def run do
case Accounts.list_users() do
Expand All @@ -15,10 +16,11 @@ defmodule Atlas.Repo.Seeds.Accounts do
end
end

def seed_users(students \\ 100, professors \\ 15, admins \\ 15) do
def seed_users(students \\ 100, professors \\ 15, admins \\ 15, departments \\ 5) do
seed_students(students)
seed_professors(professors)
seed_admins(admins)
seed_departments(departments)
end

defp seed_students(count) do
Expand Down Expand Up @@ -50,6 +52,23 @@ defmodule Atlas.Repo.Seeds.Accounts do
end
end

defp seed_departments(count) do
for i <- 1..count do
department_name = Enum.at(@department_names, i - 1)

email = "#{department_name |> String.downcase() |> String.replace(" ", ".")}@atlas.pt"

department = %{
name: department_name,
email: email,
password: "password1234",
type: :department
}

create_user(department, :department, i)
end
end

defp seed_professors(count) do
for i <- 1..count do
first_name = Enum.random(@first_names)
Expand Down