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
837b45c3
Commit
837b45c3
authored
Apr 29, 2020
by
Jason Goodman
Committed by
Shinya Maeda
Apr 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract FeatureFlagUserXidsValidator class
Remove duplicate logic from feature flag Strategy and UserList
parent
a7e49cba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
42 deletions
+33
-42
ee/app/models/operations/feature_flags/strategy.rb
ee/app/models/operations/feature_flags/strategy.rb
+1
-19
ee/app/models/operations/feature_flags/user_list.rb
ee/app/models/operations/feature_flags/user_list.rb
+1
-23
ee/app/validators/feature_flag_user_xids_validator.rb
ee/app/validators/feature_flag_user_xids_validator.rb
+31
-0
No files found.
ee/app/models/operations/feature_flags/strategy.rb
View file @
837b45c3
...
@@ -51,7 +51,7 @@ module Operations
...
@@ -51,7 +51,7 @@ module Operations
when
STRATEGY_GRADUALROLLOUTUSERID
when
STRATEGY_GRADUALROLLOUTUSERID
gradual_rollout_user_id_parameters_validation
gradual_rollout_user_id_parameters_validation
when
STRATEGY_USERWITHID
when
STRATEGY_USERWITHID
user_with_id_parameters_validation
FeatureFlagUserXidsValidator
.
validate_user_xids
(
self
,
:parameters
,
parameters
[
'userIds'
],
'userIds'
)
end
end
end
end
...
@@ -68,24 +68,6 @@ module Operations
...
@@ -68,24 +68,6 @@ module Operations
end
end
end
end
def
user_with_id_parameters_validation
user_ids
=
parameters
[
'userIds'
]
unless
user_ids
.
is_a?
(
String
)
&&
!
user_ids
.
match
(
/[\n\r\t]|,,/
)
&&
valid_ids?
(
user_ids
.
split
(
","
))
parameters_error
(
"userIds must be a string of unique comma separated values each
#{
USERID_MAX_LENGTH
}
characters or less"
)
end
end
def
valid_ids?
(
user_ids
)
user_ids
.
uniq
.
length
==
user_ids
.
length
&&
user_ids
.
all?
{
|
id
|
valid_id?
(
id
)
}
end
def
valid_id?
(
user_id
)
user_id
.
present?
&&
user_id
.
strip
==
user_id
&&
user_id
.
length
<=
USERID_MAX_LENGTH
end
def
parameters_error
(
message
)
def
parameters_error
(
message
)
errors
.
add
(
:parameters
,
message
)
errors
.
add
(
:parameters
,
message
)
false
false
...
...
ee/app/models/operations/feature_flags/user_list.rb
View file @
837b45c3
...
@@ -5,8 +5,6 @@ module Operations
...
@@ -5,8 +5,6 @@ module Operations
class
UserList
<
ApplicationRecord
class
UserList
<
ApplicationRecord
include
AtomicInternalId
include
AtomicInternalId
USERXID_MAX_LENGTH
=
256
self
.
table_name
=
'operations_user_lists'
self
.
table_name
=
'operations_user_lists'
belongs_to
:project
belongs_to
:project
...
@@ -18,27 +16,7 @@ module Operations
...
@@ -18,27 +16,7 @@ module Operations
presence:
true
,
presence:
true
,
uniqueness:
{
scope: :project_id
},
uniqueness:
{
scope: :project_id
},
length:
1
..
255
length:
1
..
255
validate
:user_xids_validation
validates
:user_xids
,
feature_flag_user_xids:
true
private
def
user_xids_validation
unless
user_xids
.
is_a?
(
String
)
&&
!
user_xids
.
match
(
/[\n\r\t]|,,/
)
&&
valid_xids?
(
user_xids
.
split
(
","
))
errors
.
add
(
:user_xids
,
"user_xids must be a string of unique comma separated values each
#{
USERXID_MAX_LENGTH
}
characters or less"
)
end
end
def
valid_xids?
(
user_xids
)
user_xids
.
uniq
.
length
==
user_xids
.
length
&&
user_xids
.
all?
{
|
xid
|
valid_xid?
(
xid
)
}
end
def
valid_xid?
(
user_xid
)
user_xid
.
present?
&&
user_xid
.
strip
==
user_xid
&&
user_xid
.
length
<=
USERXID_MAX_LENGTH
end
end
end
end
end
end
end
ee/app/validators/feature_flag_user_xids_validator.rb
0 → 100644
View file @
837b45c3
# frozen_string_literal: true
class
FeatureFlagUserXidsValidator
<
ActiveModel
::
EachValidator
USERXID_MAX_LENGTH
=
256
def
validate_each
(
record
,
attribute
,
value
)
self
.
class
.
validate_user_xids
(
record
,
attribute
,
value
,
attribute
)
end
class
<<
self
def
validate_user_xids
(
record
,
attribute
,
user_xids
,
error_message_attribute_name
)
unless
user_xids
.
is_a?
(
String
)
&&
!
user_xids
.
match
(
/[\n\r\t]|,,/
)
&&
valid_xids?
(
user_xids
.
split
(
","
))
record
.
errors
.
add
(
attribute
,
"
#{
error_message_attribute_name
}
must be a string of unique comma separated values each
#{
USERXID_MAX_LENGTH
}
characters or less"
)
end
end
private
def
valid_xids?
(
user_xids
)
user_xids
.
uniq
.
length
==
user_xids
.
length
&&
user_xids
.
all?
{
|
xid
|
valid_xid?
(
xid
)
}
end
def
valid_xid?
(
user_xid
)
user_xid
.
present?
&&
user_xid
.
strip
==
user_xid
&&
user_xid
.
length
<=
USERXID_MAX_LENGTH
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