added mass create
This commit is contained in:
parent
160a8312d4
commit
001b7ef25e
|
@ -33,6 +33,11 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
@project = Project.new(mass_import: true)
|
||||
end
|
||||
|
||||
def mass_create
|
||||
authorize :project
|
||||
@project = Project.new(mass_create: true)
|
||||
end
|
||||
|
||||
def run_mass_import
|
||||
@project = Project.new project_params
|
||||
@project.owner = choose_owner
|
||||
|
@ -48,6 +53,21 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def run_mass_create
|
||||
@project = Project.new project_params
|
||||
@project.owner = choose_owner
|
||||
authorize @project
|
||||
@project.valid?
|
||||
@project.errors.messages.slice! :url
|
||||
if @project.errors.messages.blank? # We need only url validation
|
||||
@project.init_mass_create
|
||||
flash[:notice] = t('flash.project.mass_create_added_to_queue')
|
||||
redirect_to projects_path
|
||||
else
|
||||
render :mass_create
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize @project
|
||||
@project_aliases = Project.project_aliases(@project).paginate(page: current_page)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require 'nokogiri'
|
||||
require 'open-uri'
|
||||
|
||||
module Project::MassCreate
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def run_mass_create(url, visibility, owner, add_to_repository_id)
|
||||
repository = Repository.find add_to_repository_id
|
||||
open(url) { |f|
|
||||
f.each_line {
|
||||
|line|
|
||||
project = owner.projects.build(
|
||||
name: line,
|
||||
visibility: visibility,
|
||||
is_package: false
|
||||
)
|
||||
project.owner = owner
|
||||
if project.save
|
||||
repository.projects << project rescue nil
|
||||
project.update_attributes(is_package: true)
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,7 @@ class Project < ActiveRecord::Base
|
|||
include Project::DefaultBranch
|
||||
include Project::Finders
|
||||
include Project::GithubApi
|
||||
include Project::MassCreate
|
||||
|
||||
VISIBILITIES = ['open', 'hidden']
|
||||
MAX_OWN_PROJECTS = 32000
|
||||
|
@ -41,8 +42,8 @@ class Project < ActiveRecord::Base
|
|||
message: I18n.t("activerecord.errors.project.uname") },
|
||||
length: { maximum: 100 }
|
||||
validates :maintainer, presence: true, unless: :new_record?
|
||||
validates :url, presence: true, format: { with: /\Ahttps?:\/\/[\S]+\z/ }, if: :mass_import
|
||||
validates :add_to_repository_id, presence: true, if: :mass_import
|
||||
validates :url, presence: true, format: { with: /\Ahttps?:\/\/[\S]+\z/ }, if: :mass_import or :mass_create
|
||||
validates :add_to_repository_id, presence: true, if: :mass_import or :mass_create
|
||||
validates :visibility, presence: true, inclusion: { in: VISIBILITIES }
|
||||
validate { errors.add(:base, :can_have_less_or_equal, count: MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
||||
# throws validation error message from ProjectToRepository model into Project model
|
||||
|
@ -62,12 +63,16 @@ class Project < ActiveRecord::Base
|
|||
after_save :attach_to_personal_repository
|
||||
after_update -> { update_path_to_project(name_was) }, if: :name_changed?
|
||||
|
||||
attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id
|
||||
attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id, :mass_create
|
||||
|
||||
def init_mass_import
|
||||
Project.perform_later :low, :run_mass_import, url, srpms_list, visibility, owner, add_to_repository_id
|
||||
end
|
||||
|
||||
def init_mass_create
|
||||
Project.perform_later :low, :run_mass_create, url, visibility, owner, add_to_repository_id
|
||||
end
|
||||
|
||||
def name_with_owner
|
||||
"#{owner_uname || owner.uname}/#{name}"
|
||||
end
|
||||
|
|
|
@ -56,6 +56,8 @@ class ProjectPolicy < ApplicationPolicy
|
|||
is_admin? || user.platforms.main.find{ |p| local_admin?(p) }.present?
|
||||
end
|
||||
|
||||
alias_method :mass_create?, :mass_import?
|
||||
|
||||
def run_mass_import?
|
||||
return true if is_admin?
|
||||
return false unless owner_policy.write?
|
||||
|
@ -63,6 +65,8 @@ class ProjectPolicy < ApplicationPolicy
|
|||
repo.platform.main? && PlatformPolicy.new(user, repo.platform).add_project?
|
||||
end
|
||||
|
||||
alias_method :run_mass_create?, :run_mass_import?
|
||||
|
||||
# for grack
|
||||
def write?
|
||||
return false if user.guest?
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
%p= link_to t('layout.projects.new'), new_project_path, class: 'btn btn-primary'
|
||||
- if policy(:project).mass_import?
|
||||
%p= link_to t('layout.projects.mass_import'), mass_import_projects_path, class: 'btn btn-primary'
|
||||
- if policy(:project).mass_create?
|
||||
%p= link_to t('layout.projects.mass_create'), mass_create_projects_path, class: 'btn btn-primary'
|
||||
%hr.offset10
|
||||
%h3=t('layout.relations.filters')
|
||||
%ul.nav.nav-pills.nav-stacked
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
.container.col-md-offset-2.col-md-8
|
||||
h3
|
||||
= title t("layout.projects.mass_create")
|
||||
.row ng-init="owner = 'me'"
|
||||
= simple_form_for @project, url: run_mass_create_projects_path do |f|
|
||||
= f.hidden_field :mass_create
|
||||
= f.input :url
|
||||
= f.input :add_to_repository_id,
|
||||
as: :grouped_select,
|
||||
collection: mass_import_repositories_for_group_select,
|
||||
group_method: :last,
|
||||
include_blank: false
|
||||
|
||||
= render 'owner', f: f
|
||||
|
||||
= f.input :visibility,
|
||||
collection: project_visibility_options,
|
||||
include_blank: false
|
||||
|
||||
= f.button :submit, t('layout.add')
|
|
@ -19,6 +19,7 @@ en:
|
|||
owner_name: Owner name
|
||||
build_schedule: Build schedule
|
||||
mass_import: Mass import
|
||||
mass_create: Mass create
|
||||
branches: Branches
|
||||
delete_branch: Delete branch
|
||||
restore_branch: Restore branch
|
||||
|
@ -108,6 +109,7 @@ en:
|
|||
flash:
|
||||
project:
|
||||
mass_import_added_to_queue: Mass import added to queue
|
||||
mass_create_added_to_queue: Mass create added to queue
|
||||
saved: Project saved
|
||||
save_error: Unable to save project
|
||||
save_warning_ssh_key: Project owner must provide a SSH key in his profile
|
||||
|
|
|
@ -20,6 +20,7 @@ ru:
|
|||
owner_name: Владелец проекта
|
||||
build_schedule: Расписание сборок
|
||||
mass_import: Массовый импорт
|
||||
mass_create: Массовое создание
|
||||
branches: Ветки
|
||||
delete_branch: Удалить ветку
|
||||
restore_branch: Восстановить ветку
|
||||
|
@ -109,6 +110,7 @@ ru:
|
|||
flash:
|
||||
project:
|
||||
mass_import_added_to_queue: Массовый импорт добавлен в очередь
|
||||
mass_create_added_to_queue: Массовый создание добавлено в очередь
|
||||
saved: Проект успешно сохранен
|
||||
save_error: Не удалось сохранить проект
|
||||
save_warning_ssh_key: Владельцу проекта необходимо указать в профиле свой SSH ключ
|
||||
|
|
|
@ -298,6 +298,8 @@ Rails.application.routes.draw do
|
|||
collection do
|
||||
post :run_mass_import
|
||||
get :mass_import
|
||||
post :run_mass_create
|
||||
get :mass_create
|
||||
end
|
||||
end
|
||||
scope '*name_with_owner', name_with_owner: Project::OWNER_AND_NAME_REGEXP do # project
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue