Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 720becab authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Create restriction 'admin' to create topic

parent 90cfd5fb
Branches
No related tags found
1 merge request!3Deploy runtime
......@@ -4,6 +4,7 @@ defmodule DiskuyWeb.TopicController do
alias Diskuy.Forum
alias Diskuy.Forum.Topic
alias Diskuy.Utility.Utility
alias DiskuyWeb.Auth.Guardian
action_fallback DiskuyWeb.FallbackController
......@@ -13,7 +14,9 @@ defmodule DiskuyWeb.TopicController do
end
def create(conn, %{"topic" => topic_params}) do
with {:ok, %Topic{} = topic} <- Forum.create_topic(topic_params) do
current_user = Guardian.Plug.current_resource(conn)
with {:ok, :authorized} <- Guardian.check_admin(current_user),
{:ok, %Topic{} = topic} <- Forum.create_topic(topic_params) do
conn
|> put_status(:created)
|> put_resp_header("location", Routes.topic_path(conn, :show, topic))
......@@ -28,8 +31,9 @@ defmodule DiskuyWeb.TopicController do
def update(conn, %{"id" => id, "topic" => topic_params}) do
topic = Forum.get_topic_by_name!(id)
with {:ok, %Topic{} = topic} <- Forum.update_topic(topic, topic_params) do
current_user = Guardian.Plug.current_resource(conn)
with {:ok, :authorized} <- Guardian.check_admin(current_user),
{:ok, %Topic{} = topic} <- Forum.update_topic(topic, topic_params) do
render(conn, "show.json", topic: topic)
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment