Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
99103ecc
Unverified
Commit
99103ecc
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
user & person
parent
568d82d5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/university/person.rb
+7
-0
7 additions, 0 deletions
app/models/university/person.rb
app/models/user.rb
+1
-1
1 addition, 1 deletion
app/models/user.rb
app/models/user/with_person.rb
+21
-0
21 additions, 0 deletions
app/models/user/with_person.rb
with
29 additions
and
1 deletion
app/models/university/person.rb
+
7
−
0
View file @
99103ecc
...
...
@@ -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
This diff is collapsed.
Click to expand it.
app/models/user.rb
+
1
−
1
View file @
99103ecc
...
...
@@ -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
)
}
...
...
This diff is collapsed.
Click to expand it.
app/models/user/with_person.rb
0 → 100644
+
21
−
0
View file @
99103ecc
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment