Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cbd78922
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cbd78922
编写于
1月 14, 2012
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'deploy_keys'
Conflicts: app/views/layouts/project.html.haml db/schema.rb
上级
09b877ef
dda6b0ab
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
234 addition
and
8 deletion
+234
-8
app/controllers/deploy_keys_controller.rb
app/controllers/deploy_keys_controller.rb
+44
-0
app/models/key.rb
app/models/key.rb
+15
-2
app/models/project.rb
app/models/project.rb
+2
-1
app/views/deploy_keys/_form.html.haml
app/views/deploy_keys/_form.html.haml
+16
-0
app/views/deploy_keys/_show.html.haml
app/views/deploy_keys/_show.html.haml
+7
-0
app/views/deploy_keys/create.js.haml
app/views/deploy_keys/create.js.haml
+9
-0
app/views/deploy_keys/edit.html.haml
app/views/deploy_keys/edit.html.haml
+7
-0
app/views/deploy_keys/index.html.haml
app/views/deploy_keys/index.html.haml
+11
-0
app/views/deploy_keys/new.html.haml
app/views/deploy_keys/new.html.haml
+5
-0
app/views/deploy_keys/new.js.haml
app/views/deploy_keys/new.js.haml
+11
-0
app/views/deploy_keys/show.html.haml
app/views/deploy_keys/show.html.haml
+10
-0
app/views/layouts/project.html.haml
app/views/layouts/project.html.haml
+1
-0
app/views/repositories/_head.html.haml
app/views/repositories/_head.html.haml
+8
-3
config/routes.rb
config/routes.rb
+2
-0
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
+2
-1
spec/models/key_spec.rb
spec/models/key_spec.rb
+1
-1
spec/requests/projects_deploy_keys_spec.rb
spec/requests/projects_deploy_keys_spec.rb
+68
-0
spec/requests/projects_security_spec.rb
spec/requests/projects_security_spec.rb
+9
-0
未找到文件。
app/controllers/deploy_keys_controller.rb
0 → 100644
浏览文件 @
cbd78922
class
DeployKeysController
<
ApplicationController
respond_to
:js
,
:html
layout
"project"
before_filter
:project
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_admin_project!
def
project
@project
||=
Project
.
find_by_code
(
params
[
:project_id
])
end
def
index
@keys
=
@project
.
deploy_keys
.
all
end
def
show
@key
=
@project
.
deploy_keys
.
find
(
params
[
:id
])
end
def
new
@key
=
@project
.
deploy_keys
.
new
respond_with
(
@key
)
end
def
create
@key
=
@project
.
deploy_keys
.
new
(
params
[
:key
])
@key
.
save
respond_with
(
@key
)
end
def
destroy
@key
=
@project
.
deploy_keys
.
find
(
params
[
:id
])
@key
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
project_deploy_keys_url
}
format
.
js
{
render
:nothing
=>
true
}
end
end
end
app/models/key.rb
浏览文件 @
cbd78922
class
Key
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:project
validates
:title
,
:presence
=>
true
,
...
...
@@ -15,7 +16,11 @@ class Key < ActiveRecord::Base
after_destroy
:repository_delete_key
def
set_identifier
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
if
is_deploy_key
self
.
identifier
=
"deploy_
#{
project
.
code
}
_
#{
Time
.
now
.
to_i
}
"
else
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
end
end
def
update_repository
...
...
@@ -31,10 +36,18 @@ class Key < ActiveRecord::Base
c
.
update_projects
(
projects
)
end
end
def
is_deploy_key
true
if
project_id
end
#projects that has this key
def
projects
user
.
projects
if
is_deploy_key
[
project
]
else
user
.
projects
end
end
end
# == Schema Information
...
...
app/models/project.rb
浏览文件 @
cbd78922
...
...
@@ -14,6 +14,7 @@ class Project < ActiveRecord::Base
has_many
:users
,
:through
=>
:users_projects
has_many
:notes
,
:dependent
=>
:destroy
has_many
:snippets
,
:dependent
=>
:destroy
has_many
:deploy_keys
,
:dependent
=>
:destroy
,
:foreign_key
=>
"project_id"
,
:class_name
=>
"Key"
has_many
:web_hooks
,
:dependent
=>
:destroy
acts_as_taggable
...
...
@@ -199,7 +200,7 @@ class Project < ActiveRecord::Base
def
repository_readers
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
where
(
"users_projects.project_id = ? AND users_projects.repo_access = ?"
,
id
,
Repository
::
REPO_R
)
keys
.
map
(
&
:identifier
)
keys
.
map
(
&
:identifier
)
+
deploy_keys
.
map
(
&
:identifier
)
end
def
repository_writers
...
...
app/views/deploy_keys/_form.html.haml
0 → 100644
浏览文件 @
cbd78922
%div
=
form_for
[
@project
,
@key
],
:url
=>
project_deploy_keys_path
,
:remote
=>
true
do
|
f
|
-
if
@key
.
errors
.
any?
%ul
-
@key
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.form-row
=
f
.
label
:title
=
f
.
text_field
:title
,
:style
=>
"width:300px"
.form-row
=
f
.
label
:key
=
f
.
text_area
:key
,
:style
=>
"width:300px; height:130px"
.form-row
=
f
.
submit
'Save'
,
:class
=>
"grey-button"
app/views/deploy_keys/_show.html.haml
0 → 100644
浏览文件 @
cbd78922
%a
.update-item
{
:href
=>
project_deploy_key_path
(
key
.
project
,
key
)}
%span
.update-title
=
key
.
title
%span
.update-author
Added
=
time_ago_in_words
(
key
.
created_at
)
ago
app/views/deploy_keys/create.js.haml
0 → 100644
浏览文件 @
cbd78922
-
if
@key
.
valid?
:plain
$("#new_key_dialog").dialog("close");
$("#keys-table .data").append("
#{
escape_javascript
(
render
(
:partial
=>
'show'
,
:locals
=>
{
:key
=>
@key
}
))
}
");
$("#no_ssh_key_defined").hide();
-
else
:plain
$("#new_key_dialog").empty();
$("#new_key_dialog").append("
#{
escape_javascript
(
render
(
'form'
))
}
");
app/views/deploy_keys/edit.html.haml
0 → 100644
浏览文件 @
cbd78922
%h1
Editing key
=
render
'form'
=
link_to
'Show'
,
@key
\|
=
link_to
'Back'
,
project_deploy_keys_path
app/views/deploy_keys/index.html.haml
0 → 100644
浏览文件 @
cbd78922
=
render
"repositories/head"
%div
#keys-table
{
:class
=>
"update-data ui-box ui-box-small ui-box-big"
}
.data
-
@keys
.
each
do
|
key
|
=
render
(
:partial
=>
'show'
,
:locals
=>
{
:key
=>
key
})
:javascript
$
(
'
.delete-key
'
).
live
(
'
ajax:success
'
,
function
()
{
$
(
this
).
closest
(
'
.update-item
'
).
fadeOut
();
});
app/views/deploy_keys/new.html.haml
0 → 100644
浏览文件 @
cbd78922
%h1
New key
=
render
'form'
=
link_to
'Back'
,
project_deploy_keys_path
app/views/deploy_keys/new.js.haml
0 → 100644
浏览文件 @
cbd78922
:plain
var new_key_dialog = $("<div id='new_key_dialog'></div>");
new_key_dialog.html("
#{
escape_javascript
(
render
(
'form'
))
}
");
$(new_key_dialog).dialog({
width: 350,
resizable: false,
draggable: false,
title: "Add new public key",
close: function(event, ui) { $("#new_key_dialog").remove();},
modal: true
});
app/views/deploy_keys/show.html.haml
0 → 100644
浏览文件 @
cbd78922
.ui-box.width-100p
%h3
=
@key
.
title
.data
%pre
=
@key
.
key
.clear
.buttons
=
link_to
'Remove'
,
project_deploy_key_path
(
@key
.
project
,
@key
),
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
,
:class
=>
"red-button delete-key right"
.clear
app/views/layouts/project.html.haml
浏览文件 @
cbd78922
...
...
@@ -44,5 +44,6 @@
%span{ :class => "number" }= @project.merge_requests.opened.count
.project-content
=
yield
app/views/repositories/_head.html.haml
浏览文件 @
cbd78922
...
...
@@ -11,13 +11,18 @@
=
link_to
project_hooks_path
,
:class
=>
"tab
#{
'active'
if
controller
.
controller_name
==
"hooks"
}
"
do
%span
Hooks
-#= link_to "#", :class => "tab" do
%span
Deploy Keys
-
if
can?
current_user
,
:admin_project
,
@project
=
link_to
project_deploy_keys_path
(
@project
),
:class
=>
"tab
#{
'active'
if
controller
.
controller_name
==
"deploy_keys"
}
"
do
%span
Deploy Keys
-
if
current_page?
(
project_hooks_path
(
@project
))
-
if
can?
current_user
,
:admin_project
,
@project
=
link_to
new_project_hook_path
(
@project
),
:class
=>
"add_new"
,
:title
=>
"New Web Hook"
do
=
image_tag
"add_new.png"
,
:width
=>
14
-
if
current_page?
(
project_deploy_keys_path
(
@project
))
-
if
can?
current_user
,
:admin_project
,
@project
=
link_to
new_project_deploy_key_path
(
@project
),
:class
=>
"add_new"
,
:title
=>
"New Deploy Key"
,
:remote
=>
true
do
=
image_tag
"add_new.png"
,
:width
=>
14
config/routes.rb
浏览文件 @
cbd78922
...
...
@@ -53,6 +53,8 @@ Gitlab::Application.routes.draw do
end
end
resources
:deploy_keys
resources
:refs
,
:only
=>
[],
:path
=>
"/"
do
collection
do
get
"switch"
...
...
db/migrate/20111231111825_add_project_id_to_key.rb
0 → 100644
浏览文件 @
cbd78922
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
浏览文件 @
cbd78922
...
...
@@ -39,12 +39,13 @@ ActiveRecord::Schema.define(:version => 20120110180749) do
end
create_table
"keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"user_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
string
"title"
t
.
string
"identifier"
t
.
integer
"project_id"
end
create_table
"merge_requests"
,
:force
=>
true
do
|
t
|
...
...
spec/models/key_spec.rb
浏览文件 @
cbd78922
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Key
do
describe
"Associations"
do
it
{
should
belong_to
(
:user
)
}
it
{
should
belong_to
(
:user
)
or
belong_to
(
:project
)
}
end
describe
"Validation"
do
...
...
spec/requests/projects_deploy_keys_spec.rb
0 → 100644
浏览文件 @
cbd78922
require
'spec_helper'
describe
"Projects"
,
"DeployKeys"
do
let
(
:project
)
{
Factory
:project
}
before
do
login_as
:user
project
.
add_access
(
@user
,
:read
,
:write
,
:admin
)
end
describe
"GET /keys"
do
before
do
@key
=
Factory
:key
,
:project
=>
project
visit
project_deploy_keys_path
(
project
)
end
subject
{
page
}
it
{
should
have_content
(
@key
.
title
)
}
describe
"Destroy"
do
before
{
visit
project_deploy_key_path
(
project
,
@key
)
}
it
"should remove entry"
do
expect
{
click_link
"Remove"
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
end
end
end
describe
"New key"
,
:js
=>
true
do
before
do
visit
project_deploy_keys_path
(
project
)
click_link
"New Deploy Key"
end
it
"should open new key popup"
do
page
.
should
have_content
(
"Add new public key"
)
end
describe
"fill in"
do
before
do
fill_in
"key_title"
,
:with
=>
"laptop"
fill_in
"key_key"
,
:with
=>
"publickey234="
end
it
{
expect
{
click_button
"Save"
}.
to
change
{
Key
.
count
}.
by
(
1
)
}
it
"should add new key to table"
do
click_button
"Save"
page
.
should_not
have_content
(
"Add new public key"
)
page
.
should
have_content
"laptop"
end
end
end
describe
"Show page"
do
before
do
@key
=
Factory
:key
,
:project
=>
project
visit
project_deploy_key_path
(
project
,
@key
)
end
it
{
page
.
should
have_content
@key
.
title
}
it
{
page
.
should
have_content
@key
.
key
[
0
..
10
]
}
end
end
spec/requests/projects_security_spec.rb
浏览文件 @
cbd78922
...
...
@@ -105,6 +105,15 @@ describe "Projects" do
it
{
edit_project_path
(
@project
).
should
be_denied_for
:visitor
}
end
describe
"GET /project_code/deploy_keys"
do
it
{
project_deploy_keys_path
(
@project
).
should
be_allowed_for
@u1
}
it
{
project_deploy_keys_path
(
@project
).
should
be_denied_for
@u3
}
it
{
project_deploy_keys_path
(
@project
).
should
be_denied_for
:admin
}
it
{
project_deploy_keys_path
(
@project
).
should
be_denied_for
@u2
}
it
{
project_deploy_keys_path
(
@project
).
should
be_denied_for
:user
}
it
{
project_deploy_keys_path
(
@project
).
should
be_denied_for
:visitor
}
end
describe
"GET /project_code/issues"
do
it
{
project_issues_path
(
@project
).
should
be_allowed_for
@u1
}
it
{
project_issues_path
(
@project
).
should
be_allowed_for
@u3
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录