Skip to content

Commit

Permalink
refactor: remove future features
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Aug 6, 2024
1 parent 498d687 commit a0bb6cb
Show file tree
Hide file tree
Showing 110 changed files with 204 additions and 3,247 deletions.
2 changes: 1 addition & 1 deletion lib/atomic/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions lib/atomic/accounts/course.ex
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down
23 changes: 15 additions & 8 deletions lib/atomic/accounts/user.ex
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
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}

schema "users" 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
Expand Down Expand Up @@ -226,4 +231,6 @@ defmodule Atomic.Accounts.User do
add_error(changeset, :current_password, "is not valid")
end
end

def roles, do: @roles
end
1 change: 1 addition & 0 deletions lib/atomic/accounts/user_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit a0bb6cb

Please sign in to comment.