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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2d17e8e6
Commit
2d17e8e6
authored
Jan 29, 2019
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '50352-sort-save-ee' into 'master'
Port of 50352-sort-save See merge request gitlab-org/gitlab-ee!9219
parents
7beb4d7c
8de48a40
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
151 additions
and
45 deletions
+151
-45
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+2
-2
app/controllers/concerns/issuable_collections_action.rb
app/controllers/concerns/issuable_collections_action.rb
+30
-3
app/controllers/concerns/merge_requests_action.rb
app/controllers/concerns/merge_requests_action.rb
+0
-25
app/controllers/dashboard_controller.rb
app/controllers/dashboard_controller.rb
+1
-2
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+1
-2
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+4
-0
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+4
-0
app/models/issue.rb
app/models/issue.rb
+2
-0
app/models/merge_request.rb
app/models/merge_request.rb
+2
-0
changelogs/unreleased/50352-sort-save.yml
changelogs/unreleased/50352-sort-save.yml
+5
-0
db/migrate/20190116234221_add_sorting_fields_to_user_preference.rb
...e/20190116234221_add_sorting_fields_to_user_preference.rb
+21
-0
db/schema.rb
db/schema.rb
+2
-0
spec/controllers/concerns/issuable_collections_spec.rb
spec/controllers/concerns/issuable_collections_spec.rb
+45
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+3
-1
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+3
-1
spec/models/user_preference_spec.rb
spec/models/user_preference_spec.rb
+24
-1
spec/support/shared_examples/controllers/set_sort_order_from_user_preference_shared_examples.rb
...rs/set_sort_order_from_user_preference_shared_examples.rb
+2
-8
No files found.
app/controllers/concerns/issuable_collections.rb
View file @
2d17e8e6
...
...
@@ -129,13 +129,13 @@ module IssuableCollections
return
sort_param
if
Gitlab
::
Database
.
read_only?
if
user_preference
[
issuable_sorting_field
]
!=
sort_param
user_preference
.
update
_attribute
(
issuable_sorting_field
,
sort_param
)
user_preference
.
update
(
issuable_sorting_field
=>
sort_param
)
end
sort_param
end
# Implement
default
_sorting_field method on controllers
# Implement
issuable
_sorting_field method on controllers
# to choose which column to store the sorting parameter.
def
issuable_sorting_field
nil
...
...
app/controllers/concerns/issu
e
s_action.rb
→
app/controllers/concerns/issu
able_collection
s_action.rb
View file @
2d17e8e6
# frozen_string_literal: true
module
Issu
e
sAction
module
Issu
ableCollection
sAction
extend
ActiveSupport
::
Concern
include
IssuableCollections
include
IssuesCalendar
...
...
@@ -18,6 +18,12 @@ module IssuesAction
format
.
atom
{
render
layout:
'xml.atom'
}
end
end
def
merge_requests
@merge_requests
=
issuables_collection
.
page
(
params
[
:page
])
@issuable_meta_data
=
issuable_meta_data
(
@merge_requests
,
collection_type
)
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def
issues_calendar
...
...
@@ -26,8 +32,29 @@ module IssuesAction
private
def
issuable_sorting_field
case
action_name
when
'issues'
Issue
::
SORTING_PREFERENCE_FIELD
when
'merge_requests'
MergeRequest
::
SORTING_PREFERENCE_FIELD
else
nil
end
end
def
finder_type
(
super
if
defined?
(
super
))
||
(
IssuesFinder
if
%w(issues issues_calendar)
.
include?
(
action_name
))
case
action_name
when
'issues'
,
'issues_calendar'
IssuesFinder
when
'merge_requests'
MergeRequestsFinder
else
nil
end
end
def
finder_options
super
.
merge
(
non_archived:
true
)
end
end
app/controllers/concerns/merge_requests_action.rb
deleted
100644 → 0
View file @
7beb4d7c
# frozen_string_literal: true
module
MergeRequestsAction
extend
ActiveSupport
::
Concern
include
IssuableCollections
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
merge_requests
@merge_requests
=
issuables_collection
.
page
(
params
[
:page
])
@issuable_meta_data
=
issuable_meta_data
(
@merge_requests
,
collection_type
)
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
private
def
finder_type
(
super
if
defined?
(
super
))
||
(
MergeRequestsFinder
if
action_name
==
'merge_requests'
)
end
def
finder_options
super
.
merge
(
non_archived:
true
)
end
end
app/controllers/dashboard_controller.rb
View file @
2d17e8e6
# frozen_string_literal: true
class
DashboardController
<
Dashboard
::
ApplicationController
include
IssuesAction
include
MergeRequestsAction
include
IssuableCollectionsAction
prepend_before_action
(
only:
[
:issues
])
{
authenticate_sessionless_user!
(
:rss
)
}
prepend_before_action
(
only:
[
:issues_calendar
])
{
authenticate_sessionless_user!
(
:ics
)
}
...
...
app/controllers/groups_controller.rb
View file @
2d17e8e6
...
...
@@ -2,8 +2,7 @@
class
GroupsController
<
Groups
::
ApplicationController
include
API
::
Helpers
::
RelatedResourcesHelpers
include
IssuesAction
include
MergeRequestsAction
include
IssuableCollectionsAction
include
ParamsBackwardCompatibility
include
PreviewMarkdown
...
...
app/controllers/projects/issues_controller.rb
View file @
2d17e8e6
...
...
@@ -191,6 +191,10 @@ class Projects::IssuesController < Projects::ApplicationController
protected
def
issuable_sorting_field
Issue
::
SORTING_PREFERENCE_FIELD
end
# rubocop: disable CodeReuse/ActiveRecord
def
issue
return
@issue
if
defined?
(
@issue
)
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
2d17e8e6
...
...
@@ -230,6 +230,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
alias_method
:issuable
,
:merge_request
alias_method
:awardable
,
:merge_request
def
issuable_sorting_field
MergeRequest
::
SORTING_PREFERENCE_FIELD
end
def
merge_params
params
.
permit
(
merge_params_attributes
)
end
...
...
app/models/issue.rb
View file @
2d17e8e6
...
...
@@ -26,6 +26,8 @@ class Issue < ActiveRecord::Base
DueThisMonth
=
DueDateStruct
.
new
(
'Due This Month'
,
'month'
).
freeze
DueNextMonthAndPreviousTwoWeeks
=
DueDateStruct
.
new
(
'Due Next Month And Previous Two Weeks'
,
'next_month_and_previous_two_weeks'
).
freeze
SORTING_PREFERENCE_FIELD
=
:issues_sort
belongs_to
:project
belongs_to
:moved_to
,
class_name:
'Issue'
belongs_to
:closed_by
,
class_name:
'User'
...
...
app/models/merge_request.rb
View file @
2d17e8e6
...
...
@@ -21,6 +21,8 @@ class MergeRequest < ActiveRecord::Base
self
.
reactive_cache_refresh_interval
=
10
.
minutes
self
.
reactive_cache_lifetime
=
10
.
minutes
SORTING_PREFERENCE_FIELD
=
:merge_requests_sort
ignore_column
:locked_at
,
:ref_fetched
,
:deleted_at
...
...
changelogs/unreleased/50352-sort-save.yml
0 → 100644
View file @
2d17e8e6
---
title
:
Save issues/merge request sorting options to backend
merge_request
:
24198
author
:
type
:
added
db/migrate/20190116234221_add_sorting_fields_to_user_preference.rb
0 → 100644
View file @
2d17e8e6
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddSortingFieldsToUserPreference
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
def
up
add_column
:user_preferences
,
:issues_sort
,
:string
add_column
:user_preferences
,
:merge_requests_sort
,
:string
end
def
down
remove_column
:user_preferences
,
:issues_sort
remove_column
:user_preferences
,
:merge_requests_sort
end
end
db/schema.rb
View file @
2d17e8e6
...
...
@@ -2983,6 +2983,8 @@ ActiveRecord::Schema.define(version: 20190124200344) do
t
.
string
"epics_sort"
t
.
integer
"roadmap_epics_state"
t
.
integer
"epic_notes_filter"
,
limit:
2
,
default:
0
,
null:
false
t
.
string
"issues_sort"
t
.
string
"merge_requests_sort"
t
.
index
[
"user_id"
],
name:
"index_user_preferences_on_user_id"
,
unique:
true
,
using: :btree
end
...
...
spec/controllers/concerns/issuable_collections_spec.rb
View file @
2d17e8e6
...
...
@@ -17,10 +17,55 @@ describe IssuableCollections do
controller
=
klass
.
new
allow
(
controller
).
to
receive
(
:params
).
and_return
(
ActionController
::
Parameters
.
new
(
params
))
allow
(
controller
).
to
receive
(
:current_user
).
and_return
(
user
)
controller
end
describe
'#set_sort_order_from_user_preference'
do
describe
'when sort param given'
do
let
(
:params
)
{
{
sort:
'updated_desc'
}
}
context
'when issuable_sorting_field is defined'
do
before
do
controller
.
class
.
define_method
(
:issuable_sorting_field
)
{
:issues_sort
}
end
it
'sets user_preference with the right value'
do
controller
.
send
(
:set_sort_order_from_user_preference
)
expect
(
user
.
user_preference
.
reload
.
issues_sort
).
to
eq
(
'updated_desc'
)
end
end
context
'when no issuable_sorting_field is defined on the controller'
do
it
'does not touch user_preference'
do
allow
(
user
).
to
receive
(
:user_preference
)
controller
.
send
(
:set_sort_order_from_user_preference
)
expect
(
user
).
not_to
have_received
(
:user_preference
)
end
end
end
context
'when a user sorting preference exists'
do
let
(
:params
)
{
{}
}
before
do
controller
.
class
.
define_method
(
:issuable_sorting_field
)
{
:issues_sort
}
end
it
'returns the set preference'
do
user
.
user_preference
.
update
(
issues_sort:
'updated_asc'
)
sort_preference
=
controller
.
send
(
:set_sort_order_from_user_preference
)
expect
(
sort_preference
).
to
eq
(
'updated_asc'
)
end
end
end
describe
'#set_set_order_from_cookie'
do
describe
'when sort param given'
do
let
(
:cookies
)
{
{}
}
...
...
spec/controllers/projects/issues_controller_spec.rb
View file @
2d17e8e6
...
...
@@ -42,7 +42,9 @@ describe Projects::IssuesController do
it_behaves_like
"issuables list meta-data"
,
:issue
it_behaves_like
'set sort order from user preference'
it_behaves_like
'set sort order from user preference'
do
let
(
:sorting_param
)
{
'updated_asc'
}
end
it
"returns index"
do
get
:index
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
}
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
2d17e8e6
...
...
@@ -153,7 +153,9 @@ describe Projects::MergeRequestsController do
it_behaves_like
"issuables list meta-data"
,
:merge_request
it_behaves_like
'set sort order from user preference'
it_behaves_like
'set sort order from user preference'
do
let
(
:sorting_param
)
{
'updated_asc'
}
end
context
'when page param'
do
let
(
:last_page
)
{
project
.
merge_requests
.
page
().
total_pages
}
...
...
spec/models/user_preference_spec.rb
View file @
2d17e8e6
...
...
@@ -3,9 +3,10 @@
require
'spec_helper'
describe
UserPreference
do
let
(
:user_preference
)
{
create
(
:user_preference
)
}
describe
'#set_notes_filter'
do
let
(
:issuable
)
{
build_stubbed
(
:issue
)
}
let
(
:user_preference
)
{
create
(
:user_preference
)
}
shared_examples
'setting system notes'
do
it
'returns updated discussion filter'
do
...
...
@@ -50,4 +51,26 @@ describe UserPreference do
end
end
end
describe
'sort_by preferences'
do
shared_examples_for
'a sort_by preference'
do
it
'allows nil sort fields'
do
user_preference
.
update
(
attribute
=>
nil
)
expect
(
user_preference
).
to
be_valid
end
end
context
'merge_requests_sort attribute'
do
let
(
:attribute
)
{
:merge_requests_sort
}
it_behaves_like
'a sort_by preference'
end
context
'issues_sort attribute'
do
let
(
:attribute
)
{
:issues_sort
}
it_behaves_like
'a sort_by preference'
end
end
end
spec/support/shared_examples/controllers/set_sort_order_from_user_preference_shared_examples.rb
View file @
2d17e8e6
...
...
@@ -2,18 +2,12 @@ shared_examples 'set sort order from user preference' do
describe
'#set_sort_order_from_user_preference'
do
# There is no issuable_sorting_field defined in any CE controllers yet,
# however any other field present in user_preferences table can be used for testing.
let
(
:sorting_field
)
{
:issue_notes_filter
}
let
(
:sorting_param
)
{
'any'
}
before
do
allow
(
controller
).
to
receive
(
:issuable_sorting_field
).
and_return
(
sorting_field
)
end
context
'when database is in read-only mode'
do
it
'it does not update user preference'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:read_only?
).
and_return
(
true
)
expect_any_instance_of
(
UserPreference
).
not_to
receive
(
:update
_attribute
).
with
(
sorting_field
,
sorting_param
)
expect_any_instance_of
(
UserPreference
).
not_to
receive
(
:update
).
with
({
controller
.
send
(
:issuable_sorting_field
)
=>
sorting_param
}
)
get
:index
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
sort:
sorting_param
}
end
...
...
@@ -23,7 +17,7 @@ shared_examples 'set sort order from user preference' do
it
'updates user preference'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:read_only?
).
and_return
(
false
)
expect_any_instance_of
(
UserPreference
).
to
receive
(
:update
_attribute
).
with
(
sorting_field
,
sorting_param
)
expect_any_instance_of
(
UserPreference
).
to
receive
(
:update
).
with
({
controller
.
send
(
:issuable_sorting_field
)
=>
sorting_param
}
)
get
:index
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
sort:
sorting_param
}
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