diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 868bec7c..8f137654 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 21643145..d7089fad 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 32b24459..d9a9284e 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 9c2d391d..36e65633 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 1e78e588..f18b8302 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 726a85ae..b00ab96b 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 a5fc8cee..c1abe556 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 f907b8a2..00000000 --- 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 - – - = 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 - – - = 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 35c12978..00000000 --- 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 - diff --git a/lib/gitlabhq/gitolite.rb b/lib/gitlabhq/gitolite.rb index 4f911113..701b9a8f 100644 --- a/lib/gitlabhq/gitolite.rb +++ b/lib/gitlabhq/gitolite.rb @@ -6,6 +6,14 @@ module Gitlabhq class Gitolite class AccessDenied < StandardError; end + def self.update_project(path, project) + self.new.configure { |git| git.update_project(path, project) } + end + + def self.destroy_project(project) + self.new.configure { |git| git.destroy_project(project) } + end + def pull # create tmp dir @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake index de00a68a..607250f1 100644 --- a/lib/tasks/bulk_import.rake +++ b/lib/tasks/bulk_import.rake @@ -90,8 +90,7 @@ def create_repo_project(project_name, user_email) # Add user as admin for project project.users_projects.create!( - :repo_access => Repository::REPO_RW, - :project_access => Project::PROJECT_RWA, + :project_access => UsersProject::MASTER, :user => user ) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 30aed095..112d2746 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -22,10 +22,7 @@ describe Project do end describe "Respond to" do - it { should respond_to(:readers) } - it { should respond_to(:writers) } it { should respond_to(:repository_writers) } - it { should respond_to(:admins) } it { should respond_to(:add_access) } it { should respond_to(:reset_access) } it { should respond_to(:update_repository) }