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
cb59aade
Commit
cb59aade
authored
Mar 06, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaning and refactoring
parent
74f8bc72
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
135 additions
and
232 deletions
+135
-232
app/controllers/admin/projects_controller.rb
app/controllers/admin/projects_controller.rb
+1
-2
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+1
-2
app/models/project.rb
app/models/project.rb
+120
-37
app/models/protected_branch.rb
app/models/protected_branch.rb
+1
-3
app/models/repository.rb
app/models/repository.rb
+0
-131
app/models/users_project.rb
app/models/users_project.rb
+2
-2
app/views/dashboard/_projects_feed.html.haml
app/views/dashboard/_projects_feed.html.haml
+1
-1
app/views/projects/_feed.html.haml
app/views/projects/_feed.html.haml
+0
-23
app/views/projects/_list.html.haml
app/views/projects/_list.html.haml
+0
-26
lib/gitlabhq/gitolite.rb
lib/gitlabhq/gitolite.rb
+8
-0
lib/tasks/bulk_import.rake
lib/tasks/bulk_import.rake
+1
-2
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-3
No files found.
app/controllers/admin/projects_controller.rb
View file @
cb59aade
...
...
@@ -31,8 +31,7 @@ class Admin::ProjectsController < ApplicationController
UsersProject
.
bulk_import
(
@admin_project
,
params
[
:user_ids
],
params
[
:project_access
],
params
[
:repo_access
]
params
[
:project_access
]
)
redirect_to
[
:admin
,
@admin_project
],
notice:
'Project was successfully updated.'
...
...
app/controllers/admin/users_controller.rb
View file @
cb59aade
...
...
@@ -23,8 +23,7 @@ class Admin::UsersController < ApplicationController
UsersProject
.
user_bulk_import
(
@admin_user
,
params
[
:project_ids
],
params
[
:project_access
],
params
[
:repo_access
]
params
[
:project_access
]
)
redirect_to
[
:admin
,
@admin_user
],
notice:
'Teams were successfully updated.'
...
...
app/models/project.rb
View file @
cb59aade
...
...
@@ -54,27 +54,6 @@ class Project < ActiveRecord::Base
UsersProject
.
access_roles
end
def
repository
@repository
||=
Repository
.
new
(
self
)
end
delegate
:repo
,
:url_to_repo
,
:path_to_repo
,
:update_repository
,
:destroy_repository
,
:tags
,
:repo_exists?
,
:commit
,
:commits
,
:commits_with_refs
,
:tree
,
:heads
,
:commits_since
,
:fresh_commits
,
:commits_between
,
:to
=>
:repository
,
:prefix
=>
nil
def
to_param
code
end
...
...
@@ -213,18 +192,6 @@ class Project < ActiveRecord::Base
keys
.
map
(
&
:identifier
)
end
def
readers
@readers
||=
users_projects
.
includes
(
:user
).
map
(
&
:user
)
end
def
writers
@writers
||=
users_projects
.
includes
(
:user
).
map
(
&
:user
)
end
def
admins
@admins
||=
users_projects
.
includes
(
:user
).
where
(
:project_access
=>
UsersProject
::
MASTER
).
map
(
&
:user
)
end
def
allow_read_for?
(
user
)
!
users_projects
.
where
(
:user_id
=>
user
.
id
).
empty?
end
...
...
@@ -269,10 +236,6 @@ class Project < ActiveRecord::Base
end
end
def
last_activity_date_cached
(
expire
=
1
.
hour
)
last_activity_date
end
def
check_limit
unless
owner
.
can_create_project?
errors
[
:base
]
<<
(
"Your own projects limit is
#{
owner
.
projects_limit
}
! Please contact administrator to increase it"
)
...
...
@@ -293,7 +256,127 @@ class Project < ActiveRecord::Base
errors
.
add
(
:path
,
"Invalid repository path"
)
false
end
def
commit
(
commit_id
=
nil
)
commit
=
if
commit_id
repo
.
commits
(
commit_id
).
first
else
repo
.
commits
.
first
end
Commit
.
new
(
commit
)
if
commit
end
def
fresh_commits
(
n
=
10
)
commits
=
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
...
n
]
end
def
commits_with_refs
(
n
=
20
)
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
..
n
]
end
def
commits_since
(
date
)
commits
=
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
).
each
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
end
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
if
path
repo
.
log
(
ref
,
path
,
:max_count
=>
limit
,
:skip
=>
offset
)
elsif
limit
&&
offset
repo
.
commits
(
ref
,
limit
,
offset
)
else
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
commits_between
(
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
project_id
self
.
id
end
def
write_hooks
%w(post-receive)
.
each
do
|
hook
|
write_hook
(
hook
,
File
.
read
(
File
.
join
(
Rails
.
root
,
'lib'
,
"
#{
hook
}
-hook"
)))
end
end
def
write_hook
(
name
,
content
)
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
name
)
File
.
open
(
hook_file
,
'w'
)
do
|
f
|
f
.
write
(
content
)
end
File
.
chmod
(
0775
,
hook_file
)
end
def
repo
@repo
||=
Grit
::
Repo
.
new
(
path_to_repo
)
end
def
url_to_repo
Gitlabhq
::
GitHost
.
url_to_repo
(
path
)
end
def
path_to_repo
File
.
join
(
GIT_HOST
[
"base_path"
],
"
#{
path
}
.git"
)
end
def
update_repository
Gitlabhq
::
GitHost
.
system
.
update_project
(
path
,
self
)
write_hooks
if
File
.
exists?
(
path_to_repo
)
end
def
destroy_repository
Gitlabhq
::
GitHost
.
system
.
destroy_project
(
self
)
end
def
repo_exists?
@repo_exists
||=
(
repo
&&
!
repo
.
branches
.
empty?
)
rescue
@repo_exists
=
false
end
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
def
heads
@heads
||=
repo
.
heads
end
def
tree
(
fcommit
,
path
=
nil
)
fcommit
=
commit
if
fcommit
==
:head
tree
=
fcommit
.
tree
path
?
(
tree
/
path
)
:
tree
end
end
# == Schema Information
#
# Table name: projects
...
...
app/models/protected_branch.rb
View file @
cb59aade
...
...
@@ -7,9 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy
:update_repository
def
update_repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_project
(
project
.
path
,
project
)
end
Gitlabhq
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
end
def
commit
...
...
app/models/repository.rb
View file @
cb59aade
...
...
@@ -10,135 +10,4 @@ class Repository
def
self
.
access_options
{}
end
def
initialize
(
project
)
@project
=
project
end
def
path
@path
||=
project
.
path
end
def
project_id
project
.
id
end
def
write_hooks
%w(post-receive)
.
each
do
|
hook
|
write_hook
(
hook
,
File
.
read
(
File
.
join
(
Rails
.
root
,
'lib'
,
"
#{
hook
}
-hook"
)))
end
end
def
write_hook
(
name
,
content
)
hook_file
=
File
.
join
(
project
.
path_to_repo
,
'hooks'
,
name
)
File
.
open
(
hook_file
,
'w'
)
do
|
f
|
f
.
write
(
content
)
end
File
.
chmod
(
0775
,
hook_file
)
end
def
repo
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
end
def
url_to_repo
Gitlabhq
::
GitHost
.
url_to_repo
(
path
)
end
def
path_to_repo
File
.
join
(
GIT_HOST
[
"base_path"
],
"
#{
path
}
.git"
)
end
def
update_repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_project
(
path
,
project
)
end
write_hooks
if
File
.
exists?
(
project
.
path_to_repo
)
end
def
destroy_repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
destroy_project
(
@project
)
end
end
def
repo_exists?
@repo_exists
||=
(
repo
&&
!
repo
.
branches
.
empty?
)
rescue
@repo_exists
=
false
end
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
def
heads
@heads
||=
repo
.
heads
end
def
tree
(
fcommit
,
path
=
nil
)
fcommit
=
commit
if
fcommit
==
:head
tree
=
fcommit
.
tree
path
?
(
tree
/
path
)
:
tree
end
def
commit
(
commit_id
=
nil
)
commit
=
if
commit_id
repo
.
commits
(
commit_id
).
first
else
repo
.
commits
.
first
end
Commit
.
new
(
commit
)
if
commit
end
def
fresh_commits
(
n
=
10
)
commits
=
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
...
n
]
end
def
commits_with_refs
(
n
=
20
)
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
..
n
]
end
def
commits_since
(
date
)
commits
=
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
).
each
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
end
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
if
path
repo
.
log
(
ref
,
path
,
:max_count
=>
limit
,
:skip
=>
offset
)
elsif
limit
&&
offset
repo
.
commits
(
ref
,
limit
,
offset
)
else
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
commits_between
(
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Commit
.
new
(
c
)
}
end
end
app/models/users_project.rb
View file @
cb59aade
...
...
@@ -18,7 +18,7 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
,
repo_access
)
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
)
UsersProject
.
transaction
do
user_ids
.
each
do
|
user_id
|
users_project
=
UsersProject
.
new
(
...
...
@@ -31,7 +31,7 @@ class UsersProject < ActiveRecord::Base
end
end
def
self
.
user_bulk_import
(
user
,
project_ids
,
project_access
,
repo_access
)
def
self
.
user_bulk_import
(
user
,
project_ids
,
project_access
)
UsersProject
.
transaction
do
project_ids
.
each
do
|
project_id
|
users_project
=
UsersProject
.
new
(
...
...
app/views/dashboard/_projects_feed.html.haml
View file @
cb59aade
...
...
@@ -6,4 +6,4 @@
=
project
.
name
%small
last activity at
=
project
.
last_activity_date
_cached
.
stamp
(
"Aug 25, 2011"
)
=
project
.
last_activity_date
.
stamp
(
"Aug 25, 2011"
)
app/views/projects/_feed.html.haml
deleted
100644 → 0
View file @
74f8bc72
-
@activities
.
each
do
|
update
|
.wll
=
link_to
dashboard_feed_path
(
@project
,
update
)
do
-
if
update
.
kind_of?
Note
%p
%strong
-
if
update
.
target
=
update
.
target
.
class
.
name
.
titleize
=
truncate
update
.
target
.
id
.
to_s
,
:length
=>
10
commented
-
else
Project wall
–
=
image_tag
gravatar_icon
(
update
.
author_email
),
:class
=>
""
,
:width
=>
16
=
truncate
dashboard_feed_title
(
update
),
:length
=>
50
-
else
%p
%strong
=
update
.
class
.
name
.
titleize
=
truncate
update
.
id
.
to_s
–
=
image_tag
gravatar_icon
(
update
.
author_email
),
:class
=>
""
,
:width
=>
16
=
truncate
dashboard_feed_title
(
update
),
:length
=>
50
app/views/projects/_list.html.haml
deleted
100644 → 0
View file @
74f8bc72
%table
.round-borders
#projects-list
%tr
%th
Name
%th
Path
%th
Code
%th
Web
%th
Git
%th
Admin
%th
Actions
-
@projects
.
each
do
|
project
|
%tr
{
:class
=>
"project"
,
:url
=>
project_path
(
project
)
}
%td
=
project
.
name
.small-tags
=
tag_list
project
%td
=
truncate
project
.
url_to_repo
%td
=
project
.
code
%td
=
check_box_tag
"read"
,
1
,
project
.
readers
.
include?
(
current_user
),
:disabled
=>
:disabled
%td
=
check_box_tag
"commit"
,
1
,
project
.
writers
.
include?
(
current_user
),
:disabled
=>
:disabled
%td
=
check_box_tag
"admin"
,
1
,
project
.
admins
.
include?
(
current_user
),
:disabled
=>
:disabled
%td
-
if
can?
current_user
,
:admin_project
,
project
=
link_to
'Edit'
,
edit_project_path
(
project
),
:class
=>
"lbutton positive"
%br
lib/gitlabhq/gitolite.rb
View file @
cb59aade
...
...
@@ -6,6 +6,14 @@ module Gitlabhq
class
Gitolite
class
AccessDenied
<
StandardError
;
end
def
self
.
update_project
(
path
,
project
)
self
.
new
.
configure
{
|
git
|
git
.
update_project
(
path
,
project
)
}
end
def
self
.
destroy_project
(
project
)
self
.
new
.
configure
{
|
git
|
git
.
destroy_project
(
project
)
}
end
def
pull
# create tmp dir
@local_dir
=
File
.
join
(
Dir
.
tmpdir
,
"gitlabhq-gitolite-
#{
Time
.
now
.
to_i
}
"
)
...
...
lib/tasks/bulk_import.rake
View file @
cb59aade
...
...
@@ -90,8 +90,7 @@ def create_repo_project(project_name, user_email)
# Add user as admin for project
project
.
users_projects
.
create!
(
:repo_access
=>
Repository
::
REPO_RW
,
:project_access
=>
Project
::
PROJECT_RWA
,
:project_access
=>
UsersProject
::
MASTER
,
:user
=>
user
)
...
...
spec/models/project_spec.rb
View file @
cb59aade
...
...
@@ -22,10 +22,7 @@ describe Project do
end
describe
"Respond to"
do
it
{
should
respond_to
(
:readers
)
}
it
{
should
respond_to
(
:writers
)
}
it
{
should
respond_to
(
:repository_writers
)
}
it
{
should
respond_to
(
:admins
)
}
it
{
should
respond_to
(
:add_access
)
}
it
{
should
respond_to
(
:reset_access
)
}
it
{
should
respond_to
(
:update_repository
)
}
...
...
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