Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRN2-xx: Removed default order by priority on roles #1720

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/concerns/rolify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Rolify

# Gets all roles
def all_roles(selected_role)
@roles = Role.editable_roles(@user_domain)
@roles = Role.editable_roles(@user_domain).by_priority

if @roles.count.zero?
Role.create_default_roles(@user_domain)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def language_options

# Returns a list of roles that the user can have
def role_options
Role.editable_roles(@user_domain).where("priority >= ?", current_user.role.priority)
Role.editable_roles(@user_domain).where("priority >= ?", current_user.role.priority).by_priority
end

# Parses markdown for rendering.
Expand Down
2 changes: 1 addition & 1 deletion app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Role < ApplicationRecord

has_many :users

default_scope { includes(:role_permissions).distinct.order(:priority) }
default_scope { includes(:role_permissions) }
scope :by_priority, -> { order(:priority) }
scope :editable_roles, ->(provider) { where(provider: provider).where.not(name: %w[super_admin denied pending]) }

Expand Down