Added some models
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

User
Item
Department
Categorie
AssignmentLog
Room
This commit is contained in:
2026-05-21 15:36:23 +02:00
parent 7b02520b6c
commit b7f0c35378
27 changed files with 387 additions and 2 deletions

View File

@@ -10,13 +10,18 @@ class User < ApplicationRecord
password_salt.last(10)
end
has_many :sessions, dependent: :destroy
has_many :events, dependent: :destroy
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :password, allow_nil: true, length: { minimum: @@min_length_password }
belongs_to :department, optional: true
has_many :items, dependent: :nullify
has_many :assignment_logs, dependent: :destroy
validates :first_name, :last_name, presence: true, on: :update
normalizes :email, with: -> { _1.strip.downcase }
before_validation if: :email_changed?, on: :update do
@@ -39,6 +44,20 @@ class User < ApplicationRecord
events.create! action: "email_verified"
end
# Gibt den vollen Namen zurück
def name
if first_name.present? && last_name.present?
"#{first_name} #{last_name}"
else
email
end
end
# Für das Besitzer-Auswahlfeld im Formular
def name_with_department
department.present? ? "#{name} (#{department.name})" : name
end
def self.min_length_password
@@min_length_password
end