Commit 841e4fbd08d2d642c127506001a76a973ea3d536

Authored by Nihad Abbasov
1 parent 2a4359a5

cosmetical cleanup of models

app/models/ability.rb
@@ -52,7 +52,6 @@ class Ability @@ -52,7 +52,6 @@ class Ability
52 :admin_wiki 52 :admin_wiki
53 ] if project.master_access_for?(user) || project.owner == user 53 ] if project.master_access_for?(user) || project.owner == user
54 54
55 -  
56 rules.flatten 55 rules.flatten
57 end 56 end
58 57
app/models/commit.rb
@@ -4,24 +4,11 @@ class Commit @@ -4,24 +4,11 @@ class Commit
4 include StaticModel 4 include StaticModel
5 extend ActiveModel::Naming 5 extend ActiveModel::Naming
6 6
7 - attr_accessor :commit  
8 - attr_accessor :head  
9 - attr_accessor :refs  
10 -  
11 - delegate :message,  
12 - :authored_date,  
13 - :committed_date,  
14 - :parents,  
15 - :sha,  
16 - :date,  
17 - :committer,  
18 - :author,  
19 - :message,  
20 - :diffs,  
21 - :tree,  
22 - :id,  
23 - :to_patch,  
24 - to: :commit 7 + attr_accessor :commit, :head, :refs
  8 +
  9 + delegate :message, :authored_date, :committed_date, :parents, :sha,
  10 + :date, :committer, :author, :message, :diffs, :tree, :id,
  11 + :to_patch, to: :commit
25 12
26 class << self 13 class << self
27 def find_or_first(repo, commit_id = nil, root_ref) 14 def find_or_first(repo, commit_id = nil, root_ref)
@@ -30,6 +17,7 @@ class Commit @@ -30,6 +17,7 @@ class Commit
30 else 17 else
31 repo.commits(root_ref).first 18 repo.commits(root_ref).first
32 end 19 end
  20 +
33 Commit.new(commit) if commit 21 Commit.new(commit) if commit
34 end 22 end
35 23
app/models/event.rb
@@ -16,6 +16,10 @@ class Event &lt; ActiveRecord::Base @@ -16,6 +16,10 @@ class Event &lt; ActiveRecord::Base
16 Joined = 8 # User joined project 16 Joined = 8 # User joined project
17 Left = 9 # User left project 17 Left = 9 # User left project
18 18
  19 + delegate :name, :email, to: :author, prefix: true, allow_nil: true
  20 + delegate :title, to: :issue, prefix: true, allow_nil: true
  21 + delegate :title, to: :merge_request, prefix: true, allow_nil: true
  22 +
19 belongs_to :project 23 belongs_to :project
20 belongs_to :target, polymorphic: true 24 belongs_to :target, polymorphic: true
21 25
@@ -134,12 +138,8 @@ class Event &lt; ActiveRecord::Base @@ -134,12 +138,8 @@ class Event &lt; ActiveRecord::Base
134 "opened" 138 "opened"
135 end 139 end
136 end 140 end
137 -  
138 -  
139 - delegate :name, :email, to: :author, prefix: true, allow_nil: true  
140 - delegate :title, to: :issue, prefix: true, allow_nil: true  
141 - delegate :title, to: :merge_request, prefix: true, allow_nil: true  
142 end 141 end
  142 +
143 # == Schema Information 143 # == Schema Information
144 # 144 #
145 # Table name: events 145 # Table name: events
@@ -155,4 +155,3 @@ end @@ -155,4 +155,3 @@ end
155 # action :integer 155 # action :integer
156 # author_id :integer 156 # author_id :integer
157 # 157 #
158 -  
app/models/issue.rb
@@ -9,8 +9,7 @@ class Issue &lt; ActiveRecord::Base @@ -9,8 +9,7 @@ class Issue &lt; ActiveRecord::Base
9 9
10 belongs_to :milestone 10 belongs_to :milestone
11 11
12 - validates :description,  
13 - length: { within: 0..2000 } 12 + validates :description, length: { within: 0..2000 }
14 13
15 def self.open_for(user) 14 def self.open_for(user)
16 opened.assigned(user) 15 opened.assigned(user)
@@ -32,6 +31,7 @@ class Issue &lt; ActiveRecord::Base @@ -32,6 +31,7 @@ class Issue &lt; ActiveRecord::Base
32 closed_changed? && !closed 31 closed_changed? && !closed
33 end 32 end
34 end 33 end
  34 +
