docbrown/app/models/role.rb
Dwight Scott 8b70e9e1f3
added ability to assign moderator role via admin/super admin (#17759)
* added ability to assign moderator role via admin/super admin

* create Mod User in seeds

* add Cypress specs

* fix failing Cypress tests

* fix failing specs by moving test Mod user to the end

* nudge Travis

* nudge Travis

Co-authored-by: Arit Amana <msarit@gmail.com>
2022-05-26 10:57:08 -04:00

44 lines
1 KiB
Ruby

class Role < ApplicationRecord
ROLES = %w[
admin
codeland_admin
comment_suspended
creator
mod_relations_admin
moderator
podcast_admin
restricted_liquid_tag
single_resource_admin
super_admin
support_admin
suspended
tag_moderator
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