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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
5b4382e1
Commit
5b4382e1
authored
13 years ago
by
miks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate key uniqueness across Key and DeployKey tables
parent
c973fce6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
app/models/deploy_key.rb
app/models/deploy_key.rb
+4
-0
app/models/key.rb
app/models/key.rb
+4
-0
lib/unique_public_key_validator.rb
lib/unique_public_key_validator.rb
+7
-0
No files found.
app/models/deploy_key.rb
View file @
5b4382e1
require
'unique_public_key_validator'
class
DeployKey
<
ActiveRecord
::
Base
class
DeployKey
<
ActiveRecord
::
Base
belongs_to
:project
belongs_to
:project
...
@@ -10,6 +12,8 @@ class DeployKey < ActiveRecord::Base
...
@@ -10,6 +12,8 @@ class DeployKey < ActiveRecord::Base
:uniqueness
=>
true
,
:uniqueness
=>
true
,
:length
=>
{
:within
=>
0
..
5000
}
:length
=>
{
:within
=>
0
..
5000
}
validates_with
UniquePublicKeyValidator
before_save
:set_identifier
before_save
:set_identifier
after_save
:update_repository
after_save
:update_repository
after_destroy
:repository_delete_key
after_destroy
:repository_delete_key
...
...
This diff is collapsed.
Click to expand it.
app/models/key.rb
View file @
5b4382e1
require
'unique_public_key_validator'
class
Key
<
ActiveRecord
::
Base
class
Key
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:user
...
@@ -10,6 +12,8 @@ class Key < ActiveRecord::Base
...
@@ -10,6 +12,8 @@ class Key < ActiveRecord::Base
:uniqueness
=>
true
,
:uniqueness
=>
true
,
:length
=>
{
:within
=>
0
..
5000
}
:length
=>
{
:within
=>
0
..
5000
}
validates_with
UniquePublicKeyValidator
before_save
:set_identifier
before_save
:set_identifier
after_save
:update_repository
after_save
:update_repository
after_destroy
:repository_delete_key
after_destroy
:repository_delete_key
...
...
This diff is collapsed.
Click to expand it.
lib/unique_public_key_validator.rb
0 → 100644
View file @
5b4382e1
class
UniquePublicKeyValidator
<
ActiveModel
::
Validator
def
validate
(
record
)
if
(
DeployKey
.
where
(
'key = ? AND id !=?'
,
record
.
key
,
record
.
id
).
count
>
0
||
Key
.
where
(
'key = ? AND id !=?'
,
record
.
key
,
record
.
id
).
count
>
0
)
record
.
errors
.
add
:key
,
'already exist.'
end
end
end
This diff is collapsed.
Click to expand it.
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