35 # == Schema Information 35 # == Schema Information
36 # 36 #
37 # Table name: issues 37 # Table name: issues
@@ -49,4 +49,3 @@ end @@ -49,4 +49,3 @@ end
49 # description :text 49 # description :text
50 # milestone_id :integer 50 # milestone_id :integer
51 # 51 #
52 -  
app/models/key.rb
@@ -6,14 +6,10 @@ class Key &lt; ActiveRecord::Base @@ -6,14 +6,10 @@ class Key &lt; ActiveRecord::Base
6 6
7 attr_accessible :key, :title 7 attr_accessible :key, :title
8 8
9 - validates :title,  
10 - presence: true,  
11 - length: { within: 0..255 }  
12 -  
13 - validates :key,  
14 - presence: true,  
15 - format: { :with => /ssh-.{3} / },  
16 - length: { within: 0..5000 } 9 + validates :title, presence: true, length: { within: 0..255 }
  10 + validates :key, presence: true,
  11 + length: { within: 0..5000 },
  12 + format: { :with => /ssh-.{3} / }
17 13
18 before_save :set_identifier 14 before_save :set_identifier
19 before_validation :strip_white_space 15 before_validation :strip_white_space
@@ -34,7 +30,7 @@ class Key &lt; ActiveRecord::Base @@ -34,7 +30,7 @@ class Key &lt; ActiveRecord::Base
34 30
35 def set_identifier 31 def set_identifier
36 if is_deploy_key 32 if is_deploy_key
37 - self.identifier = "deploy_" + Digest::MD5.hexdigest(key) 33 + self.identifier = "deploy_#{Digest::MD5.hexdigest(key)}"
38 else 34 else
39 self.identifier = "#{user.identifier}_#{Time.now.to_i}" 35 self.identifier = "#{user.identifier}_#{Time.now.to_i}"
40 end 36 end
@@ -57,6 +53,7 @@ class Key &lt; ActiveRecord::Base @@ -57,6 +53,7 @@ class Key &lt; ActiveRecord::Base
57 Key.where(identifier: identifier).count == 0 53 Key.where(identifier: identifier).count == 0
58 end 54 end
59 end 55 end
  56 +
60 # == Schema Information 57 # == Schema Information
61 # 58 #
62 # Table name: keys 59 # Table name: keys
@@ -70,4 +67,3 @@ end @@ -70,4 +67,3 @@ end
70 # identifier :string(255) 67 # identifier :string(255)
71 # project_id :integer 68 # project_id :integer
72 # 69 #
73 -  
app/models/merge_request.rb
@@ -18,8 +18,7 @@ class MergeRequest &lt; ActiveRecord::Base @@ -18,8 +18,7 @@ class MergeRequest &lt; ActiveRecord::Base
18 18
19 attr_accessor :should_remove_source_branch 19 attr_accessor :should_remove_source_branch
20 20
21 - validates_presence_of :source_branch  
22 - validates_presence_of :target_branch 21 + validates_presence_of :source_branch, :target_branch
23 validate :validate_branches 22 validate :validate_branches
24 23
25 def self.find_all_by_branch(branch_name) 24 def self.find_all_by_branch(branch_name)
@@ -187,6 +186,7 @@ class MergeRequest &lt; ActiveRecord::Base @@ -187,6 +186,7 @@ class MergeRequest &lt; ActiveRecord::Base
187 patch_path 186 patch_path
188 end 187 end
189 end 188 end
  189 +
