-
Notifications
You must be signed in to change notification settings - Fork 900
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
Use feature for admin #17444
Use feature for admin #17444
Changes from all commits
9c9a52f
83ad831
fd13a8a
db76d96
f6c02e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,15 @@ class User < ApplicationRecord | |
belongs_to :current_group, :class_name => "MiqGroup" | ||
has_and_belongs_to_many :miq_groups | ||
scope :superadmins, lambda { | ||
joins(:miq_groups => :miq_user_role).where(:miq_user_roles => {:name => MiqUserRole::SUPER_ADMIN_ROLE_NAME }) | ||
joins(:miq_groups => {:miq_user_role => :miq_product_features}) | ||
.where(:miq_product_features => {:identifier => MiqProductFeature::SUPER_ADMIN_FEATURE }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First off, totally fine with this query, and it probably doesn't need to change. But am kinda curious where it is being used. Since we aren't setting a (might be the former now that I think about it) Anyway, you really aren't changing how this worked much before, so you probably don't have to worry about it. |
||
} | ||
|
||
virtual_has_many :active_vms, :class_name => "VmOrTemplate" | ||
|
||
delegate :miq_user_role, :current_tenant, :get_filters, :has_filters?, :get_managed_filters, :get_belongsto_filters, | ||
:to => :current_group, :allow_nil => true | ||
delegate :super_admin_user?, :admin_user?, :self_service?, :limited_self_service?, :disallowed_roles, | ||
delegate :super_admin_user?, :admin_user?, :self_service?, :limited_self_service?, :report_admin_user?, | ||
:to => :miq_user_role, :allow_nil => true | ||
|
||
validates_presence_of :name, :userid | ||
|
@@ -50,8 +51,10 @@ class User < ApplicationRecord | |
|
||
scope :with_same_userid, ->(id) { where(:userid => User.find(id).userid) } | ||
|
||
def self.with_allowed_roles_for(user_or_group) | ||
includes(:miq_groups => :miq_user_role).where.not(:miq_user_roles => {:name => user_or_group.disallowed_roles}) | ||
def self.with_roles_excluding(identifier) | ||
where.not(:id => User.joins(:miq_groups => :miq_product_features) | ||
.where(:miq_product_features => {:identifier => identifier}) | ||
.select(:id)) | ||
end | ||
|
||
def self.scope_by_tenant? | ||
|
@@ -285,9 +288,9 @@ def self.current_user | |
Thread.current[:user] ||= find_by_userid(current_userid) | ||
end | ||
|
||
def self.with_current_user_groups(user = nil) | ||
user ||= current_user | ||
user.admin_user? ? all : includes(:miq_groups).where(:miq_groups => {:id => user.miq_group_ids}) | ||
# parallel to MiqGroup.with_groups - only show users with these groups | ||
def self.with_groups(miq_group_ids) | ||
includes(:miq_groups).where(:miq_groups => {:id => miq_group_ids}) | ||
end | ||
|
||
def self.missing_user_features(db_user) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,13 +76,6 @@ class Filterer | |
VmOrTemplate | ||
) + NETWORK_MODELS_FOR_BELONGSTO_FILTER | ||
|
||
# key: MiqUserRole#name - user's role | ||
# value: | ||
# array - disallowed roles for the user's role | ||
DISALLOWED_ROLES_FOR_USER_ROLE = { | ||
'EvmRole-tenant_administrator' => %w(EvmRole-super_administrator EvmRole-administrator) | ||
}.freeze | ||
|
||
# key: descendant::klass | ||
# value: | ||
# if it is a symbol/method_name: | ||
|
@@ -164,7 +157,7 @@ def self.accessible_tenant_ids_strategy(klass) | |
# @option options :where_clause [] | ||
# @option options :sub_filter | ||
# @option options :include_for_find [Array<Symbol>] | ||
# @option options :filter | ||
# @option options :filter [MiqExpression] (optional) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedantic: This seems like a random change for this PR. |
||
|
||
# @option options :user [User] (default: current_user) | ||
# @option options :userid [String] User#userid (not user_id) | ||
|
@@ -521,13 +514,15 @@ def scope_for_user_role_group(klass, scope, miq_group, user, managed_filters) | |
if user_or_group.try!(:self_service?) && MiqUserRole != klass | ||
scope.where(:id => klass == User ? user.id : miq_group.id) | ||
else | ||
if user_or_group.disallowed_roles | ||
scope = scope.with_allowed_roles_for(user_or_group) | ||
# hide creating admin group / roles from non-super administrators | ||
unless user_or_group.miq_user_role&.super_admin_user? | ||
scope = scope.with_roles_excluding(MiqProductFeature::SUPER_ADMIN_FEATURE) | ||
end | ||
|
||
if MiqUserRole != klass | ||
filtered_ids = pluck_ids(get_managed_filter_object_ids(scope, managed_filters)) | ||
scope = scope.with_current_user_groups(user) | ||
# Non admins can only see their own groups | ||
scope = scope.with_groups(user.miq_group_ids) unless user_or_group.miq_user_role&.super_admin_user? | ||
end | ||
|
||
scope_by_ids(scope, filtered_ids) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you changed this to just
:name
? It seems ambiguous as it can be misconstrued as the name of the group when it's really the name of the groups role.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not change
The
:name
refers toRole#name
. Theprefix => true
tacks on the association name so the attribute name will be calledmiq_user_role_name
(same as it originally was)