1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/policies/user_policy.rb

36 lines
953 B
Ruby

class UserPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.admin?
scope.includes(:group, :training_credits, :machine_credits, subscriptions: [plan: [:credits]], profile: [:user_avatar])
.joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").order('users.created_at desc')
else
scope.includes(profile: [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'")
.where(is_allow_contact: true).order('users.created_at desc')
end
end
end
def show?
user.admin? or (record.is_allow_contact and record.member?) or (user.id == record.id)
end
def update?
user.admin? or (user.id == record.id)
end
def destroy?
user.id == record.id
end
def merge?
user.id == record.id
end
%w[list create mapping].each do |action|
define_method "#{action}?" do
user.admin?
end
end
end