190 # == Schema Information 190 # == Schema Information
191 # 191 #
192 # Table name: merge_requests 192 # Table name: merge_requests
@@ -206,4 +206,3 @@ end @@ -206,4 +206,3 @@ end
206 # merged :boolean default(FALSE), not null 206 # merged :boolean default(FALSE), not null
207 # state :integer default(1), not null 207 # state :integer default(1), not null
208 # 208 #
209 -  
app/models/milestone.rb
1 -# == Schema Information  
2 -#  
3 -# Table name: milestones  
4 -#  
5 -# id :integer not null, primary key  
6 -# title :string(255) not null  
7 -# project_id :integer not null  
8 -# description :text  
9 -# due_date :date  
10 -# closed :boolean default(FALSE), not null  
11 -# created_at :datetime not null  
12 -# updated_at :datetime not null  
13 -#  
14 -  
15 class Milestone < ActiveRecord::Base 1 class Milestone < ActiveRecord::Base
16 attr_accessible :title, :description, :due_date, :closed 2 attr_accessible :title, :description, :due_date, :closed
17 3
18 belongs_to :project 4 belongs_to :project
19 has_many :issues 5 has_many :issues
20 6
21 - validates_presence_of :project_id  
22 - validates_presence_of :title 7 + validates_presence_of :title, :project_id
23 8
24 def self.active 9 def self.active
25 where("due_date > ? OR due_date IS NULL", Date.today) 10 where("due_date > ? OR due_date IS NULL", Date.today)
@@ -39,3 +24,17 @@ class Milestone &lt; ActiveRecord::Base @@ -39,3 +24,17 @@ class Milestone &lt; ActiveRecord::Base
39 "expires at #{due_date.stamp("Aug 21, 2011")}" if due_date 24 "expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
40 end 25 end
41 end 26 end
  27 +
  28 +# == Schema Information
  29 +#
  30 +# Table name: milestones
  31 +#
  32 +# id :integer not null, primary key
  33 +# title :string(255) not null
  34 +# project_id :integer not null
  35 +# description :text
  36 +# due_date :date
  37 +# closed :boolean default(FALSE), not null
  38 +# created_at :datetime not null
  39 +# updated_at :datetime not null
  40 +#
app/models/note.rb
@@ -2,39 +2,26 @@ require &#39;carrierwave/orm/activerecord&#39; @@ -2,39 +2,26 @@ require &#39;carrierwave/orm/activerecord&#39;
2 require 'file_size_validator' 2 require 'file_size_validator'
3 3
4 class Note < ActiveRecord::Base 4 class Note < ActiveRecord::Base
  5 + mount_uploader :attachment, AttachmentUploader
5 attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id, 6 attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id,
6 :attachment, :line_code 7 :attachment, :line_code
7 8
8 belongs_to :project 9 belongs_to :project
9 belongs_to :noteable, polymorphic: true 10 belongs_to :noteable, polymorphic: true
10 - belongs_to :author,  
11 - class_name: "User" 11 + belongs_to :author, class_name: "User"
12 12
13 - delegate :name,  
14 - to: :project,  
15 - prefix: true  
16 -  
17 - delegate :name,  
18 - :email,  
19 - to: :author,  
20 - prefix: true 13 + delegate :name, to: :project, prefix: true
  14 + delegate :name, :email, to: :author, prefix: true
21 15
22 attr_accessor :notify 16 attr_accessor :notify
23 attr_accessor :notify_author 17 attr_accessor :notify_author
24 18
25 validates_presence_of :project 19 validates_presence_of :project
26 20
27 - validates :note,  
28 - presence: true,  
29 - length: { within: 0..5000 }  
30 -  
31 - validates :attachment,  
32 - file_size: {  
33 - maximum: 10.megabytes.to_i  
34 - } 21 + validates :note, presence: true, length: { within: 0..5000 }
  22 + validates :attachment, file_size: { maximum: 10.megabytes.to_i }
