2012-05-02 10:18:07 +01:00
|
|
|
class Platforms::RepositoriesController < Platforms::BaseController
|
2014-06-26 22:21:31 +01:00
|
|
|
include DatatableHelper
|
2013-08-27 16:43:30 +01:00
|
|
|
include FileStoreHelper
|
2014-05-15 20:52:43 +01:00
|
|
|
include RepositoriesHelper
|
2014-10-28 23:04:45 +00:00
|
|
|
include PaginateHelper
|
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
|
|
|
skip_before_action :authenticate_user!, only: [:index, :show, :projects_list] if APP_CONFIG['anonymous_access']
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :set_members, only: [:edit, :update]
|
2015-03-17 23:06:03 +00:00
|
|
|
before_action :load_repository
|
|
|
|
before_action -> { @repository = @platform.repositories.find(params[:id]) if params[:id] }
|
2011-10-17 15:20:35 +01:00
|
|
|
|
|
|
|
def index
|
2015-03-17 23:06:03 +00:00
|
|
|
@repositories = @platform.repositories
|
2014-10-30 18:07:43 +00:00
|
|
|
@repositories = Repository.custom_sort(@repositories).paginate(page: current_page)
|
2011-10-17 15:20:35 +01:00
|
|
|
end
|
2011-03-11 16:08:41 +00:00
|
|
|
|
|
|
|
def show
|
2014-10-30 18:07:43 +00:00
|
|
|
params[:per_page] = 30
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 14:43:50 +01:00
|
|
|
def edit
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2012-09-06 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2014-06-02 17:49:50 +01:00
|
|
|
if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications, :publish_builds_only_from_branch).merge(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('. ')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :edit
|
2012-09-06 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 16:30:14 +01:00
|
|
|
def remove_members
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
|
|
|
User.where(id: params[:members]).find_each do |user|
|
2014-11-11 23:50:15 +00:00
|
|
|
@repository.remove_member(user)
|
|
|
|
end
|
2012-09-11 16:30:14 +01:00
|
|
|
redirect_to edit_platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_member
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
|
|
|
if member = User.find_by(id: params[:member_id])
|
2012-09-12 21:47:39 +01:00
|
|
|
if @repository.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:notice] = t('flash.repository.members.successfully_added', name: member.uname)
|
2012-09-12 14:25:46 +01:00
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:error] = t('flash.repository.members.error_in_adding', name: member.uname)
|
2012-09-12 14:25:46 +01:00
|
|
|
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
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository = @platform.repositories.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
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
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
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository = @platform.repositories.build(params[:repository])
|
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')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :new
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-19 14:16:29 +01:00
|
|
|
def add_project
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2013-11-12 12:04:40 +00:00
|
|
|
if projects_list = params.try(:[], :repository).try(:[], :projects_list)
|
|
|
|
@repository.add_projects projects_list, current_user
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to platform_repository_path(@platform, @repository), notice: t('flash.repository.projects_will_be_added')
|
2013-11-12 17:13:05 +00:00
|
|
|
return
|
2013-11-12 12:04:40 +00:00
|
|
|
end
|
2013-11-13 09:33:36 +00:00
|
|
|
if params[:project_id].present?
|
2011-10-19 14:16:29 +01:00
|
|
|
@project = Project.find(params[:project_id])
|
2015-03-14 22:10:04 +00:00
|
|
|
if policy(@project).read?
|
2013-11-12 12:04:40 +00:00
|
|
|
begin
|
|
|
|
@repository.projects << @project
|
|
|
|
flash[:notice] = t('flash.repository.project_added')
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
flash[:error] = t('flash.repository.project_not_added')
|
|
|
|
end
|
|
|
|
else
|
2013-11-13 09:33:36 +00:00
|
|
|
flash[:error] = t('flash.repository.no_access_to_read_project')
|
2011-10-19 14:16:29 +01:00
|
|
|
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
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2014-01-21 04:51:49 +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"
|
2011-12-30 22:42:58 +00:00
|
|
|
|
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)
|
2013-09-16 14:47:33 +01:00
|
|
|
@projects = @projects.opened if @repository.platform.main? && !@repository.platform.hidden?
|
2012-12-11 13:48:16 +00:00
|
|
|
end
|
2014-10-28 23:04:45 +00:00
|
|
|
# @projects = @projects.paginate(page: page, per_page: per_page)
|
2012-12-11 13:48:16 +00:00
|
|
|
|
2014-10-28 23:04:45 +00:00
|
|
|
# @total_projects = @projects.count
|
2014-05-15 20:52:43 +01:00
|
|
|
@projects = @projects.by_owner(params[:owner_name]).
|
2014-10-30 18:07:43 +00:00
|
|
|
search(params[:project_name]).order("projects.name #{sort_dir}")
|
|
|
|
|
|
|
|
@total_items = @projects.count
|
|
|
|
@projects = @projects.paginate(paginate_params)
|
2012-12-11 13:48:16 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json {
|
2014-01-21 04:51:49 +00:00
|
|
|
render partial: (params[:added] == "true") ? 'project' : 'proj_ajax', layout: false
|
2012-12-11 13:48:16 +00:00
|
|
|
}
|
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
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2013-11-12 12:04:40 +00:00
|
|
|
if projects_list = params.try(:[], :repository).try(:[], :projects_list)
|
|
|
|
@repository.remove_projects projects_list
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to platform_repository_path(@platform, @repository), notice: t('flash.repository.projects_will_be_removed')
|
2013-11-12 12:04:40 +00:00
|
|
|
end
|
2013-11-13 09:33:36 +00:00
|
|
|
if params[:project_id].present?
|
2015-03-20 10:12:33 +00:00
|
|
|
ProjectToRepository.where(project_id: params[:project_id], repository_id: @repository.id).destroy_all
|
2015-03-19 17:24:54 +00:00
|
|
|
message = t('flash.repository.project_removed')
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {redirect_to platform_repository_path(@platform, @repository), notice: message}
|
|
|
|
format.json {render json: { message: message }}
|
|
|
|
end
|
2013-11-12 12:04:40 +00:00
|
|
|
end
|
2011-10-19 14:16:29 +01:00
|
|
|
end
|
|
|
|
|
2013-02-11 15:12:58 +00:00
|
|
|
def regenerate_metadata
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2015-04-02 15:54:13 +01:00
|
|
|
if @repository.regenerate(params[:repository].try :[], :build_for_platform_id)
|
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
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
def sync_lock_file
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository
|
2013-07-29 13:24:41 +01:00
|
|
|
if params[:remove]
|
|
|
|
@repository.remove_sync_lock_file
|
|
|
|
flash[:notice] = t('flash.repository.sync_lock_file_removed')
|
|
|
|
else
|
|
|
|
flash[:notice] = t('flash.repository.sync_lock_file_added')
|
|
|
|
@repository.add_sync_lock_file
|
|
|
|
end
|
2013-07-26 15:41:39 +01:00
|
|
|
redirect_to edit_platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
2015-03-19 23:45:15 +00:00
|
|
|
protected
|
2015-03-17 23:06:03 +00:00
|
|
|
|
2015-03-19 23:45:15 +00:00
|
|
|
# Private: before_action hook which loads Repository.
|
2015-03-17 23:06:03 +00:00
|
|
|
def load_repository
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @repository = @platform.repositories.find(params[:id]), :show? if params[:id]
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
2012-09-12 14:43:02 +01:00
|
|
|
|
|
|
|
def set_members
|
|
|
|
@members = @repository.members.order('name')
|
|
|
|
end
|
|
|
|
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|