app/models/concerns/spotlight/user.rb in blacklight-spotlight-0.13.0 vs app/models/concerns/spotlight/user.rb in blacklight-spotlight-0.14.0
- old
+ new
@@ -3,24 +3,28 @@
# Spotlight user mixins for roles
module User
extend ActiveSupport::Concern
included do
has_many :roles, class_name: 'Spotlight::Role', dependent: :destroy
- has_many :exhibits, class_name: 'Spotlight::Exhibit', through: :roles
+ has_many :exhibits, class_name: 'Spotlight::Exhibit', through: :roles, source: 'resource', source_type: 'Spotlight::Exhibit'
before_create :add_default_roles
end
def superadmin?
- admin_roles.where(exhibit_id: nil).any?
+ roles.where(role: 'admin', resource: Spotlight::Site.instance).any?
end
+ def exhibit_roles
+ roles.where(resource_type: 'Spotlight::Exhibit')
+ end
+
def admin_roles
- roles.where(role: 'admin')
+ exhibit_roles.where(role: 'admin')
end
def add_default_roles
- roles.build role: 'admin' unless self.class.any?
+ roles.build role: 'admin', resource: Spotlight::Site.instance unless self.class.any?
end
def invite_pending?
invited_to_sign_up? && !invitation_accepted?
end