35 23
36 scope :common, where(noteable_id: nil) 24 scope :common, where(noteable_id: nil)
37 -  
38 scope :today, where("created_at >= :date", date: Date.today) 25 scope :today, where("created_at >= :date", date: Date.today)
39 scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) 26 scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
40 scope :since, lambda { |day| where("created_at >= :date", date: (day)) } 27 scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
@@ -42,14 +29,13 @@ class Note &lt; ActiveRecord::Base @@ -42,14 +29,13 @@ class Note &lt; ActiveRecord::Base
42 scope :inc_author_project, includes(:project, :author) 29 scope :inc_author_project, includes(:project, :author)
43 scope :inc_author, includes(:author) 30 scope :inc_author, includes(:author)
44 31
45 - mount_uploader :attachment, AttachmentUploader  
46 -  
47 def self.create_status_change_note(noteable, author, status) 32 def self.create_status_change_note(noteable, author, status)
48 - create({ noteable: noteable,  
49 - project: noteable.project,  
50 - author: author,  
51 - note: "_Status changed to #{status}_" },  
52 - without_protection: true) 33 + create({
  34 + noteable: noteable,
  35 + project: noteable.project,
  36 + author: author,
  37 + note: "_Status changed to #{status}_"
  38 + }, without_protection: true)
53 end 39 end
54 40
55 def notify 41 def notify
@@ -114,6 +100,7 @@ class Note &lt; ActiveRecord::Base @@ -114,6 +100,7 @@ class Note &lt; ActiveRecord::Base
114 note.start_with?('-1') || note.start_with?(':-1:') 100 note.start_with?('-1') || note.start_with?(':-1:')
115 end 101 end
116 end 102 end
  103 +
117 # == Schema Information 104 # == Schema Information
118 # 105 #
119 # Table name: notes 106 # Table name: notes
@@ -129,4 +116,3 @@ end @@ -129,4 +116,3 @@ end
129 # attachment :string(255) 116 # attachment :string(255)
130 # line_code :string(255) 117 # line_code :string(255)
131 # 118 #
132 -  
app/models/project.rb
@@ -8,10 +8,9 @@ class Project &lt; ActiveRecord::Base @@ -8,10 +8,9 @@ class Project &lt; ActiveRecord::Base
8 8
9 attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled, 9 attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
10 :wall_enabled, :merge_requests_enabled, :wiki_enabled 10 :wall_enabled, :merge_requests_enabled, :wiki_enabled
  11 + attr_accessor :error_code
11 12
12 - #  
13 # Relations 13 # Relations
14 - #  
15 belongs_to :owner, class_name: "User" 14 belongs_to :owner, class_name: "User"
16 has_many :users, through: :users_projects 15 has_many :users, through: :users_projects
17 has_many :events, dependent: :destroy 16 has_many :events, dependent: :destroy
@@ -26,11 +25,7 @@ class Project &lt; ActiveRecord::Base @@ -26,11 +25,7 @@ class Project &lt; ActiveRecord::Base
26 has_many :wikis, dependent: :destroy 25 has_many :wikis, dependent: :destroy
27 has_many :protected_branches, dependent: :destroy 26 has_many :protected_branches, dependent: :destroy
28 27
29 - attr_accessor :error_code  
30 -  
31 - #  
32 # Scopes 28 # Scopes
33 - #  
34 scope :public_only, where(private_flag: false) 29 scope :public_only, where(private_flag: false)
35 scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) } 30 scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
36 31
@@ -47,7 +42,6 @@ class Project &lt; ActiveRecord::Base @@ -47,7 +42,6 @@ class Project &lt; ActiveRecord::Base
47 42
48 Project.transaction do 43 Project.transaction do
49 project.owner = user 44 project.owner = user
50 -  
51 project.save! 45 project.save!
52 46
53 # Add user as project master 47 # Add user as project master
@@ -76,36 +70,19 @@ class Project &lt; ActiveRecord::Base @@ -76,36 +70,19 @@ class Project &lt; ActiveRecord::Base
76 id && valid? 70 id && valid?
77 end 71 end
78 72
79 - #  
80 # Validations 73 # Validations
81 - #  
82 - validates :name,  
83 - uniqueness: true,  
84 - presence: true,  
85 - length: { within: 0..255 }  
86 -  
87 - validates :path,  
88 - uniqueness: true,  
89 - presence: true, 74 + validates :owner, presence: true
  75 + validates :description, length: { within: 0..2000 }
  76 + validates :name, uniqueness: true, presence: true, length: { within: 0..255 }
  77 + validates :path, uniqueness: true, presence: true, length: { within: 0..255 },
