diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-08-15 13:27:37 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-07 15:01:59 +0300 |
commit | cfd475a45ee2655fa0148b0b561f95b44fe8641b (patch) | |
tree | 84bc8f20239d58ed19e35cb515c50d3b36735c4f /app | |
parent | d1b60cbc67dc14b21820ef3f823a8e1ea851697d (diff) |
Removes default scope from sortable
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/broadcast_messages_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/admin/dashboard_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/admin/users_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/dashboard/groups_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/profiles/emails_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/profiles/keys_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests/diffs_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/project_members_controller.rb | 4 | ||||
-rw-r--r-- | app/finders/move_to_project_finder.rb | 1 | ||||
-rw-r--r-- | app/finders/projects_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/todos_finder.rb | 2 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 4 | ||||
-rw-r--r-- | app/models/broadcast_message.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/sortable.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 10 | ||||
-rw-r--r-- | app/services/quick_actions/interpret_service.rb | 2 | ||||
-rw-r--r-- | app/views/projects/project_members/import.html.haml | 2 |
18 files changed, 30 insertions, 25 deletions
diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb index 762e36ee2e9..c49b6459452 100644 --- a/app/controllers/admin/broadcast_messages_controller.rb +++ b/app/controllers/admin/broadcast_messages_controller.rb @@ -2,7 +2,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController before_action :finder, only: [:edit, :update, :destroy] def index - @broadcast_messages = BroadcastMessage.reorder("ends_at DESC").page(params[:page]) + @broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page]) @broadcast_message = BroadcastMessage.new end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 05e749c00c0..e85cdcb8db7 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,7 +1,7 @@ class Admin::DashboardController < Admin::ApplicationController def index - @projects = Project.without_deleted.with_route.limit(10) - @users = User.limit(10) - @groups = Group.with_route.limit(10) + @projects = Project.order_id_desc.without_deleted.with_route.limit(10) + @users = User.order_id_desc.limit(10) + @groups = Group.order_id_desc.with_route.limit(10) end end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index a99563b7100..9ec7719fabb 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -17,7 +17,7 @@ class Admin::UsersController < Admin::ApplicationController end def keys - @keys = user.keys + @keys = user.keys.order_id_desc end def new diff --git a/app/controllers/dashboard/groups_controller.rb b/app/controllers/dashboard/groups_controller.rb index 742157d113d..8057a0b455c 100644 --- a/app/controllers/dashboard/groups_controller.rb +++ b/app/controllers/dashboard/groups_controller.rb @@ -1,5 +1,7 @@ class Dashboard::GroupsController < Dashboard::ApplicationController def index + @sort = params[:sort] || 'id_desc' + @groups = if params[:parent_id] && Group.supports_nested_groups? parent = Group.find_by(id: params[:parent_id]) @@ -15,7 +17,7 @@ class Dashboard::GroupsController < Dashboard::ApplicationController @groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present? @groups = @groups.includes(:route) - @groups = @groups.sort(@sort = params[:sort]) + @groups = @groups.sort(@sort) @groups = @groups.page(params[:page]) respond_to do |format| diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb index 17b66df43e7..ddb67d1c4d1 100644 --- a/app/controllers/profiles/emails_controller.rb +++ b/app/controllers/profiles/emails_controller.rb @@ -1,7 +1,7 @@ class Profiles::EmailsController < Profiles::ApplicationController def index @primary = current_user.email - @emails = current_user.emails + @emails = current_user.emails.order_id_desc end def create diff --git a/app/controllers/profiles/keys_controller.rb b/app/controllers/profiles/keys_controller.rb index 88f49da555a..f9f0e8eef83 100644 --- a/app/controllers/profiles/keys_controller.rb +++ b/app/controllers/profiles/keys_controller.rb @@ -2,7 +2,7 @@ class Profiles::KeysController < Profiles::ApplicationController skip_before_action :authenticate_user!, only: [:get_keys] def index - @keys = current_user.keys + @keys = current_user.keys.order_id_desc @key = Key.new end diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 330b7df4541..63d61c98f34 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -27,7 +27,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @merge_request.merge_request_diff end - @merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff + @merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff.order_id_desc @comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id } if params[:start_sha].present? diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index f8ff7413b53..d925dcd21ff 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -47,6 +47,10 @@ class Projects::ProjectMembersController < Projects::ApplicationController end end + def import + @projects = current_user.authorized_projects.order_id_desc + end + def apply_import source_project = Project.find(params[:source_project_id]) diff --git a/app/finders/move_to_project_finder.rb b/app/finders/move_to_project_finder.rb index 79eb45568be..038d5565a1e 100644 --- a/app/finders/move_to_project_finder.rb +++ b/app/finders/move_to_project_finder.rb @@ -9,6 +9,7 @@ class MoveToProjectFinder projects = @user.projects_where_can_admin_issues projects = projects.search(search) if search.present? projects = projects.excluding_project(from_project) + projects = projects.order_id_desc # infinite scroll using offset projects = projects.where('projects.id < ?', offset_id) if offset_id.present? diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index fa6fea2588a..eac6095d8dc 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -121,7 +121,7 @@ class ProjectsFinder < UnionFinder end def sort(items) - params[:sort].present? ? items.sort(params[:sort]) : items + params[:sort].present? ? items.sort(params[:sort]) : items.order_id_desc end def by_archived(projects) diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index b276116f0c6..3502bf08971 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -118,7 +118,7 @@ class TodosFinder end def sort(items) - params[:sort] ? items.sort(params[:sort]) : items.reorder(id: :desc) + params[:sort] ? items.sort(params[:sort]) : items.order_id_desc end def by_action(items) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 3d0fdce6a43..212cdbb8157 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -56,7 +56,7 @@ module IssuesHelper end def project_options(issuable, current_user, ability: :read_project) - projects = current_user.authorized_projects + projects = current_user.authorized_projects.order_id_desc projects = projects.select do |project| current_user.can?(ability, project) end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index ae0e0aa3cf9..e1309dc0761 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -85,7 +85,7 @@ module SearchHelper # Autocomplete results for the current user's groups def groups_autocomplete(term, limit = 5) - current_user.authorized_groups.search(term).limit(limit).map do |group| + current_user.authorized_groups.order_id_desc.search(term).limit(limit).map do |group| { category: "Groups", id: group.id, @@ -97,7 +97,7 @@ module SearchHelper # Autocomplete results for the current user's projects def projects_autocomplete(term, limit = 5) - current_user.authorized_projects.search_by_title(term) + current_user.authorized_projects.order_id_desc.search_by_title(term) .sorted_by_stars.non_archived.limit(limit).map do |p| { category: "Projects", diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index fdc5a2adea0..0b561203914 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -33,7 +33,7 @@ class BroadcastMessage < ActiveRecord::Base end def self.current_and_future_messages - where('ends_at > :now', now: Time.zone.now).reorder(id: :asc) + where('ends_at > :now', now: Time.zone.now).order_id_asc end def active? diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index a155a064032..db3cd257584 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -6,10 +6,6 @@ module Sortable extend ActiveSupport::Concern included do - # By default all models should be ordered - # by created_at field starting from newest - default_scope { order_id_desc } - scope :order_id_desc, -> { reorder(id: :desc) } scope :order_id_asc, -> { reorder(id: :asc) } scope :order_created_desc, -> { reorder(created_at: :desc) } diff --git a/app/models/user.rb b/app/models/user.rb index c5b5f09722f..1ac5b029c81 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,7 @@ class User < ActiveRecord::Base # # Namespace for personal projects - has_one :namespace, -> { where type: nil }, dependent: :destroy, foreign_key: :owner_id, autosave: true # rubocop:disable Cop/ActiveRecordDependent + has_one :namespace, -> { where(type: nil) }, dependent: :destroy, foreign_key: :owner_id, autosave: true # rubocop:disable Cop/ActiveRecordDependent # Profile has_many :keys, -> do @@ -255,11 +255,13 @@ class User < ActiveRecord::Base end def sort(method) - case method.to_s + order_method = method || 'id_desc' + + case order_method.to_s when 'recent_sign_in' then order_recent_sign_in when 'oldest_sign_in' then order_oldest_sign_in else - order_by(method) + order_by(order_method) end end @@ -367,7 +369,7 @@ class User < ActiveRecord::Base # Returns a user for the given SSH key. def find_by_ssh_key_id(key_id) - find_by(id: Key.unscoped.select(:user_id).where(id: key_id)) + Key.find_by(id: key_id)&.user end def find_by_full_path(path, follow_redirects: false) diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index 9cdb9935bea..a077b3584b0 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -115,7 +115,7 @@ module QuickActions if issuable.allows_multiple_assignees? issuable.assignees.pluck(:id) + users.map(&:id) else - [users.last.id] + [users.first.id] end end diff --git a/app/views/projects/project_members/import.html.haml b/app/views/projects/project_members/import.html.haml index f6ca8d5a921..755128af565 100644 --- a/app/views/projects/project_members/import.html.haml +++ b/app/views/projects/project_members/import.html.haml @@ -8,7 +8,7 @@ = form_tag apply_import_project_project_members_path(@project), method: 'post', class: 'form-horizontal' do .form-group = label_tag :source_project_id, "Project", class: 'control-label' - .col-sm-10= select_tag(:source_project_id, options_from_collection_for_select(current_user.authorized_projects, :id, :name_with_namespace), prompt: "Select project", class: "select2 lg", required: true) + .col-sm-10= select_tag(:source_project_id, options_from_collection_for_select(@projects, :id, :name_with_namespace), prompt: "Select project", class: "select2 lg", required: true) .form-actions = button_tag 'Import project members', class: "btn btn-create" |