This instance will be upgraded to Heptapod 0.26.0rc1 on 2021-10-26 at 14:30 UTC+2 (a few minutes of down time)

project.rb 3.25 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
2
3
require "grit"

class Project < ActiveRecord::Base
gitlabhq's avatar
gitlabhq committed
4
5
  belongs_to :owner, :class_name => "User"

6
7
8
9
10
  does "project/validations"
  does "project/repository"
  does "project/permissions"
  does "project/hooks"

11
12
  has_many :users,          :through => :users_projects
  has_many :events,         :dependent => :destroy
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13
  has_many :merge_requests, :dependent => :destroy
14
  has_many :issues,         :dependent => :destroy, :order => "position"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
  has_many :milestones,     :dependent => :destroy
gitlabhq's avatar
gitlabhq committed
16
  has_many :users_projects, :dependent => :destroy
17
18
19
20
21
  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 :wikis,          :dependent => :destroy
22
  has_many :protected_branches, :dependent => :destroy
Aleksei Kvitinskii's avatar
Aleksei Kvitinskii committed
23

24
  attr_protected :private_flag, :owner_id
gitlabhq's avatar
gitlabhq committed
25
26

  scope :public_only, where(:private_flag => false)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
27
  scope :without_user, lambda { |user|  where("id not in (:ids)", :ids => user.projects.map(&:id) ) }
gitlabhq's avatar
gitlabhq committed
28

29
30
31
  def self.active
    joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
  end
32
33

  def self.access_options
34
    UsersProject.access_roles
35
36
  end

37
38
39
40
  def self.search query
    where("name like :query or code like :query or path like :query", :query => "%#{query}%")
  end

gitlabhq's avatar
gitlabhq committed
41
42
43
44
  def to_param
    code
  end

45
46
47
48
  def web_url
    [GIT_HOST['host'], code].join("/")
  end

49
50
51
52
53
  def team_member_by_name_or_email(email = nil, name = nil)
    user = users.where("email like ? or name like ?", email, name).first
    users_projects.find_by_user_id(user.id) if user
  end

54
55
56
57
  def team_member_by_id(user_id)
    users_projects.find_by_user_id(user_id)
  end

gitlabhq's avatar
gitlabhq committed
58
  def common_notes
gitlabhq's avatar
gitlabhq committed
59
    notes.where(:noteable_type => ["", nil]).inc_author_project
gitlabhq's avatar
gitlabhq committed
60
61
  end

62
63
  def build_commit_note(commit)
    notes.new(:noteable_id => commit.id, :noteable_type => "Commit")
gitlabhq's avatar
gitlabhq committed
64
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
65

66
  def commit_notes(commit)
67
68
69
70
    notes.where(:noteable_id => commit.id, :noteable_type => "Commit", :line_code => nil)
  end

  def commit_line_notes(commit)
Valery Sizov's avatar
Valery Sizov committed
71
    notes.where(:noteable_id => commit.id, :noteable_type => "Commit").where("line_code is not null")
gitlabhq's avatar
gitlabhq committed
72
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
73

gitlabhq's avatar
gitlabhq committed
74
75
76
77
78
79
80
81
  def public?
    !private_flag
  end

  def private?
    private_flag
  end

82
  def last_activity
83
    events.last || nil
gitlabhq's avatar
gitlabhq committed
84
85
86
  end

  def last_activity_date
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
87
88
    if events.last
      events.last.created_at
89
    else
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
90
      updated_at
91
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
92
  end
93

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
94
95
96
  def project_id
    self.id
  end
gitlabhq's avatar
gitlabhq committed
97
end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
98

gitlabhq's avatar
gitlabhq committed
99
100
101
102
# == Schema Information
#
# Table name: projects
#
103
104
105
106
107
108
109
110
111
112
113
114
115
#  id                     :integer         not null, primary key
#  name                   :string(255)
#  path                   :string(255)
#  description            :text
#  created_at             :datetime
#  updated_at             :datetime
#  private_flag           :boolean         default(TRUE), not null
#  code                   :string(255)
#  owner_id               :integer
#  default_branch         :string(255)     default("master"), not null
#  issues_enabled         :boolean         default(TRUE), not null
#  wall_enabled           :boolean         default(TRUE), not null
#  merge_requests_enabled :boolean         default(TRUE), not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116
#  wiki_enabled           :boolean         default(TRUE), not null
gitlabhq's avatar
gitlabhq committed
117
118
#