90 format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/, 78 format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
91 - message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },  
92 - length: { within: 0..255 }  
93 -  
94 - validates :description,  
95 - length: { within: 0..2000 }  
96 -  
97 - validates :code,  
98 - presence: true,  
99 - uniqueness: true, 79 + message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
  80 + validates :code, presence: true, uniqueness: true, length: { within: 1..255 },
100 format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/, 81 format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
101 - message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },  
102 - length: { within: 1..255 }  
103 -  
104 - validates :owner, presence: true 82 + message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
105 validates :issues_enabled, :wall_enabled, :merge_requests_enabled, 83 validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
106 :wiki_enabled, inclusion: { in: [true, false] } 84 :wiki_enabled, inclusion: { in: [true, false] }
107 - validate :check_limit  
108 - validate :repo_name 85 + validate :check_limit, :repo_name
109 86
110 def check_limit 87 def check_limit
111 unless owner.can_create_project? 88 unless owner.can_create_project?
@@ -197,4 +174,3 @@ end @@ -197,4 +174,3 @@ end
197 # merge_requests_enabled :boolean default(TRUE), not null 174 # merge_requests_enabled :boolean default(TRUE), not null
198 # wiki_enabled :boolean default(TRUE), not null 175 # wiki_enabled :boolean default(TRUE), not null
199 # 176 #
200 -  
app/models/project_hook.rb
  1 +class ProjectHook < WebHook
  2 + belongs_to :project
  3 +end
  4 +
1 # == Schema Information 5 # == Schema Information
2 # 6 #
3 # Table name: web_hooks 7 # Table name: web_hooks
@@ -9,7 +13,3 @@ @@ -9,7 +13,3 @@
9 # updated_at :datetime not null 13 # updated_at :datetime not null
10 # type :string(255) default("ProjectHook") 14 # type :string(255) default("ProjectHook")
11 # 15 #
12 -  
13 -class ProjectHook < WebHook  
14 - belongs_to :project  
15 -end  
app/models/protected_branch.rb
@@ -4,8 +4,7 @@ class ProtectedBranch &lt; ActiveRecord::Base @@ -4,8 +4,7 @@ class ProtectedBranch &lt; ActiveRecord::Base
4 attr_accessible :name 4 attr_accessible :name
5 5
6 belongs_to :project 6 belongs_to :project
7 - validates_presence_of :project_id  
8 - validates_presence_of :name 7 + validates_presence_of :name, :project_id
9 8
10 after_save :update_repository 9 after_save :update_repository
11 after_destroy :update_repository 10 after_destroy :update_repository
@@ -18,6 +17,7 @@ class ProtectedBranch &lt; ActiveRecord::Base @@ -18,6 +17,7 @@ class ProtectedBranch &lt; ActiveRecord::Base
18 project.commit(self.name) 17 project.commit(self.name)
19 end 18 end
20 end 19 end
  20 +
21 # == Schema Information 21 # == Schema Information
22 # 22 #
23 # Table name: protected_branches 23 # Table name: protected_branches
@@ -28,4 +28,3 @@ end @@ -28,4 +28,3 @@ end
28 # created_at :datetime not null 28 # created_at :datetime not null
29 # updated_at :datetime not null 29 # updated_at :datetime not null
30 # 30 #
31 -  
app/models/snippet.rb
@@ -7,25 +7,12 @@ class Snippet &lt; ActiveRecord::Base @@ -7,25 +7,12 @@ class Snippet &lt; ActiveRecord::Base
7 belongs_to :author, class_name: "User" 7 belongs_to :author, class_name: "User"
8 has_many :notes, as: :noteable, dependent: :destroy 8 has_many :notes, as: :noteable, dependent: :destroy
9 9
10 - delegate :name,  
11 - :email,  
12 - to: :author,  
13 - prefix: true 10 + delegate :name, :email, to: :author, prefix: true
14 11
15 - validates_presence_of :project_id  
16 - validates_presence_of :author_id  
17 -  
18 - validates :title,  
19 - presence: true,  
20 - length: { within: 0..255 }  
21 -  
22 - validates :file_name,  
23 - presence: true,  
24 - length: { within: 0..255 }  
25 -  
26 - validates :content,  
27 - presence: true,  
28 - length: { within: 0..10000 } 12 + validates_presence_of :author_id, :project_id
  13 + validates :title, presence: true, length: { within: 0..255 }
  14 + validates :file_name, presence: true, length: { within: 0..255 }
  15 + validates :content, presence: true, length: { within: 0..10000 }
