Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
c4a238e4
Commit
c4a238e4
authored
7 years ago
by
Marcela Ribeiro de Oliveira
Browse files
Options
Downloads
Patches
Plain Diff
add route to update infohash of learning_object attachments
parent
009e044b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/v1/learning_objects/attachment_controller.rb
+24
-1
24 additions, 1 deletion
app/controllers/v1/learning_objects/attachment_controller.rb
app/policies/learning_object_policy.rb
+4
-0
4 additions, 0 deletions
app/policies/learning_object_policy.rb
with
28 additions
and
1 deletion
app/controllers/v1/learning_objects/attachment_controller.rb
+
24
−
1
View file @
c4a238e4
...
...
@@ -19,7 +19,9 @@
class
V1::LearningObjects::AttachmentController
<
ApplicationController
before_action
:set_objects
before_action
:authorize!
before_action
:authenticate_user!
,
only: :update
before_action
:authorize!
,
only: :destroy
before_action
:authorize_update_attachment!
,
only: :update
# DELETE /learning_objects/:learning_object_id/attachments/:id
def
destroy
...
...
@@ -30,6 +32,16 @@ class V1::LearningObjects::AttachmentController < ApplicationController
render
status: :ok
end
# PUT /learning_objects/:learning_object_id/attachments/:id
def
update
return
render
status: :not_found
if
@learning_object
.
nil?
||
@attachment
.
nil?
if
@attachment
.
update
(
infohash:
infohash_params
[
:infohash
])
render
status: :ok
else
render
status: :unprocessable_entity
end
end
private
...
...
@@ -37,6 +49,10 @@ class V1::LearningObjects::AttachmentController < ApplicationController
params
.
permit
(
:learning_object_id
,
:id
)
end
def
infohash_params
params
.
permit
(
:infohash
)
end
def
set_objects
@learning_object
=
LearningObject
.
find
(
attachment_params
[
:learning_object_id
])
@attachment
=
LearningObject
::
Attachment
.
find
(
attachment_params
[
:id
])
...
...
@@ -47,4 +63,11 @@ class V1::LearningObjects::AttachmentController < ApplicationController
authorize
(
@learning_object
,
:destroy?
)
end
def
authorize_update_attachment!
return
render
status: :unauthorized
unless
@learning_object
.
attachments
.
include?
@attachment
authorize
(
@learning_object
,
:add_infohash?
)
end
end
This diff is collapsed.
Click to expand it.
app/policies/learning_object_policy.rb
+
4
−
0
View file @
c4a238e4
...
...
@@ -61,6 +61,10 @@ class LearningObjectPolicy < ApplicationPolicy
record
if
owns?
end
def
add_infohash?
record
if
user
.
is_admin?
end
def
show?
return
record
if
record
.
published?
||
(
!
user
.
nil?
&&
user_can_edit?
)
return
record
if
user
==
record
.
publisher
...
...
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