-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…459) (#460) Co-authored-by: abdelghani <[email protected]>
- Loading branch information
1 parent
68fb755
commit 95e3704
Showing
34 changed files
with
906 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule Erlef.AcademicPapers do | ||
@moduledoc """ | ||
Context responsible for managing Academic Papers | ||
""" | ||
|
||
alias Erlef.AcademicPapers.Query | ||
alias Erlef.AcademicPapers.AcademicPaper | ||
|
||
@spec all() :: [AcademicPaper.t()] | ||
def all(), do: Query.published() | ||
|
||
@spec get(Ecto.UUID.t()) :: AcademicPaper.t() | ||
def get(id), do: Query.get(id) | ||
|
||
@spec create_academic_paper(params :: map()) :: | ||
{:ok, AcademicPaper.t()} | {:error, Ecto.Changeset.t()} | ||
def create_academic_paper(params) do | ||
new_params = normalize_params(params) | ||
|
||
%AcademicPaper{} | ||
|> change_academic_paper(new_params) | ||
|> Query.create() | ||
end | ||
|
||
@spec update_academic_paper(academic_paper :: AcademicPaper.t(), params :: map()) :: | ||
{:ok, AcademicPaper.t()} | {:error, Ecto.Changeset.t()} | ||
def update_academic_paper(%AcademicPaper{} = academic_paper, params) do | ||
new_params = normalize_params(params) | ||
|
||
academic_paper | ||
|> change_academic_paper(new_params) | ||
|> Query.update() | ||
end | ||
|
||
@spec delete_academic_paper(academic_paper :: AcademicPaper.t()) :: | ||
{:ok, AcademicPaper.t()} | {:error, Ecto.Changeset.t()} | ||
def delete_academic_paper(%AcademicPaper{} = academic_paper) do | ||
academic_paper | ||
|> change_academic_paper(%{deleted_at: DateTime.utc_now()}) | ||
|> Query.update() | ||
end | ||
|
||
@spec change_academic_paper(academic_paper :: Ecto.Schema.t(), params :: map()) :: | ||
Ecto.Changeset.t() | ||
def change_academic_paper(%AcademicPaper{} = academic_paper, attrs \\ %{}), | ||
do: AcademicPaper.changeset(academic_paper, attrs) | ||
|
||
@spec unapproved_all() :: [AcademicPaper.t()] | ||
def unapproved_all(), do: Query.unpublished() | ||
|
||
@spec approve_academic_paper(academic_paper :: AcademicPaper.t(), params :: map()) :: | ||
{:ok, AcademicPaper.t()} | {:error, Ecto.Changeset.t()} | ||
def approve_academic_paper(%AcademicPaper{} = unapproved_academic_paper, params) do | ||
params0 = normalize_params(params) | ||
new_params = Map.put(params0, "published_at", DateTime.utc_now()) | ||
|
||
unapproved_academic_paper | ||
|> change_academic_paper(new_params) | ||
|> Query.update() | ||
end | ||
|
||
# Private Internal Functions | ||
|
||
defp normalize_params(%{"technologies" => _val} = params), do: params | ||
|
||
defp normalize_params(params), do: Map.put(params, "technologies", "") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ defmodule Erlef.Admins.Notifications do | |
|
||
import Swoosh.Email | ||
|
||
@type notification_type() :: :new_email_request | :new_event_submitted | :new_slack_invite | ||
@type notification_type() :: | ||
:new_email_request | ||
| :new_event_submitted | ||
| :new_academic_paper_submitted | ||
| :new_slack_invite | ||
|
||
@type params() :: map() | ||
|
||
|
@@ -31,4 +35,16 @@ defmodule Erlef.Admins.Notifications do | |
|> subject("A new event was submitted") | ||
|> text_body(msg) | ||
end | ||
|
||
def new(:new_academic_paper_submitted, _) do | ||
msg = """ | ||
A new academic paper was submitted, Visit https://erlef.org/admin/unapproved_academic_papers/ to view unapproved academic papers | ||
""" | ||
|
||
new() | ||
|> to({"Website Admins", "[email protected]"}) | ||
|> from({"Erlef Notifications", "[email protected]"}) | ||
|> subject("A new academic paper was submitted") | ||
|> text_body(msg) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ defmodule Erlef.Members.Notifications do | |
|
||
import Swoosh.Email | ||
|
||
@type notification_type() :: :new_event_submitted | :new_event_approved | ||
@type notification_type() :: | ||
:new_event_submitted | ||
| :new_academic_paper_submitted | ||
| :new_event_approved | ||
| :new_academic_paper_approved | ||
|
||
@type params() :: map() | ||
|
||
|
@@ -26,6 +30,25 @@ defmodule Erlef.Members.Notifications do | |
|> text_body(msg) | ||
end | ||
|
||
def new(:new_academic_paper_submitted, %{member: member}) do | ||
msg = """ | ||
Thanks for submitting a new academic paper, we appreciate your involvement in our community. | ||
An admin will approve the paper for display shortly. Once approved you will get an email stating so. | ||
If you haven't seen an approval for this academic paper in 48 hours please send an email to [email protected]. | ||
Thanks | ||
The Erlang Ecosystem Foundation | ||
""" | ||
|
||
new() | ||
|> to({member.name, member.email}) | ||
|> from({"Erlef Notifications", "[email protected]"}) | ||
|> subject("You submitted a new academic paper") | ||
|> text_body(msg) | ||
end | ||
|
||
def new(:new_event_approved, %{member: member}) do | ||
msg = """ | ||
An event you submitted has been approved and is now published on the site. | ||
|
@@ -44,4 +67,23 @@ defmodule Erlef.Members.Notifications do | |
|> subject("Your submitted event has been approved!") | ||
|> text_body(msg) | ||
end | ||
|
||
def new(:new_academic_paper_approved, %{member: member}) do | ||
msg = """ | ||
An academic paper you submitted has been approved and is now published on the site. | ||
Once again, we appreciate your involvement with our community and hope to see more academic papers | ||
submissions from you in the future! | ||
Thanks | ||
The Erlang Ecosystem Foundation | ||
""" | ||
|
||
new() | ||
|> to({member.name, member.email}) | ||
|> from({"Erlef Notifications", "[email protected]"}) | ||
|> subject("Your submitted academic paper has been approved!") | ||
|> text_body(msg) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
defmodule ErlefWeb.AcademicPaperController do | ||
use ErlefWeb, :controller | ||
|
||
alias Erlef.Publications | ||
alias Erlef.AcademicPapers | ||
alias Erlef.AcademicPapers.AcademicPaper | ||
alias Erlef.{Accounts, Admins, Members} | ||
|
||
action_fallback ErlefWeb.FallbackController | ||
|
||
def index(conn, _params) do | ||
render(conn, :index, academic_papers: Publications.all()) | ||
render(conn, :index, academic_papers: AcademicPapers.all()) | ||
end | ||
|
||
def new(conn, _params) do | ||
changeset = AcademicPapers.change_academic_paper(%AcademicPaper{}) | ||
render(conn, :new, changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"academic_paper" => params}) do | ||
submitter_id = conn.assigns.current_user.id | ||
new_params = Map.put(params, "submitted_by", submitter_id) | ||
|
||
case AcademicPapers.create_academic_paper(new_params) do | ||
{:ok, _academic_paper} -> | ||
type = :new_academic_paper_submitted | ||
submitter = Accounts.get_member(submitter_id) | ||
opts = %{member: submitter} | ||
{:ok, _notify} = Admins.notify(type, opts) | ||
{:ok, _notify} = Members.notify(type, opts) | ||
|
||
conn | ||
|> put_flash(:info, "Paper Submitted and has to be Approved") | ||
|> redirect(to: "/") | ||
|
||
{:error, changeset} -> | ||
render(conn, :new, changeset: changeset) | ||
end | ||
end | ||
end |
Oops, something went wrong.