29 16
30 scope :fresh, order("created_at DESC") 17 scope :fresh, order("created_at DESC")
31 scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) 18 scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])
@@ -59,6 +46,7 @@ class Snippet &lt; ActiveRecord::Base @@ -59,6 +46,7 @@ class Snippet &lt; ActiveRecord::Base
59 expires_at && expires_at < Time.current 46 expires_at && expires_at < Time.current
60 end 47 end
61 end 48 end
  49 +
62 # == Schema Information 50 # == Schema Information
63 # 51 #
64 # Table name: snippets 52 # Table name: snippets
@@ -73,4 +61,3 @@ end @@ -73,4 +61,3 @@ end
73 # file_name :string(255) 61 # file_name :string(255)
74 # expires_at :datetime 62 # expires_at :datetime
75 # 63 #
76 -  
app/models/system_hook.rb
1 -# == Schema Information  
2 -#  
3 -# Table name: web_hooks  
4 -#  
5 -# id :integer not null, primary key  
6 -# url :string(255)  
7 -# project_id :integer  
8 -# created_at :datetime not null  
9 -# updated_at :datetime not null  
10 -# type :string(255) default("ProjectHook")  
11 -#  
12 -  
13 class SystemHook < WebHook 1 class SystemHook < WebHook
14 -  
15 def async_execute(data) 2 def async_execute(data)
16 Resque.enqueue(SystemHookWorker, id, data) 3 Resque.enqueue(SystemHookWorker, id, data)
17 end 4 end
@@ -21,5 +8,16 @@ class SystemHook &lt; WebHook @@ -21,5 +8,16 @@ class SystemHook &lt; WebHook
21 sh.async_execute data 8 sh.async_execute data
22 end 9 end
23 end 10 end
24 -  
25 end 11 end
  12 +
  13 +# == Schema Information
  14 +#
  15 +# Table name: web_hooks
  16 +#
  17 +# id :integer not null, primary key
  18 +# url :string(255)
  19 +# project_id :integer
  20 +# created_at :datetime not null
  21 +# updated_at :datetime not null
  22 +# type :string(255) default("ProjectHook")
  23 +#
app/models/tree.rb
@@ -2,16 +2,8 @@ class Tree @@ -2,16 +2,8 @@ class Tree
2 include Linguist::BlobHelper 2 include Linguist::BlobHelper
3 attr_accessor :path, :tree, :project, :ref 3 attr_accessor :path, :tree, :project, :ref
4 4
5 - delegate :contents,  
6 - :basename,  
7 - :name,  
8 - :data,  
9 - :mime_type,  
10 - :mode,  
11 - :size,  
12 - :text?,  
13 - :colorize,  
14 - to: :tree 5 + delegate :contents, :basename, :name, :data, :mime_type,
  6 + :mode, :size, :text?, :colorize, to: :tree
