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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
99b8b577
Commit
99b8b577
authored
Dec 31, 2011
by
miks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DeployKey moved to Key model
parent
5b4382e1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
93 deletions
+35
-93
app/controllers/deploy_keys_controller.rb
app/controllers/deploy_keys_controller.rb
+5
-5
app/models/deploy_key.rb
app/models/deploy_key.rb
+0
-53
app/models/key.rb
app/models/key.rb
+15
-6
app/models/project.rb
app/models/project.rb
+5
-5
app/views/deploy_keys/_form.html.haml
app/views/deploy_keys/_form.html.haml
+1
-1
db/migrate/20111225202855_create_deploy_keys.rb
db/migrate/20111225202855_create_deploy_keys.rb
+0
-12
db/migrate/20111231111825_add_project_id_to_key.rb
db/migrate/20111231111825_add_project_id_to_key.rb
+6
-0
db/schema.rb
db/schema.rb
+3
-11
No files found.
app/controllers/deploy_keys_controller.rb
View file @
99b8b577
...
@@ -12,28 +12,28 @@ class DeployKeysController < ApplicationController
...
@@ -12,28 +12,28 @@ class DeployKeysController < ApplicationController
end
end
def
index
def
index
@keys
=
@project
.
deploy_
keys
.
all
@keys
=
@project
.
keys
.
all
end
end
def
show
def
show
@key
=
@project
.
deploy_
keys
.
find
(
params
[
:id
])
@key
=
@project
.
keys
.
find
(
params
[
:id
])
end
end
def
new
def
new
@key
=
@project
.
deploy_
keys
.
new
@key
=
@project
.
keys
.
new
respond_with
(
@key
)
respond_with
(
@key
)
end
end
def
create
def
create
@key
=
@project
.
deploy_keys
.
new
(
params
[
:deploy_
key
])
@key
=
@project
.
keys
.
new
(
params
[
:
key
])
@key
.
save
@key
.
save
respond_with
(
@key
)
respond_with
(
@key
)
end
end
def
destroy
def
destroy
@key
=
@project
.
deploy_
keys
.
find
(
params
[
:id
])
@key
=
@project
.
keys
.
find
(
params
[
:id
])
@key
.
destroy
@key
.
destroy
respond_to
do
|
format
|
respond_to
do
|
format
|
...
...
app/models/deploy_key.rb
deleted
100644 → 0
View file @
5b4382e1
require
'unique_public_key_validator'
class
DeployKey
<
ActiveRecord
::
Base
belongs_to
:project
validates
:title
,
:presence
=>
true
,
:length
=>
{
:within
=>
0
..
255
}
validates
:key
,
:presence
=>
true
,
:uniqueness
=>
true
,
:length
=>
{
:within
=>
0
..
5000
}
validates_with
UniquePublicKeyValidator
before_save
:set_identifier
after_save
:update_repository
after_destroy
:repository_delete_key
def
set_identifier
self
.
identifier
=
"deploy_
#{
project
.
code
}
_
#{
Time
.
now
.
to_i
}
"
end
def
update_repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_keys
(
identifier
,
key
)
c
.
update_project
(
project
.
path
,
project
)
end
end
def
repository_delete_key
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
delete_key
(
identifier
)
c
.
update_project
(
project
.
path
,
project
)
end
end
end
# == Schema Information
#
# Table name: keys
#
# id :integer not null, primary key
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
# key :text
# title :string(255)
# identifier :string(255)
#
app/models/key.rb
View file @
99b8b577
require
'unique_public_key_validator'
class
Key
<
ActiveRecord
::
Base
class
Key
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:user
belongs_to
:project
validates
:title
,
validates
:title
,
:presence
=>
true
,
:presence
=>
true
,
...
@@ -12,15 +11,17 @@ class Key < ActiveRecord::Base
...
@@ -12,15 +11,17 @@ 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
def
set_identifier
def
set_identifier
if
is_deploy_key
self
.
identifier
=
"deploy_
#{
project
.
code
}
_
#{
Time
.
now
.
to_i
}
"
else
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
end
end
end
def
update_repository
def
update_repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
...
@@ -36,10 +37,18 @@ class Key < ActiveRecord::Base
...
@@ -36,10 +37,18 @@ class Key < ActiveRecord::Base
end
end
end
end
def
is_deploy_key
true
if
project_id
end
#projects that has this key
#projects that has this key
def
projects
def
projects
if
is_deploy_key
[
project
]
else
user
.
projects
user
.
projects
end
end
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/models/project.rb
View file @
99b8b577
...
@@ -14,7 +14,7 @@ class Project < ActiveRecord::Base
...
@@ -14,7 +14,7 @@ class Project < ActiveRecord::Base
has_many
:users
,
:through
=>
:users_projects
has_many
:users
,
:through
=>
:users_projects
has_many
:notes
,
:dependent
=>
:destroy
has_many
:notes
,
:dependent
=>
:destroy
has_many
:snippets
,
:dependent
=>
:destroy
has_many
:snippets
,
:dependent
=>
:destroy
has_many
:
deploy_
keys
,
:dependent
=>
:destroy
has_many
:keys
,
:dependent
=>
:destroy
has_many
:web_hooks
,
:dependent
=>
:destroy
has_many
:web_hooks
,
:dependent
=>
:destroy
acts_as_taggable
acts_as_taggable
...
@@ -189,15 +189,15 @@ class Project < ActiveRecord::Base
...
@@ -189,15 +189,15 @@ class Project < ActiveRecord::Base
end
end
def
repository_readers
def
repository_readers
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
read_
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
where
(
"users_projects.project_id = ? AND users_projects.repo_access = ?"
,
id
,
Repository
::
REPO_R
)
where
(
"users_projects.project_id = ? AND users_projects.repo_access = ?"
,
id
,
Repository
::
REPO_R
)
keys
.
map
(
&
:identifier
)
+
deploy_
keys
.
map
(
&
:identifier
)
read_keys
.
map
(
&
:identifier
)
+
keys
.
map
(
&
:identifier
)
end
end
def
repository_writers
def
repository_writers
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
write_
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
where
(
"users_projects.project_id = ? AND users_projects.repo_access = ?"
,
id
,
Repository
::
REPO_RW
)
where
(
"users_projects.project_id = ? AND users_projects.repo_access = ?"
,
id
,
Repository
::
REPO_RW
)
keys
.
map
(
&
:identifier
)
write_
keys
.
map
(
&
:identifier
)
end
end
def
readers
def
readers
...
...
app/views/deploy_keys/_form.html.haml
View file @
99b8b577
%div
%div
=
form_for
[
@project
,
@key
],
:remote
=>
true
do
|
f
|
=
form_for
[
@project
,
@key
],
:
url
=>
project_deploy_keys_path
,
:
remote
=>
true
do
|
f
|
-
if
@key
.
errors
.
any?
-
if
@key
.
errors
.
any?
%ul
%ul
-
@key
.
errors
.
full_messages
.
each
do
|
msg
|
-
@key
.
errors
.
full_messages
.
each
do
|
msg
|
...
...
db/migrate/20111225202855_create_deploy_keys.rb
deleted
100644 → 0
View file @
5b4382e1
class
CreateDeployKeys
<
ActiveRecord
::
Migration
def
change
create_table
:deploy_keys
do
|
t
|
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
string
"title"
t
.
string
"identifier"
end
end
end
db/migrate/20111231111825_add_project_id_to_key.rb
0 → 100644
View file @
99b8b577
class
AddProjectIdToKey
<
ActiveRecord
::
Migration
def
change
add_column
:keys
,
:project_id
,
:integer
,
:null
=>
true
change_column
:keys
,
:user_id
,
:integer
,
:null
=>
true
end
end
db/schema.rb
View file @
99b8b577
...
@@ -11,16 +11,7 @@
...
@@ -11,16 +11,7 @@
#
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
20111225202855
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
20111231111825
)
do
create_table
"deploy_keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
string
"title"
t
.
string
"identifier"
end
create_table
"issues"
,
:force
=>
true
do
|
t
|
create_table
"issues"
,
:force
=>
true
do
|
t
|
t
.
string
"title"
t
.
string
"title"
...
@@ -36,12 +27,13 @@ ActiveRecord::Schema.define(:version => 20111225202855) do
...
@@ -36,12 +27,13 @@ ActiveRecord::Schema.define(:version => 20111225202855) do
end
end
create_table
"keys"
,
:force
=>
true
do
|
t
|
create_table
"keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"user_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
text
"key"
t
.
string
"title"
t
.
string
"title"
t
.
string
"identifier"
t
.
string
"identifier"
t
.
integer
"project_id"
end
end
create_table
"merge_requests"
,
:force
=>
true
do
|
t
|
create_table
"merge_requests"
,
:force
=>
true
do
|
t
|
...
...
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