Manuel Bustillo 5cceb1e6ed
All checks were successful
Add copyright notice / copyright_notice (pull_request) Successful in 1m13s
Run unit tests / unit_tests (pull_request) Successful in 1m54s
Check usage of free licenses / build-static-assets (pull_request) Successful in 27s
Choose light colors for the groups
2024-11-04 23:39:44 +01:00

24 lines
539 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
class Group < ApplicationRecord
validates :name, uniqueness: true
validates :name, :order, presence: true
has_many :children, class_name: 'Group', foreign_key: 'parent_id'
belongs_to :parent, class_name: 'Group', optional: true
before_create :set_color
scope :roots, -> { where(parent_id: nil) }
has_many :guests
private
def set_color
new_color = "##{SecureRandom.hex(3)}".paint
new_color = new_color.lighten(30) if new_color.dark?
self.color = new_color
end
end