15 7
16 def initialize(raw_tree, project, ref = nil, path = nil) 8 def initialize(raw_tree, project, ref = nil, path = nil)
17 @project, @ref, @path = project, ref, path 9 @project, @ref, @path = project, ref, path
app/models/user.rb
1 class User < ActiveRecord::Base 1 class User < ActiveRecord::Base
2 -  
3 include Account 2 include Account
4 3
5 devise :database_authenticatable, :token_authenticatable, :lockable, 4 devise :database_authenticatable, :token_authenticatable, :lockable,
6 :recoverable, :rememberable, :trackable, :validatable, :omniauthable 5 :recoverable, :rememberable, :trackable, :validatable, :omniauthable
7 6
8 - attr_accessible :email, :password, :password_confirmation, :remember_me, :bio,  
9 - :name, :skype, :linkedin, :twitter, :dark_scheme,  
10 - :theme_id, :force_random_password, :extern_uid, :provider, :as => [:default, :admin] 7 + attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name,
  8 + :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
  9 + :extern_uid, :provider, :as => [:default, :admin]
11 attr_accessible :projects_limit, :as => :admin 10 attr_accessible :projects_limit, :as => :admin
12 11
13 attr_accessor :force_random_password 12 attr_accessor :force_random_password
14 13
15 - has_many :users_projects, dependent: :destroy 14 + has_many :keys, dependent: :destroy
16 has_many :projects, through: :users_projects 15 has_many :projects, through: :users_projects
  16 + has_many :users_projects, dependent: :destroy
  17 + has_many :issues, foreign_key: :author_id, dependent: :destroy
  18 + has_many :notes, foreign_key: :author_id, dependent: :destroy
  19 + has_many :merge_requests, foreign_key: :author_id, dependent: :destroy
17 has_many :my_own_projects, class_name: "Project", foreign_key: :owner_id 20 has_many :my_own_projects, class_name: "Project", foreign_key: :owner_id
18 - has_many :keys, dependent: :destroy  
19 -  
20 - has_many :events,  
21 - class_name: "Event",  
22 - foreign_key: :author_id,  
23 - dependent: :destroy  
24 -  
25 - has_many :recent_events,  
26 - class_name: "Event",  
27 - foreign_key: :author_id,  
28 - order: "id DESC"  
29 -  
30 - has_many :issues,  
31 - foreign_key: :author_id,  
32 - dependent: :destroy  
33 -  
34 - has_many :notes,  
35 - foreign_key: :author_id,  
36 - dependent: :destroy  
37 -  
38 - has_many :assigned_issues,  
39 - class_name: "Issue",  
40 - foreign_key: :assignee_id,  
41 - dependent: :destroy  
42 -  
43 - has_many :merge_requests,  
44 - foreign_key: :author_id,  
45 - dependent: :destroy  
46 -  
47 - has_many :assigned_merge_requests,  
48 - class_name: "MergeRequest",  
49 - foreign_key: :assignee_id,  
50 - dependent: :destroy  
51 -  
52 - validates :projects_limit,  
53 - presence: true,  
54 - numericality: {greater_than_or_equal_to: 0} 21 + has_many :events, class_name: "Event", foreign_key: :author_id, dependent: :destroy
  22 + has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC"
  23 + has_many :assigned_issues, class_name: "Issue", foreign_key: :assignee_id, dependent: :destroy
  24 + has_many :assigned_merge_requests, class_name: "MergeRequest", foreign_key: :assignee_id, dependent: :destroy
55 25
56 validates :bio, length: { within: 0..255 } 26 validates :bio, length: { within: 0..255 }
57 -  
58 validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider} 27 validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider}
59 -  
60 - before_save :ensure_authentication_token  
61 - alias_attribute :private_token, :authentication_token 28 + validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
62 29
63 scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) } 30 scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) }
64 scope :admins, where(admin: true) 31 scope :admins, where(admin: true)
@@ -66,6 +33,8 @@ class User &lt; ActiveRecord::Base @@ -66,6 +33,8 @@ class User &lt; ActiveRecord::Base
66 scope :active, where(blocked: false) 33 scope :active, where(blocked: false)
67 34
68 before_validation :generate_password, on: :create 35 before_validation :generate_password, on: :create
  36 + before_save :ensure_authentication_token
  37 + alias_attribute :private_token, :authentication_token
