Allow to add only own projects to personal repository. Fix tests. Remove deprected relation. Refs #47

This commit is contained in:
Pavel Chipiga 2011-12-15 23:52:45 +02:00
parent 3575d5a266
commit 7448d74416
3 changed files with 7 additions and 6 deletions

View File

@ -26,8 +26,7 @@ class PersonalRepositoriesController < ApplicationController
def add_project def add_project
if params[:project_id] if params[:project_id]
@project = Project.find(params[:project_id]) @project = current_user.own_projects.find(params[:project_id])
# params[:project_id] = nil
unless @repository.projects.find_by_name(@project.name) unless @repository.projects.find_by_name(@project.name)
@repository.projects << @project @repository.projects << @project
flash[:notice] = t('flash.repository.project_added') flash[:notice] = t('flash.repository.project_added')
@ -36,13 +35,13 @@ class PersonalRepositoriesController < ApplicationController
end end
redirect_to personal_repository_path(@repository) redirect_to personal_repository_path(@repository)
else else
@projects = Project.addable_to_repository(@repository.id).paginate(:page => params[:project_page]) @projects = current_user.own_projects.addable_to_repository(@repository.id).paginate(:page => params[:project_page])
render 'projects_list' render 'projects_list'
end end
end end
def remove_project def remove_project
@project = Project.find(params[:project_id]) @project = current_user.own_projects.find(params[:project_id])
ProjectToRepository.where(:project_id => @project.id, :repository_id => @repository.id).destroy_all ProjectToRepository.where(:project_id => @project.id, :repository_id => @repository.id).destroy_all
redirect_to personal_repository_path(@repository), :notice => t('flash.repository.project_removed') redirect_to personal_repository_path(@repository), :notice => t('flash.repository.project_removed')
end end

View File

@ -6,8 +6,6 @@ class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy has_many :authentications, :dependent => :destroy
has_many :roles, :through => :targets
has_many :relations, :as => :object, :dependent => :destroy has_many :relations, :as => :object, :dependent => :destroy
has_many :targets, :as => :object, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation'

View File

@ -67,6 +67,8 @@ describe PersonalRepositoriesController do
before(:each) do before(:each) do
@admin = Factory(:admin) @admin = Factory(:admin)
set_session_for(@admin) set_session_for(@admin)
@project.update_attribute(:owner, @admin)
end end
it_should_behave_like 'personal repository owner' it_should_behave_like 'personal repository owner'
@ -87,6 +89,8 @@ describe PersonalRepositoriesController do
@user = Factory(:user) @user = Factory(:user)
set_session_for(@user) set_session_for(@user)
@project.update_attribute(:owner, @user)
@repository.update_attribute(:owner, @user) @repository.update_attribute(:owner, @user)
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')