Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Diskuy-Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Functional Programming
Diskuy-Backend
Commits
720becab
Commit
720becab
authored
4 years ago
by
Muhammad Rafif Elfazri
Browse files
Options
Downloads
Patches
Plain Diff
Create restriction 'admin' to create topic
parent
90cfd5fb
Branches
Branches containing commit
No related tags found
1 merge request
!3
Deploy runtime
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/diskuy_web/controllers/topic_controller.ex
+7
-3
7 additions, 3 deletions
lib/diskuy_web/controllers/topic_controller.ex
with
7 additions
and
3 deletions
lib/diskuy_web/controllers/topic_controller.ex
+
7
−
3
View file @
720becab
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment