#319: Added ability to mass adding projects to the repository
This commit is contained in:
parent
136bd3be27
commit
a7e908b102
|
@ -45,7 +45,7 @@ class Api::V1::RepositoriesController < Api::V1::BaseController
|
|||
|
||||
def add_project
|
||||
project = Project.where(:id => params[:project_id]).first
|
||||
if project
|
||||
if project && can?(:read, project)
|
||||
begin
|
||||
@repository.projects << project
|
||||
render_json_response @repository, "Project '#{project.id}' has been added to repository successfully"
|
||||
|
|
|
@ -83,12 +83,20 @@ class Platforms::RepositoriesController < Platforms::BaseController
|
|||
end
|
||||
|
||||
def add_project
|
||||
if projects_list = params.try(:[], :repository).try(:[], :projects_list)
|
||||
@repository.add_projects projects_list, current_user
|
||||
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.projects_will_be_added')
|
||||
end
|
||||
if params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
begin
|
||||
@repository.projects << @project
|
||||
flash[:notice] = t('flash.repository.project_added')
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
if can?(:read, @project)
|
||||
begin
|
||||
@repository.projects << @project
|
||||
flash[:notice] = t('flash.repository.project_added')
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
flash[:error] = t('flash.repository.project_not_added')
|
||||
end
|
||||
else
|
||||
flash[:error] = t('flash.repository.project_not_added')
|
||||
end
|
||||
redirect_to platform_repository_path(@platform, @repository)
|
||||
|
@ -136,8 +144,14 @@ class Platforms::RepositoriesController < Platforms::BaseController
|
|||
end
|
||||
|
||||
def remove_project
|
||||
ProjectToRepository.where(:project_id => params[:project_id], :repository_id => @repository.id).destroy_all
|
||||
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
|
||||
if projects_list = params.try(:[], :repository).try(:[], :projects_list)
|
||||
@repository.remove_projects projects_list
|
||||
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.projects_will_be_removed')
|
||||
end
|
||||
if params[:project_id]
|
||||
ProjectToRepository.where(:project_id => params[:project_id], :repository_id => @repository.id).destroy_all
|
||||
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
|
||||
end
|
||||
end
|
||||
|
||||
def regenerate_metadata
|
||||
|
|
|
@ -28,6 +28,7 @@ class Repository < ActiveRecord::Base
|
|||
|
||||
attr_accessible :name, :description, :publish_without_qa
|
||||
attr_readonly :name, :platform_id
|
||||
attr_accessor :projects_list
|
||||
|
||||
def regenerate(build_for_platform_id = nil)
|
||||
build_for_platform = Platform.main.find build_for_platform_id if platform.personal?
|
||||
|
@ -57,6 +58,34 @@ class Repository < ActiveRecord::Base
|
|||
end
|
||||
later :clone_relations, :loner => true, :queue => :clone_build
|
||||
|
||||
def add_projects(list, user)
|
||||
current_ability = Ability.new(user)
|
||||
list.lines.each do |line|
|
||||
begin
|
||||
line.chomp!; line.strip!
|
||||
owner, name = line.split('/')
|
||||
next if owner.blank? || name.blank?
|
||||
|
||||
project = Project.where(:owner_uname => owner, :name => name).accessible_by(current_ability, :read).first
|
||||
projects << project if project
|
||||
rescue RuntimeError, Exception
|
||||
end
|
||||
end
|
||||
end
|
||||
later :add_projects, :queue => :clone_build
|
||||
|
||||
def remove_projects(list)
|
||||
list.lines.each do |name|
|
||||
begin
|
||||
name.chomp!; name.strip!
|
||||
next if name.blank?
|
||||
project_to_repositories.where(:projects => { :name => name }).joins(:project).destroy_all
|
||||
rescue RuntimeError, Exception
|
||||
end
|
||||
end
|
||||
end
|
||||
later :remove_projects, :queue => :clone_build
|
||||
|
||||
def full_clone(attrs = {})
|
||||
base_clone(attrs).tap do |c|
|
||||
with_skip {c.save} and c.clone_relations(self) # later with resque
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%h3= raw "#{t("layout.repositories.add_project_to")}: #{link_to @repository.name, platform_repository_path(@platform, @repository)}"
|
||||
%h3= raw "#{t("layout.repositories.add_projects_to")}: #{link_to @repository.name, platform_repository_path(@platform, @repository)}"
|
||||
|
||||
= form_for :repository, :url => add_project_platform_repository_path(@platform, @repository), :html => { :class => :form } do |f|
|
||||
.leftlist= f.label :projects_list
|
||||
.rightlist= f.text_area :projects_list
|
||||
.both
|
||||
.hr
|
||||
.button_block
|
||||
= submit_tag t('layout.add'), :data => {'disable-with' => t('layout.saving')}
|
||||
|
||||
= render 'proj_list', :object => @projects
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%h3= raw "#{t("layout.repositories.remove_projects_from")}: #{link_to @repository.name, platform_repository_path(@platform, @repository)}"
|
||||
|
||||
= form_for :repository, :url => remove_project_platform_repository_path(@platform, @repository), :html => { :class => :form } do |f|
|
||||
.leftlist= f.label :projects_list
|
||||
.rightlist= f.text_area :projects_list
|
||||
.both
|
||||
.hr
|
||||
.button_block
|
||||
= submit_tag t('layout.delete'), :data => {'disable-with' => t('layout.saving')}
|
|
@ -16,5 +16,7 @@
|
|||
%h3.fix= t("layout.projects.list_header")
|
||||
- if can? :add_project, @repository
|
||||
= link_to t("layout.projects.add"), add_project_platform_repository_path(@platform, @repository), :class => 'button'
|
||||
- if can? :remove_project, @repository
|
||||
= link_to t("layout.repositories.mass_delete"), remove_project_platform_repository_path(@platform, @repository), :class => 'button'
|
||||
|
||||
= render 'proj_list'
|
||||
|
|
|
@ -5,7 +5,8 @@ en:
|
|||
add_sync_lock_file: "Add '.sync.lock' file"
|
||||
remove_sync_lock_file: "Remove '.sync.lock' file"
|
||||
sync_lock_file_info: "Presence of '.sync.lock' file means that repository is not ready for sync with mirror"
|
||||
add_project_to: Add project to repository
|
||||
add_projects_to: Add projects to repository
|
||||
remove_projects_from: Remove projets from repository
|
||||
edit: Settings
|
||||
list: List
|
||||
about: About repository
|
||||
|
@ -23,6 +24,7 @@ en:
|
|||
clear_confirm: Are you sure you want to clear this platform?
|
||||
clear_warning: Attention! Cleared packages cannot be restored!
|
||||
regenerate_metadata: Regenerate metadata
|
||||
mass_delete: Mass delete
|
||||
|
||||
personal_repositories:
|
||||
settings_header: Settings
|
||||
|
@ -34,7 +36,8 @@ en:
|
|||
repository:
|
||||
sync_lock_file_added: "'.sync.lock' file has been added to repository"
|
||||
sync_lock_file_removed: "'.sync.lock' file has been removed from repository"
|
||||
|
||||
projects_will_be_removed: Projects added to queue for removing
|
||||
projects_will_be_added: Projects added to queue for adding
|
||||
|
||||
saved: Repository added
|
||||
updated: Repository updated
|
||||
|
@ -57,6 +60,7 @@ en:
|
|||
repository: Repository
|
||||
attributes:
|
||||
repository:
|
||||
projects_list: Projects list
|
||||
name: Name
|
||||
description: Description
|
||||
publish_without_qa: Publication without QA
|
||||
|
|
|
@ -5,7 +5,8 @@ ru:
|
|||
add_sync_lock_file: "Добавить '.sync.lock' файл"
|
||||
remove_sync_lock_file: "Удалить '.sync.lock' файл"
|
||||
sync_lock_file_info: "Наличие '.sync.lock' файла означает, что репозиторий не готов для синхронизации с зеркалом"
|
||||
add_project_to: Добавить проект к репозиторию
|
||||
add_projects_to: Добавить проекты к репозиторию
|
||||
remove_projects_from: Удалить проекты из репозитория
|
||||
edit: Настройки
|
||||
list: Список
|
||||
about: О репозитории
|
||||
|
@ -23,6 +24,7 @@ ru:
|
|||
clear_confirm: Уверены, что хотите очистить платформу?
|
||||
clear_warning: Внимание! Очищенные пакеты не могут быть восстановлены!
|
||||
regenerate_metadata: Регенерировать метаданные
|
||||
mass_delete: Массовое удаление
|
||||
|
||||
personal_repositories:
|
||||
settings_header: Настройки
|
||||
|
@ -34,6 +36,8 @@ ru:
|
|||
repository:
|
||||
sync_lock_file_added: "'.sync.lock' файл добавлен в репозиторий"
|
||||
sync_lock_file_removed: "'.sync.lock' файл удален из репозитория"
|
||||
projects_will_be_removed: Проекты добавлены в очередь на удаление
|
||||
projects_will_be_added: Проекты добавлены в очередь на добавление
|
||||
|
||||
saved: Репозиторий успешно добавлен
|
||||
updated: Репозиторий успешно обновлен
|
||||
|
@ -56,6 +60,7 @@ ru:
|
|||
repository: Репозиторий
|
||||
attributes:
|
||||
repository:
|
||||
projects_list: Список проектов
|
||||
name: Название
|
||||
description: Описание
|
||||
publish_without_qa: Публикация без участия QA
|
||||
|
|
|
@ -192,6 +192,7 @@ Rosa::Application.routes.draw do
|
|||
resources :repositories do
|
||||
member do
|
||||
get :add_project
|
||||
get :remove_project
|
||||
delete :remove_project
|
||||
get :projects_list
|
||||
post :remove_members # fixme: change post to delete
|
||||
|
|
Loading…
Reference in New Issue