Commit 1a278b5e authored by Tyler Amos's avatar Tyler Amos Committed by Markus Koller

Adjust sync_seat_link action to respond with JSON

This allows the FE to leverage async actions instead of a full page
refresh.
parent 69bd1adf
......@@ -59,15 +59,15 @@ class Admin::LicensesController < Admin::ApplicationController
end
def sync_seat_link
sync_result = Gitlab::SeatLinkData.new.sync
if sync_result
flash[:notice] = _('Your license was successfully synced.')
respond_to do |format|
format.json do
if Gitlab::SeatLinkData.new.sync
render json: { success: true }
else
flash[:error] = _('There was an error when trying to sync your license. Please verify that your instance is using an active license key.')
render json: { success: false }, status: :unprocessable_entity
end
end
end
redirect_to admin_license_path
end
private
......
......@@ -115,22 +115,22 @@ RSpec.describe Admin::LicensesController do
context 'with seat link enabled' do
let(:seat_link_enabled) { true }
it 'redirects with a successful message' do
post :sync_seat_link
it 'returns a success response' do
post :sync_seat_link, format: :json
expect(response).to redirect_to(admin_license_path)
expect(flash[:notice]).to eq('Your license was successfully synced.')
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq({ 'success' => true })
end
end
context 'with seat link disabled' do
let(:seat_link_enabled) { false }
it 'redirects with an error message' do
post :sync_seat_link
it 'returns a failure response' do
post :sync_seat_link, format: :json
expect(response).to redirect_to(admin_license_path)
expect(flash[:error]).to match('There was an error when trying to sync your license.')
expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response).to eq({ 'success' => false })
end
end
end
......
......@@ -31914,9 +31914,6 @@ msgstr ""
msgid "There was an error when subscribing to this label."
msgstr ""
msgid "There was an error when trying to sync your license. Please verify that your instance is using an active license key."
msgstr ""
msgid "There was an error when unsubscribing from this label."
msgstr ""
......@@ -36549,9 +36546,6 @@ msgstr ""
msgid "Your license is valid from"
msgstr ""
msgid "Your license was successfully synced."
msgstr ""
msgid "Your license will be included in your GitLab backup and will survive upgrades, so in normal usage you should never need to re-upload your %{code_open}.gitlab-license%{code_close} file."
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment