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
Léo-Paul Géneau
gitlab-ce
Commits
b0b72c3b
Commit
b0b72c3b
authored
Mar 09, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
parents
0f149803
68f1535a
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
42 additions
and
69 deletions
+42
-69
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+3
-3
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+0
-10
app/models/personal_snippet.rb
app/models/personal_snippet.rb
+0
-1
app/models/project_snippet.rb
app/models/project_snippet.rb
+0
-3
app/models/snippet.rb
app/models/snippet.rb
+0
-7
db/migrate/20160305220806_remove_expires_at_from_snippets.rb
db/migrate/20160305220806_remove_expires_at_from_snippets.rb
+5
-0
db/schema.rb
db/schema.rb
+1
-3
doc/api/notes.md
doc/api/notes.md
+0
-1
doc/api/project_snippets.md
doc/api/project_snippets.md
+0
-1
doc/web_hooks/web_hooks.md
doc/web_hooks/web_hooks.md
+0
-1
lib/api/entities.rb
lib/api/entities.rb
+1
-1
spec/controllers/projects/forks_controller_spec.rb
spec/controllers/projects/forks_controller_spec.rb
+1
-1
spec/factories/personal_snippets.rb
spec/factories/personal_snippets.rb
+0
-11
spec/factories/project_snippets.rb
spec/factories/project_snippets.rb
+1
-5
spec/factories/snippets.rb
spec/factories/snippets.rb
+12
-0
spec/finders/snippets_finder_spec.rb
spec/finders/snippets_finder_spec.rb
+12
-13
spec/helpers/visibility_level_helper_spec.rb
spec/helpers/visibility_level_helper_spec.rb
+3
-3
spec/models/project_snippet_spec.rb
spec/models/project_snippet_spec.rb
+0
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+0
-1
spec/services/projects/update_service_spec.rb
spec/services/projects/update_service_spec.rb
+2
-2
No files found.
app/finders/snippets_finder.rb
View file @
b0b72c3b
...
...
@@ -4,7 +4,7 @@ class SnippetsFinder
case
filter
when
:all
then
snippets
(
current_user
).
fresh
.
non_expired
snippets
(
current_user
).
fresh
when
:by_user
then
by_user
(
current_user
,
params
[
:user
],
params
[
:scope
])
when
:by_project
...
...
@@ -27,7 +27,7 @@ class SnippetsFinder
end
def
by_user
(
current_user
,
user
,
scope
)
snippets
=
user
.
snippets
.
fresh
.
non_expired
snippets
=
user
.
snippets
.
fresh
return
snippets
.
are_public
unless
current_user
...
...
@@ -48,7 +48,7 @@ class SnippetsFinder
end
def
by_project
(
current_user
,
project
)
snippets
=
project
.
snippets
.
fresh
.
non_expired
snippets
=
project
.
snippets
.
fresh
if
current_user
if
project
.
team
.
member?
(
current_user
.
id
)
...
...
app/helpers/snippets_helper.rb
View file @
b0b72c3b
module
SnippetsHelper
def
lifetime_select_options
options
=
[
[
'forever'
,
nil
],
[
'1 day'
,
"
#{
Date
.
current
+
1
.
day
}
"
],
[
'1 week'
,
"
#{
Date
.
current
+
1
.
week
}
"
],
[
'1 month'
,
"
#{
Date
.
current
+
1
.
month
}
"
]
]
options_for_select
(
options
)
end
def
reliable_snippet_path
(
snippet
)
if
snippet
.
project_id?
namespace_project_snippet_path
(
snippet
.
project
.
namespace
,
...
...
app/models/personal_snippet.rb
View file @
b0b72c3b
...
...
@@ -10,7 +10,6 @@
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# visibility_level :integer default(0), not null
#
...
...
app/models/project_snippet.rb
View file @
b0b72c3b
...
...
@@ -10,7 +10,6 @@
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# visibility_level :integer default(0), not null
#
...
...
@@ -23,6 +22,4 @@ class ProjectSnippet < Snippet
# Scopes
scope
:fresh
,
->
{
order
(
"created_at DESC"
)
}
scope
:non_expired
,
->
{
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
}
scope
:expired
,
->
{
where
([
"expires_at IS NOT NULL AND expires_at < ?"
,
Time
.
current
])
}
end
app/models/snippet.rb
View file @
b0b72c3b
...
...
@@ -10,7 +10,6 @@
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# visibility_level :integer default(0), not null
#
...
...
@@ -46,8 +45,6 @@ class Snippet < ActiveRecord::Base
scope
:are_public
,
->
{
where
(
visibility_level:
Snippet
::
PUBLIC
)
}
scope
:public_and_internal
,
->
{
where
(
visibility_level:
[
Snippet
::
PUBLIC
,
Snippet
::
INTERNAL
])
}
scope
:fresh
,
->
{
order
(
"created_at DESC"
)
}
scope
:expired
,
->
{
where
([
"expires_at IS NOT NULL AND expires_at < ?"
,
Time
.
current
])
}
scope
:non_expired
,
->
{
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
}
participant
:author
,
:notes
...
...
@@ -111,10 +108,6 @@ class Snippet < ActiveRecord::Base
nil
end
def
expired?
expires_at
&&
expires_at
<
Time
.
current
end
def
visibility_level_field
visibility_level
end
...
...
db/migrate/20160305220806_remove_expires_at_from_snippets.rb
0 → 100644
View file @
b0b72c3b
class
RemoveExpiresAtFromSnippets
<
ActiveRecord
::
Migration
def
change
remove_column
:snippets
,
:expires_at
,
:datetime
end
end
db/schema.rb
View file @
b0b72c3b
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20160
222153918
)
do
ActiveRecord
::
Schema
.
define
(
version:
20160
305220806
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -777,7 +777,6 @@ ActiveRecord::Schema.define(version: 20160222153918) do
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"file_name"
t
.
datetime
"expires_at"
t
.
string
"type"
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
end
...
...
@@ -785,7 +784,6 @@ ActiveRecord::Schema.define(version: 20160222153918) do
add_index
"snippets"
,
[
"author_id"
],
name:
"index_snippets_on_author_id"
,
using: :btree
add_index
"snippets"
,
[
"created_at"
,
"id"
],
name:
"index_snippets_on_created_at_and_id"
,
using: :btree
add_index
"snippets"
,
[
"created_at"
],
name:
"index_snippets_on_created_at"
,
using: :btree
add_index
"snippets"
,
[
"expires_at"
],
name:
"index_snippets_on_expires_at"
,
using: :btree
add_index
"snippets"
,
[
"project_id"
],
name:
"index_snippets_on_project_id"
,
using: :btree
add_index
"snippets"
,
[
"updated_at"
],
name:
"index_snippets_on_updated_at"
,
using: :btree
add_index
"snippets"
,
[
"visibility_level"
],
name:
"index_snippets_on_visibility_level"
,
using: :btree
...
...
doc/api/notes.md
View file @
b0b72c3b
...
...
@@ -145,7 +145,6 @@ Parameters:
"state"
:
"active"
,
"created_at"
:
"2013-09-30T13:46:01Z"
},
"expires_at"
:
null
,
"updated_at"
:
"2013-10-02T07:34:20Z"
,
"created_at"
:
"2013-10-02T07:34:20Z"
}
...
...
doc/api/project_snippets.md
View file @
b0b72c3b
...
...
@@ -51,7 +51,6 @@ Parameters:
"state"
:
"active"
,
"created_at"
:
"2012-05-23T08:00:58Z"
},
"expires_at"
:
null
,
"updated_at"
:
"2012-06-28T10:52:04Z"
,
"created_at"
:
"2012-06-28T10:52:04Z"
}
...
...
doc/web_hooks/web_hooks.md
View file @
b0b72c3b
...
...
@@ -582,7 +582,6 @@ X-Gitlab-Event: Note Hook
"created_at"
:
"2015-04-09 02:40:38 UTC"
,
"updated_at"
:
"2015-04-09 02:40:38 UTC"
,
"file_name"
:
"test.rb"
,
"expires_at"
:
null
,
"type"
:
"ProjectSnippet"
,
"visibility_level"
:
0
}
...
...
lib/api/entities.rb
View file @
b0b72c3b
...
...
@@ -143,7 +143,7 @@ module API
class
ProjectSnippet
<
Grape
::
Entity
expose
:id
,
:title
,
:file_name
expose
:author
,
using:
Entities
::
UserBasic
expose
:
expires_at
,
:
updated_at
,
:created_at
expose
:updated_at
,
:created_at
end
class
ProjectEntity
<
Grape
::
Entity
...
...
spec/controllers/projects/forks_controller_spec.rb
View file @
b0b72c3b
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Projects
::
ForksController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
visibility_level:
Project
::
PUBLIC
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:forked_project
)
{
Projects
::
ForkService
.
new
(
project
,
user
).
execute
}
let
(
:group
)
{
create
(
:group
,
owner:
forked_project
.
creator
)
}
...
...
spec/factories/personal_snippets.rb
View file @
b0b72c3b
FactoryGirl
.
define
do
factory
:personal_snippet
,
parent: :snippet
,
class: :PersonalSnippet
do
trait
:public
do
visibility_level
PersonalSnippet
::
PUBLIC
end
trait
:internal
do
visibility_level
PersonalSnippet
::
INTERNAL
end
trait
:private
do
visibility_level
PersonalSnippet
::
PRIVATE
end
end
end
spec/factories/project_snippets.rb
View file @
b0b72c3b
FactoryGirl
.
define
do
factory
:project_snippet
do
factory
:project_snippet
,
parent: :snippet
,
class: :ProjectSnippet
do
project
author
title
content
file_name
end
end
spec/factories/snippets.rb
View file @
b0b72c3b
...
...
@@ -12,5 +12,17 @@ FactoryGirl.define do
title
content
file_name
trait
:public
do
visibility_level
Snippet
::
PUBLIC
end
trait
:internal
do
visibility_level
Snippet
::
INTERNAL
end
trait
:private
do
visibility_level
Snippet
::
PRIVATE
end
end
end
spec/finders/snippets_finder_spec.rb
View file @
b0b72c3b
...
...
@@ -8,12 +8,11 @@ describe SnippetsFinder do
let
(
:project1
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:private
,
group:
group
)
}
context
':all filter'
do
before
do
@snippet1
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
PRIVATE
)
@snippet2
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
INTERNAL
)
@snippet3
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
PUBLIC
)
@snippet1
=
create
(
:personal_snippet
,
:private
)
@snippet2
=
create
(
:personal_snippet
,
:internal
)
@snippet3
=
create
(
:personal_snippet
,
:public
)
end
it
"returns all private and internal snippets"
do
...
...
@@ -31,9 +30,9 @@ describe SnippetsFinder do
context
':by_user filter'
do
before
do
@snippet1
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
PRIVATE
,
author:
user
)
@snippet2
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
INTERNAL
,
author:
user
)
@snippet3
=
create
(
:personal_snippet
,
visibility_level:
Snippet
::
PUBLIC
,
author:
user
)
@snippet1
=
create
(
:personal_snippet
,
:private
,
author:
user
)
@snippet2
=
create
(
:personal_snippet
,
:internal
,
author:
user
)
@snippet3
=
create
(
:personal_snippet
,
:public
,
author:
user
)
end
it
"returns all public and internal snippets"
do
...
...
@@ -75,9 +74,9 @@ describe SnippetsFinder do
context
'by_project filter'
do
before
do
@snippet1
=
create
(
:project_snippet
,
visibility_level:
Snippet
::
PRIVATE
,
project:
project1
)
@snippet2
=
create
(
:project_snippet
,
visibility_level:
Snippet
::
INTERNAL
,
project:
project1
)
@snippet3
=
create
(
:project_snippet
,
visibility_level:
Snippet
::
PUBLIC
,
project:
project1
)
@snippet1
=
create
(
:project_snippet
,
:private
,
project:
project1
)
@snippet2
=
create
(
:project_snippet
,
:internal
,
project:
project1
)
@snippet3
=
create
(
:project_snippet
,
:public
,
project:
project1
)
end
it
"returns public snippets for unauthorized user"
do
...
...
spec/helpers/visibility_level_helper_spec.rb
View file @
b0b72c3b
...
...
@@ -58,7 +58,7 @@ describe VisibilityLevelHelper do
describe
"skip_level?"
do
describe
"forks"
do
let
(
:project
)
{
create
(
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
let
(
:fork_project
)
{
create
(
:forked_project_with_submodules
)
}
before
do
...
...
@@ -74,7 +74,7 @@ describe VisibilityLevelHelper do
end
describe
"non-forked project"
do
let
(
:project
)
{
create
(
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
it
"skips levels"
do
expect
(
skip_level?
(
project
,
Gitlab
::
VisibilityLevel
::
PUBLIC
)).
to
be_falsey
...
...
@@ -84,7 +84,7 @@ describe VisibilityLevelHelper do
end
describe
"Snippet"
do
let
(
:snippet
)
{
create
(
:snippet
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let
(
:snippet
)
{
create
(
:snippet
,
:internal
)
}
it
"skips levels"
do
expect
(
skip_level?
(
snippet
,
Gitlab
::
VisibilityLevel
::
PUBLIC
)).
to
be_falsey
...
...
spec/models/project_snippet_spec.rb
View file @
b0b72c3b
...
...
@@ -10,7 +10,6 @@
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# visibility_level :integer default(0), not null
#
...
...
spec/models/project_spec.rb
View file @
b0b72c3b
...
...
@@ -561,7 +561,7 @@ describe Project, models: true do
end
describe
'#visibility_level_allowed?'
do
let
(
:project
)
{
create
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
context
'when checking on non-forked project'
do
it
{
expect
(
project
.
visibility_level_allowed?
(
Gitlab
::
VisibilityLevel
::
PRIVATE
)).
to
be_truthy
}
...
...
spec/models/snippet_spec.rb
View file @
b0b72c3b
...
...
@@ -10,7 +10,6 @@
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
# type :string(255)
# visibility_level :integer default(0), not null
#
...
...
spec/services/projects/update_service_spec.rb
View file @
b0b72c3b
...
...
@@ -102,8 +102,8 @@ describe Projects::UpdateService, services: true do
describe
:visibility_level
do
let
(
:user
)
{
create
:user
,
admin:
true
}
let
(
:project
)
{
create
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
}
let
(
:forked_project
)
{
create
:forked_project_with_submodules
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
let
(
:forked_project
)
{
create
(
:forked_project_with_submodules
,
:internal
)
}
let
(
:opts
)
{
{}
}
before
do
...
...
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