ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
1.1 KiB

  1. class User < ApplicationRecord
  2. enum :role, guest: 'guest', member: 'member', admin: 'admin'
  3. validates :name, length: { maximum: 255 }
  4. validates :inheritance_code, presence: true, length: { maximum: 64 }
  5. validates :role, presence: true, inclusion: { in: roles.keys }
  6. has_many :created_posts,
  7. class_name: 'Post', foreign_key: :uploaded_user_id, dependent: :nullify
  8. has_many :settings
  9. has_many :user_ips, dependent: :destroy
  10. has_many :ip_addresses, through: :user_ips
  11. has_many :user_post_views, dependent: :destroy
  12. has_many :viewed_posts, through: :user_post_views, source: :post
  13. has_many :created_wiki_pages,
  14. class_name: 'WikiPage', foreign_key: :created_user_id, dependent: :nullify
  15. has_many :updated_wiki_pages,
  16. class_name: 'WikiPage', foreign_key: :updated_user_id, dependent: :nullify
  17. def viewed?(post) = user_post_views.exists?(post_id: post.id)
  18. def gte_member? = member? || admin?
  19. def banned? = banned_at.present?
  20. def ban! = banned? || update!(banned_at: Time.current)
  21. def unban! = update!(banned_at: nil)
  22. end