mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-14 05:05:55 +08:00
56 lines
1.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Repositories
|
|
class ArchiveRepositoryBaseService
|
|
extend Service
|
|
|
|
attr_reader :errors
|
|
|
|
def initialize(user:, team:, repositories:)
|
|
@user = user
|
|
@team = team
|
|
@repositories = repositories
|
|
@errors = {}
|
|
end
|
|
|
|
def call
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def succeed?
|
|
@errors.none?
|
|
end
|
|
|
|
def error_message
|
|
@errors.values.join(', ')
|
|
end
|
|
|
|
private
|
|
|
|
def valid?
|
|
unless @user
|
|
@errors[:invalid_arguments] =
|
|
{ 'user': @user }
|
|
.map do |key, value|
|
|
"Can't find #{key.capitalize}" if value.nil?
|
|
end.compact
|
|
end
|
|
if @repositories.blank?
|
|
@errors[:repositories] = I18n.t('repositories.archive_inventories.invalid_inventories_flash')
|
|
end
|
|
|
|
succeed?
|
|
end
|
|
|
|
def log_activity(type, repository)
|
|
Activities::CreateActivityService
|
|
.call(activity_type: type,
|
|
owner: @user,
|
|
subject: repository,
|
|
team: @team,
|
|
message_items: {
|
|
repository: repository.id
|
|
})
|
|
end
|
|
end
|
|
end
|