X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/eb0f9ff63d5ad5d91ea941420e094dd2980df094..fc5260d71b764d4ebda340f073df5ab39ab1c2fa:/app/models/user_role.rb?ds=sidebyside diff --git a/app/models/user_role.rb b/app/models/user_role.rb index fb783281e..a081361a7 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -1,8 +1,29 @@ -class UserRole < ActiveRecord::Base +# == Schema Information +# +# Table name: user_roles +# +# id :integer not null, primary key +# user_id :bigint(8) not null +# role :enum not null +# created_at :datetime +# updated_at :datetime +# granter_id :bigint(8) not null +# +# Indexes +# +# user_roles_id_role_unique (user_id,role) UNIQUE +# +# Foreign Keys +# +# user_roles_granter_id_fkey (granter_id => users.id) +# user_roles_user_id_fkey (user_id => users.id) +# + +class UserRole < ApplicationRecord belongs_to :user + belongs_to :granter, :class_name => "User" - ALL_ROLES = ['administrator', 'moderator'] + ALL_ROLES = %w[administrator moderator].freeze - validates_inclusion_of :role, :in => ALL_ROLES - validates_uniqueness_of :role, :scope => :user_id + validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id } end