Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3b229bb6
Commit
3b229bb6
authored
Jul 27, 2021
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add invitation debug logging
parent
7dfd9546
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
app/models/member.rb
app/models/member.rb
+9
-0
spec/models/member_spec.rb
spec/models/member_spec.rb
+40
-0
No files found.
app/models/member.rb
View file @
3b229bb6
...
...
@@ -175,6 +175,8 @@ class Member < ApplicationRecord
after_update
:post_update_hook
,
unless:
[
:pending?
,
:importing?
],
if: :hook_prerequisites_met?
after_destroy
:destroy_notification_setting
after_destroy
:post_destroy_hook
,
unless: :pending?
,
if: :hook_prerequisites_met?
after_save
:log_invitation_token_cleanup
after_commit
:refresh_member_authorized_projects
default_value_for
:notification_level
,
NotificationSetting
.
levels
[
:global
]
...
...
@@ -449,6 +451,13 @@ class Member < ApplicationRecord
def
project_bot?
user
&
.
project_bot?
end
def
log_invitation_token_cleanup
return
true
unless
Gitlab
.
com?
&&
invite?
&&
invite_accepted_at?
error
=
StandardError
.
new
(
"Invitation token is present but invite was already accepted!"
)
Gitlab
::
ErrorTracking
.
track_exception
(
error
,
attributes
.
slice
(
%w["invite_accepted_at created_at source_type source_id user_id id"]
))
end
end
Member
.
prepend_mod_with
(
'Member'
)
spec/models/member_spec.rb
View file @
3b229bb6
...
...
@@ -749,4 +749,44 @@ RSpec.describe Member do
end
end
end
describe
'log_invitation_token_cleanup'
do
let_it_be
(
:project
)
{
create
:project
}
context
'when on gitlab.com'
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
true
end
it
"doesn't log info for members without invitation or accepted invitation"
do
expect
(
Gitlab
::
ErrorTracking
).
not_to
receive
(
:track_exception
)
create
:project_member
create
:project_member
,
:invited
,
invite_accepted_at:
nil
create
:project_member
,
invite_token:
nil
,
invite_accepted_at:
Time
.
zone
.
now
end
it
'logs error for accepted members with token and creates membership'
do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_exception
).
with
(
kind_of
(
StandardError
),
kind_of
(
Hash
))
expect
do
create
:project_member
,
:invited
,
source:
project
,
invite_accepted_at:
Time
.
zone
.
now
end
.
to
change
{
Member
.
count
}.
by
(
1
)
end
end
context
'when not on gitlab.com'
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
false
end
it
'does not log error for accepted members with token and creates membership'
do
expect
(
Gitlab
::
ErrorTracking
).
not_to
receive
(
:track_exception
)
expect
do
create
:project_member
,
:invited
,
source:
project
,
invite_accepted_at:
Time
.
zone
.
now
end
.
to
change
{
Member
.
count
}.
by
(
1
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment