# Class Project < ActiveRecord::Base

- app/models/project.rb

Namespace

- CLASS Project::TransferError

Methods

A
  - access_options,
  - active,
  - authorized_for
B
  - build_commit_note
C
  - check_limit,
  - code,
  - commit_line_notes,
  - commit_notes,
  - common_notes,
  - create_by_user
F
  - find_with_namespace
G
  - git_error?,
  - gitlab_ci?
I
  - issues_labels,
  - items_for
L
  - last_activity,
  - last_activity_date
P
  - private?,
  - project_id,
  - public?
R
  - repo_name
S
  - saved?,
  - search,
  - send_move_instructions,
  - services
T
  - to_param
W
  - web_url

Included Modules

- Repository
- PushObserver
- Authority
- Team
- NamespacedProject

Attributes

[RW] | error_code |

Class Public methods
access_options() Link

Source: show

    # File app/models/project.rb, line 163
    def access_options
      UsersProject.access_roles
    end

active() Link

Source: show

    # File app/models/project.rb, line 96
    def active
      joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
    end

authorized_for(user) Link

Source: show

    # File app/models/project.rb, line 91
    def authorized_for user
      projects = includes(:users_projects, :namespace)
      projects = projects.where("users_projects.user_id = :user_id or projects.owner_id = :user_id or namespaces.owner_id = :user_id", user_id: user.id)
    end

create_by_user(params, user) Link

Source: show

    # File app/models/project.rb, line 114
    def create_by_user(params, user)
      namespace_id = params.delete(:namespace_id)

      project = Project.new params

      Project.transaction do

        # Parametrize path for project
        #
        # Ex.
        #  'GitLab HQ'.parameterize => "gitlab-hq"
        #
        project.path = project.name.dup.parameterize

        project.owner = user

        # Apply namespace if user has access to it
        # else fallback to user namespace
        if namespace_id != Namespace.global_id
          project.namespace_id = user.namespace_id

          if namespace_id
            group = Group.find_by_id(namespace_id)
            if user.can? :manage_group, group
              project.namespace_id = namespace_id
            end
          end
        end

        project.save!

        # Add user as project master
        project.users_projects.create!(project_access: UsersProject::MASTER, user: user)

        # when project saved no team member exist so
        # project repository should be updated after first user add
        project.update_repository
      end

      project
    rescue Gitlab::Gitolite::AccessDenied => ex
      project.error_code = :gitolite
      project
    rescue => ex
      project.error_code = :db
      project.errors.add(:base, "Can't save project. Please try again later")
      project
    end

find_with_namespace(id) Link

Source: show

    # File app/models/project.rb, line 104
    def find_with_namespace(id)
      if id.include?("/")
        id = id.split("/")
        namespace_id = Namespace.find_by_path(id.first).id
        where(namespace_id: namespace_id).find_by_path(id.second)
      else
        where(path: id, namespace_id: nil).last
      end
    end

search(query) Link

Source: show

    # File app/models/project.rb, line 100
    def search query
      where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
    end

Instance Public methods
build_commit_note(commit) Link

Source: show

    # File app/models/project.rb, line 208
    def build_commit_note(commit)
      notes.new(commit_id: commit.id, noteable_type: "Commit")
    end

check_limit() Link

Source: show

    # File app/models/project.rb, line 176
    def check_limit
      unless owner.can_create_project?
        errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
      end
    rescue
      errors[:base] << ("Can't check your ability to create project")
    end

code() Link

For compatibility with old code

Source: show

    # File app/models/project.rb, line 253
    def code
      path
    end

commit_line_notes(commit) Link

Source: show

    # File app/models/project.rb, line 216
    def commit_line_notes(commit)
      notes.where(commit_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL")
    end

commit_notes(commit) Link

Source: show

    # File app/models/project.rb, line 212
    def commit_notes(commit)
      notes.where(commit_id: commit.id, noteable_type: "Commit", line_code: nil)
    end

common_notes() Link

Source: show

    # File app/models/project.rb, line 204
    def common_notes
      notes.where(noteable_type: ["", nil]).inc_author_project
    end

git_error?() Link

Source: show

    # File app/models/project.rb, line 168
    def git_error?
      error_code == :gitolite
    end

gitlab_ci?() Link

Source: show

    # File app/models/project.rb, line 248
    def gitlab_ci?
      gitlab_ci_service && gitlab_ci_service.active
    end

issues_labels() Link

Source: show

    # File app/models/project.rb, line 240
    def issues_labels
      issues.tag_counts_on(:labels)
    end

items_for(entity) Link

Source: show

    # File app/models/project.rb, line 257
    def items_for entity
      case entity
      when 'issue' then
        issues
      when 'merge_request' then
        merge_requests
      end
    end

last_activity() Link

Source: show

    # File app/models/project.rb, line 228
    def last_activity
      last_event
    end

last_activity_date() Link

Source: show

    # File app/models/project.rb, line 232
    def last_activity_date
      last_event.try(:created_at) || updated_at
    end

private?() Link

Source: show

    # File app/models/project.rb, line 224
    def private?
      private_flag
    end

project_id() Link

Source: show

    # File app/models/project.rb, line 236
    def project_id
      self.id
    end

public?() Link

Source: show

    # File app/models/project.rb, line 220
    def public?
      !private_flag
    end

repo_name() Link

Source: show

    # File app/models/project.rb, line 184
    def repo_name
      denied_paths = %w(gitolite-admin admin dashboard groups help profile projects search)

      if denied_paths.include?(path)
        errors.add(:path, "like #{path} is not allowed")
      end
    end

saved?() Link

Source: show

    # File app/models/project.rb, line 172
    def saved?
      id && valid?
    end

send_move_instructions() Link

Source: show

    # File app/models/project.rb, line 266
    def send_move_instructions
      self.users_projects.each do |member|
        Notify.project_was_moved_email(member.id).deliver
      end
    end

services() Link

Source: show

    # File app/models/project.rb, line 244
    def services
      [gitlab_ci_service].compact
    end

to_param() Link

Source: show

    # File app/models/project.rb, line 192
    def to_param
      if namespace
        namespace.path + "/" + path
      else
        path
      end
    end

web_url() Link

Source: show

    # File app/models/project.rb, line 200
    def web_url
      [Gitlab.config.gitlab.url, path_with_namespace].join("/")
    end