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
Harbor 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
ab8514fe
Commit
ab8514fe
authored
9 years ago
by
Giovanne Marcelo
Browse files
Options
Downloads
Patches
Plain Diff
Adding learning object policy
parent
0d2ba1b1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/learning_objects_controller.rb
+6
-1
6 additions, 1 deletion
app/controllers/learning_objects_controller.rb
app/policies/learning_object_policy.rb
+25
-0
25 additions, 0 deletions
app/policies/learning_object_policy.rb
with
31 additions
and
1 deletion
app/controllers/learning_objects_controller.rb
+
6
−
1
View file @
ab8514fe
...
...
@@ -12,11 +12,11 @@ class LearningObjectsController < ApplicationController
:collections
,
:upload
,
:upload_link
,
:download
,
:user_not_authorized
]
after_action
:increment_learning_object_views
,
only:
[
:show
]
before_action
:authorize_action
# GET /learning_objects/1
# GET /learning_objects/1.json
def
show
authorize
@learning_object
@liked
=
!
@learning_object
.
liked?
(
current_user
)
if
user_signed_in?
@reviews
=
Review
.
where
(
reviewable:
@learning_object
)
end
...
...
@@ -135,4 +135,9 @@ class LearningObjectsController < ApplicationController
redirect_to
(
root_path
)
end
def
authorize_action
@learning_object
||=
LearningObject
.
new
authorize
@learning_object
end
end
This diff is collapsed.
Click to expand it.
app/policies/learning_object_policy.rb
+
25
−
0
View file @
ab8514fe
...
...
@@ -11,6 +11,18 @@ class LearningObjectPolicy < ApplicationPolicy
end
end
def
create?
record
unless
user
.
nil?
end
def
update?
record
if
user_authorized?
end
def
destroy?
record
if
user_authorized?
end
def
show?
if
user
.
nil?
record
.
state
==
'published'
...
...
@@ -20,4 +32,17 @@ class LearningObjectPolicy < ApplicationPolicy
record
.
state
==
'published'
end
end
private
def
user_authorized?
return
false
if
user
.
nil?
return
true
if
user
.
is_admin?
if
record
.
publisher
.
is_a?
Institution
record
.
publisher
.
users
.
include?
user
else
record
.
publisher
==
user
end
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