Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform alerts #3769

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/dashboard/app/javascript/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

export function alert(message) {
const div = alertDiv(message);
const main = document.getElementById('main_container');
main.prepend(div);
}

function alertDiv(message) {
const span = document.createElement('span');
span.innerText = message;

const div = document.createElement('div');
div.classList.add('alert', 'alert-danger', 'alert-dismissible');
div.setAttribute('role', 'alert');
div.appendChild(span);
div.appendChild(closeButton());

return div;
}

function closeButton() {
const button = document.createElement('button');
button.classList.add('btn-close');
button.dataset.bsDismiss = 'alert';

const span = document.createElement('span');
span.classList.add('sr-only');
span.innerText = 'Close';

button.appendChild(span);

return button;
}
5 changes: 3 additions & 2 deletions apps/dashboard/app/javascript/files/sweet_alert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Swal from 'sweetalert2'
import Swal from 'sweetalert2';
import { alert } from '../alert';
import {CONTENTID, EVENTNAME as DATATABLE_EVENTNAME} from './data_table.js';

export {EVENTNAME};
Expand All @@ -16,7 +17,7 @@ let sweetAlert = null;
jQuery(function() {
sweetAlert = new SweetAlert();
$(CONTENTID).on(EVENTNAME.showError, function(e,options) {
sweetAlert.alertError(options.title, options.message);
alert(options.message);
});

$(CONTENTID).on(EVENTNAME.showPrompt, function(e,options) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</nav>
</header>

<div class="<%= local_assigns[:layout_container_class] || 'container-md' %> content mt-4" role="main">
<div id="main_container" class="<%= local_assigns[:layout_container_class] || 'container-md' %> content mt-4" role="main">

<%= render "layouts/announcements" %>

Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/test/system/files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,24 @@ def setup

assert_equal(expected_links, null_links)
end

test 'allowlist errors flash' do
with_modified_env({ OOD_ALLOWLIST_PATH: Rails.root.to_s }) do
visit(files_url(Rails.root))

alerts = all('.alert')
assert(alerts.empty?)

find('#goto-btn').click
find('#swal2-input').set('/etc')
find('.swal2-confirm').click

alerts = all('.alert')
refute(alerts.empty?)
assert_equal(1, alerts.size)

alert_text = find('.alert > span').text
assert_equal('/etc does not have an ancestor directory specified in ALLOWLIST_PATH', alert_text)
end
end
end
Loading