69 38
70 def generate_password 39 def generate_password
71 if self.force_random_password 40 if self.force_random_password
@@ -107,6 +76,7 @@ class User &lt; ActiveRecord::Base @@ -107,6 +76,7 @@ class User &lt; ActiveRecord::Base
107 where("name like :query or email like :query", query: "%#{query}%") 76 where("name like :query or email like :query", query: "%#{query}%")
108 end 77 end
109 end 78 end
  79 +
110 # == Schema Information 80 # == Schema Information
111 # 81 #
112 # Table name: users 82 # Table name: users
@@ -140,4 +110,3 @@ end @@ -140,4 +110,3 @@ end
140 # extern_uid :string(255) 110 # extern_uid :string(255)
141 # provider :string(255) 111 # provider :string(255)
142 # 112 #
143 -  
app/models/users_project.rb
@@ -88,6 +88,7 @@ class UsersProject &lt; ActiveRecord::Base @@ -88,6 +88,7 @@ class UsersProject &lt; ActiveRecord::Base
88 self.class.access_roles.invert[self.project_access] 88 self.class.access_roles.invert[self.project_access]
89 end 89 end
90 end 90 end
  91 +
91 # == Schema Information 92 # == Schema Information
92 # 93 #
93 # Table name: users_projects 94 # Table name: users_projects
@@ -99,4 +100,3 @@ end @@ -99,4 +100,3 @@ end
99 # updated_at :datetime not null 100 # updated_at :datetime not null
100 # project_access :integer default(0), not null 101 # project_access :integer default(0), not null
101 # 102 #
102 -  
app/models/web_hook.rb
@@ -6,26 +6,23 @@ class WebHook &lt; ActiveRecord::Base @@ -6,26 +6,23 @@ class WebHook &lt; ActiveRecord::Base
6 # HTTParty timeout 6 # HTTParty timeout
7 default_timeout 10 7 default_timeout 10
8 8
9 - validates :url,  
10 - presence: true,  
11 - format: {  
12 - with: URI::regexp(%w(http https)),  
13 - message: "should be a valid url" } 9 + validates :url, presence: true,
  10 + format: { with: URI::regexp(%w(http https)), message: "should be a valid url" }
14 11
15 def execute(data) 12 def execute(data)
16 parsed_url = URI.parse(url) 13 parsed_url = URI.parse(url)
17 if parsed_url.userinfo.blank? 14 if parsed_url.userinfo.blank?
18 WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }) 15 WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
19 else 16 else
20 - post_url = url.gsub(parsed_url.userinfo+"@", "") 17 + post_url = url.gsub("#{parsed_url.userinfo}@", "")
21 WebHook.post(post_url, 18 WebHook.post(post_url,
22 body: data.to_json, 19 body: data.to_json,
23 - headers: { "Content-Type" => "application/json" }, 20 + headers: {"Content-Type" => "application/json"},
24 basic_auth: {username: parsed_url.user, password: parsed_url.password}) 21 basic_auth: {username: parsed_url.user, password: parsed_url.password})
25 end 22 end
26 end 23 end
27 -  
28 end 24 end
  25 +
29 # == Schema Information 26 # == Schema Information
30 # 27 #
31 # Table name: web_hooks 28 # Table name: web_hooks
@@ -37,4 +34,3 @@ end @@ -37,4 +34,3 @@ end
37 # updated_at :datetime not null 34 # updated_at :datetime not null
38 # type :string(255) default("ProjectHook") 35 # type :string(255) default("ProjectHook")
39 # 36 #
40 -  
app/models/wiki.rb
@@ -32,6 +32,7 @@ class Wiki &lt; ActiveRecord::Base @@ -32,6 +32,7 @@ class Wiki &lt; ActiveRecord::Base
32 end 32 end
33 end 33 end
34 end 34 end
  35 +
35 # == Schema Information 36 # == Schema Information
36 # 37 #
37 # Table name: wikis 38 # Table name: wikis
@@ -45,4 +46,3 @@ end @@ -45,4 +46,3 @@ end
45 # slug :string(255) 46 # slug :string(255)
46 # user_id :integer 47 # user_id :integer
47 # 48 #
48 -