BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
62ed1c53
Commit
62ed1c53
authored
Feb 05, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Explicitly define ordering in models using default_scope
parent
dbca8c97
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
67 additions
and
16 deletions
+67
-16
dashboard_controller.rb
app/controllers/admin/dashboard_controller.rb
+3
-3
groups_controller.rb
app/controllers/admin/groups_controller.rb
+1
-1
users_controller.rb
app/controllers/admin/users_controller.rb
+2
-2
keys_controller.rb
app/controllers/profiles/keys_controller.rb
+1
-1
broadcast_message.rb
app/models/broadcast_message.rb
+2
-0
internal_id.rb
app/models/concerns/internal_id.rb
+1
-0
sortable.rb
app/models/concerns/sortable.rb
+32
-0
email.rb
app/models/email.rb
+2
-0
event.rb
app/models/event.rb
+1
-0
web_hook.rb
app/models/hooks/web_hook.rb
+1
-0
identity.rb
app/models/identity.rb
+1
-0
key.rb
app/models/key.rb
+1
-0
label.rb
app/models/label.rb
+2
-0
member.rb
app/models/member.rb
+1
-0
merge_request_diff.rb
app/models/merge_request_diff.rb
+2
-0
namespace.rb
app/models/namespace.rb
+1
-0
note.rb
app/models/note.rb
+1
-0
project.rb
app/models/project.rb
+7
-4
service.rb
app/models/service.rb
+1
-0
snippet.rb
app/models/snippet.rb
+1
-0
user.rb
app/models/user.rb
+3
-3
issues.rb
lib/api/issues.rb
+0
-2
No files found.
app/controllers/admin/dashboard_controller.rb
View file @
62ed1c53
class
Admin
::
DashboardController
<
Admin
::
ApplicationController
def
index
@projects
=
Project
.
order
(
"created_at DESC"
).
limit
(
10
)
@users
=
User
.
order
(
"created_at DESC"
).
limit
(
10
)
@groups
=
Group
.
order
(
"created_at DESC"
).
limit
(
10
)
@projects
=
Project
.
limit
(
10
)
@users
=
User
.
limit
(
10
)
@groups
=
Group
.
limit
(
10
)
end
end
app/controllers/admin/groups_controller.rb
View file @
62ed1c53
...
...
@@ -2,7 +2,7 @@ class Admin::GroupsController < Admin::ApplicationController
before_filter
:group
,
only:
[
:edit
,
:show
,
:update
,
:destroy
,
:project_update
,
:project_teams_update
]
def
index
@groups
=
Group
.
order
(
'name ASC'
)
@groups
=
Group
.
order
_name
@groups
=
@groups
.
search
(
params
[
:name
])
if
params
[
:name
].
present?
@groups
=
@groups
.
page
(
params
[
:page
]).
per
(
20
)
end
...
...
app/controllers/admin/users_controller.rb
View file @
62ed1c53
...
...
@@ -5,13 +5,13 @@ class Admin::UsersController < Admin::ApplicationController
@users
=
User
.
filter
(
params
[
:filter
])
@users
=
@users
.
search
(
params
[
:name
])
if
params
[
:name
].
present?
@users
=
@users
.
sort
(
@sort
=
params
[
:sort
])
@users
=
@users
.
alphabetically
.
page
(
params
[
:page
])
@users
=
@users
.
order_name
.
page
(
params
[
:page
])
end
def
show
@personal_projects
=
user
.
personal_projects
@joined_projects
=
user
.
projects
.
joined
(
@user
)
@keys
=
user
.
keys
.
order
(
'id DESC'
)
@keys
=
user
.
keys
end
def
new
...
...
app/controllers/profiles/keys_controller.rb
View file @
62ed1c53
...
...
@@ -3,7 +3,7 @@ class Profiles::KeysController < ApplicationController
skip_before_filter
:authenticate_user!
,
only:
[
:get_keys
]
def
index
@keys
=
current_user
.
keys
.
order
(
'id DESC'
)
@keys
=
current_user
.
keys
end
def
show
...
...
app/models/broadcast_message.rb
View file @
62ed1c53
...
...
@@ -14,6 +14,8 @@
#
class
BroadcastMessage
<
ActiveRecord
::
Base
include
Sortable
validates
:message
,
presence:
true
validates
:starts_at
,
presence:
true
validates
:ends_at
,
presence:
true
...
...
app/models/concerns/internal_id.rb
View file @
62ed1c53
module
InternalId
extend
ActiveSupport
::
Concern
include
Sortable
included
do
validate
:set_iid
,
on: :create
...
...
app/models/concerns/sortable.rb
0 → 100644
View file @
62ed1c53
# == Sortable concern
#
# Set default scope for ordering objects
#
module
Sortable
extend
ActiveSupport
::
Concern
included
do
# By default all models should be ordered
# by created_at field starting from newest
default_scope
{
order
(
created_at: :desc
,
id: :desc
)
}
scope
:order_name
,
->
{
reorder
(
name: :asc
)
}
scope
:order_recent
,
->
{
reorder
(
created_at: :desc
,
id: :desc
)
}
scope
:order_oldest
,
->
{
reorder
(
created_at: :asc
,
id: :asc
)
}
scope
:order_recent_updated
,
->
{
reorder
(
updated_at: :desc
,
id: :desc
)
}
scope
:order_oldest_updated
,
->
{
reorder
(
updated_at: :asc
,
id: :asc
)
}
end
module
ClassMethods
def
sort
(
method
)
case
method
.
to_s
when
'name'
then
order_name_asc
when
'recent'
then
order_recent
when
'oldest'
then
order_oldest
when
'recent_updated'
then
order_recent_updated
when
'oldest_updated'
then
order_oldest_updated
else
self
end
end
end
end
app/models/email.rb
View file @
62ed1c53
...
...
@@ -10,6 +10,8 @@
#
class
Email
<
ActiveRecord
::
Base
include
Sortable
belongs_to
:user
validates
:user_id
,
presence:
true
...
...
app/models/event.rb
View file @
62ed1c53
...
...
@@ -15,6 +15,7 @@
#
class
Event
<
ActiveRecord
::
Base
include
Sortable
default_scope
{
where
.
not
(
author_id:
nil
)
}
CREATED
=
1
...
...
app/models/hooks/web_hook.rb
View file @
62ed1c53
...
...
@@ -16,6 +16,7 @@
#
class
WebHook
<
ActiveRecord
::
Base
include
Sortable
include
HTTParty
default_value_for
:push_events
,
true
...
...
app/models/identity.rb
View file @
62ed1c53
...
...
@@ -9,6 +9,7 @@
#
class
Identity
<
ActiveRecord
::
Base
include
Sortable
belongs_to
:user
validates
:extern_uid
,
allow_blank:
true
,
uniqueness:
{
scope: :provider
}
...
...
app/models/key.rb
View file @
62ed1c53
...
...
@@ -15,6 +15,7 @@
require
'digest/md5'
class
Key
<
ActiveRecord
::
Base
include
Sortable
include
Gitlab
::
Popen
belongs_to
:user
...
...
app/models/label.rb
View file @
62ed1c53
...
...
@@ -11,6 +11,8 @@
#
class
Label
<
ActiveRecord
::
Base
include
Sortable
DEFAULT_COLOR
=
'#428BCA'
belongs_to
:project
...
...
app/models/member.rb
View file @
62ed1c53
...
...
@@ -14,6 +14,7 @@
#
class
Member
<
ActiveRecord
::
Base
include
Sortable
include
Notifiable
include
Gitlab
::
Access
...
...
app/models/merge_request_diff.rb
View file @
62ed1c53
...
...
@@ -14,6 +14,8 @@
require
Rails
.
root
.
join
(
"app/models/commit"
)
class
MergeRequestDiff
<
ActiveRecord
::
Base
include
Sortable
# Prevent store of diff
# if commits amount more then 200
COMMITS_SAFE_SIZE
=
200
...
...
app/models/namespace.rb
View file @
62ed1c53
...
...
@@ -14,6 +14,7 @@
#
class
Namespace
<
ActiveRecord
::
Base
include
Sortable
include
Gitlab
::
ShellAdapter
has_many
:projects
,
dependent: :destroy
...
...
app/models/note.rb
View file @
62ed1c53
...
...
@@ -23,6 +23,7 @@ require 'file_size_validator'
class
Note
<
ActiveRecord
::
Base
include
Mentionable
default_scope
{
order
(
created_at: :asc
,
id: :asc
)
}
default_value_for
:system
,
false
attr_mentionable
:note
...
...
app/models/project.rb
View file @
62ed1c53
...
...
@@ -33,6 +33,7 @@ require 'carrierwave/orm/activerecord'
require
'file_size_validator'
class
Project
<
ActiveRecord
::
Base
include
Sortable
include
Gitlab
::
ShellAdapter
include
Gitlab
::
VisibilityLevel
include
Gitlab
::
ConfigHelper
...
...
@@ -53,7 +54,7 @@ class Project < ActiveRecord::Base
attr_accessor
:new_default_branch
# Relations
belongs_to
:creator
,
foreign_key:
'creator_id'
,
class_name:
'User'
belongs_to
:creator
,
foreign_key:
'creator_id'
,
class_name:
'User'
belongs_to
:group
,
->
{
where
(
type:
Group
)
},
foreign_key:
'namespace_id'
belongs_to
:namespace
...
...
@@ -86,7 +87,7 @@ class Project < ActiveRecord::Base
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
'target_project_id'
# 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
,
->
{
order
'issues.state DESC, issues.created_at DESC'
},
dependent: :destroy
has_many
:issues
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
...
...
@@ -139,14 +140,16 @@ class Project < ActiveRecord::Base
mount_uploader
:avatar
,
AttachmentUploader
# Scopes
scope
:sorted_by_activity
,
->
{
reorder
(
'projects.last_activity_at DESC'
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
'projects.star_count DESC'
)
}
scope
:sorted_by_names
,
->
{
joins
(
:namespace
).
reorder
(
'namespaces.name ASC, projects.name ASC'
)
}
scope
:without_user
,
->
(
user
)
{
where
(
'projects.id NOT IN (:ids)'
,
ids:
user
.
authorized_projects
.
map
(
&
:id
)
)
}
scope
:without_team
,
->
(
team
)
{
team
.
projects
.
present?
?
where
(
'projects.id NOT IN (:ids)'
,
ids:
team
.
projects
.
map
(
&
:
id
))
:
scoped
}
scope
:not_in_group
,
->
(
group
)
{
where
(
'projects.id NOT IN (:ids)'
,
ids:
group
.
project_ids
)
}
scope
:in_team
,
->
(
team
)
{
where
(
'projects.id IN (:ids)'
,
ids:
team
.
projects
.
map
(
&
:id
))
}
scope
:in_namespace
,
->
(
namespace
)
{
where
(
namespace_id:
namespace
.
id
)
}
scope
:in_group_namespace
,
->
{
joins
(
:group
)
}
scope
:sorted_by_activity
,
->
{
reorder
(
'projects.last_activity_at DESC'
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
'projects.star_count DESC'
)
}
scope
:personal
,
->
(
user
)
{
where
(
namespace_id:
user
.
namespace_id
)
}
scope
:joined
,
->
(
user
)
{
where
(
'namespace_id != ?'
,
user
.
namespace_id
)
}
scope
:public_only
,
->
{
where
(
visibility_level:
Project
::
PUBLIC
)
}
...
...
app/models/service.rb
View file @
62ed1c53
...
...
@@ -15,6 +15,7 @@
# To add new service you should build a class inherited from Service
# and implement a set of methods
class
Service
<
ActiveRecord
::
Base
include
Sortable
serialize
:properties
,
JSON
default_value_for
:active
,
false
...
...
app/models/snippet.rb
View file @
62ed1c53
...
...
@@ -16,6 +16,7 @@
#
class
Snippet
<
ActiveRecord
::
Base
include
Sortable
include
Linguist
::
BlobHelper
include
Gitlab
::
VisibilityLevel
...
...
app/models/user.rb
View file @
62ed1c53
...
...
@@ -49,6 +49,7 @@ require 'carrierwave/orm/activerecord'
require
'file_size_validator'
class
User
<
ActiveRecord
::
Base
include
Sortable
include
Gitlab
::
ConfigHelper
include
TokenAuthenticatable
extend
Gitlab
::
ConfigHelper
...
...
@@ -176,7 +177,6 @@ class User < ActiveRecord::Base
scope
:admins
,
->
{
where
(
admin:
true
)
}
scope
:blocked
,
->
{
with_state
(
:blocked
)
}
scope
:active
,
->
{
with_state
(
:active
)
}
scope
:alphabetically
,
->
{
order
(
'name ASC'
)
}
scope
:in_team
,
->
(
team
){
where
(
id:
team
.
member_ids
)
}
scope
:not_in_team
,
->
(
team
){
where
(
'users.id NOT IN (:ids)'
,
ids:
team
.
member_ids
)
}
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:
id
)
)
:
all
}
...
...
@@ -290,7 +290,7 @@ class User < ActiveRecord::Base
def
authorized_groups
@authorized_groups
||=
begin
group_ids
=
(
groups
.
pluck
(
:id
)
+
authorized_projects
.
pluck
(
:namespace_id
))
Group
.
where
(
id:
group_ids
)
.
order
(
'namespaces.name ASC'
)
Group
.
where
(
id:
group_ids
)
end
end
...
...
@@ -301,7 +301,7 @@ class User < ActiveRecord::Base
project_ids
=
personal_projects
.
pluck
(
:id
)
project_ids
.
push
(
*
groups_projects
.
pluck
(
:id
))
project_ids
.
push
(
*
projects
.
pluck
(
:id
).
uniq
)
Project
.
where
(
id:
project_ids
)
.
joins
(
:namespace
).
order
(
'namespaces.name ASC'
)
Project
.
where
(
id:
project_ids
)
end
end
...
...
lib/api/issues.rb
View file @
62ed1c53
...
...
@@ -39,7 +39,6 @@ module API
issues
=
current_user
.
issues
issues
=
filter_issues_state
(
issues
,
params
[
:state
])
unless
params
[
:state
].
nil?
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
issues
.
order
(
'issues.id DESC'
)
present
paginate
(
issues
),
with:
Entities
::
Issue
end
...
...
@@ -70,7 +69,6 @@ module API
unless
params
[
:milestone
].
nil?
issues
=
filter_issues_milestone
(
issues
,
params
[
:milestone
])
end
issues
=
issues
.
order
(
'issues.id DESC'
)
present
paginate
(
issues
),
with:
Entities
::
Issue
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