2019-08-19 19:30:56 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-22 23:54:30 +08:00
|
|
|
class RepositoriesController < ApplicationController
|
2019-09-02 16:30:29 +08:00
|
|
|
include InventoriesHelper
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
include ActionView::Context
|
|
|
|
include IconsHelper
|
2020-04-23 22:02:36 +08:00
|
|
|
include TeamsHelper
|
2020-06-01 16:24:03 +08:00
|
|
|
include RepositoriesDatatableHelper
|
2021-12-07 22:28:20 +08:00
|
|
|
include MyModulesHelper
|
2019-09-02 16:30:29 +08:00
|
|
|
|
2023-06-16 16:48:39 +08:00
|
|
|
before_action :load_repository, except: %i(index create create_modal sidebar archive restore actions_toolbar
|
|
|
|
export_modal export_repositories)
|
2020-06-04 20:39:56 +08:00
|
|
|
before_action :load_repositories, only: %i(index show sidebar)
|
2020-06-24 18:01:38 +08:00
|
|
|
before_action :load_repositories_for_archiving, only: :archive
|
|
|
|
before_action :load_repositories_for_restoring, only: :restore
|
2020-06-04 20:39:56 +08:00
|
|
|
before_action :check_view_all_permissions, only: %i(index sidebar)
|
2023-06-16 16:48:39 +08:00
|
|
|
before_action :check_view_permissions, except: %i(index create_modal create update destroy parse_sheet
|
|
|
|
import_records sidebar archive restore actions_toolbar
|
|
|
|
export_modal export_repositories)
|
2022-02-28 17:33:43 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(rename_modal update)
|
|
|
|
before_action :check_delete_permissions, only: %i(destroy destroy_modal)
|
2020-06-19 00:07:23 +08:00
|
|
|
before_action :check_archive_permissions, only: %i(archive restore)
|
2019-08-20 22:07:22 +08:00
|
|
|
before_action :check_share_permissions, only: :share_modal
|
2020-05-15 23:46:59 +08:00
|
|
|
before_action :check_create_permissions, only: %i(create_modal create)
|
|
|
|
before_action :check_copy_permissions, only: %i(copy_modal copy)
|
2019-08-19 19:30:56 +08:00
|
|
|
before_action :set_inline_name_editing, only: %i(show)
|
2023-04-19 16:53:39 +08:00
|
|
|
before_action :set_breadcrumbs_items, only: %i(index show)
|
2017-05-22 23:54:30 +08:00
|
|
|
|
2018-03-28 20:12:11 +08:00
|
|
|
layout 'fluid'
|
2018-03-21 16:22:55 +08:00
|
|
|
|
2017-05-22 23:54:30 +08:00
|
|
|
def index
|
2020-06-01 16:24:03 +08:00
|
|
|
respond_to do |format|
|
2020-12-22 19:08:13 +08:00
|
|
|
format.html do
|
2023-05-30 17:19:10 +08:00
|
|
|
render 'index'
|
2020-12-22 19:08:13 +08:00
|
|
|
end
|
2020-06-01 16:24:03 +08:00
|
|
|
format.json do
|
|
|
|
render json: prepare_repositories_datatable(@repositories, current_team, params)
|
|
|
|
end
|
2018-03-20 21:45:57 +08:00
|
|
|
end
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|
|
|
|
|
2020-06-04 20:39:56 +08:00
|
|
|
def sidebar
|
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string(partial: 'repositories/sidebar', locals: {
|
2020-06-04 20:39:56 +08:00
|
|
|
repositories: @repositories,
|
2020-07-06 20:03:55 +08:00
|
|
|
archived: params[:archived] == 'true'
|
2020-06-04 20:39:56 +08:00
|
|
|
})
|
|
|
|
}
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|
|
|
|
|
2018-03-20 21:45:57 +08:00
|
|
|
def show
|
2022-09-07 17:01:53 +08:00
|
|
|
current_team_switch(@repository.team) unless @repository.shared_with?(current_team)
|
2019-11-26 00:40:29 +08:00
|
|
|
@display_edit_button = can_create_repository_rows?(@repository)
|
|
|
|
@display_delete_button = can_delete_repository_rows?(@repository)
|
|
|
|
@display_duplicate_button = can_create_repository_rows?(@repository)
|
2020-05-15 23:46:59 +08:00
|
|
|
@snapshot_provisioning = @repository.repository_snapshots.provisioning.any?
|
2021-08-02 17:11:11 +08:00
|
|
|
|
|
|
|
@busy_printer = LabelPrinter.where.not(current_print_job_ids: []).first
|
2020-05-15 23:46:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def table_toolbar
|
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string(partial: 'repositories/toolbar_buttons')
|
2020-05-15 23:46:59 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
|
|
|
render json: {
|
|
|
|
editable: can_manage_repository_rows?(@repository),
|
|
|
|
snapshot_provisioning: @repository.repository_snapshots.provisioning.any?
|
|
|
|
}
|
2019-11-21 00:12:47 +08:00
|
|
|
end
|
2017-06-08 17:44:24 +08:00
|
|
|
|
2020-01-14 18:13:19 +08:00
|
|
|
def load_table
|
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string(partial: 'repositories/repository_table',
|
2020-01-14 18:13:19 +08:00
|
|
|
locals: {
|
|
|
|
repository: @repository,
|
|
|
|
repository_index_link: repository_table_index_path(@repository)
|
|
|
|
})
|
|
|
|
}
|
2017-06-08 17:44:24 +08:00
|
|
|
end
|
|
|
|
|
2017-06-06 21:50:43 +08:00
|
|
|
def create_modal
|
|
|
|
@repository = Repository.new
|
2023-07-05 18:43:23 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'create_repository_modal', formats: :html)
|
|
|
|
}
|
2017-05-24 15:29:44 +08:00
|
|
|
end
|
|
|
|
|
2019-08-05 19:07:29 +08:00
|
|
|
def share_modal
|
2023-07-05 18:43:23 +08:00
|
|
|
render json: { html: render_to_string(partial: 'share_repository_modal', formats: :html) }
|
2019-08-05 19:07:29 +08:00
|
|
|
end
|
|
|
|
|
2022-03-30 16:54:55 +08:00
|
|
|
def hide_reminders
|
|
|
|
# synchronously hide currently visible reminders
|
|
|
|
if params[:visible_reminder_repository_row_ids].present?
|
|
|
|
repository_cell_ids =
|
|
|
|
RepositoryCell.joins(:repository_row)
|
|
|
|
.where(repository_rows: { id: params[:visible_reminder_repository_row_ids] })
|
|
|
|
.where.not(id: current_user.hidden_repository_cell_reminders.select(:repository_cell_id))
|
|
|
|
.with_active_reminder(current_user).pluck(:id)
|
|
|
|
|
|
|
|
HiddenRepositoryCellReminder.import(
|
|
|
|
repository_cell_ids.map { |id| { repository_cell_id: id, user_id: current_user.id } }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# offload the rest to background job
|
2023-08-11 21:31:29 +08:00
|
|
|
HideRepositoryRemindersJob.perform_later(@repository, current_user.id)
|
2022-03-30 16:54:55 +08:00
|
|
|
|
|
|
|
render json: { status: :ok }, status: :accepted
|
|
|
|
end
|
|
|
|
|
2017-05-24 15:29:44 +08:00
|
|
|
def create
|
|
|
|
@repository = Repository.new(
|
2020-05-15 23:46:59 +08:00
|
|
|
team: current_team,
|
2017-05-24 15:29:44 +08:00
|
|
|
created_by: current_user
|
|
|
|
)
|
|
|
|
@repository.assign_attributes(repository_params)
|
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
if @repository.save
|
|
|
|
log_activity(:create_inventory)
|
|
|
|
|
|
|
|
flash[:success] = t('repositories.index.modal_create.success_flash_html', name: @repository.name)
|
|
|
|
render json: { url: repository_path(@repository) }
|
|
|
|
else
|
|
|
|
render json: @repository.errors,
|
|
|
|
status: :unprocessable_entity
|
2017-05-24 15:29:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-30 21:11:28 +08:00
|
|
|
def destroy_modal
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
2023-07-18 19:36:41 +08:00
|
|
|
partial: 'delete_repository_modal',
|
|
|
|
formats: :html
|
2023-06-21 20:13:20 +08:00
|
|
|
)
|
|
|
|
}
|
2017-05-30 21:11:28 +08:00
|
|
|
end
|
|
|
|
|
2020-06-19 00:07:23 +08:00
|
|
|
def archive
|
2020-06-24 17:32:20 +08:00
|
|
|
service = Repositories::ArchiveRepositoryService.call(repositories: @repositories,
|
2020-06-19 00:07:23 +08:00
|
|
|
user: current_user,
|
|
|
|
team: current_team)
|
|
|
|
if service.succeed?
|
2023-05-29 17:48:13 +08:00
|
|
|
render json: { message: t('repositories.archive_inventories.success_flash') }, status: :ok
|
2020-06-19 00:07:23 +08:00
|
|
|
else
|
2023-05-29 17:48:13 +08:00
|
|
|
render json: { message: service.error_message }, status: :unprocessable_entity
|
2020-06-19 00:07:23 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
2020-06-24 17:32:20 +08:00
|
|
|
service = Repositories::RestoreRepositoryService.call(repositories: @repositories,
|
2020-06-19 00:07:23 +08:00
|
|
|
user: current_user,
|
|
|
|
team: current_team)
|
|
|
|
if service.succeed?
|
2023-05-29 17:48:13 +08:00
|
|
|
render json: { message: t('repositories.restore_inventories.success_flash') }, status: :ok
|
2020-06-19 00:07:23 +08:00
|
|
|
else
|
2023-05-29 17:48:13 +08:00
|
|
|
render json: { message: service.error_message }, status: :unprocessable_entity
|
2020-06-19 00:07:23 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-30 21:09:09 +08:00
|
|
|
def destroy
|
2017-06-02 23:38:46 +08:00
|
|
|
flash[:success] = t('repositories.index.delete_flash',
|
|
|
|
name: @repository.name)
|
2019-03-07 02:27:40 +08:00
|
|
|
|
|
|
|
log_activity(:delete_inventory) # Log before delete id
|
|
|
|
|
2018-05-25 17:41:43 +08:00
|
|
|
@repository.discard
|
2018-05-29 21:33:02 +08:00
|
|
|
@repository.destroy_discarded(current_user.id)
|
2020-06-19 21:54:45 +08:00
|
|
|
redirect_to team_repositories_path(archived: true)
|
2017-06-01 01:24:38 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def rename_modal
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
2023-07-20 22:46:16 +08:00
|
|
|
html: render_to_string(partial: 'rename_repository_modal', formats: :html)
|
2023-06-21 20:13:20 +08:00
|
|
|
}
|
2017-06-01 01:24:38 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-09-12 23:21:48 +08:00
|
|
|
@repository.update(repository_params)
|
2017-05-30 21:09:09 +08:00
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
if @repository.save
|
|
|
|
log_activity(:rename_inventory) # Acton only for renaming
|
2019-03-07 02:27:40 +08:00
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: { url: team_repositories_path }
|
|
|
|
else
|
|
|
|
render json: @repository.errors, status: :unprocessable_entity
|
2017-05-30 21:09:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 01:11:25 +08:00
|
|
|
def copy_modal
|
|
|
|
@tmp_repository = Repository.new(
|
2020-05-15 23:46:59 +08:00
|
|
|
team: current_team,
|
2017-06-08 01:11:25 +08:00
|
|
|
created_by: current_user,
|
|
|
|
name: @repository.name
|
|
|
|
)
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
2023-07-20 18:59:45 +08:00
|
|
|
html: render_to_string(partial: 'copy_repository_modal', formats: :html)
|
2023-06-21 20:13:20 +08:00
|
|
|
}
|
2017-06-08 01:11:25 +08:00
|
|
|
end
|
|
|
|
|
2023-06-16 16:48:39 +08:00
|
|
|
def export_modal
|
2023-06-23 18:10:58 +08:00
|
|
|
if current_user.has_available_exports?
|
2023-07-13 19:10:59 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'export_repositories_modal',
|
|
|
|
locals: { team_name: current_team.name,
|
2023-07-25 19:37:45 +08:00
|
|
|
counter: params[:counter].to_i,
|
2023-07-13 19:10:59 +08:00
|
|
|
export_limit: TeamZipExport.exports_limit,
|
|
|
|
num_of_requests_left: current_user.exports_left - 1 },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
2023-06-23 18:10:58 +08:00
|
|
|
else
|
2023-07-13 19:10:59 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'export_limit_exceeded_modal',
|
|
|
|
locals: { requests_limit: TeamZipExport.exports_limit },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
2023-06-16 16:48:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 01:11:25 +08:00
|
|
|
def copy
|
|
|
|
@tmp_repository = Repository.new(
|
2020-05-15 23:46:59 +08:00
|
|
|
team: current_team,
|
2017-06-08 01:11:25 +08:00
|
|
|
created_by: current_user
|
|
|
|
)
|
|
|
|
@tmp_repository.assign_attributes(repository_params)
|
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
if !@tmp_repository.valid?
|
|
|
|
render json: @tmp_repository.errors, status: :unprocessable_entity
|
|
|
|
else
|
|
|
|
copied_repository = @repository.copy(current_user, @tmp_repository.name)
|
2017-06-08 01:11:25 +08:00
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
if !copied_repository
|
|
|
|
render json: { name: ['Server error'] }, status: :unprocessable_entity
|
|
|
|
else
|
|
|
|
flash[:success] = t(
|
|
|
|
'repositories.index.copy_flash',
|
|
|
|
old: @repository.name,
|
|
|
|
new: copied_repository.name
|
|
|
|
)
|
|
|
|
render json: {
|
|
|
|
url: repository_path(copied_repository)
|
|
|
|
}
|
2017-06-08 01:11:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
# AJAX actions
|
|
|
|
def repository_table_index
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: ::RepositoryDatatable.new(view_context, @repository, nil, current_user)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2017-06-13 14:10:10 +08:00
|
|
|
def parse_sheet
|
2020-05-15 23:46:59 +08:00
|
|
|
render_403 unless can_create_repository_rows?(@repository)
|
2017-06-14 15:11:20 +08:00
|
|
|
|
2018-01-16 01:01:35 +08:00
|
|
|
unless import_params[:file]
|
2019-01-07 20:29:17 +08:00
|
|
|
repository_response(t('repositories.parse_sheet.errors.no_file_selected'))
|
2017-07-14 22:19:03 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
parsed_file = ImportRepository::ParseRepository.new(
|
2018-01-16 01:01:35 +08:00
|
|
|
file: import_params[:file],
|
2020-05-15 23:46:59 +08:00
|
|
|
repository: @repository,
|
2017-07-14 22:19:03 +08:00
|
|
|
session: session
|
|
|
|
)
|
|
|
|
if parsed_file.too_large?
|
|
|
|
repository_response(t('general.file.size_exceeded',
|
2018-06-19 20:15:14 +08:00
|
|
|
file_size: Rails.configuration.x.file_max_size_mb))
|
2018-05-31 16:45:31 +08:00
|
|
|
elsif parsed_file.has_too_many_rows?
|
|
|
|
repository_response(
|
|
|
|
t('repositories.import_records.error_message.items_limit',
|
|
|
|
items_size: Constants::IMPORT_REPOSITORY_ITEMS_LIMIT)
|
|
|
|
)
|
2017-07-14 22:19:03 +08:00
|
|
|
else
|
|
|
|
@import_data = parsed_file.data
|
2017-10-12 20:43:25 +08:00
|
|
|
|
2021-07-23 17:56:28 +08:00
|
|
|
if @import_data.header.blank? || @import_data.columns.blank?
|
2019-01-07 20:29:17 +08:00
|
|
|
return repository_response(t('repositories.parse_sheet.errors.empty_file'))
|
2017-10-12 20:43:25 +08:00
|
|
|
end
|
|
|
|
|
2017-10-17 20:42:06 +08:00
|
|
|
if (@temp_file = parsed_file.generate_temp_file)
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
2023-07-21 18:48:32 +08:00
|
|
|
html: render_to_string(partial: 'repositories/parse_records_modal', formats: :html)
|
2023-06-21 20:13:20 +08:00
|
|
|
}
|
2017-07-14 22:19:03 +08:00
|
|
|
else
|
2019-01-07 20:29:17 +08:00
|
|
|
repository_response(t('repositories.parse_sheet.errors.temp_file_failure'))
|
2017-06-14 15:11:20 +08:00
|
|
|
end
|
|
|
|
end
|
2017-07-14 22:19:03 +08:00
|
|
|
rescue ArgumentError, CSV::MalformedCSVError
|
2019-01-07 20:29:17 +08:00
|
|
|
repository_response(t('repositories.parse_sheet.errors.invalid_file',
|
2017-07-14 22:19:03 +08:00
|
|
|
encoding: ''.encoding))
|
|
|
|
rescue TypeError
|
2019-01-07 20:29:17 +08:00
|
|
|
repository_response(t('repositories.parse_sheet.errors.invalid_extension'))
|
2017-06-14 15:11:20 +08:00
|
|
|
end
|
2017-06-13 14:10:10 +08:00
|
|
|
end
|
|
|
|
|
2017-06-19 20:05:37 +08:00
|
|
|
def import_records
|
2019-08-21 21:32:45 +08:00
|
|
|
render_403 unless can_create_repository_rows?(Repository.accessible_by_teams(current_team)
|
|
|
|
.find_by_id(import_params[:id]))
|
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
# Check if there exist mapping for repository record (it's mandatory)
|
|
|
|
if import_params[:mappings].value?('-1')
|
|
|
|
import_records = repostiory_import_actions
|
|
|
|
status = import_records.import!
|
|
|
|
|
|
|
|
if status[:status] == :ok
|
|
|
|
log_activity(:import_inventory_items,
|
|
|
|
num_of_items: status[:nr_of_added])
|
|
|
|
|
|
|
|
flash[:success] = t('repositories.import_records.success_flash',
|
|
|
|
number_of_rows: status[:nr_of_added],
|
|
|
|
total_nr: status[:total_nr])
|
|
|
|
render json: {}, status: :ok
|
|
|
|
else
|
|
|
|
flash[:alert] =
|
|
|
|
t('repositories.import_records.partial_success_flash',
|
|
|
|
nr: status[:nr_of_added], total_nr: status[:total_nr])
|
|
|
|
render json: {}, status: :unprocessable_entity
|
2017-06-21 20:45:50 +08:00
|
|
|
end
|
2023-06-21 20:13:20 +08:00
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'shared/flash_errors',
|
|
|
|
locals: { error_title: t('repositories.import_records.error_message.errors_list_title'),
|
|
|
|
error: t('repositories.import_records.error_message.no_repository_name') }
|
|
|
|
)
|
|
|
|
}, status: :unprocessable_entity
|
2017-06-21 15:31:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:12:34 +08:00
|
|
|
def export_repository
|
2023-06-21 20:13:20 +08:00
|
|
|
if params[:row_ids] && params[:header_ids]
|
|
|
|
RepositoryZipExport.generate_zip(params, @repository, current_user)
|
|
|
|
log_activity(:export_inventory_items)
|
|
|
|
render json: { message: t('zip_export.export_request_success') }, status: :ok
|
|
|
|
else
|
|
|
|
render json: { message: t('zip_export.export_error') }, status: :unprocessable_entity
|
2017-06-06 22:12:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-12 16:29:17 +08:00
|
|
|
def export_repositories
|
|
|
|
repositories = Repository.viewable_by_user(current_user, current_team).where(id: params[:repository_ids])
|
2023-06-16 16:48:39 +08:00
|
|
|
if repositories.present? && current_user.has_available_exports?
|
|
|
|
current_user.increase_daily_exports_counter!
|
2023-08-11 21:31:29 +08:00
|
|
|
RepositoriesExportJob.perform_later(repositories.pluck(:id), current_user.id, current_team)
|
2023-06-12 16:29:17 +08:00
|
|
|
render json: { message: t('zip_export.export_request_success') }
|
|
|
|
else
|
|
|
|
render json: { message: t('zip_export.export_error') }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-07 22:28:20 +08:00
|
|
|
def assigned_my_modules
|
|
|
|
my_modules = MyModule.joins(:repository_rows).where(repository_rows: { repository: @repository })
|
|
|
|
.readable_by_user(current_user).distinct
|
2022-01-27 21:01:09 +08:00
|
|
|
render json: {data: grouped_by_prj_exp(my_modules).map { |g|
|
|
|
|
{
|
|
|
|
label: "#{g[:project_name]} / #{g[:experiment_name]}", options: g[:tasks].map do |t|
|
|
|
|
{ label: t.name, value: t.id }
|
|
|
|
end
|
|
|
|
}
|
|
|
|
} }
|
2021-12-07 22:28:20 +08:00
|
|
|
end
|
|
|
|
|
2021-12-15 22:16:12 +08:00
|
|
|
def repository_users
|
2022-01-28 05:50:04 +08:00
|
|
|
rows_type = params[:archived_by].present? ? :archived_repository_rows : :created_repository_rows
|
|
|
|
users = User.joins(rows_type)
|
|
|
|
.where(rows_type => { repository: @repository })
|
|
|
|
.group(:id)
|
2021-12-15 22:16:12 +08:00
|
|
|
|
|
|
|
render json: { users: users.map do |u|
|
|
|
|
{
|
|
|
|
label: u.full_name,
|
|
|
|
value: u.id,
|
|
|
|
params: {
|
|
|
|
email: u.email, avatar_url: u.avatar_url('icon_small')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end }
|
|
|
|
end
|
|
|
|
|
2023-05-24 15:57:06 +08:00
|
|
|
def actions_toolbar
|
|
|
|
render json: {
|
|
|
|
actions:
|
|
|
|
Toolbars::RepositoriesService.new(
|
|
|
|
current_user,
|
|
|
|
current_team,
|
|
|
|
repository_ids: params[:repository_ids].split(',')
|
|
|
|
).actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-06-21 15:31:39 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def repostiory_import_actions
|
|
|
|
ImportRepository::ImportRecords.new(
|
2018-01-16 01:01:35 +08:00
|
|
|
temp_file: TempFile.find_by_id(import_params[:file_id]),
|
2019-08-21 21:32:45 +08:00
|
|
|
repository: Repository.accessible_by_teams(current_team).find_by_id(import_params[:id]),
|
2018-01-16 01:01:35 +08:00
|
|
|
mappings: import_params[:mappings],
|
2017-06-19 20:05:37 +08:00
|
|
|
session: session,
|
|
|
|
user: current_user
|
|
|
|
)
|
2017-06-13 14:10:10 +08:00
|
|
|
end
|
2017-06-14 15:11:20 +08:00
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def load_repository
|
2017-06-12 23:49:42 +08:00
|
|
|
repository_id = params[:id] || params[:repository_id]
|
2022-08-05 20:13:36 +08:00
|
|
|
@repository = Repository.accessible_by_teams(current_user.teams).find_by(id: repository_id)
|
2017-06-12 23:49:42 +08:00
|
|
|
render_404 unless @repository
|
|
|
|
end
|
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def load_repositories
|
|
|
|
@repositories = Repository.accessible_by_teams(current_team).order('repositories.created_at ASC')
|
2020-07-06 20:03:55 +08:00
|
|
|
@repositories = if params[:archived] == 'true' || @repository&.archived?
|
2020-06-22 20:57:35 +08:00
|
|
|
@repositories.archived
|
|
|
|
else
|
|
|
|
@repositories.active
|
|
|
|
end
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|
|
|
|
|
2020-06-24 17:32:20 +08:00
|
|
|
def load_repositories_for_archiving
|
2020-06-24 18:01:38 +08:00
|
|
|
@repositories = current_team.repositories.active.where(id: params[:repository_ids])
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_repositories_for_restoring
|
|
|
|
@repositories = current_team.repositories.archived.where(id: params[:repository_ids])
|
2020-06-24 17:32:20 +08:00
|
|
|
end
|
|
|
|
|
2019-08-19 19:30:56 +08:00
|
|
|
def set_inline_name_editing
|
|
|
|
return unless can_manage_repository?(@repository)
|
|
|
|
|
|
|
|
@inline_editable_title_config = {
|
|
|
|
name: 'title',
|
|
|
|
params_group: 'repository',
|
2020-01-06 23:07:23 +08:00
|
|
|
item_id: @repository.id,
|
2019-08-19 19:30:56 +08:00
|
|
|
field_to_udpate: 'name',
|
2019-09-02 16:30:29 +08:00
|
|
|
path_to_update: team_repository_path(@repository),
|
2023-03-14 01:00:30 +08:00
|
|
|
label_after:
|
|
|
|
sanitize_input(
|
|
|
|
"<span class=\"repository-share-icon\">#{inventory_shared_status_icon(@repository, current_team)}</span>"
|
|
|
|
)
|
2019-08-19 19:30:56 +08:00
|
|
|
}
|
2017-06-19 20:05:37 +08:00
|
|
|
end
|
|
|
|
|
2017-05-22 23:54:30 +08:00
|
|
|
def check_view_all_permissions
|
2020-05-15 23:46:59 +08:00
|
|
|
render_403 unless can_read_team?(current_team)
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|
2017-06-01 01:24:38 +08:00
|
|
|
|
2017-06-12 23:49:42 +08:00
|
|
|
def check_view_permissions
|
2019-07-17 22:00:49 +08:00
|
|
|
render_403 unless can_read_repository?(@repository)
|
2017-06-12 23:49:42 +08:00
|
|
|
end
|
|
|
|
|
2017-05-24 15:29:44 +08:00
|
|
|
def check_create_permissions
|
2020-05-15 23:46:59 +08:00
|
|
|
render_403 unless can_create_repositories?(current_team)
|
2017-05-24 15:29:44 +08:00
|
|
|
end
|
|
|
|
|
2019-08-29 19:39:22 +08:00
|
|
|
def check_copy_permissions
|
2020-05-15 23:46:59 +08:00
|
|
|
render_403 if !can_create_repositories?(current_team) || @repository.shared_with?(current_team)
|
2017-05-24 15:29:44 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
def check_manage_permissions
|
|
|
|
render_403 unless can_manage_repository?(@repository)
|
2017-06-08 01:11:25 +08:00
|
|
|
end
|
|
|
|
|
2020-06-19 00:07:23 +08:00
|
|
|
def check_archive_permissions
|
2020-06-24 17:32:20 +08:00
|
|
|
@repositories.each do |repository|
|
|
|
|
return render_403 unless can_archive_repository?(repository)
|
|
|
|
end
|
2020-06-19 00:07:23 +08:00
|
|
|
end
|
|
|
|
|
2022-02-28 17:33:43 +08:00
|
|
|
def check_delete_permissions
|
|
|
|
render_403 unless can_delete_repository?(@repository)
|
|
|
|
end
|
|
|
|
|
2019-08-20 22:07:22 +08:00
|
|
|
def check_share_permissions
|
2022-07-01 17:55:27 +08:00
|
|
|
render_403 unless can_share_repository?(@repository)
|
2019-08-20 22:07:22 +08:00
|
|
|
end
|
|
|
|
|
2017-06-01 01:24:38 +08:00
|
|
|
def repository_params
|
|
|
|
params.require(:repository).permit(:name)
|
|
|
|
end
|
2017-06-14 15:11:20 +08:00
|
|
|
|
2018-01-16 01:01:35 +08:00
|
|
|
def import_params
|
|
|
|
params.permit(:id, :file, :file_id, mappings: {}).to_h
|
|
|
|
end
|
|
|
|
|
2017-06-14 15:11:20 +08:00
|
|
|
def repository_response(message)
|
2017-07-14 22:19:03 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
flash[:alert] = message
|
2017-12-08 00:59:23 +08:00
|
|
|
redirect_back(fallback_location: root_path)
|
2017-07-14 22:19:03 +08:00
|
|
|
end
|
|
|
|
format.json do
|
|
|
|
render json: { message: message },
|
|
|
|
status: :unprocessable_entity
|
|
|
|
end
|
2017-06-14 15:11:20 +08:00
|
|
|
end
|
|
|
|
end
|
2019-03-07 02:27:40 +08:00
|
|
|
|
2019-04-18 21:18:10 +08:00
|
|
|
def log_activity(type_of, message_items = {})
|
|
|
|
message_items = { repository: @repository.id }.merge(message_items)
|
|
|
|
|
2019-03-07 02:27:40 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
|
|
|
subject: @repository,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: @repository.team,
|
2019-04-18 21:18:10 +08:00
|
|
|
message_items: message_items)
|
2019-03-07 02:27:40 +08:00
|
|
|
end
|
2023-04-19 16:53:39 +08:00
|
|
|
|
|
|
|
def set_breadcrumbs_items
|
|
|
|
@breadcrumbs_items = []
|
2023-06-22 21:41:37 +08:00
|
|
|
archived_branch = @repository&.archived? || (!@repository && params[:archived] == 'true')
|
2023-04-19 16:53:39 +08:00
|
|
|
|
|
|
|
@breadcrumbs_items.push({
|
|
|
|
label: t('breadcrumbs.inventories'),
|
2023-06-01 20:28:47 +08:00
|
|
|
url: archived_branch ? repositories_path(archived: true) : repositories_path,
|
|
|
|
archived: archived_branch
|
2023-04-19 16:53:39 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
if @repository
|
|
|
|
@breadcrumbs_items.push({
|
|
|
|
label: @repository.name,
|
|
|
|
url: repository_path(@repository),
|
2023-06-01 20:28:47 +08:00
|
|
|
archived: archived_branch
|
2023-04-19 16:53:39 +08:00
|
|
|
})
|
|
|
|
end
|
2023-05-24 06:52:26 +08:00
|
|
|
|
2023-06-01 17:31:54 +08:00
|
|
|
@breadcrumbs_items.each do |item|
|
|
|
|
item[:label] = "(A) #{item[:label]}" if item[:archived]
|
2023-05-24 06:52:26 +08:00
|
|
|
end
|
2023-04-19 16:53:39 +08:00
|
|
|
end
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|