Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-03-06 02:26:40 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-03-06 02:26:40 +0400
commitcb59aade4e568e6146a966362385ac41af4dc604 (patch)
tree5b755ded0186a81c15d8da2b7b4ce865a5b73a0d /app
parent74f8bc7298f112c2d414c6f71be054adce01012a (diff)
Cleaning and refactoring
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/projects_controller.rb3
-rw-r--r--app/controllers/admin/users_controller.rb3
-rw-r--r--app/models/project.rb157
-rw-r--r--app/models/protected_branch.rb4
-rw-r--r--app/models/repository.rb131
-rw-r--r--app/models/users_project.rb4
-rw-r--r--app/views/dashboard/_projects_feed.html.haml2
-rw-r--r--app/views/projects/_feed.html.haml23
-rw-r--r--app/views/projects/_list.html.haml26
9 files changed, 126 insertions, 227 deletions
diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb
index 868bec7c9fe..8f1376540c8 100644
--- a/app/controllers/admin/projects_controller.rb
+++ b/app/controllers/admin/projects_controller.rb
@@ -31,8 +31,7 @@ class Admin::ProjectsController < ApplicationController
UsersProject.bulk_import(
@admin_project,
params[:user_ids],
- params[:project_access],
- params[:repo_access]
+ params[:project_access]
)
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 216431456c0..d7089fad27e 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -23,8 +23,7 @@ class Admin::UsersController < ApplicationController
UsersProject.user_bulk_import(
@admin_user,
params[:project_ids],
- params[:project_access],
- params[:repo_access]
+ params[:project_access]
)
redirect_to [:admin, @admin_user], notice: 'Teams were successfully updated.'
diff --git a/app/models/project.rb b/app/models/project.rb
index 32b244597f3..d9a9284e059 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -54,27 +54,6 @@ class Project < ActiveRecord::Base
UsersProject.access_roles
end
- def repository
- @repository ||= Repository.new(self)
- end
-
- delegate :repo,
- :url_to_repo,
- :path_to_repo,
- :update_repository,
- :destroy_repository,
- :tags,
- :repo_exists?,
- :commit,
- :commits,
- :commits_with_refs,
- :tree,
- :heads,
- :commits_since,
- :fresh_commits,
- :commits_between,
- :to => :repository, :prefix => nil
-
def to_param
code
end
@@ -213,18 +192,6 @@ class Project < ActiveRecord::Base
keys.map(&:identifier)
end
- def readers
- @readers ||= users_projects.includes(:user).map(&:user)
- end
-
- def writers
- @writers ||= users_projects.includes(:user).map(&:user)
- end
-
- def admins
- @admins ||= users_projects.includes(:user).where(:project_access => UsersProject::MASTER).map(&:user)
- end
-
def allow_read_for?(user)
!users_projects.where(:user_id => user.id).empty?
end
@@ -269,10 +236,6 @@ class Project < ActiveRecord::Base
end
end
- def last_activity_date_cached(expire = 1.hour)
- last_activity_date
- end
-
def check_limit
unless owner.can_create_project?
errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
@@ -293,7 +256,127 @@ class Project < ActiveRecord::Base
errors.add(:path, "Invalid repository path")
false
end
+
+ def commit(commit_id = nil)
+ commit = if commit_id
+ repo.commits(commit_id).first
+ else
+ repo.commits.first
+ end
+ Commit.new(commit) if commit
+ end
+
+ def fresh_commits(n = 10)
+ commits = heads.map do |h|
+ repo.commits(h.name, n).map { |c| Commit.new(c, h) }
+ end.flatten.uniq { |c| c.id }
+
+ commits.sort! do |x, y|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits[0...n]
+ end
+
+ def commits_with_refs(n = 20)
+ commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
+
+ commits.sort! do |x, y|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits[0..n]
+ end
+
+ def commits_since(date)
+ commits = heads.map do |h|
+ repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
+ end.flatten.uniq { |c| c.id }
+
+ commits.sort! do |x, y|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits
+ end
+
+ def commits(ref, path = nil, limit = nil, offset = nil)
+ if path
+ repo.log(ref, path, :max_count => limit, :skip => offset)
+ elsif limit && offset
+ repo.commits(ref, limit, offset)
+ else
+ repo.commits(ref)
+ end.map{ |c| Commit.new(c) }
+ end
+
+ def commits_between(from, to)
+ repo.commits_between(from, to).map { |c| Commit.new(c) }
+ end
+
+ def project_id
+ self.id
+ end
+
+ def write_hooks
+ %w(post-receive).each do |hook|
+ write_hook(hook, File.read(File.join(Rails.root, 'lib', "#{hook}-hook")))
+ end
+ end
+
+ def write_hook(name, content)
+ hook_file = File.join(path_to_repo, 'hooks', name)
+
+ File.open(hook_file, 'w') do |f|
+ f.write(content)
+ end
+
+ File.chmod(0775, hook_file)
+ end
+
+ def repo
+ @repo ||= Grit::Repo.new(path_to_repo)
+ end
+
+ def url_to_repo
+ Gitlabhq::GitHost.url_to_repo(path)
+ end
+
+ def path_to_repo
+ File.join(GIT_HOST["base_path"], "#{path}.git")
+ end
+
+ def update_repository
+ Gitlabhq::GitHost.system.update_project(path, self)
+
+ write_hooks if File.exists?(path_to_repo)
+ end
+
+ def destroy_repository
+ Gitlabhq::GitHost.system.destroy_project(self)
+ end
+
+ def repo_exists?
+ @repo_exists ||= (repo && !repo.branches.empty?)
+ rescue
+ @repo_exists = false
+ end
+
+ def tags
+ repo.tags.map(&:name).sort.reverse
+ end
+
+ def heads
+ @heads ||= repo.heads
+ end
+
+ def tree(fcommit, path = nil)
+ fcommit = commit if fcommit == :head
+ tree = fcommit.tree
+ path ? (tree / path) : tree
+ end
end
+
# == Schema Information
#
# Table name: projects
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index 9c2d391d0c1..36e65633f58 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -7,9 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy :update_repository
def update_repository
- Gitlabhq::GitHost.system.new.configure do |c|
- c.update_project(project.path, project)
- end
+ Gitlabhq::GitHost.system.update_project(project.path, project)
end
def commit
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 1e78e588b69..f18b8302715 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -10,135 +10,4 @@ class Repository
def self.access_options
{}
end
-
- def initialize(project)
- @project = project
- end
-
- def path
- @path ||= project.path
- end
-
- def project_id
- project.id
- end
-
- def write_hooks
- %w(post-receive).each do |hook|
- write_hook(hook, File.read(File.join(Rails.root, 'lib', "#{hook}-hook")))
- end
- end
-
- def write_hook(name, content)
- hook_file = File.join(project.path_to_repo, 'hooks', name)
-
- File.open(hook_file, 'w') do |f|
- f.write(content)
- end
-
- File.chmod(0775, hook_file)
- end
-
- def repo
- @repo ||= Grit::Repo.new(project.path_to_repo)
- end
-
- def url_to_repo
- Gitlabhq::GitHost.url_to_repo(path)
- end
-
- def path_to_repo
- File.join(GIT_HOST["base_path"], "#{path}.git")
- end
-
- def update_repository
- Gitlabhq::GitHost.system.new.configure do |c|
- c.update_project(path, project)
- end
-
- write_hooks if File.exists?(project.path_to_repo)
- end
-
- def destroy_repository
- Gitlabhq::GitHost.system.new.configure do |c|
- c.destroy_project(@project)
- end
- end
-
- def repo_exists?
- @repo_exists ||= (repo && !repo.branches.empty?)
- rescue
- @repo_exists = false
- end
-
- def tags
- repo.tags.map(&:name).sort.reverse
- end
-
- def heads
- @heads ||= repo.heads
- end
-
- def tree(fcommit, path = nil)
- fcommit = commit if fcommit == :head
- tree = fcommit.tree
- path ? (tree / path) : tree
- end
-
- def commit(commit_id = nil)
- commit = if commit_id
- repo.commits(commit_id).first
- else
- repo.commits.first
- end
- Commit.new(commit) if commit
- end
-
- def fresh_commits(n = 10)
- commits = heads.map do |h|
- repo.commits(h.name, n).map { |c| Commit.new(c, h) }
- end.flatten.uniq { |c| c.id }
-
- commits.sort! do |x, y|
- y.committed_date <=> x.committed_date
- end
-
- commits[0...n]
- end
-
- def commits_with_refs(n = 20)
- commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
-
- commits.sort! do |x, y|
- y.committed_date <=> x.committed_date
- end
-
- commits[0..n]
- end
-
- def commits_since(date)
- commits = heads.map do |h|
- repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
- end.flatten.uniq { |c| c.id }
-
- commits.sort! do |x, y|
- y.committed_date <=> x.committed_date
- end
-
- commits
- end
-
- def commits(ref, path = nil, limit = nil, offset = nil)
- if path
- repo.log(ref, path, :max_count => limit, :skip => offset)
- elsif limit && offset
- repo.commits(ref, limit, offset)
- else
- repo.commits(ref)
- end.map{ |c| Commit.new(c) }
- end
-
- def commits_between(from, to)
- repo.commits_between(from, to).map { |c| Commit.new(c) }
- end
end
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index 726a85ae5b0..b00ab96b6f2 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -18,7 +18,7 @@ class UsersProject < ActiveRecord::Base
delegate :name, :email, :to => :user, :prefix => true
- def self.bulk_import(project, user_ids, project_access, repo_access)
+ def self.bulk_import(project, user_ids, project_access)
UsersProject.transaction do
user_ids.each do |user_id|
users_project = UsersProject.new(
@@ -31,7 +31,7 @@ class UsersProject < ActiveRecord::Base
end
end
- def self.user_bulk_import(user, project_ids, project_access, repo_access)
+ def self.user_bulk_import(user, project_ids, project_access)
UsersProject.transaction do
project_ids.each do |project_id|
users_project = UsersProject.new(
diff --git a/app/views/dashboard/_projects_feed.html.haml b/app/views/dashboard/_projects_feed.html.haml
index a5fc8ceece7..c1abe556a88 100644
--- a/app/views/dashboard/_projects_feed.html.haml
+++ b/app/views/dashboard/_projects_feed.html.haml
@@ -6,4 +6,4 @@
= project.name
%small
last activity at
- = project.last_activity_date_cached.stamp("Aug 25, 2011")
+ = project.last_activity_date.stamp("Aug 25, 2011")
diff --git a/app/views/projects/_feed.html.haml b/app/views/projects/_feed.html.haml
deleted file mode 100644
index f907b8a253f..00000000000
--- a/app/views/projects/_feed.html.haml
+++ /dev/null
@@ -1,23 +0,0 @@
-- @activities.each do |update|
- .wll
- = link_to dashboard_feed_path(@project, update) do
- - if update.kind_of? Note
- %p
- %strong
- - if update.target
- = update.target.class.name.titleize
- = truncate update.target.id.to_s, :length => 10
- commented
- - else
- Project wall
- &ndash;
- = image_tag gravatar_icon(update.author_email), :class => "", :width => 16
- = truncate dashboard_feed_title(update), :length => 50
- - else
- %p
- %strong
- = update.class.name.titleize
- = truncate update.id.to_s
- &ndash;
- = image_tag gravatar_icon(update.author_email), :class => "", :width => 16
- = truncate dashboard_feed_title(update), :length => 50
diff --git a/app/views/projects/_list.html.haml b/app/views/projects/_list.html.haml
deleted file mode 100644
index 35c12978b31..00000000000
--- a/app/views/projects/_list.html.haml
+++ /dev/null
@@ -1,26 +0,0 @@
-%table.round-borders#projects-list
- %tr
- %th Name
- %th Path
- %th Code
- %th Web
- %th Git
- %th Admin
- %th Actions
-
- - @projects.each do |project|
- %tr{ :class => "project", :url => project_path(project) }
- %td
- = project.name
- .small-tags= tag_list project
-
- %td= truncate project.url_to_repo
- %td= project.code
- %td= check_box_tag "read", 1, project.readers.include?(current_user), :disabled => :disabled
- %td= check_box_tag "commit", 1, project.writers.include?(current_user), :disabled => :disabled
- %td= check_box_tag "admin", 1, project.admins.include?(current_user), :disabled => :disabled
- %td
- -if can? current_user, :admin_project, project
- = link_to 'Edit', edit_project_path(project), :class => "lbutton positive"
-%br
-