2018-05-03 08:55:14 -04:00
|
|
|
class Projects::MirrorsController < Projects::ApplicationController
|
|
|
|
include RepositorySettingsRedirect
|
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_action :remote_mirror, only: [:update]
|
2018-05-03 10:19:21 -04:00
|
|
|
before_action :check_mirror_available!
|
|
|
|
before_action :authorize_admin_project!
|
2018-05-03 08:55:14 -04:00
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
|
|
|
def show
|
2018-08-08 02:17:43 -04:00
|
|
|
redirect_to_repository_settings(project, anchor: 'js-push-remote-settings')
|
2018-05-03 08:55:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-07-27 11:24:43 -04:00
|
|
|
result = ::Projects::UpdateService.new(project, current_user, mirror_params).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
2018-05-03 08:55:14 -04:00
|
|
|
flash[:notice] = 'Mirroring settings were successfully updated.'
|
|
|
|
else
|
|
|
|
flash[:alert] = project.errors.full_messages.join(', ').html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
2018-08-08 02:17:43 -04:00
|
|
|
format.html { redirect_to_repository_settings(project, anchor: 'js-push-remote-settings') }
|
2018-05-03 08:55:14 -04:00
|
|
|
format.json do
|
|
|
|
if project.errors.present?
|
|
|
|
render json: project.errors, status: :unprocessable_entity
|
|
|
|
else
|
|
|
|
render json: ProjectMirrorSerializer.new.represent(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_now
|
|
|
|
if params[:sync_remote]
|
|
|
|
project.update_remote_mirrors
|
|
|
|
flash[:notice] = "The remote repository is being updated..."
|
|
|
|
end
|
|
|
|
|
2018-08-08 02:17:43 -04:00
|
|
|
redirect_to_repository_settings(project, anchor: 'js-push-remote-settings')
|
2018-05-03 08:55:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def remote_mirror
|
|
|
|
@remote_mirror = project.remote_mirrors.first_or_initialize
|
|
|
|
end
|
|
|
|
|
2018-05-03 10:19:21 -04:00
|
|
|
def check_mirror_available!
|
|
|
|
Gitlab::CurrentSettings.current_application_settings.mirror_available || current_user&.admin?
|
|
|
|
end
|
|
|
|
|
2018-05-03 08:55:14 -04:00
|
|
|
def mirror_params_attributes
|
|
|
|
[
|
|
|
|
remote_mirrors_attributes: %i[
|
|
|
|
url
|
|
|
|
id
|
|
|
|
enabled
|
|
|
|
only_protected_branches
|
|
|
|
]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def mirror_params
|
|
|
|
params.require(:project).permit(mirror_params_attributes)
|
|
|
|
end
|
|
|
|
end
|