summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-21 19:32:37 +0100
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-21 19:32:37 +0100
commit6e5461c6ee8b408e35324b32c0b5ba99328ec763 (patch)
treef233cbfad4cd0773e7d0b30f057fed0076fee91d /app/models
parentd28a587e82836d28524339586e1b6c1546a4bff5 (diff)
parent2bcbc7c6db934d56448c4c261861e62982b9b573 (diff)
downloadgitlab-ce-6e5461c6ee8b408e35324b32c0b5ba99328ec763.tar.gz
Merge branch 'master' into 2489-soft-delete-issues
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/issuable.rb9
-rw-r--r--app/models/issue.rb21
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/project_wiki.rb12
-rw-r--r--app/models/repository.rb25
-rw-r--r--app/models/user.rb2
6 files changed, 57 insertions, 13 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 31ab5682ad2..476e1ce7af0 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -211,4 +211,13 @@ module Issuable
Taskable.get_updated_tasks(old_content: previous_changes['description'].first,
new_content: description)
end
+
+ ##
+ # Method that checks if issuable can be moved to another project.
+ #
+ # Should be overridden if issuable can be moved.
+ #
+ def can_move?(*)
+ false
+ end
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 5347d4fa1be..ddb51ad5775 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -16,6 +16,7 @@
# state :string(255)
# iid :integer
# updated_by_id :integer
+# moved_to_id :integer
#
require 'carrierwave/orm/activerecord'
@@ -31,6 +32,8 @@ class Issue < ActiveRecord::Base
ActsAsTaggableOn.strict_case_match = true
belongs_to :project
+ belongs_to :moved_to, class_name: 'Issue'
+
validates :project, presence: true
scope :of_group,
@@ -105,9 +108,9 @@ class Issue < ActiveRecord::Base
end
def related_branches
- return [] if self.project.empty_repo?
-
- self.project.repository.branch_names.select { |branch| branch.end_with?("-#{iid}") }
+ project.repository.branch_names.select do |branch|
+ branch.end_with?("-#{iid}")
+ end
end
# Reset issue events cache
@@ -137,6 +140,18 @@ class Issue < ActiveRecord::Base
end.uniq.select { |mr| mr.open? && mr.closes_issue?(self) }
end
+ def moved?
+ !moved_to.nil?
+ end
+
+ def can_move?(user, to_project = nil)
+ if to_project
+ return false unless user.can?(:admin_issue, to_project)
+ end
+
+ !moved? && user.can?(:admin_issue, self.project)
+ end
+
def to_branch_name
"#{title.parameterize}-#{iid}"
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 412c6c6732d..fd36dca0cad 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -876,6 +876,7 @@ class Project < ActiveRecord::Base
# Forked import is handled asynchronously
unless forked?
if gitlab_shell.add_repository(path_with_namespace)
+ repository.after_create
true
else
errors.add(:base, 'Failed to create repository via gitlab-shell')
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 59b1b86d1fb..7c1a61bb0bf 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -123,23 +123,27 @@ class ProjectWiki
end
def repository
- Repository.new(path_with_namespace, @project)
+ @repository ||= Repository.new(path_with_namespace, @project)
end
def default_branch
wiki.class.default_ref
end
- private
-
def create_repo!
if init_repo(path_with_namespace)
- Gollum::Wiki.new(path_to_repo)
+ wiki = Gollum::Wiki.new(path_to_repo)
else
raise CouldNotCreateWikiError
end
+
+ repository.after_create
+
+ wiki
end
+ private
+
def init_repo(path_with_namespace)
gitlab_shell.add_repository(path_with_namespace)
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 25d24493f6e..13154eb4205 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -42,12 +42,15 @@ class Repository
end
def exists?
- return false unless raw_repository
+ return @exists unless @exists.nil?
- raw_repository.rugged
- true
- rescue Gitlab::Git::Repository::NoRepository
- false
+ @exists = cache.fetch(:exists?) do
+ begin
+ raw_repository && raw_repository.rugged ? true : false
+ rescue Gitlab::Git::Repository::NoRepository
+ false
+ end
+ end
end
def empty?
@@ -320,12 +323,23 @@ class Repository
@avatar = nil
end
+ def expire_exists_cache
+ cache.expire(:exists?)
+ @exists = nil
+ end
+
+ # Runs code after a repository has been created.
+ def after_create
+ expire_exists_cache
+ end
+
# Runs code just before a repository is deleted.
def before_delete
expire_cache if exists?
expire_root_ref_cache
expire_emptiness_caches
+ expire_exists_cache
end
# Runs code just before the HEAD of a repository is changed.
@@ -351,6 +365,7 @@ class Repository
# Runs code after a repository has been forked/imported.
def after_import
expire_emptiness_caches
+ expire_exists_cache
end
# Runs code after a new commit has been pushed.
diff --git a/app/models/user.rb b/app/models/user.rb
index c011af03591..9c315cfe966 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -435,7 +435,7 @@ class User < ActiveRecord::Base
Group.where("namespaces.id IN (#{union.to_sql})")
end
- # Returns the groups a user is authorized to access.
+ # Returns projects user is authorized to access.
def authorized_projects
Project.where("projects.id IN (#{projects_union.to_sql})")
end