2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Platforms::RepositoriesController < Platforms::BaseController
|
2011-03-11 16:08:41 +00:00
|
|
|
before_filter :authenticate_user!
|
2012-08-31 23:00:39 +01:00
|
|
|
skip_before_filter :authenticate_user!, :only => [:index, :show, :projects_list] if APP_CONFIG['anonymous_access']
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2011-11-24 21:46:19 +00:00
|
|
|
load_and_authorize_resource :platform
|
|
|
|
load_and_authorize_resource :repository, :through => :platform, :shallow => true
|
2012-09-12 14:43:02 +01:00
|
|
|
before_filter :set_members, :only => [:edit, :update]
|
2011-10-17 15:20:35 +01:00
|
|
|
|
|
|
|
def index
|
2012-04-01 16:19:54 +01:00
|
|
|
@repositories = @repositories.paginate(:page => params[:page])
|
2011-10-17 15:20:35 +01:00
|
|
|
end
|
2011-03-11 16:08:41 +00:00
|
|
|
|
|
|
|
def show
|
2013-07-01 11:50:35 +01:00
|
|
|
@projects = @repository.projects.recent
|
|
|
|
.search(params[:query]).paginate(:page => params[:project_page], :per_page => 30)
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 14:43:50 +01:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @repository.update_attributes(
|
|
|
|
:description => params[:repository][:description],
|
2012-09-06 16:43:07 +01:00
|
|
|
:publish_without_qa => (params[:repository][:publish_without_qa] || @repository.publish_without_qa)
|
2012-09-06 14:43:50 +01:00
|
|
|
)
|
|
|
|
flash[:notice] = I18n.t("flash.repository.updated")
|
|
|
|
redirect_to platform_repository_path(@platform, @repository)
|
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.repository.update_error")
|
|
|
|
flash[:warning] = @repository.errors.full_messages.join('. ')
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 16:30:14 +01:00
|
|
|
def remove_members
|
2012-09-12 21:47:39 +01:00
|
|
|
user_ids = params[:user_remove] ?
|
|
|
|
params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : []
|
|
|
|
User.where(:id => user_ids).each{ |user| @repository.remove_member(user) }
|
2012-09-11 16:30:14 +01:00
|
|
|
redirect_to edit_platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_member
|
2012-09-12 21:47:39 +01:00
|
|
|
User.where(:id => params[:member_id]).each{ |user| @repository.remove_member(user) }
|
2012-09-11 16:30:14 +01:00
|
|
|
redirect_to edit_platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_member
|
2012-09-12 14:25:46 +01:00
|
|
|
if member = User.where(:id => params[:member_id]).first
|
2012-09-12 21:47:39 +01:00
|
|
|
if @repository.add_member(member)
|
2012-09-12 14:25:46 +01:00
|
|
|
flash[:notice] = t('flash.repository.members.successfully_added', :name => member.uname)
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.repository.members.error_in_adding', :name => member.uname)
|
|
|
|
end
|
2012-09-11 16:30:14 +01:00
|
|
|
end
|
|
|
|
redirect_to edit_platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
2011-03-11 16:08:41 +00:00
|
|
|
def new
|
2011-10-17 15:20:35 +01:00
|
|
|
@repository = Repository.new
|
2011-10-27 23:48:39 +01:00
|
|
|
@platform_id = params[:platform_id]
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-03-31 01:58:27 +01:00
|
|
|
@repository.destroy
|
|
|
|
|
2011-03-31 03:00:21 +01:00
|
|
|
flash[:notice] = t("flash.repository.destroyed")
|
2012-04-02 16:43:59 +01:00
|
|
|
redirect_to platform_repositories_path(@repository.platform)
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-10-17 15:20:35 +01:00
|
|
|
@repository = Repository.new(params[:repository])
|
2011-11-24 21:46:19 +00:00
|
|
|
@repository.platform_id = params[:platform_id]
|
2011-03-11 16:08:41 +00:00
|
|
|
if @repository.save
|
2011-03-31 01:59:12 +01:00
|
|
|
flash[:notice] = t('flash.repository.saved')
|
2012-04-02 16:43:59 +01:00
|
|
|
redirect_to platform_repository_path(@platform, @repository)
|
2011-03-11 16:08:41 +00:00
|
|
|
else
|
2011-03-31 01:59:12 +01:00
|
|
|
flash[:error] = t('flash.repository.save_error')
|
2012-04-01 16:19:54 +01:00
|
|
|
flash[:warning] = @repository.errors.full_messages.join('. ')
|
2011-03-11 16:08:41 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-19 14:16:29 +01:00
|
|
|
def add_project
|
|
|
|
if params[:project_id]
|
|
|
|
@project = Project.find(params[:project_id])
|
2012-03-31 00:37:54 +01:00
|
|
|
begin
|
2011-10-19 14:16:29 +01:00
|
|
|
@repository.projects << @project
|
2011-11-02 21:37:00 +00:00
|
|
|
flash[:notice] = t('flash.repository.project_added')
|
2012-03-31 00:37:54 +01:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
2011-10-19 14:16:29 +01:00
|
|
|
flash[:error] = t('flash.repository.project_not_added')
|
|
|
|
end
|
2012-03-14 17:22:47 +00:00
|
|
|
redirect_to platform_repository_path(@platform, @repository)
|
2011-10-19 14:16:29 +01:00
|
|
|
else
|
2012-01-11 21:12:56 +00:00
|
|
|
render :projects_list
|
2011-10-19 14:16:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-30 22:42:58 +00:00
|
|
|
def projects_list
|
2012-12-11 14:32:11 +00:00
|
|
|
render(:text => @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true'
|
2012-03-15 13:53:36 +00:00
|
|
|
|
2012-01-12 16:37:50 +00:00
|
|
|
owner_subquery = "
|
|
|
|
INNER JOIN (
|
|
|
|
SELECT id, 'User' AS type, uname
|
|
|
|
FROM users
|
|
|
|
UNION
|
|
|
|
SELECT id, 'Group' AS type, uname
|
|
|
|
FROM groups
|
|
|
|
) AS owner
|
|
|
|
ON projects.owner_id = owner.id AND projects.owner_type = owner.type"
|
2012-03-15 13:53:36 +00:00
|
|
|
colName = ['projects.name']
|
2011-12-30 22:42:58 +00:00
|
|
|
sort_col = params[:iSortCol_0] || 0
|
|
|
|
sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc'
|
|
|
|
order = "#{colName[sort_col.to_i]} #{sort_dir}"
|
|
|
|
|
2012-12-11 13:48:16 +00:00
|
|
|
if params[:added] == "true"
|
|
|
|
@projects = @repository.projects
|
2012-03-15 13:53:36 +00:00
|
|
|
else
|
2012-12-11 13:48:16 +00:00
|
|
|
@projects = Project.joins(owner_subquery).addable_to_repository(@repository.id)
|
|
|
|
@projects = @projects.by_visibilities('open') if @repository.platform.platform_type == 'main'
|
|
|
|
end
|
|
|
|
@projects = @projects.paginate(
|
|
|
|
:page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1,
|
|
|
|
:per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25
|
|
|
|
)
|
|
|
|
|
|
|
|
@total_projects = @projects.count
|
2013-07-01 11:50:35 +01:00
|
|
|
@projects = @projects.search(params[:sSearch]).order(order)
|
2012-12-11 13:48:16 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json {
|
|
|
|
render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false
|
|
|
|
}
|
2012-10-22 09:26:00 +01:00
|
|
|
end
|
2011-12-30 22:42:58 +00:00
|
|
|
end
|
|
|
|
|
2011-10-19 14:16:29 +01:00
|
|
|
def remove_project
|
2012-10-14 14:38:06 +01:00
|
|
|
ProjectToRepository.where(:project_id => params[:project_id], :repository_id => @repository.id).destroy_all
|
2012-03-14 17:22:47 +00:00
|
|
|
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
|
2011-10-19 14:16:29 +01:00
|
|
|
end
|
|
|
|
|
2013-02-11 15:12:58 +00:00
|
|
|
def regenerate_metadata
|
2013-06-13 16:56:34 +01:00
|
|
|
build_for_platform = Platform.main.find params[:build_for_platform_id] if @repository.platform.personal?
|
|
|
|
if AbfWorker::BuildListsPublishTaskManager.repository_regenerate_metadata @repository, (build_for_platform || @repository.platform)
|
2013-02-12 13:30:28 +00:00
|
|
|
flash[:notice] = t('flash.repository.regenerate_in_queue')
|
2013-02-13 09:32:28 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.repository.regenerate_already_in_queue')
|
2013-02-12 13:30:28 +00:00
|
|
|
end
|
2013-02-11 17:32:31 +00:00
|
|
|
redirect_to platform_repository_path(@platform, @repository)
|
2013-02-11 15:12:58 +00:00
|
|
|
end
|
|
|
|
|
2012-09-12 14:43:02 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
def set_members
|
|
|
|
@members = @repository.members.order('name')
|
|
|
|
end
|
|
|
|
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|