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
b0fae780
Commit
b0fae780
authored
Dec 07, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor access_level_inclusion into base class
Member model.
parent
ad8186fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
11 deletions
+18
-11
app/models/member.rb
app/models/member.rb
+7
-0
app/models/members/group_member.rb
app/models/members/group_member.rb
+2
-9
app/models/members/project_member.rb
app/models/members/project_member.rb
+9
-2
No files found.
app/models/member.rb
View file @
b0fae780
...
...
@@ -52,6 +52,7 @@ class Member < ApplicationRecord
message:
_
(
'project bots cannot be added to other groups / projects'
)
},
if: :project_bot?
validate
:access_level_inclusion
scope
:with_invited_user_state
,
->
do
joins
(
'LEFT JOIN users as invited_user ON invited_user.email = members.invite_email'
)
...
...
@@ -382,6 +383,12 @@ class Member < ApplicationRecord
private
def
access_level_inclusion
return
if
access_level
.
in?
(
Gitlab
::
Access
.
all_values
)
errors
.
add
(
:access_level
,
"is not included in the list"
)
end
def
send_invite
# override in subclass
end
...
...
app/models/members/group_member.rb
View file @
b0fae780
...
...
@@ -6,6 +6,7 @@ class GroupMember < Member
include
CreatedAtFilterable
SOURCE_TYPE
=
'Namespace'
SOURCE_TYPE_FORMAT
=
/\ANamespace\z/
.
freeze
belongs_to
:group
,
foreign_key:
'source_id'
alias_attribute
:namespace_id
,
:source_id
...
...
@@ -13,9 +14,7 @@ class GroupMember < Member
# Make sure group member points only to group as it source
default_value_for
:source_type
,
SOURCE_TYPE
validates
:source_type
,
format:
{
with:
/\ANamespace\z/
}
validates
:access_level
,
presence:
true
validate
:access_level_inclusion
validates
:source_type
,
format:
{
with:
SOURCE_TYPE_FORMAT
}
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
# rubocop:disable Cop/DefaultScope
...
...
@@ -65,12 +64,6 @@ class GroupMember < Member
super
end
def
access_level_inclusion
return
if
access_level
.
in?
(
Gitlab
::
Access
.
all_values
)
errors
.
add
(
:access_level
,
"is not included in the list"
)
end
def
send_invite
run_after_commit_or_now
{
notification_service
.
invite_group_member
(
self
,
@raw_invite_token
)
}
...
...
app/models/members/project_member.rb
View file @
b0fae780
...
...
@@ -3,6 +3,7 @@
class
ProjectMember
<
Member
extend
::
Gitlab
::
Utils
::
Override
SOURCE_TYPE
=
'Project'
SOURCE_TYPE_FORMAT
=
/\AProject\z/
.
freeze
belongs_to
:project
,
foreign_key:
'source_id'
...
...
@@ -10,8 +11,7 @@ class ProjectMember < Member
# Make sure project member points only to project as it source
default_value_for
:source_type
,
SOURCE_TYPE
validates
:source_type
,
format:
{
with:
/\AProject\z/
}
validates
:access_level
,
inclusion:
{
in:
Gitlab
::
Access
.
values
}
validates
:source_type
,
format:
{
with:
SOURCE_TYPE_FORMAT
}
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
# rubocop:disable Cop/DefaultScope
scope
:in_project
,
->
(
project
)
{
where
(
source_id:
project
.
id
)
}
...
...
@@ -92,6 +92,13 @@ class ProjectMember < Member
private
override
:access_level_inclusion
def
access_level_inclusion
return
if
access_level
.
in?
(
Gitlab
::
Access
.
values
)
errors
.
add
(
:access_level
,
"is not included in the list"
)
end
override
:refresh_member_authorized_projects
def
refresh_member_authorized_projects
(
blocking
:)
return
unless
user
...
...
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