Skip to content
Snippets Groups Projects
Commit cfd475a4 authored by Tiago Botelho's avatar Tiago Botelho
Browse files

Removes default scope from sortable

parent d1b60cbc
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 26 deletions
Loading
Loading
@@ -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
 
Loading
Loading
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
Loading
Loading
@@ -17,7 +17,7 @@ class Admin::UsersController < Admin::ApplicationController
end
 
def keys
@keys = user.keys
@keys = user.keys.order_id_desc
end
 
def new
Loading
Loading
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])
Loading
Loading
@@ -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|
Loading
Loading
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
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -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])
 
Loading
Loading
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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,
Loading
Loading
@@ -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",
Loading
Loading
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -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) }
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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"
Loading
Loading
---
title: Removes Sortable default scope.
merge_request: 13558
author:
type: fixed
Loading
Loading
@@ -52,7 +52,7 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
end
 
step 'I visit the forks page of the "Shop" project' do
@project = Project.where(name: 'Shop').last
@project = Project.where(name: 'Shop').first
visit project_forks_path(@project)
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment