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
97dfd052
Commit
97dfd052
authored
Jan 18, 2022
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set member_namespace_id when creating a Member
parent
810bd9cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
0 deletions
+36
-0
app/models/member.rb
app/models/member.rb
+7
-0
app/models/members/project_member.rb
app/models/members/project_member.rb
+7
-0
spec/models/member_spec.rb
spec/models/member_spec.rb
+11
-0
spec/models/members/project_member_spec.rb
spec/models/members/project_member_spec.rb
+11
-0
No files found.
app/models/member.rb
View file @
97dfd052
...
...
@@ -181,6 +181,7 @@ class Member < ApplicationRecord
scope
:on_project_and_ancestors
,
->
(
project
)
{
where
(
source:
[
project
]
+
project
.
ancestors
)
}
before_validation
:set_member_namespace_id
,
on: :create
before_validation
:generate_invite_token
,
on: :create
,
if:
->
(
member
)
{
member
.
invite_email
.
present?
&&
!
member
.
invite_accepted_at?
}
after_create
:send_invite
,
if: :invite?
,
unless: :importing?
...
...
@@ -381,6 +382,12 @@ class Member < ApplicationRecord
private
# TODO: https://gitlab.com/groups/gitlab-org/-/epics/7054
# temporary until we can we properly remove the source columns
def
set_member_namespace_id
self
.
member_namespace_id
=
self
.
source_id
end
def
access_level_inclusion
return
if
access_level
.
in?
(
Gitlab
::
Access
.
all_values
)
...
...
app/models/members/project_member.rb
View file @
97dfd052
...
...
@@ -118,6 +118,13 @@ class ProjectMember < Member
# rubocop:enable CodeReuse/ServiceClass
end
# TODO: https://gitlab.com/groups/gitlab-org/-/epics/7054
# temporary until we can we properly remove the source columns
override
:set_member_namespace_id
def
set_member_namespace_id
self
.
member_namespace_id
=
project
&
.
project_namespace_id
end
def
send_invite
run_after_commit_or_now
{
notification_service
.
invite_project_member
(
self
,
@raw_invite_token
)
}
...
...
spec/models/member_spec.rb
View file @
97dfd052
...
...
@@ -894,4 +894,15 @@ RSpec.describe Member do
end
end
end
describe
'#set_member_namespace_id'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:member
)
{
create
(
:group_member
,
group:
group
)
}
describe
'on create'
do
it
'sets the member_namespace_id'
do
expect
(
member
.
member_namespace_id
).
to
eq
group
.
id
end
end
end
end
spec/models/members/project_member_spec.rb
View file @
97dfd052
...
...
@@ -257,4 +257,15 @@ RSpec.describe ProjectMember do
it_behaves_like
'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations'
end
end
describe
'#set_member_namespace_id'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:member
)
{
create
(
:project_member
,
project:
project
)
}
context
'on create'
do
it
'sets the member_namespace_id'
do
expect
(
member
.
member_namespace_id
).
to
eq
project
.
project_namespace_id
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