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
Jérome Perrin
gitlab-ce
Commits
70e3bffd
Commit
70e3bffd
authored
Feb 05, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed: post-receive, project remove, tests
parent
39e37677
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
43 additions
and
47 deletions
+43
-47
app/observers/project_observer.rb
app/observers/project_observer.rb
+1
-2
app/workers/post_receive.rb
app/workers/post_receive.rb
+3
-2
lib/api/internal.rb
lib/api/internal.rb
+29
-15
spec/lib/shell_spec.rb
spec/lib/shell_spec.rb
+3
-4
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-2
spec/models/protected_branch_spec.rb
spec/models/protected_branch_spec.rb
+0
-15
spec/observers/key_observer_spec.rb
spec/observers/key_observer_spec.rb
+3
-3
spec/support/stubbed_repository.rb
spec/support/stubbed_repository.rb
+2
-2
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+2
-2
No files found.
app/observers/project_observer.rb
View file @
70e3bffd
...
...
@@ -15,11 +15,10 @@ class ProjectObserver < ActiveRecord::Observer
def
after_destroy
(
project
)
GitoliteWorker
.
perform_async
(
:remove_repository
,
self
.
path_with_namespace
project
.
path_with_namespace
)
project
.
satellite
.
destroy
project
.
destroy_repository
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
end
...
...
app/workers/post_receive.rb
View file @
70e3bffd
...
...
@@ -27,8 +27,9 @@ class PostReceive
User
.
find_by_email
(
email
)
if
email
elsif
/^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/
.
match
(
identifier
)
User
.
find_by_email
(
identifier
)
else
User
.
find_by_username
(
identifier
.
strip
)
elsif
identifier
=~
/key/
key_id
=
identifier
.
gsub
(
"key-"
,
""
)
Key
.
find_by_id
(
key_id
).
try
(
:user
)
end
unless
user
...
...
lib/api/internal.rb
View file @
70e3bffd
module
Gitlab
#
A
ccess API
#
Internal a
ccess API
class
Internal
<
Grape
::
API
namespace
'internal'
do
#
# Check if ssh key has access to project code
#
get
"/allowed"
do
user
=
User
.
find_by_username
(
params
[
:username
])
key
=
Key
.
find
(
params
[
:key_id
])
user
=
key
.
user
project
=
Project
.
find_with_namespace
(
params
[
:project
])
action
=
case
params
[
:action
]
when
'git-upload-pack'
...
...
@@ -19,6 +24,15 @@ module Gitlab
user
.
can?
(
action
,
project
)
end
#
# Discover user by ssh key
#
get
"/discover"
do
key
=
Key
.
find
(
params
[
:key_id
])
present
key
.
user
,
with:
Entities
::
User
end
end
end
end
spec/lib/
gitolite
_spec.rb
→
spec/lib/
shell
_spec.rb
View file @
70e3bffd
require
'spec_helper'
describe
Gitlab
::
Gitolite
do
describe
Gitlab
::
Shell
do
let
(
:project
)
{
double
(
'Project'
,
id:
7
,
path:
'diaspora'
)
}
let
(
:gitolite
)
{
Gitlab
::
Gitolite
.
new
}
let
(
:gitolite
)
{
Gitlab
::
Shell
.
new
}
before
do
Project
.
stub
(
find:
project
)
end
it
{
should
respond_to
:
set
_key
}
it
{
should
respond_to
:
add
_key
}
it
{
should
respond_to
:remove_key
}
it
{
should
respond_to
:add_repository
}
it
{
should
respond_to
:remove_repository
}
...
...
spec/models/project_spec.rb
View file @
70e3bffd
...
...
@@ -77,8 +77,6 @@ describe Project do
it
{
should
respond_to
(
:url_to_repo
)
}
it
{
should
respond_to
(
:repo_exists?
)
}
it
{
should
respond_to
(
:satellite
)
}
it
{
should
respond_to
(
:update_repository
)
}
it
{
should
respond_to
(
:destroy_repository
)
}
it
{
should
respond_to
(
:observe_push
)
}
it
{
should
respond_to
(
:update_merge_requests
)
}
it
{
should
respond_to
(
:execute_hooks
)
}
...
...
spec/models/protected_branch_spec.rb
View file @
70e3bffd
...
...
@@ -24,19 +24,4 @@ describe ProtectedBranch do
it
{
should
validate_presence_of
(
:project
)
}
it
{
should
validate_presence_of
(
:name
)
}
end
describe
'Callbacks'
do
let
(
:branch
)
{
build
(
:protected_branch
)
}
it
'call update_repository after save'
do
branch
.
should_receive
(
:update_repository
)
branch
.
save
end
it
'call update_repository after destroy'
do
branch
.
save
branch
.
should_receive
(
:update_repository
)
branch
.
destroy
end
end
end
spec/observers/key_observer_spec.rb
View file @
70e3bffd
...
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
KeyObserver
do
before
do
@key
=
double
(
'Key'
,
identifier:
'admin_654654
'
,
shell_id:
'key-32
'
,
key:
'== a vaild ssh key'
,
projects:
[],
is_deploy_key:
false
...
...
@@ -14,14 +14,14 @@ describe KeyObserver do
context
:after_save
do
it
do
GitoliteWorker
.
should_receive
(
:perform_async
).
with
(
:
set_key
,
@key
.
identifier
,
@key
.
key
,
@key
.
projects
.
map
(
&
:id
)
)
GitoliteWorker
.
should_receive
(
:perform_async
).
with
(
:
add_key
,
@key
.
shell_id
,
@key
.
key
)
@observer
.
after_save
(
@key
)
end
end
context
:after_destroy
do
it
do
GitoliteWorker
.
should_receive
(
:perform_async
).
with
(
:remove_key
,
@key
.
identifier
,
@key
.
projects
.
map
(
&
:id
)
)
GitoliteWorker
.
should_receive
(
:perform_async
).
with
(
:remove_key
,
@key
.
shell_id
,
@key
.
key
)
@observer
.
after_destroy
(
@key
)
end
end
...
...
spec/support/stubbed_repository.rb
View file @
70e3bffd
...
...
@@ -48,11 +48,11 @@ module Gitlab
true
end
def
add_key
name
,
key
def
add_key
id
,
key
true
end
def
remove_key
key
def
remove_key
id
,
key
true
end
end
...
...
spec/workers/post_receive_spec.rb
View file @
70e3bffd
...
...
@@ -11,7 +11,7 @@ describe PostReceive do
context
"web hook"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:key
)
{
create
(
:key
,
user:
project
.
owner
)
}
let
(
:key_id
)
{
key
.
identifier
}
let
(
:key_id
)
{
key
.
shell_id
}
it
"fetches the correct project"
do
Project
.
should_receive
(
:find_with_namespace
).
with
(
project
.
path_with_namespace
).
and_return
(
project
)
...
...
@@ -19,7 +19,7 @@ describe PostReceive do
end
it
"does not run if the author is not in the project"
do
Key
.
stub
(
find_by_id
entifier
:
nil
)
Key
.
stub
(
find_by_id:
nil
)
project
.
should_not_receive
(
:observe_push
)
project
.
should_not_receive
(
:execute_hooks
)
...
...
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