rosa-build/app/controllers/repositories_controller.rb

131 lines
4.3 KiB
Ruby
Raw Normal View History

2011-03-11 16:15:06 +00:00
class RepositoriesController < ApplicationController
before_filter :authenticate_user!
2011-10-19 14:16:29 +01:00
#before_filter :find_platform, :except => [:index, :new, :create]
before_filter :find_repository, :only => [:show, :destroy, :add_project, :remove_project]
before_filter :get_paths, :only => [:show, :new, :create, :add_project, :remove_project]
before_filter :find_platforms, :only => [:new, :create]
2011-10-31 21:55:56 +00:00
before_filter :check_global_access, :only => [:index, :new, :create]
def index
@repositories = Repository.paginate(:page => params[:repository_page])
end
def show
2011-10-31 18:14:25 +00:00
can_perform? @repository if @repository
2011-04-28 12:01:58 +01:00
if params[:query]
2011-10-19 14:16:29 +01:00
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30
2011-04-28 12:01:58 +01:00
else
2011-10-19 14:16:29 +01:00
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
2011-04-28 12:01:58 +01:00
end
end
def new
@repository = Repository.new
@platform_id = params[:platform_id]
end
def destroy
2011-10-31 18:14:25 +00:00
can_perform? @repository if @repository
@repository.destroy
2011-10-28 00:16:22 +01:00
platform_id = @repository.platform_id
2011-03-31 03:00:21 +01:00
flash[:notice] = t("flash.repository.destroyed")
2011-10-28 00:16:22 +01:00
redirect_to platform_path(platform_id)
end
def create
@repository = Repository.new(params[:repository])
@repository.owner = get_owner
if @repository.save
2011-03-31 01:59:12 +01:00
flash[:notice] = t('flash.repository.saved')
redirect_to @repositories_path
else
2011-03-31 01:59:12 +01:00
flash[:error] = t('flash.repository.save_error')
render :action => :new
end
end
2011-10-19 14:16:29 +01:00
def add_project
2011-10-31 18:14:25 +00:00
can_perform? @repository if @repository
2011-10-19 14:16:29 +01:00
if params[:project_id]
@project = Project.find(params[:project_id])
params[:project_id] = nil
unless @repository.projects.include? @project
@repository.projects << @project
# if @repository.save
flash[:notice] = t('flash.repository.project_added')
redirect_to platform_repository_path(@repository.platform, @repository)
# else
# flash[:error] = t('flash.repository.project_not_added')
# redirect_to url_for(:action => :add_project)
# end
else
flash[:error] = t('flash.repository.project_not_added')
redirect_to url_for(:action => :add_project)
end
else
@projects = Project.scoped
@projects = @projects.addable_to_repository(@repository.id)
@projects = @projects.by_visibilities(['open']) if @repository.platform.platform_type == 'main'
@projects.paginate(:page => params[:project_page])
#@projects = Project.addable_to_repository(@repository.id).paginate(:page => params[:project_page])
2011-10-19 14:16:29 +01:00
render 'projects_list'
end
end
def remove_project
2011-10-31 18:14:25 +00:00
can_perform? @repository if @repository
2011-10-19 14:16:29 +01:00
if params[:project_id]
@project = Project.find(params[:project_id])
params[:project_id] = nil
if @repository.projects.include? @project
@repository.projects.delete @project
# if @repository.save
flash[:notice] = t('flash.repository.project_removed')
redirect_to platform_repository_path(@repository.platform, @repository)
# else
# flash[:error] = t('flash.repository.project_not_removed')
# redirect_to url_for(:action => :remove_project)
# end
else
redirect_to url_for(:action => :remove_project)
end
else
redirect_to platform_repository_path(@repository.platform, @repository)
end
end
protected
def get_paths
if params[:user_id]
@user = User.find params[:user_id]
@repositories_path = user_repositories_path @user
@new_repository_path = new_user_repository_path @user
elsif params[:group_id]
@group = Group.find params[:group_id]
@repositories_path = group_repositories_path @group
@new_repository_path = new_group_repository_path @group
elsif params[:platform_id]
@platform = Platform.find params[:platform_id]
@repositories_path = platform_repositories_path @platform
@new_repository_path = new_platform_repository_path @platform
else
@repositories_path = repositories_path
@new_repository_path = new_repository_path
end
end
2011-10-19 14:16:29 +01:00
def find_platform
@platform = @repository.platform
end
def find_platforms
@platforms = Platform.all
end
def find_repository
@repository = Repository.find(params[:id])
end
end