Created
August 3, 2018 14:24
-
-
Save Fcukit/75fd6f75c471b3c6b7a8fac6454b3d4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AssetPolicy < ApplicationPolicy | |
# some code | |
class MetricScope < Scope | |
def resolve | |
if superadmin? | |
scope.all | |
else | |
scope.none | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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