docbrown/app/models/role.rb
Vaidehi Joshi 95055b2a89
Remove pro role + expose analytics to all users via dashboard (#13156)
* Remove pro role on user, expose pro dashboard to all users as analytics

* Remove pro from Elasticsearch mappings

* Update user role docs to use :trusted over :pro

* Remove pro from Role model spec

* Remove more references to pro, as noted by @rhymes
2021-03-30 15:02:18 -07:00

43 lines
1 KiB
Ruby

class Role < ApplicationRecord
ROLES = %w[
admin
banned
chatroom_beta_tester
codeland_admin
comment_banned
podcast_admin
restricted_liquid_tag
single_resource_admin
super_admin
tag_moderator
mod_relations_admin
support_admin
tech_admin
trusted
warned
workshop_pass
].freeze
has_and_belongs_to_many :users, join_table: :users_roles # rubocop:disable Rails/HasAndBelongsToMany
belongs_to :resource,
polymorphic: true, optional: true
validates :resource_type,
inclusion: { in: Rolify.resource_types },
allow_nil: true
validates :name,
inclusion: { in: ROLES }
scopify
# Returns a somewhat friendly name for the resource related to a given role.
# In the case of Tag Moderators, a resource_type is not present, so we use the
# resource_id to grab the specific Tag related to that moderator's role.
def resource_name
return resource_type unless resource_id
Tag.find(resource_id).name
end
end