Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
30c6db8f
Commit
30c6db8f
authored
Dec 11, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move embeddable? to model to be used outside view
parent
00096b52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
9 deletions
+46
-9
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+0
-8
app/models/snippet.rb
app/models/snippet.rb
+8
-0
app/views/shared/snippets/_header.html.haml
app/views/shared/snippets/_header.html.haml
+1
-1
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+37
-0
No files found.
app/helpers/snippets_helper.rb
View file @
30c6db8f
...
@@ -130,12 +130,4 @@ module SnippetsHelper
...
@@ -130,12 +130,4 @@ module SnippetsHelper
link_to
external_snippet_icon
(
'download'
),
download_url
,
class:
'btn'
,
target:
'_blank'
,
title:
'Download'
,
rel:
'noopener noreferrer'
link_to
external_snippet_icon
(
'download'
),
download_url
,
class:
'btn'
,
target:
'_blank'
,
title:
'Download'
,
rel:
'noopener noreferrer'
end
end
def
public_snippet?
if
@snippet
.
project_id?
can?
(
nil
,
:read_project_snippet
,
@snippet
)
else
can?
(
nil
,
:read_personal_snippet
,
@snippet
)
end
end
end
end
app/models/snippet.rb
View file @
30c6db8f
...
@@ -175,6 +175,14 @@ class Snippet < ActiveRecord::Base
...
@@ -175,6 +175,14 @@ class Snippet < ActiveRecord::Base
:visibility_level
:visibility_level
end
end
def
embeddable?
if
project_id?
Ability
.
allowed?
(
nil
,
:read_project_snippet
,
self
)
else
Ability
.
allowed?
(
nil
,
:read_personal_snippet
,
self
)
end
end
def
notes_with_associations
def
notes_with_associations
notes
.
includes
(
:author
)
notes
.
includes
(
:author
)
end
end
...
...
app/views/shared/snippets/_header.html.haml
View file @
30c6db8f
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
-
if
@snippet
.
updated_at
!=
@snippet
.
created_at
-
if
@snippet
.
updated_at
!=
@snippet
.
created_at
=
edited_time_ago_with_tooltip
(
@snippet
,
placement:
'bottom'
,
html_class:
'snippet-edited-ago'
,
exclude_author:
true
)
=
edited_time_ago_with_tooltip
(
@snippet
,
placement:
'bottom'
,
html_class:
'snippet-edited-ago'
,
exclude_author:
true
)
-
if
public_snippet
?
-
if
@snippet
.
embeddable
?
.embed-snippet
.embed-snippet
.input-group
.input-group
.input-group-prepend
.input-group-prepend
...
...
spec/models/snippet_spec.rb
View file @
30c6db8f
...
@@ -423,4 +423,41 @@ describe Snippet do
...
@@ -423,4 +423,41 @@ describe Snippet do
expect
(
blob
.
data
).
to
eq
(
snippet
.
content
)
expect
(
blob
.
data
).
to
eq
(
snippet
.
content
)
end
end
end
end
describe
'#embeddable?'
do
context
'project snippet'
do
[
{
project: :public
,
snippet: :public
,
embeddable:
true
},
{
project: :internal
,
snippet: :public
,
embeddable:
false
},
{
project: :private
,
snippet: :public
,
embeddable:
false
},
{
project: :public
,
snippet: :internal
,
embeddable:
false
},
{
project: :internal
,
snippet: :internal
,
embeddable:
false
},
{
project: :private
,
snippet: :internal
,
embeddable:
false
},
{
project: :public
,
snippet: :private
,
embeddable:
false
},
{
project: :internal
,
snippet: :private
,
embeddable:
false
},
{
project: :private
,
snippet: :private
,
embeddable:
false
}
].
each
do
|
combination
|
it
'only returns true when both project and snippet are public'
do
project
=
create
(
:project
,
combination
[
:project
])
snippet
=
create
(
:project_snippet
,
combination
[
:snippet
],
project:
project
)
expect
(
snippet
.
embeddable?
).
to
eq
(
combination
[
:embeddable
])
end
end
end
context
'personal snippet'
do
[
{
snippet: :public
,
embeddable:
true
},
{
snippet: :internal
,
embeddable:
false
},
{
snippet: :private
,
embeddable:
false
}
].
each
do
|
combination
|
it
'only returns true when snippet is public'
do
snippet
=
create
(
:personal_snippet
,
combination
[
:snippet
])
expect
(
snippet
.
embeddable?
).
to
eq
(
combination
[
:embeddable
])
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment