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
841e4fbd
Commit
841e4fbd
authored
Sep 26, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cosmetical cleanup of models
parent
2a4359a5
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
107 additions
and
225 deletions
+107
-225
app/models/ability.rb
app/models/ability.rb
+0
-1
app/models/commit.rb
app/models/commit.rb
+6
-18
app/models/event.rb
app/models/event.rb
+5
-6
app/models/issue.rb
app/models/issue.rb
+2
-3
app/models/key.rb
app/models/key.rb
+6
-10
app/models/merge_request.rb
app/models/merge_request.rb
+2
-3
app/models/milestone.rb
app/models/milestone.rb
+15
-16
app/models/note.rb
app/models/note.rb
+13
-27
app/models/project.rb
app/models/project.rb
+9
-33
app/models/project_hook.rb
app/models/project_hook.rb
+4
-4
app/models/protected_branch.rb
app/models/protected_branch.rb
+2
-3
app/models/snippet.rb
app/models/snippet.rb
+6
-19
app/models/system_hook.rb
app/models/system_hook.rb
+12
-14
app/models/tree.rb
app/models/tree.rb
+2
-10
app/models/user.rb
app/models/user.rb
+16
-47
app/models/users_project.rb
app/models/users_project.rb
+1
-1
app/models/web_hook.rb
app/models/web_hook.rb
+5
-9
app/models/wiki.rb
app/models/wiki.rb
+1
-1
No files found.
app/models/ability.rb
View file @
841e4fbd
...
...
@@ -52,7 +52,6 @@ class Ability
:admin_wiki
]
if
project
.
master_access_for?
(
user
)
||
project
.
owner
==
user
rules
.
flatten
end
...
...
app/models/commit.rb
View file @
841e4fbd
...
...
@@ -4,24 +4,11 @@ class Commit
include
StaticModel
extend
ActiveModel
::
Naming
attr_accessor
:commit
attr_accessor
:head
attr_accessor
:refs
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
:date
,
:committer
,
:author
,
:message
,
:diffs
,
:tree
,
:id
,
:to_patch
,
to: :commit
attr_accessor
:commit
,
:head
,
:refs
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
:date
,
:committer
,
:author
,
:message
,
:diffs
,
:tree
,
:id
,
:to_patch
,
to: :commit
class
<<
self
def
find_or_first
(
repo
,
commit_id
=
nil
,
root_ref
)
...
...
@@ -30,6 +17,7 @@ class Commit
else
repo
.
commits
(
root_ref
).
first
end
Commit
.
new
(
commit
)
if
commit
end
...
...
app/models/event.rb
View file @
841e4fbd
...
...
@@ -16,6 +16,10 @@ class Event < ActiveRecord::Base
Joined
=
8
# User joined project
Left
=
9
# User left project
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :issue
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :merge_request
,
prefix:
true
,
allow_nil:
true
belongs_to
:project
belongs_to
:target
,
polymorphic:
true
...
...
@@ -134,12 +138,8 @@ class Event < ActiveRecord::Base
"opened"
end
end
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :issue
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :merge_request
,
prefix:
true
,
allow_nil:
true
end
# == Schema Information
#
# Table name: events
...
...
@@ -155,4 +155,3 @@ end
# action :integer
# author_id :integer
#
app/models/issue.rb
View file @
841e4fbd
...
...
@@ -9,8 +9,7 @@ class Issue < ActiveRecord::Base
belongs_to
:milestone
validates
:description
,
length:
{
within:
0
..
2000
}
validates
:description
,
length:
{
within:
0
..
2000
}
def
self
.
open_for
(
user
)
opened
.
assigned
(
user
)
...
...
@@ -32,6 +31,7 @@ class Issue < ActiveRecord::Base
closed_changed?
&&
!
closed
end
end
# == Schema Information
#
# Table name: issues
...
...
@@ -49,4 +49,3 @@ end
# description :text
# milestone_id :integer
#
app/models/key.rb
View file @
841e4fbd
...
...
@@ -6,14 +6,10 @@ class Key < ActiveRecord::Base
attr_accessible
:key
,
:title
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:key
,
presence:
true
,
format:
{
:with
=>
/ssh-.{3} /
},
length:
{
within:
0
..
5000
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
:with
=>
/ssh-.{3} /
}
before_save
:set_identifier
before_validation
:strip_white_space
...
...
@@ -34,7 +30,7 @@ class Key < ActiveRecord::Base
def
set_identifier
if
is_deploy_key
self
.
identifier
=
"deploy_
"
+
Digest
::
MD5
.
hexdigest
(
key
)
self
.
identifier
=
"deploy_
#{
Digest
::
MD5
.
hexdigest
(
key
)
}
"
else
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
end
...
...
@@ -57,6 +53,7 @@ class Key < ActiveRecord::Base
Key
.
where
(
identifier:
identifier
).
count
==
0
end
end
# == Schema Information
#
# Table name: keys
...
...
@@ -70,4 +67,3 @@ end
# identifier :string(255)
# project_id :integer
#
app/models/merge_request.rb
View file @
841e4fbd
...
...
@@ -18,8 +18,7 @@ class MergeRequest < ActiveRecord::Base
attr_accessor
:should_remove_source_branch
validates_presence_of
:source_branch
validates_presence_of
:target_branch
validates_presence_of
:source_branch
,
:target_branch
validate
:validate_branches
def
self
.
find_all_by_branch
(
branch_name
)
...
...
@@ -187,6 +186,7 @@ class MergeRequest < ActiveRecord::Base
patch_path
end
end
# == Schema Information
#
# Table name: merge_requests
...
...
@@ -206,4 +206,3 @@ end
# merged :boolean default(FALSE), not null
# state :integer default(1), not null
#
app/models/milestone.rb
View file @
841e4fbd
# == Schema Information
#
# Table name: milestones
#
# id :integer not null, primary key
# title :string(255) not null
# project_id :integer not null
# description :text
# due_date :date
# closed :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class
Milestone
<
ActiveRecord
::
Base
attr_accessible
:title
,
:description
,
:due_date
,
:closed
belongs_to
:project
has_many
:issues
validates_presence_of
:project_id
validates_presence_of
:title
validates_presence_of
:title
,
:project_id
def
self
.
active
where
(
"due_date > ? OR due_date IS NULL"
,
Date
.
today
)
...
...
@@ -39,3 +24,17 @@ class Milestone < ActiveRecord::Base
"expires at
#{
due_date
.
stamp
(
"Aug 21, 2011"
)
}
"
if
due_date
end
end
# == Schema Information
#
# Table name: milestones
#
# id :integer not null, primary key
# title :string(255) not null
# project_id :integer not null
# description :text
# due_date :date
# closed :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
app/models/note.rb
View file @
841e4fbd
...
...
@@ -2,39 +2,26 @@ require 'carrierwave/orm/activerecord'
require
'file_size_validator'
class
Note
<
ActiveRecord
::
Base
mount_uploader
:attachment
,
AttachmentUploader
attr_accessible
:note
,
:noteable
,
:noteable_id
,
:noteable_type
,
:project_id
,
:attachment
,
:line_code
belongs_to
:project
belongs_to
:noteable
,
polymorphic:
true
belongs_to
:author
,
class_name:
"User"
delegate
:name
,
to: :project
,
prefix:
true
belongs_to
:author
,
class_name:
"User"
delegate
:name
,
:email
,
to: :author
,
prefix:
true
delegate
:name
,
to: :project
,
prefix:
true
delegate
:name
,
:email
,
to: :author
,
prefix:
true
attr_accessor
:notify
attr_accessor
:notify_author
validates_presence_of
:project
validates
:note
,
presence:
true
,
length:
{
within:
0
..
5000
}
validates
:attachment
,
file_size:
{
maximum:
10
.
megabytes
.
to_i
}
validates
:note
,
presence:
true
,
length:
{
within:
0
..
5000
}
validates
:attachment
,
file_size:
{
maximum:
10
.
megabytes
.
to_i
}
scope
:common
,
where
(
noteable_id:
nil
)
scope
:today
,
where
(
"created_at >= :date"
,
date:
Date
.
today
)
scope
:last_week
,
where
(
"created_at >= :date"
,
date:
(
Date
.
today
-
7
.
days
))
scope
:since
,
lambda
{
|
day
|
where
(
"created_at >= :date"
,
date:
(
day
))
}
...
...
@@ -42,14 +29,13 @@ class Note < ActiveRecord::Base
scope
:inc_author_project
,
includes
(
:project
,
:author
)
scope
:inc_author
,
includes
(
:author
)
mount_uploader
:attachment
,
AttachmentUploader
def
self
.
create_status_change_note
(
noteable
,
author
,
status
)
create
({
noteable:
noteable
,
create
({
noteable:
noteable
,
project:
noteable
.
project
,
author:
author
,
note:
"_Status changed to
#{
status
}
_"
},
without_protection:
true
)
note:
"_Status changed to
#{
status
}
_"
},
without_protection:
true
)
end
def
notify
...
...
@@ -114,6 +100,7 @@ class Note < ActiveRecord::Base
note
.
start_with?
(
'-1'
)
||
note
.
start_with?
(
':-1:'
)
end
end
# == Schema Information
#
# Table name: notes
...
...
@@ -129,4 +116,3 @@ end
# attachment :string(255)
# line_code :string(255)
#
app/models/project.rb
View file @
841e4fbd
...
...
@@ -8,10 +8,9 @@ class Project < ActiveRecord::Base
attr_accessible
:name
,
:path
,
:description
,
:code
,
:default_branch
,
:issues_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
:wiki_enabled
attr_accessor
:error_code
#
# Relations
#
belongs_to
:owner
,
class_name:
"User"
has_many
:users
,
through: :users_projects
has_many
:events
,
dependent: :destroy
...
...
@@ -26,11 +25,7 @@ class Project < ActiveRecord::Base
has_many
:wikis
,
dependent: :destroy
has_many
:protected_branches
,
dependent: :destroy
attr_accessor
:error_code
#
# Scopes
#
scope
:public_only
,
where
(
private_flag:
false
)
scope
:without_user
,
lambda
{
|
user
|
where
(
"id not in (:ids)"
,
ids:
user
.
projects
.
map
(
&
:id
)
)
}
...
...
@@ -47,7 +42,6 @@ class Project < ActiveRecord::Base
Project
.
transaction
do
project
.
owner
=
user
project
.
save!
# Add user as project master
...
...
@@ -76,36 +70,19 @@ class Project < ActiveRecord::Base
id
&&
valid?
end
#
# Validations
#
validates
:name
,
uniqueness:
true
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:path
,
uniqueness:
true
,
presence:
true
,
validates
:owner
,
presence:
true
validates
:description
,
length:
{
within:
0
..
2000
}
validates
:name
,
uniqueness:
true
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:path
,
uniqueness:
true
,
presence:
true
,
length:
{
within:
0
..
255
},
format:
{
with:
/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/
,
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
},
length:
{
within:
0
..
255
}
validates
:description
,
length:
{
within:
0
..
2000
}
validates
:code
,
presence:
true
,
uniqueness:
true
,
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
}
validates
:code
,
presence:
true
,
uniqueness:
true
,
length:
{
within:
1
..
255
},
format:
{
with:
/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/
,
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
},
length:
{
within:
1
..
255
}
validates
:owner
,
presence:
true
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
}
validates
:issues_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
:wiki_enabled
,
inclusion:
{
in:
[
true
,
false
]
}
validate
:check_limit
validate
:repo_name
validate
:check_limit
,
:repo_name
def
check_limit
unless
owner
.
can_create_project?
...
...
@@ -197,4 +174,3 @@ end
# merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean default(TRUE), not null
#
app/models/project_hook.rb
View file @
841e4fbd
class
ProjectHook
<
WebHook
belongs_to
:project
end
# == Schema Information
#
# Table name: web_hooks
...
...
@@ -9,7 +13,3 @@
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#
class
ProjectHook
<
WebHook
belongs_to
:project
end
app/models/protected_branch.rb
View file @
841e4fbd
...
...
@@ -4,8 +4,7 @@ class ProtectedBranch < ActiveRecord::Base
attr_accessible
:name
belongs_to
:project
validates_presence_of
:project_id
validates_presence_of
:name
validates_presence_of
:name
,
:project_id
after_save
:update_repository
after_destroy
:update_repository
...
...
@@ -18,6 +17,7 @@ class ProtectedBranch < ActiveRecord::Base
project
.
commit
(
self
.
name
)
end
end
# == Schema Information
#
# Table name: protected_branches
...
...
@@ -28,4 +28,3 @@ end
# created_at :datetime not null
# updated_at :datetime not null
#
app/models/snippet.rb
View file @
841e4fbd
...
...
@@ -7,25 +7,12 @@ class Snippet < ActiveRecord::Base
belongs_to
:author
,
class_name:
"User"
has_many
:notes
,
as: :noteable
,
dependent: :destroy
delegate
:name
,
:email
,
to: :author
,
prefix:
true
delegate
:name
,
:email
,
to: :author
,
prefix:
true
validates_presence_of
:project_id
validates_presence_of
:author_id
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:file_name
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:content
,
presence:
true
,
length:
{
within:
0
..
10000
}
validates_presence_of
:author_id
,
:project_id
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:file_name
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:content
,
presence:
true
,
length:
{
within:
0
..
10000
}
scope
:fresh
,
order
(
"created_at DESC"
)
scope
:non_expired
,
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
...
...
@@ -59,6 +46,7 @@ class Snippet < ActiveRecord::Base
expires_at
&&
expires_at
<
Time
.
current
end
end
# == Schema Information
#
# Table name: snippets
...
...
@@ -73,4 +61,3 @@ end
# file_name :string(255)
# expires_at :datetime
#
app/models/system_hook.rb
View file @
841e4fbd
# == Schema Information
#
# Table name: web_hooks
#
# id :integer not null, primary key
# url :string(255)
# project_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#
class
SystemHook
<
WebHook
def
async_execute
(
data
)
Resque
.
enqueue
(
SystemHookWorker
,
id
,
data
)
end
...
...
@@ -21,5 +8,16 @@ class SystemHook < WebHook
sh
.
async_execute
data
end
end
end
# == Schema Information
#
# Table name: web_hooks
#
# id :integer not null, primary key
# url :string(255)
# project_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#
app/models/tree.rb
View file @
841e4fbd
...
...
@@ -2,16 +2,8 @@ class Tree
include
Linguist
::
BlobHelper
attr_accessor
:path
,
:tree
,
:project
,
:ref
delegate
:contents
,
:basename
,
:name
,
:data
,
:mime_type
,
:mode
,
:size
,
:text?
,
:colorize
,
to: :tree
delegate
:contents
,
:basename
,
:name
,
:data
,
:mime_type
,
:mode
,
:size
,
:text?
,
:colorize
,
to: :tree
def
initialize
(
raw_tree
,
project
,
ref
=
nil
,
path
=
nil
)
@project
,
@ref
,
@path
=
project
,
ref
,
path
...
...
app/models/user.rb
View file @
841e4fbd
class
User
<
ActiveRecord
::
Base
include
Account
devise
:database_authenticatable
,
:token_authenticatable
,
:lockable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:omniauthable
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
:
name
,
:skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:
theme_id
,
:force_random_password
,
:
extern_uid
,
:provider
,
:as
=>
[
:default
,
:admin
]
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
:name
,
:
skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:theme_id
,
:force_random_password
,
:extern_uid
,
:provider
,
:as
=>
[
:default
,
:admin
]
attr_accessible
:projects_limit
,
:as
=>
:admin
attr_accessor
:force_random_password
has_many
:
users_project
s
,
dependent: :destroy
has_many
:
key
s
,
dependent: :destroy
has_many
:projects
,
through: :users_projects
has_many
:users_projects
,
dependent: :destroy
has_many
:issues
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:notes
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:merge_requests
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:my_own_projects
,
class_name:
"Project"
,
foreign_key: :owner_id
has_many
:keys
,
dependent: :destroy
has_many
:events
,
class_name:
"Event"
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:recent_events
,
class_name:
"Event"
,
foreign_key: :author_id
,
order:
"id DESC"
has_many
:issues
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:notes
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:assigned_issues
,
class_name:
"Issue"
,
foreign_key: :assignee_id
,
dependent: :destroy
has_many
:merge_requests
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:assigned_merge_requests
,
class_name:
"MergeRequest"
,
foreign_key: :assignee_id
,
dependent: :destroy
validates
:projects_limit
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
has_many
:events
,
class_name:
"Event"
,
foreign_key: :author_id
,
dependent: :destroy
has_many
:recent_events
,
class_name:
"Event"
,
foreign_key: :author_id
,
order:
"id DESC"
has_many
:assigned_issues
,
class_name:
"Issue"
,
foreign_key: :assignee_id
,
dependent: :destroy
has_many
:assigned_merge_requests
,
class_name:
"MergeRequest"
,
foreign_key: :assignee_id
,
dependent: :destroy
validates
:bio
,
length:
{
within:
0
..
255
}
validates
:extern_uid
,
:allow_blank
=>
true
,
:uniqueness
=>
{
:scope
=>
:provider
}
before_save
:ensure_authentication_token
alias_attribute
:private_token
,
:authentication_token
validates
:projects_limit
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
scope
:not_in_project
,
lambda
{
|
project
|
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
}
scope
:admins
,
where
(
admin:
true
)
...
...
@@ -66,6 +33,8 @@ class User < ActiveRecord::Base
scope
:active
,
where
(
blocked:
false
)
before_validation
:generate_password
,
on: :create
before_save
:ensure_authentication_token
alias_attribute
:private_token
,
:authentication_token
def
generate_password
if
self
.
force_random_password
...
...
@@ -107,6 +76,7 @@ class User < ActiveRecord::Base
where
(
"name like :query or email like :query"
,
query:
"%
#{
query
}
%"
)
end
end
# == Schema Information
#
# Table name: users
...
...
@@ -140,4 +110,3 @@ end
# extern_uid :string(255)
# provider :string(255)
#
app/models/users_project.rb
View file @
841e4fbd
...
...
@@ -88,6 +88,7 @@ class UsersProject < ActiveRecord::Base
self
.
class
.
access_roles
.
invert
[
self
.
project_access
]
end
end
# == Schema Information
#
# Table name: users_projects
...
...
@@ -99,4 +100,3 @@ end
# updated_at :datetime not null
# project_access :integer default(0), not null
#
app/models/web_hook.rb
View file @
841e4fbd
...
...
@@ -6,26 +6,23 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout
default_timeout
10
validates
:url
,
presence:
true
,
format:
{
with:
URI
::
regexp
(
%w(http https)
),
message:
"should be a valid url"
}
validates
:url
,
presence:
true
,
format:
{
with:
URI
::
regexp
(
%w(http https)
),
message:
"should be a valid url"
}
def
execute
(
data
)
parsed_url
=
URI
.
parse
(
url
)
if
parsed_url
.
userinfo
.
blank?
WebHook
.
post
(
url
,
body:
data
.
to_json
,
headers:
{
"Content-Type"
=>
"application/json"
})
else
post_url
=
url
.
gsub
(
parsed_url
.
userinfo
+
"
@"
,
""
)
post_url
=
url
.
gsub
(
"
#{
parsed_url
.
userinfo
}
@"
,
""
)
WebHook
.
post
(
post_url
,
body:
data
.
to_json
,
headers:
{
"Content-Type"
=>
"application/json"
},
headers:
{
"Content-Type"
=>
"application/json"
},
basic_auth:
{
username:
parsed_url
.
user
,
password:
parsed_url
.
password
})
end
end
end
# == Schema Information
#
# Table name: web_hooks
...
...
@@ -37,4 +34,3 @@ end
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#
app/models/wiki.rb
View file @
841e4fbd
...
...
@@ -32,6 +32,7 @@ class Wiki < ActiveRecord::Base
end
end
end
# == Schema Information
#
# Table name: wikis
...
...
@@ -45,4 +46,3 @@ end
# slug :string(255)
# user_id :integer
#
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