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
Tatuya Kamada
gitlab-ce
Commits
e739eb03
Commit
e739eb03
authored
Apr 21, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move participants method to shared Participable concern.
parent
0ff778c0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
43 deletions
+51
-43
app/models/commit.rb
app/models/commit.rb
+2
-15
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+2
-16
app/models/concerns/participable.rb
app/models/concerns/participable.rb
+42
-0
app/models/note.rb
app/models/note.rb
+2
-0
app/models/snippet.rb
app/models/snippet.rb
+3
-12
No files found.
app/models/commit.rb
View file @
e739eb03
...
@@ -3,8 +3,10 @@ class Commit
...
@@ -3,8 +3,10 @@ class Commit
include
StaticModel
include
StaticModel
extend
ActiveModel
::
Naming
extend
ActiveModel
::
Naming
include
Mentionable
include
Mentionable
include
Participable
attr_mentionable
:safe_message
attr_mentionable
:safe_message
participant
:author
,
:committer
,
:notes
,
:mentioned_users
attr_accessor
:project
attr_accessor
:project
...
@@ -137,21 +139,6 @@ class Commit
...
@@ -137,21 +139,6 @@ class Commit
User
.
find_for_commit
(
committer_email
,
committer_name
)
User
.
find_for_commit
(
committer_email
,
committer_name
)
end
end
def
participants
(
current_user
=
nil
)
users
=
[]
users
<<
author
users
<<
committer
users
.
push
*
self
.
mentioned_users
(
current_user
)
notes
.
each
do
|
note
|
users
<<
note
.
author
users
.
push
*
note
.
mentioned_users
(
current_user
)
end
users
.
uniq
end
def
notes
def
notes
project
.
notes
.
for_commit_id
(
self
.
id
)
project
.
notes
.
for_commit_id
(
self
.
id
)
end
end
...
...
app/models/concerns/issuable.rb
View file @
e739eb03
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
module
Issuable
module
Issuable
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
include
Mentionable
include
Mentionable
include
Participable
included
do
included
do
belongs_to
:author
,
class_name:
"User"
belongs_to
:author
,
class_name:
"User"
...
@@ -45,6 +46,7 @@ module Issuable
...
@@ -45,6 +46,7 @@ module Issuable
prefix:
true
prefix:
true
attr_mentionable
:title
,
:description
attr_mentionable
:title
,
:description
participant
:author
,
:assignee
,
:notes
,
:mentioned_users
end
end
module
ClassMethods
module
ClassMethods
...
@@ -117,22 +119,6 @@ module Issuable
...
@@ -117,22 +119,6 @@ module Issuable
upvotes
+
downvotes
upvotes
+
downvotes
end
end
# Return all users participating on the discussion
def
participants
(
current_user
=
self
.
author
)
users
=
[]
users
<<
author
users
<<
assignee
if
is_assigned?
users
.
push
*
self
.
mentioned_users
(
current_user
)
notes
.
each
do
|
note
|
users
<<
note
.
author
users
.
push
*
note
.
mentioned_users
(
current_user
)
end
users
.
uniq
end
def
subscribed?
(
user
)
def
subscribed?
(
user
)
subscription
=
subscriptions
.
find_by_user_id
(
user
.
id
)
subscription
=
subscriptions
.
find_by_user_id
(
user
.
id
)
...
...
app/models/concerns/participable.rb
0 → 100644
View file @
e739eb03
module
Participable
extend
ActiveSupport
::
Concern
module
ClassMethods
def
participant
(
*
attrs
)
participant_attrs
.
concat
(
attrs
.
map
(
&
:to_s
))
end
def
participant_attrs
@participant_attrs
||=
[]
end
end
def
participants
(
current_user
=
self
.
author
)
self
.
class
.
participant_attrs
.
flat_map
do
|
attr
|
meth
=
method
(
attr
)
value
=
if
meth
.
arity
==
1
meth
.
call
(
current_user
)
else
meth
.
call
end
participants_for
(
value
,
current_user
)
end
.
compact
.
uniq
end
private
def
participants_for
(
value
,
current_user
=
nil
)
case
value
when
User
[
value
]
when
Array
value
.
flat_map
{
|
v
|
participants_for
(
v
,
current_user
)
}
when
Participable
value
.
participants
(
current_user
)
when
Mentionable
value
.
mentioned_users
(
current_user
)
end
end
end
app/models/note.rb
View file @
e739eb03
...
@@ -23,10 +23,12 @@ require 'file_size_validator'
...
@@ -23,10 +23,12 @@ require 'file_size_validator'
class
Note
<
ActiveRecord
::
Base
class
Note
<
ActiveRecord
::
Base
include
Mentionable
include
Mentionable
include
Gitlab
::
CurrentSettings
include
Gitlab
::
CurrentSettings
include
Participable
default_value_for
:system
,
false
default_value_for
:system
,
false
attr_mentionable
:note
attr_mentionable
:note
participant
:author
,
:mentioned_users
belongs_to
:project
belongs_to
:project
belongs_to
:noteable
,
polymorphic:
true
belongs_to
:noteable
,
polymorphic:
true
...
...
app/models/snippet.rb
View file @
e739eb03
...
@@ -19,6 +19,7 @@ class Snippet < ActiveRecord::Base
...
@@ -19,6 +19,7 @@ class Snippet < ActiveRecord::Base
include
Sortable
include
Sortable
include
Linguist
::
BlobHelper
include
Linguist
::
BlobHelper
include
Gitlab
::
VisibilityLevel
include
Gitlab
::
VisibilityLevel
include
Participable
default_value_for
:visibility_level
,
Snippet
::
PRIVATE
default_value_for
:visibility_level
,
Snippet
::
PRIVATE
...
@@ -47,6 +48,8 @@ class Snippet < ActiveRecord::Base
...
@@ -47,6 +48,8 @@ class Snippet < ActiveRecord::Base
scope
:expired
,
->
{
where
([
"expires_at IS NOT NULL AND expires_at < ?"
,
Time
.
current
])
}
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
])
}
scope
:non_expired
,
->
{
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
}
participant
:author
,
:notes
def
self
.
content_types
def
self
.
content_types
[
[
".rb"
,
".py"
,
".pl"
,
".scala"
,
".c"
,
".cpp"
,
".java"
,
".rb"
,
".py"
,
".pl"
,
".scala"
,
".c"
,
".cpp"
,
".java"
,
...
@@ -87,18 +90,6 @@ class Snippet < ActiveRecord::Base
...
@@ -87,18 +90,6 @@ class Snippet < ActiveRecord::Base
visibility_level
visibility_level
end
end
def
participants
(
current_user
=
self
.
author
)
users
=
[]
users
<<
author
notes
.
each
do
|
note
|
users
<<
note
.
author
users
.
push
*
note
.
mentioned_users
(
current_user
)
end
users
.
uniq
end
class
<<
self
class
<<
self
def
search
(
query
)
def
search
(
query
)
where
(
'(title LIKE :query OR file_name LIKE :query)'
,
query:
"%
#{
query
}
%"
)
where
(
'(title LIKE :query OR file_name LIKE :query)'
,
query:
"%
#{
query
}
%"
)
...
...
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