Skip to content

Instantly share code, notes, and snippets.

@Fcukit
Created August 3, 2018 14:24
Show Gist options
  • Save Fcukit/75fd6f75c471b3c6b7a8fac6454b3d4b to your computer and use it in GitHub Desktop.
Save Fcukit/75fd6f75c471b3c6b7a8fac6454b3d4b to your computer and use it in GitHub Desktop.
class AssetPolicy < ApplicationPolicy
# some code
class MetricScope < Scope
def resolve
if superadmin?
scope.all
else
scope.none
end
end
end
end
class Admin::DashboardController < Admin::AdminController
def index
scope = AssetPolicy::MetricScope.new(current_user, Asset.not_edited.not_sold.visible).resolve
@assets_quarter = Metrics::Dashboard::Assets.new(start_datetime: @quarter_start, end_datetime: @quarter_end, scope: scope )
scope = UserPolicy::MetricScope.new(current_user, User.where(role: :user)).resolve
@investors_quarter = Metrics::Dashboard::Investors.new(start_datetime: @quarter_start, end_datetime: @quarter_end, scope: scope)
scope = OfferPolicy::MetricScope.new(current_user, Offer).resolve
@offers_quarter = Metrics::Dashboard::Offers.new(start_datetime: @quarter_start, end_datetime: @quarter_end, scope: scope)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment