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
97e0662c
Commit
97e0662c
authored
7 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Plain Diff
Merge branch 'bugs' into 'master'
Bugs - Collections See merge request !417
parents
4d58eaa6
65a9d2f8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/collection_item.rb
+8
-0
8 additions, 0 deletions
app/models/collection_item.rb
app/policies/collection_policy.rb
+6
-2
6 additions, 2 deletions
app/policies/collection_policy.rb
app/serializers/collection_item_serializer.rb
+11
-2
11 additions, 2 deletions
app/serializers/collection_item_serializer.rb
with
25 additions
and
4 deletions
app/models/collection_item.rb
+
8
−
0
View file @
97e0662c
...
...
@@ -25,6 +25,14 @@ class CollectionItem < ApplicationRecord
collection
end
def
public?
collectionable
.
privacy
==
'public'
end
def
owner?
(
candidate
)
collectionable
.
owner
==
candidate
end
def
thumbnail
collectionable_type
==
'LearningObject'
?
LearningObject
.
find
(
collectionable_id
).
default_thumbnail
:
Collection
.
find
(
collectionable_id
).
thumbnail
end
...
...
This diff is collapsed.
Click to expand it.
app/policies/collection_policy.rb
+
6
−
2
View file @
97e0662c
...
...
@@ -7,8 +7,12 @@ class CollectionPolicy < ApplicationPolicy
class
Scope
<
Scope
def
resolve
if
!
user
.
nil?
&&
user
.
is_admin?
scope
.
all
if
!
user
.
nil?
if
user
.
is_admin?
scope
.
all
else
scope
.
includes
(
:collection_items
).
where
.
not
(
:collection_items
=>
{
:collection_id
=>
nil
}).
where
(
"privacy = ? OR owner_id = ?"
,
'public'
,
user
.
id
)
end
else
scope
.
includes
(
:collection_items
).
where
.
not
(
:collection_items
=>
{
:collection_id
=>
nil
}).
where
(
privacy:
'public'
)
end
...
...
This diff is collapsed.
Click to expand it.
app/serializers/collection_item_serializer.rb
+
11
−
2
View file @
97e0662c
class
CollectionItemSerializer
<
ActiveModel
::
Serializer
cache
key:
'collection_item'
,
expires_in:
24
.
hours
def
collectionable
serializer
=
object
.
collectionable_type
==
"LearningObject"
?
::
LearningObjectSerializer
:
::
CollectionMinSerializer
serializer
.
new
(
object
.
collectionable
,
{
scope:
current_user
,
scope_name: :current_user
}).
serializable_hash
if
(
object
.
collectionable_type
==
"LearningObject"
)
serializer
=
::
LearningObjectSerializer
elsif
(
object
.
public?
||
(
current_user
&&
(
object
.
owner?
(
current_user
)
||
current_user
.
is_admin?
))
)
serializer
=
::
CollectionMinSerializer
end
if
(
!
serializer
.
blank?
)
serializer
.
new
(
object
.
collectionable
,
{
scope:
current_user
,
scope_name: :current_user
}).
serializable_hash
end
end
belongs_to
:collectionable
,
polymorphic:
true
attributes
:id
,
:position
,
:collectionable
,
:collectionable_type
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