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
Jérome Perrin
gitlab-ce
Commits
cfedd42b
Commit
cfedd42b
authored
Sep 20, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ProjectLabel model
parent
e2dd75c0
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
75 additions
and
52 deletions
+75
-52
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-1
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+4
-4
app/models/label.rb
app/models/label.rb
+0
-7
app/models/project.rb
app/models/project.rb
+4
-2
app/models/project_label.rb
app/models/project_label.rb
+5
-0
app/policies/project_label_policy.rb
app/policies/project_label_policy.rb
+1
-3
app/views/projects/labels/_form.html.haml
app/views/projects/labels/_form.html.haml
+1
-1
app/views/projects/labels/edit.html.haml
app/views/projects/labels/edit.html.haml
+1
-1
app/views/projects/labels/new.html.haml
app/views/projects/labels/new.html.haml
+1
-1
db/migrate/20160920191518_set_project_label_type_on_labels.rb
...igrate/20160920191518_set_project_label_type_on_labels.rb
+17
-0
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+1
-1
lib/gitlab/google_code_import/importer.rb
lib/gitlab/google_code_import/importer.rb
+1
-1
spec/factories/labels.rb
spec/factories/labels.rb
+1
-1
spec/models/label_spec.rb
spec/models/label_spec.rb
+24
-28
spec/models/project_label_spec.rb
spec/models/project_label_spec.rb
+11
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
No files found.
app/finders/issuable_finder.rb
View file @
cfedd42b
...
...
@@ -128,7 +128,8 @@ class IssuableFinder
@labels
=
Label
.
where
(
title:
label_names
)
if
projects
@labels
=
@labels
.
where
(
project:
projects
)
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
).
execute
.
select
(
:id
)
@labels
=
@labels
.
where
(
labels:
{
id:
label_ids
})
end
else
@labels
=
Label
.
none
...
...
app/helpers/labels_helper.rb
View file @
cfedd42b
...
...
@@ -57,21 +57,21 @@ module LabelsHelper
def
edit_label_path
(
label
)
case
label
when
GroupLabel
then
edit_group_label_path
(
label
.
group
,
label
)
else
edit_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
edit_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
def
destroy_label_path
(
label
)
case
label
when
GroupLabel
then
group_label_path
(
label
.
group
,
label
)
else
namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
def
toggle_subscription_label_path
(
label
)
case
label
when
GroupLabel
then
toggle_subscription_group_label_path
(
label
.
group
,
label
)
else
toggle_subscription_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
toggle_subscription_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
...
...
@@ -79,7 +79,7 @@ module LabelsHelper
title
,
icon
=
case
label
when
GroupLabel
then
[
'Group'
,
'folder-open'
]
else
[
'Project'
,
'bookmark'
]
when
ProjectLabel
then
[
'Project'
,
'bookmark'
]
end
options
[
:class
]
||=
''
...
...
app/models/label.rb
View file @
cfedd42b
...
...
@@ -15,15 +15,12 @@ class Label < ActiveRecord::Base
default_value_for
:color
,
DEFAULT_COLOR
belongs_to
:project
has_many
:lists
,
dependent: :destroy
has_many
:label_links
,
dependent: :destroy
has_many
:issues
,
through: :label_links
,
source: :target
,
source_type:
'Issue'
has_many
:merge_requests
,
through: :label_links
,
source: :target
,
source_type:
'MergeRequest'
validates
:color
,
color:
true
,
allow_blank:
false
validates
:project
,
presence:
true
,
if: :project_label?
# Don't allow ',' for label titles
validates
:title
,
presence:
true
,
format:
{
with:
/\A[^,]+\z/
}
...
...
@@ -137,10 +134,6 @@ class Label < ActiveRecord::Base
.
count
end
def
project_label?
type
.
blank?
&&
!
template?
end
def
label_format_reference
(
format
=
:id
)
raise
StandardError
,
'Unknown format'
unless
[
:id
,
:name
].
include?
(
format
)
...
...
app/models/project.rb
View file @
cfedd42b
...
...
@@ -107,7 +107,7 @@ class Project < ActiveRecord::Base
# Merge requests from source project should be kept when source project was removed
has_many
:fork_merge_requests
,
foreign_key:
'source_project_id'
,
class_name:
MergeRequest
has_many
:issues
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
,
class_name:
'ProjectLabel'
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:milestones
,
dependent: :destroy
...
...
@@ -730,8 +730,10 @@ class Project < ActiveRecord::Base
def
create_labels
Label
.
templates
.
each
do
|
label
|
label
=
label
.
dup
label
.
template
=
nil
label
.
template
=
false
label
.
project_id
=
self
.
id
label
.
type
=
'ProjectLabel'
label
.
save
end
end
...
...
app/models/project_label.rb
0 → 100644
View file @
cfedd42b
class
ProjectLabel
<
Label
belongs_to
:project
validates
:project
,
presence:
true
end
app/policies/label_policy.rb
→
app/policies/
project_
label_policy.rb
View file @
cfedd42b
class
LabelPolicy
<
BasePolicy
class
Project
LabelPolicy
<
BasePolicy
def
rules
return
unless
@user
can!
:admin_label
if
Ability
.
allowed?
(
@user
,
:admin_label
,
@subject
.
project
)
end
end
app/views/projects/labels/_form.html.haml
View file @
cfedd42b
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@label
]
,
html:
{
class:
'form-horizontal label-form js-quick-submit js-requires-input'
}
do
|
f
|
=
form_for
@label
,
as: :label
,
url:
url
,
html:
{
class:
'form-horizontal label-form js-quick-submit js-requires-input'
}
do
|
f
|
=
form_errors
(
@label
)
.form-group
...
...
app/views/projects/labels/edit.html.haml
View file @
cfedd42b
...
...
@@ -7,4 +7,4 @@
=
icon
(
'bookmark'
)
Edit Project Label
%hr
=
render
'form'
=
render
'form'
,
url:
namespace_project_label_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@label
)
app/views/projects/labels/new.html.haml
View file @
cfedd42b
...
...
@@ -7,4 +7,4 @@
=
icon
(
'bookmark'
)
New Project Label
%hr
=
render
'form'
=
render
'form'
,
url:
namespace_project_labels_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
db/migrate/20160920191518_set_project_label_type_on_labels.rb
0 → 100644
View file @
cfedd42b
class
SetProjectLabelTypeOnLabels
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
update_column_in_batches
(
:labels
,
:type
,
'ProjectLabel'
)
do
|
table
,
query
|
query
.
where
(
table
[
:project_id
].
not_eq
(
nil
))
end
end
def
down
update_column_in_batches
(
:labels
,
:type
,
nil
)
do
|
table
,
query
|
query
.
where
(
table
[
:project_id
].
not_eq
(
nil
))
end
end
end
lib/banzai/filter/label_reference_filter.rb
View file @
cfedd42b
...
...
@@ -70,7 +70,7 @@ module Banzai
end
def
object_link_text
(
object
,
matches
)
if
object
.
project
.
nil?
||
object
.
project
==
context
[
:project
]
if
object
.
is_a?
(
GroupLabel
)
||
object
.
project
==
context
[
:project
]
LabelsHelper
.
render_colored_label
(
object
)
else
LabelsHelper
.
render_colored_cross_project_label
(
object
)
...
...
lib/gitlab/google_code_import/importer.rb
View file @
cfedd42b
...
...
@@ -237,7 +237,7 @@ module Gitlab
def
create_label
(
name
)
color
=
nice_label_color
(
name
)
Label
.
create!
(
project_id:
project
.
id
,
name:
name
,
color:
color
)
project
.
labels
.
create!
(
name:
name
,
color:
color
)
end
def
format_content
(
raw_content
)
...
...
spec/factories/labels.rb
View file @
cfedd42b
FactoryGirl
.
define
do
factory
:label
do
factory
:label
,
class:
ProjectLabel
do
sequence
(
:title
)
{
|
n
|
"label
#{
n
}
"
}
color
"#990000"
project
...
...
spec/models/label_spec.rb
View file @
cfedd42b
require
'spec_helper'
describe
Label
,
models:
true
do
let
(
:label
)
{
create
(
:label
)
}
describe
'modules'
do
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Subscribable
)
}
end
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
have_many
(
:label_links
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
through
(
:label_links
).
source
(
:target
)
}
it
{
is_expected
.
to
have_many
(
:label_links
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:lists
).
dependent
(
:destroy
)
}
end
describe
'modules'
do
subject
{
described_class
}
it
{
is_expected
.
to
include_module
(
Referable
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:title
)
}
it
'validates color code'
do
expect
(
label
)
.
not_to
allow_value
(
'G-ITLAB'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'AABBCC'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'#AABBCCEE'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'GGHHII'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'#'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
''
).
for
(
:color
)
expect
(
label
)
.
to
allow_value
(
'#AABBCC'
).
for
(
:color
)
expect
(
label
)
.
to
allow_value
(
'#abcdef'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'G-ITLAB'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'AABBCC'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'#AABBCCEE'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'GGHHII'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'#'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
''
).
for
(
:color
)
is_expected
.
to
allow_value
(
'#AABBCC'
).
for
(
:color
)
is_expected
.
to
allow_value
(
'#abcdef'
).
for
(
:color
)
end
it
'validates title'
do
expect
(
label
)
.
not_to
allow_value
(
'G,ITLAB'
).
for
(
:title
)
expect
(
label
)
.
not_to
allow_value
(
''
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'GITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'gitlab'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'G?ITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'G&ITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
"customer's request"
).
for
(
:title
)
is_expected
.
not_to
allow_value
(
'G,ITLAB'
).
for
(
:title
)
is_expected
.
not_to
allow_value
(
''
).
for
(
:title
)
is_expected
.
to
allow_value
(
'GITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'gitlab'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'G?ITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'G&ITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
"customer's request"
).
for
(
:title
)
end
end
...
...
@@ -53,6 +47,8 @@ describe Label, models: true do
end
describe
'#to_reference'
do
let
(
:label
)
{
create
(
:label
)
}
context
'using id'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
...
...
spec/models/project_label_spec.rb
0 → 100644
View file @
cfedd42b
require
'spec_helper'
describe
ProjectLabel
,
models:
true
do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
end
end
spec/models/project_spec.rb
View file @
cfedd42b
...
...
@@ -56,7 +56,7 @@ describe Project, models: true do
it
{
is_expected
.
to
have_many
(
:runners
)
}
it
{
is_expected
.
to
have_many
(
:variables
)
}
it
{
is_expected
.
to
have_many
(
:triggers
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
class_name
(
'ProjectLabel'
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:users_star_projects
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:environments
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deployments
).
dependent
(
:destroy
)
}
...
...
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