Skip to content
Snippets Groups Projects
Unverified Commit 99103ecc authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

user & person

parent 568d82d5
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,7 @@ class University::Person < ApplicationRecord
allow_blank: true,
if: :will_save_change_to_email?
before_validation :sanitize_email
scope :ordered, -> { order(:last_name, :first_name) }
scope :administratives, -> { where(is_administrative: true) }
......@@ -149,4 +150,10 @@ class University::Person < ApplicationRecord
def git_dependencies_administrator
[]
end
protected
def sanitize_email
self.email = self.email.downcase.strip
end
end
......@@ -55,12 +55,12 @@
class User < ApplicationRecord
has_one_attached_deletable :picture # In this order, "resize avatar" callback will be fired after the others.
include WithAuthentication
include WithPerson
include WithRoles
include WithSyncBetweenUniversities
belongs_to :university
belongs_to :language
has_one :person, class_name: 'University::Person', dependent: :nullify
scope :ordered, -> { order(:last_name, :first_name) }
......
module User::WithPerson
extend ActiveSupport::Concern
included do
has_one :person, class_name: 'University::Person', dependent: :nullify
after_create_commit :find_or_create_person
end
protected
def find_or_create_person
person = university.people.where(email: email).first_or_initialize do |person|
person.first_name = first_name
person.last_name = last_name
person.phone = mobile_phone
end
person.user = self
person.save
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment