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
5926bbac
Commit
5926bbac
authored
Jul 31, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend Refactoring
parent
69e41250
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
151 additions
and
78 deletions
+151
-78
app/contexts/notes/create_context.rb
app/contexts/notes/create_context.rb
+12
-0
app/contexts/notes/load_context.rb
app/contexts/notes/load_context.rb
+34
-0
app/contexts/notes_load.rb
app/contexts/notes_load.rb
+0
-32
app/contexts/test_hook_context.rb
app/contexts/test_hook_context.rb
+8
-0
app/controllers/admin/projects_controller.rb
app/controllers/admin/projects_controller.rb
+11
-20
app/controllers/hooks_controller.rb
app/controllers/hooks_controller.rb
+1
-4
app/controllers/notes_controller.rb
app/controllers/notes_controller.rb
+2
-6
app/controllers/profile_controller.rb
app/controllers/profile_controller.rb
+8
-6
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+6
-5
app/roles/team.rb
app/roles/team.rb
+29
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+40
-5
No files found.
app/contexts/notes/create_context.rb
0 → 100644
View file @
5926bbac
module
Notes
class
CreateContext
<
BaseContext
def
execute
note
=
project
.
notes
.
new
(
params
[
:note
])
note
.
author
=
current_user
note
.
notify
=
true
if
params
[
:notify
]
==
'1'
note
.
notify_author
=
true
if
params
[
:notify_author
]
==
'1'
note
.
save
note
end
end
end
app/contexts/notes/load_context.rb
0 → 100644
View file @
5926bbac
module
Notes
class
LoadContext
<
BaseContext
def
execute
target_type
=
params
[
:target_type
]
target_id
=
params
[
:target_id
]
first_id
=
params
[
:first_id
]
last_id
=
params
[
:last_id
]
@notes
=
case
target_type
when
"commit"
then
project
.
commit_notes
(
project
.
commit
(
target_id
)).
fresh
.
limit
(
20
)
when
"snippet"
then
project
.
snippets
.
find
(
target_id
).
notes
when
"wall"
then
project
.
common_notes
.
order
(
"created_at DESC"
).
fresh
.
limit
(
50
)
when
"issue"
then
project
.
issues
.
find
(
target_id
).
notes
.
inc_author
.
order
(
"created_at DESC"
).
limit
(
20
)
when
"merge_request"
then
project
.
merge_requests
.
find
(
target_id
).
notes
.
inc_author
.
order
(
"created_at DESC"
).
limit
(
20
)
when
"wiki"
then
project
.
wikis
.
reverse
.
map
{
|
w
|
w
.
notes
.
fresh
}.
flatten
[
0
..
20
]
end
@notes
=
if
last_id
@notes
.
where
(
"id > ?"
,
last_id
)
elsif
first_id
@notes
.
where
(
"id < ?"
,
first_id
)
else
@notes
end
end
end
end
app/contexts/notes_load.rb
deleted
100644 → 0
View file @
69e41250
class
NotesLoad
<
BaseContext
def
execute
target_type
=
params
[
:target_type
]
target_id
=
params
[
:target_id
]
first_id
=
params
[
:first_id
]
last_id
=
params
[
:last_id
]
@notes
=
case
target_type
when
"commit"
then
project
.
commit_notes
(
project
.
commit
(
target_id
)).
fresh
.
limit
(
20
)
when
"snippet"
then
project
.
snippets
.
find
(
target_id
).
notes
when
"wall"
then
project
.
common_notes
.
order
(
"created_at DESC"
).
fresh
.
limit
(
50
)
when
"issue"
then
project
.
issues
.
find
(
target_id
).
notes
.
inc_author
.
order
(
"created_at DESC"
).
limit
(
20
)
when
"merge_request"
then
project
.
merge_requests
.
find
(
target_id
).
notes
.
inc_author
.
order
(
"created_at DESC"
).
limit
(
20
)
when
"wiki"
then
project
.
wikis
.
reverse
.
map
{
|
w
|
w
.
notes
.
fresh
}.
flatten
[
0
..
20
]
end
@notes
=
if
last_id
@notes
.
where
(
"id > ?"
,
last_id
)
elsif
first_id
@notes
.
where
(
"id < ?"
,
first_id
)
else
@notes
end
end
end
app/contexts/test_hook_context.rb
0 → 100644
View file @
5926bbac
class
TestHookContext
<
BaseContext
def
execute
hook
=
project
.
hooks
.
find
(
params
[
:id
])
commits
=
project
.
commits
(
project
.
default_branch
,
nil
,
3
)
data
=
project
.
post_receive_data
(
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
project
.
default_branch
}
"
,
current_user
)
hook
.
execute
(
data
)
end
end
app/controllers/admin/projects_controller.rb
View file @
5926bbac
...
@@ -2,6 +2,7 @@ class Admin::ProjectsController < ApplicationController
...
@@ -2,6 +2,7 @@ class Admin::ProjectsController < ApplicationController
layout
"admin"
layout
"admin"
before_filter
:authenticate_user!
before_filter
:authenticate_user!
before_filter
:authenticate_admin!
before_filter
:authenticate_admin!
before_filter
:admin_project
,
:only
=>
[
:edit
,
:show
,
:update
,
:destroy
,
:team_update
]
def
index
def
index
@admin_projects
=
Project
.
scoped
@admin_projects
=
Project
.
scoped
...
@@ -10,13 +11,9 @@ class Admin::ProjectsController < ApplicationController
...
@@ -10,13 +11,9 @@ class Admin::ProjectsController < ApplicationController
end
end
def
show
def
show
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
@users
=
User
.
scoped
@users
=
@users
.
not_in_project
(
@admin_project
)
if
@admin_project
.
users
.
present?
@users
=
if
@admin_project
.
users
.
empty?
@users
=
@users
.
all
User
else
User
.
not_in_project
(
@admin_project
)
end
.
all
end
end
def
new
def
new
...
@@ -24,19 +21,10 @@ class Admin::ProjectsController < ApplicationController
...
@@ -24,19 +21,10 @@ class Admin::ProjectsController < ApplicationController
end
end
def
edit
def
edit
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
end
end
def
team_update
def
team_update
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
@admin_project
.
add_users_ids_to_team
(
params
[
:user_ids
],
params
[
:project_access
])
UsersProject
.
bulk_import
(
@admin_project
,
params
[
:user_ids
],
params
[
:project_access
]
)
@admin_project
.
update_repository
redirect_to
[
:admin
,
@admin_project
],
notice:
'Project was successfully updated.'
redirect_to
[
:admin
,
@admin_project
],
notice:
'Project was successfully updated.'
end
end
...
@@ -53,8 +41,6 @@ class Admin::ProjectsController < ApplicationController
...
@@ -53,8 +41,6 @@ class Admin::ProjectsController < ApplicationController
end
end
def
update
def
update
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
owner_id
=
params
[
:project
].
delete
(
:owner_id
)
owner_id
=
params
[
:project
].
delete
(
:owner_id
)
if
owner_id
if
owner_id
...
@@ -69,9 +55,14 @@ class Admin::ProjectsController < ApplicationController
...
@@ -69,9 +55,14 @@ class Admin::ProjectsController < ApplicationController
end
end
def
destroy
def
destroy
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
@admin_project
.
destroy
@admin_project
.
destroy
redirect_to
admin_projects_url
,
notice:
'Project was successfully deleted.'
redirect_to
admin_projects_url
,
notice:
'Project was successfully deleted.'
end
end
private
def
admin_project
@admin_project
=
Project
.
find_by_code
(
params
[
:id
])
end
end
end
app/controllers/hooks_controller.rb
View file @
5926bbac
...
@@ -28,10 +28,7 @@ class HooksController < ApplicationController
...
@@ -28,10 +28,7 @@ class HooksController < ApplicationController
end
end
def
test
def
test
@hook
=
@project
.
hooks
.
find
(
params
[
:id
])
TestHookContext
.
new
(
project
,
current_user
,
params
).
execute
commits
=
@project
.
commits
(
@project
.
default_branch
,
nil
,
3
)
data
=
@project
.
post_receive_data
(
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
@project
.
default_branch
}
"
,
current_user
)
@hook
.
execute
(
data
)
redirect_to
:back
redirect_to
:back
end
end
...
...
app/controllers/notes_controller.rb
View file @
5926bbac
...
@@ -15,11 +15,7 @@ class NotesController < ApplicationController
...
@@ -15,11 +15,7 @@ class NotesController < ApplicationController
end
end
def
create
def
create
@note
=
@project
.
notes
.
new
(
params
[
:note
])
@note
=
Notes
::
CreateContext
.
new
(
project
,
current_user
,
params
).
execute
@note
.
author
=
current_user
@note
.
notify
=
true
if
params
[
:notify
]
==
'1'
@note
.
notify_author
=
true
if
params
[
:notify_author
]
==
'1'
@note
.
save
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
format
.
html
{
redirect_to
:back
}
...
@@ -40,6 +36,6 @@ class NotesController < ApplicationController
...
@@ -40,6 +36,6 @@ class NotesController < ApplicationController
protected
protected
def
notes
def
notes
@notes
=
Notes
Load
.
new
(
project
,
current_user
,
params
).
execute
@notes
=
Notes
::
LoadContext
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
end
app/controllers/profile_controller.rb
View file @
5926bbac
class
ProfileController
<
ApplicationController
class
ProfileController
<
ApplicationController
layout
"profile"
layout
"profile"
before_filter
:user
def
show
def
show
@user
=
current_user
end
end
def
design
def
design
@user
=
current_user
end
end
def
update
def
update
@user
=
current_user
@user
.
update_attributes
(
params
[
:user
])
@user
.
update_attributes
(
params
[
:user
])
redirect_to
:back
redirect_to
:back
end
end
def
token
def
token
@user
=
current_user
end
end
def
password
def
password
@user
=
current_user
end
end
def
password_update
def
password_update
params
[
:user
].
reject!
{
|
k
,
v
|
k
!=
"password"
&&
k
!=
"password_confirmation"
}
params
[
:user
].
reject!
{
|
k
,
v
|
k
!=
"password"
&&
k
!=
"password_confirmation"
}
@user
=
current_user
if
@user
.
update_attributes
(
params
[
:user
])
if
@user
.
update_attributes
(
params
[
:user
])
flash
[
:notice
]
=
"Password was successfully updated. Please login with it"
flash
[
:notice
]
=
"Password was successfully updated. Please login with it"
...
@@ -38,4 +34,10 @@ class ProfileController < ApplicationController
...
@@ -38,4 +34,10 @@ class ProfileController < ApplicationController
current_user
.
reset_authentication_token!
current_user
.
reset_authentication_token!
redirect_to
profile_token_path
redirect_to
profile_token_path
end
end
private
def
user
@user
=
current_user
end
end
end
app/controllers/search_controller.rb
View file @
5926bbac
class
SearchController
<
ApplicationController
class
SearchController
<
ApplicationController
def
show
def
show
query
=
params
[
:search
]
query
=
params
[
:search
]
if
query
.
blank?
@projects
=
[]
@projects
=
[]
@merge_requests
=
[]
@merge_requests
=
[]
@issues
=
[]
@issues
=
[]
else
if
query
.
present?
@projects
=
current_user
.
projects
.
search
(
query
).
limit
(
10
)
@projects
=
current_user
.
projects
.
search
(
query
).
limit
(
10
)
@merge_requests
=
MergeRequest
.
where
(
:project_id
=>
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
@merge_requests
=
MergeRequest
.
where
(
:project_id
=>
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
@issues
=
Issue
.
where
(
:project_id
=>
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
@issues
=
Issue
.
where
(
:project_id
=>
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
...
...
app/roles/team.rb
View file @
5926bbac
...
@@ -4,7 +4,36 @@ module Team
...
@@ -4,7 +4,36 @@ module Team
users_projects
.
find_by_user_id
(
user
.
id
)
if
user
users_projects
.
find_by_user_id
(
user
.
id
)
if
user
end
end
# Get Team Member record by user id
def
team_member_by_id
(
user_id
)
def
team_member_by_id
(
user_id
)
users_projects
.
find_by_user_id
(
user_id
)
users_projects
.
find_by_user_id
(
user_id
)
end
end
# Add user to project
# with passed access role
def
add_user_to_team
(
user
,
access_role
)
add_user_id_to_team
(
user
.
id
,
access_role
)
end
# Add multiple users to project
# with same access role
def
add_users_to_team
(
users
,
access_role
)
add_users_ids_to_team
(
users
.
map
(
&
:id
),
access_role
)
end
# Add user to project
# with passed access role by user id
def
add_user_id_to_team
(
user_id
,
access_role
)
users_projects
.
create
(
:user_id
=>
user_id
,
:project_access
=>
access_role
)
end
# Add multiple users to project
# with same access role by user ids
def
add_users_ids_to_team
(
users_ids
,
access_role
)
UsersProject
.
bulk_import
(
self
,
users_ids
,
access_role
)
self
.
update_repository
end
end
end
spec/models/project_spec.rb
View file @
5926bbac
...
@@ -22,21 +22,56 @@ describe Project do
...
@@ -22,21 +22,56 @@ describe Project do
end
end
describe
"Respond to"
do
describe
"Respond to"
do
it
{
should
respond_to
(
:repository_writers
)
}
it
{
should
respond_to
(
:add_access
)
}
it
{
should
respond_to
(
:reset_access
)
}
it
{
should
respond_to
(
:update_repository
)
}
it
{
should
respond_to
(
:destroy_repository
)
}
it
{
should
respond_to
(
:public?
)
}
it
{
should
respond_to
(
:public?
)
}
it
{
should
respond_to
(
:private?
)
}
it
{
should
respond_to
(
:private?
)
}
it
{
should
respond_to
(
:url_to_repo
)
}
it
{
should
respond_to
(
:url_to_repo
)
}
it
{
should
respond_to
(
:path_to_repo
)
}
it
{
should
respond_to
(
:path_to_repo
)
}
it
{
should
respond_to
(
:valid_repo?
)
}
it
{
should
respond_to
(
:valid_repo?
)
}
it
{
should
respond_to
(
:repo_exists?
)
}
it
{
should
respond_to
(
:repo_exists?
)
}
# Repository Role
it
{
should
respond_to
(
:tree
)
}
it
{
should
respond_to
(
:root_ref
)
}
it
{
should
respond_to
(
:repo
)
}
it
{
should
respond_to
(
:repo
)
}
it
{
should
respond_to
(
:tags
)
}
it
{
should
respond_to
(
:tags
)
}
it
{
should
respond_to
(
:commit
)
}
it
{
should
respond_to
(
:commit
)
}
it
{
should
respond_to
(
:commits
)
}
it
{
should
respond_to
(
:commits_between
)
}
it
{
should
respond_to
(
:commits_with_refs
)
}
it
{
should
respond_to
(
:commits_since
)
}
it
{
should
respond_to
(
:commits_between
)
}
it
{
should
respond_to
(
:commits_between
)
}
it
{
should
respond_to
(
:write_hooks
)
}
it
{
should
respond_to
(
:satellite
)
}
it
{
should
respond_to
(
:update_repository
)
}
it
{
should
respond_to
(
:destroy_repository
)
}
it
{
should
respond_to
(
:archive_repo
)
}
# Authority Role
it
{
should
respond_to
(
:add_access
)
}
it
{
should
respond_to
(
:reset_access
)
}
it
{
should
respond_to
(
:repository_writers
)
}
it
{
should
respond_to
(
:repository_masters
)
}
it
{
should
respond_to
(
:repository_readers
)
}
it
{
should
respond_to
(
:allow_read_for?
)
}
it
{
should
respond_to
(
:guest_access_for?
)
}
it
{
should
respond_to
(
:report_access_for?
)
}
it
{
should
respond_to
(
:dev_access_for?
)
}
it
{
should
respond_to
(
:master_access_for?
)
}
# Team Role
it
{
should
respond_to
(
:team_member_by_name_or_email
)
}
it
{
should
respond_to
(
:team_member_by_id
)
}
it
{
should
respond_to
(
:add_user_to_team
)
}
it
{
should
respond_to
(
:add_users_to_team
)
}
it
{
should
respond_to
(
:add_user_id_to_team
)
}
it
{
should
respond_to
(
:add_users_ids_to_team
)
}
# Project Push Role
it
{
should
respond_to
(
:observe_push
)
}
it
{
should
respond_to
(
:update_merge_requests
)
}
it
{
should
respond_to
(
:execute_hooks
)
}
it
{
should
respond_to
(
:post_receive_data
)
}
it
{
should
respond_to
(
:trigger_post_receive
)
}
end
end
it
"should not allow 'gitolite-admin' as repo name"
do
it
"should not allow 'gitolite-admin' as repo name"
do
...
...
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