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
Kazuhiko Shiozaki
gitlab-ce
Commits
0727edd8
Commit
0727edd8
authored
Mar 04, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed issues,mr delete buttons. Refactored models
parent
3fe9d297
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
82 additions
and
186 deletions
+82
-186
app/controllers/merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+1
-1
app/models/key.rb
app/models/key.rb
+0
-2
app/models/key_observer.rb
app/models/key_observer.rb
+9
-0
app/models/project.rb
app/models/project.rb
+10
-68
app/models/project_observer.rb
app/models/project_observer.rb
+9
-0
app/views/issues/_form.html.haml
app/views/issues/_form.html.haml
+4
-8
app/views/issues/_show.html.haml
app/views/issues/_show.html.haml
+0
-2
app/views/merge_requests/_form.html.haml
app/views/merge_requests/_form.html.haml
+3
-8
app/views/projects/index.html.haml
app/views/projects/index.html.haml
+18
-22
config/application.rb
config/application.rb
+1
-1
db/schema.rb
db/schema.rb
+18
-30
spec/models/project_spec.rb
spec/models/project_spec.rb
+9
-29
spec/requests/issues_spec.rb
spec/requests/issues_spec.rb
+0
-15
No files found.
app/controllers/merge_requests_controller.rb
View file @
0727edd8
...
...
@@ -30,7 +30,7 @@ class MergeRequestsController < ApplicationController
else
@merge_requests
.
opened
end
@merge_requests
=
@merge_requests
.
includes
(
:author
,
:project
)
@merge_requests
=
@merge_requests
.
includes
(
:author
,
:project
)
.
order
(
"created_at desc"
)
end
def
show
...
...
app/models/key.rb
View file @
0727edd8
...
...
@@ -14,8 +14,6 @@ class Key < ActiveRecord::Base
before_save
:set_identifier
before_validation
:strip_white_space
after_save
:update_repository
after_destroy
:repository_delete_key
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
validate
:unique_key
...
...
app/models/key_observer.rb
0 → 100644
View file @
0727edd8
class
KeyObserver
<
ActiveRecord
::
Observer
def
after_save
(
key
)
key
.
update_repository
end
def
after_destroy
(
key
)
key
.
repository_delete_key
end
end
app/models/project.rb
View file @
0727edd8
...
...
@@ -3,19 +3,17 @@ require "grit"
class
Project
<
ActiveRecord
::
Base
belongs_to
:owner
,
:class_name
=>
"User"
has_many
:events
,
:dependent
=>
:destroy
has_many
:users
,
:through
=>
:users_projects
has_many
:events
,
:dependent
=>
:destroy
has_many
:merge_requests
,
:dependent
=>
:destroy
has_many
:issues
,
:dependent
=>
:destroy
,
:order
=>
"position"
has_many
:issues
,
:dependent
=>
:destroy
,
:order
=>
"position"
has_many
:users_projects
,
:dependent
=>
:destroy
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
:w
eb_hooks
,
:dependent
=>
:destroy
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
has_many
:w
ikis
,
:dependent
=>
:destroy
has_many
:protected_branches
,
:dependent
=>
:destroy
has_many
:wikis
,
:dependent
=>
:destroy
acts_as_taggable
validates
:name
,
:uniqueness
=>
true
,
...
...
@@ -39,15 +37,10 @@ class Project < ActiveRecord::Base
:message
=>
"only letters, digits & '_' '-' '.' allowed"
},
:length
=>
{
:within
=>
3
..
255
}
validates
:owner
,
:presence
=>
true
validates
:owner
,
:presence
=>
true
validate
:check_limit
validate
:repo_name
after_destroy
:destroy_repository
after_save
:update_repository
attr_protected
:private_flag
,
:owner_id
scope
:public_only
,
where
(
:private_flag
=>
false
)
...
...
@@ -163,18 +156,6 @@ class Project < ActiveRecord::Base
users_projects
.
find_by_user_id
(
user_id
)
end
def
fresh_merge_requests
(
n
)
merge_requests
.
includes
(
:project
,
:author
).
order
(
"created_at desc"
).
first
(
n
)
end
def
fresh_issues
(
n
)
issues
.
includes
(
:project
,
:author
).
order
(
"created_at desc"
).
first
(
n
)
end
def
fresh_notes
(
n
)
notes
.
inc_author_project
.
order
(
"created_at desc"
).
first
(
n
)
end
def
common_notes
notes
.
where
(
:noteable_type
=>
[
""
,
nil
]).
inc_author_project
end
...
...
@@ -277,9 +258,7 @@ class Project < ActiveRecord::Base
end
def
last_activity
events
.
last
rescue
nil
events
.
last
||
nil
end
def
last_activity_date
...
...
@@ -294,43 +273,6 @@ class Project < ActiveRecord::Base
last_activity_date
end
# Get project updates from cache
# or calculate.
def
cached_updates
(
limit
,
expire
=
2
.
minutes
)
activities_key
=
"project_
#{
id
}
_activities"
cached_activities
=
Rails
.
cache
.
read
(
activities_key
)
if
cached_activities
activities
=
cached_activities
else
activities
=
updates
(
limit
)
Rails
.
cache
.
write
(
activities_key
,
activities
,
:expires_in
=>
expire
)
end
activities
end
# Get 20 events for project like
# commits, issues or notes
def
updates
(
n
=
3
)
[
fresh_commits
(
n
),
fresh_issues
(
n
),
fresh_notes
(
n
)
].
compact
.
flatten
.
sort
do
|
x
,
y
|
y
.
created_at
<=>
x
.
created_at
end
[
0
...
n
]
end
def
activities
(
n
=
3
)
[
fresh_issues
(
n
),
fresh_merge_requests
(
n
),
notes
.
inc_author_project
.
where
(
"noteable_type is not null"
).
order
(
"created_at desc"
).
first
(
n
)
].
compact
.
flatten
.
sort
do
|
x
,
y
|
y
.
created_at
<=>
x
.
created_at
end
[
0
...
n
]
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"
)
...
...
app/models/project_observer.rb
0 → 100644
View file @
0727edd8
class
ProjectObserver
<
ActiveRecord
::
Observer
def
after_save
(
project
)
project
.
update_repository
end
def
after_destroy
(
project
)
project
.
destroy_repository
end
end
app/views/issues/_form.html.haml
View file @
0727edd8
...
...
@@ -8,6 +8,10 @@
-
@issue
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.clearfix
=
f
.
label
:title
.input
=
f
.
text_area
:title
,
:maxlength
=>
255
,
:class
=>
"xxlarge"
.clearfix
=
f
.
label
:assignee_id
.input
=
f
.
select
(
:assignee_id
,
@project
.
users
.
all
.
collect
{
|
p
|
[
p
.
name
,
p
.
id
]
},
{
:include_blank
=>
"Select user"
})
...
...
@@ -21,9 +25,6 @@
=
f
.
label
:closed
.input
=
f
.
check_box
:closed
.clearfix
=
f
.
label
:title
.input
=
f
.
text_area
:title
,
:maxlength
=>
255
,
:class
=>
"xxlarge"
.actions
=
f
.
submit
'Save'
,
:class
=>
"primary btn"
...
...
@@ -34,8 +35,3 @@
=
link_to
"Cancel"
,
project_issues_path
(
@project
),
:class
=>
"btn"
-
else
=
link_to
"Cancel"
,
project_issue_path
(
@project
,
@issue
),
:class
=>
"btn"
-
unless
@issue
.
new_record?
.right
=
link_to
'Remove'
,
[
@project
,
@issue
],
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
,
:class
=>
"danger btn"
app/views/issues/_show.html.haml
View file @
0727edd8
...
...
@@ -6,8 +6,6 @@
-
else
=
link_to
'Resolve'
,
project_issue_path
(
issue
.
project
,
issue
,
:issue
=>
{
:closed
=>
true
},
:status_only
=>
true
),
:method
=>
:put
,
:class
=>
"success btn small"
,
:remote
=>
true
=
link_to
'Edit'
,
edit_project_issue_path
(
issue
.
project
,
issue
),
:class
=>
"btn small edit-issue-link"
,
:remote
=>
true
-#- if can?(current_user, :admin_issue, @project) || issue.author == current_user
= link_to 'Remove', [issue.project, issue], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "danger btn small delete-issue", :id => "destroy_issue_#{issue.id}"
=
image_tag
gravatar_icon
(
issue
.
assignee_email
),
:class
=>
"avatar"
%span
.update-author
assigned to
...
...
app/views/merge_requests/_form.html.haml
View file @
0727edd8
...
...
@@ -5,6 +5,9 @@
-
@merge_request
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.clearfix
=
f
.
label
:title
.input
=
f
.
text_area
:title
,
:class
=>
"xxlarge"
,
:maxlength
=>
255
,
:rows
=>
5
.clearfix
=
f
.
label
:source_branch
,
"From"
.input
=
f
.
select
(
:source_branch
,
@project
.
heads
.
map
(
&
:name
),
{
:include_blank
=>
"Select branch"
},
:style
=>
"width:250px"
)
...
...
@@ -15,9 +18,6 @@
=
f
.
label
:assignee_id
,
"Assign to"
.input
=
f
.
select
(
:assignee_id
,
@project
.
users
.
all
.
collect
{
|
p
|
[
p
.
name
,
p
.
id
]
},
{
:include_blank
=>
"Select user"
},
:style
=>
"width:250px"
)
.clearfix
=
f
.
label
:title
.input
=
f
.
text_area
:title
,
:class
=>
"xlarge"
,
:maxlength
=>
255
,
:rows
=>
5
.actions
=
f
.
submit
'Save'
,
:class
=>
"primary btn"
-
if
@merge_request
.
new_record?
...
...
@@ -26,11 +26,6 @@
-
else
=
link_to
project_merge_request_path
(
@project
,
@merge_request
),
:class
=>
"btn"
do
Cancel
-
unless
@merge_request
.
new_record?
.right
=
link_to
'Remove'
,
[
@project
,
@merge_request
],
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
,
:class
=>
"btn danger"
...
...
app/views/projects/index.html.haml
View file @
0727edd8
-
unless
@projects
.
empty?
.row
.span4
%div
.leftbar.ui-box
%h5
Projects
-
if
current_user
.
can_create_project?
%span
.right
=
link_to
new_project_path
,
:class
=>
"btn very_small info"
do
New Project
.content_list
-
@projects
.
each
do
|
project
|
=
link_to
project_path
(
project
),
:remote
=>
true
,
:class
=>
dom_class
(
project
)
do
%h4
%span
.ico.project
=
truncate
(
project
.
name
,
:length
=>
22
)
.span12.right
.show_holder.ui-box.padded
.loading
-
else
%h2
Nothing here
.row
.span4
%div
.leftbar.ui-box
%h5
Projects
-
if
current_user
.
can_create_project?
%span
.right
=
link_to
new_project_path
,
:class
=>
"btn very_small info"
do
New Project
.content_list
-
@projects
.
each
do
|
project
|
=
link_to
project_path
(
project
),
:remote
=>
true
,
:class
=>
dom_class
(
project
)
do
%h4
%span
.ico.project
=
truncate
(
project
.
name
,
:length
=>
22
)
.span12.right
.show_holder.ui-box.padded
.loading
:javascript
...
...
config/application.rb
View file @
0727edd8
...
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
...
...
db/schema.rb
View file @
0727edd8
...
...
@@ -24,25 +24,13 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
integer
"action"
end
create_table
"features"
,
:force
=>
true
do
|
t
|
t
.
string
"name"
t
.
string
"branch_name"
t
.
integer
"assignee_id"
t
.
integer
"author_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"version"
t
.
integer
"status"
,
:default
=>
0
,
:null
=>
false
end
create_table
"issues"
,
:force
=>
true
do
|
t
|
t
.
string
"title"
t
.
integer
"assignee_id"
t
.
integer
"author_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"position"
,
:default
=>
0
t
.
boolean
"critical"
,
:default
=>
false
,
:null
=>
false
...
...
@@ -53,8 +41,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
create_table
"keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
text
"key"
t
.
string
"title"
t
.
string
"identifier"
...
...
@@ -69,8 +57,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
integer
"assignee_id"
t
.
string
"title"
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
end
add_index
"merge_requests"
,
[
"project_id"
],
:name
=>
"index_merge_requests_on_project_id"
...
...
@@ -80,8 +68,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
string
"noteable_id"
t
.
string
"noteable_type"
t
.
integer
"author_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
integer
"project_id"
t
.
string
"attachment"
t
.
string
"line_code"
...
...
@@ -94,8 +82,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
string
"name"
t
.
string
"path"
t
.
text
"description"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
boolean
"private_flag"
,
:default
=>
true
,
:null
=>
false
t
.
string
"code"
t
.
integer
"owner_id"
...
...
@@ -118,8 +106,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
text
"content"
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
string
"file_name"
t
.
datetime
"expires_at"
end
...
...
@@ -152,8 +140,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t
.
datetime
"last_sign_in_at"
t
.
string
"current_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
string
"name"
t
.
boolean
"admin"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"projects_limit"
,
:default
=>
10
...
...
@@ -171,16 +159,16 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
integer
"project_access"
,
:default
=>
0
,
:null
=>
false
end
create_table
"web_hooks"
,
:force
=>
true
do
|
t
|
t
.
string
"url"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
end
create_table
"wikis"
,
:force
=>
true
do
|
t
|
...
...
spec/models/project_spec.rb
View file @
0727edd8
...
...
@@ -2,13 +2,17 @@ require 'spec_helper'
describe
Project
do
describe
"Associations"
do
it
{
should
have_many
(
:events
)
}
it
{
should
have_many
(
:users
)
}
it
{
should
have_many
(
:users_projects
)
}
it
{
should
have_many
(
:issues
)
}
it
{
should
have_many
(
:notes
)
}
it
{
should
have_many
(
:snippets
)
}
it
{
should
have_many
(
:protected_branches
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:wikis
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:web_hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
end
describe
"Validation"
do
...
...
@@ -70,30 +74,6 @@ describe Project do
end
end
describe
"updates"
do
let
(
:project
)
{
Factory
:project
}
before
do
@issue
=
Factory
:issue
,
:project
=>
project
,
:author
=>
Factory
(
:user
),
:assignee
=>
Factory
(
:user
)
@note
=
Factory
:note
,
:project
=>
project
,
:author
=>
Factory
(
:user
)
@commit
=
project
.
fresh_commits
(
1
).
first
end
describe
"return commit, note & issue"
do
it
{
project
.
updates
(
3
).
count
.
should
==
3
}
it
{
project
.
updates
(
3
).
last
.
id
.
should
==
@commit
.
id
}
it
{
project
.
updates
(
3
).
include?
(
@issue
).
should
be_true
}
it
{
project
.
updates
(
3
).
include?
(
@note
).
should
be_true
}
end
end
describe
"last_activity"
do
let
(
:project
)
{
Factory
:project
}
...
...
spec/requests/issues_spec.rb
View file @
0727edd8
...
...
@@ -46,21 +46,6 @@ describe "Issues" do
page
.
body
.
should
have_selector
(
"entry summary"
,
:text
=>
@issue
.
title
)
end
describe
"Destroy"
do
before
do
# admin access to remove issue
@user
.
users_projects
.
destroy_all
project
.
add_access
(
@user
,
:read
,
:write
,
:admin
)
visit
edit_project_issue_path
(
project
,
@issue
)
end
it
"should remove entry"
do
expect
{
click_link
"Remove"
}.
to
change
{
Issue
.
count
}.
by
(
-
1
)
end
end
describe
"statuses"
do
before
do
@closed_issue
=
Factory
:issue
,
...
...
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