Skip to content

Commit

Permalink
Maintenance banner moved to admin site (#1775)
Browse files Browse the repository at this point in the history
* initial

* finish

* travis fixes

* travis again

* not required
  • Loading branch information
mrkeksi authored Jun 26, 2020
1 parent 495c375 commit 9a96df6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ function changePrivacyPolicyURL(path) {
$.post(path, {value: url})
}

// Display the maintenance Banner
function displayMaintenanceBanner(path) {
var message = $("#maintenance-banner").val()
$.post(path, {value: message})
}

// Clear the maintenance Banner
function clearMaintenanceBanner(path) {
$.post(path, {value: ""})
}

function mergeUsers() {
let userToMerge = $("#from-uid").text()
$.post($("#merge-save-access").data("path"), {merge: userToMerge})
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ input:focus {
border-color: $primary !important;
}

.input-group button:focus {
box-shadow: none !important;
}

.list-group-item-action.active {
color: $primary;
}
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def maintenance_mode?
help: I18n.t("errors.maintenance.help"),
}
end
if Rails.configuration.maintenance_window.present?
unless cookies[:maintenance_window] == Rails.configuration.maintenance_window
flash.now[:maintenance] = Rails.configuration.maintenance_window
if @settings.get_value("Maintenance Banner").present?
unless cookies[:maintenance_window] == @settings.get_value("Maintenance Banner")
flash.now[:maintenance] = @settings.get_value("Maintenance Banner")
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/theming_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ def privpolicy_url
def user_color
@settings.get_value("Primary Color") || Rails.configuration.primary_color_default
end

def maintenance_banner
@settings.get_value("Maintenance Banner")
end
end
15 changes: 15 additions & 0 deletions app/views/admins/components/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@
</div>
</div>
</div>
<div class="mb-6 row">
<div class="col-12">
<div class="form-group">
<label class="form-label"><%= t("administrator.site_settings.maintenance_banner.title") %></label>
<label class="form-label text-muted"><%= t("administrator.site_settings.maintenance_banner.info") %></label>
<div class="input-group">
<input id="maintenance-banner" type="text" class="form-control" value="<%= maintenance_banner %>" placeholder="<%= t("administrator.site_settings.maintenance_banner.time") %>">
<span class="input-group-append">
<button onclick="displayMaintenanceBanner('<%= admin_update_settings_path(setting: 'Maintenance Banner') %>')" class="settings-button btn btn-primary" type="button"><%= t("administrator.site_settings.maintenance_banner.display") %></button>
<button onclick="clearMaintenanceBanner('<%= admin_update_settings_path(setting: 'Maintenance Banner') %>')" class="settings-button btn btn-danger" type="button"><%= t("administrator.site_settings.maintenance_banner.clear") %></button>
</span>
</div>
</div>
</div>
</div>
<% if current_user.has_role? :super_admin%>
<hr>
<div class="row">
Expand Down
12 changes: 9 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ en:
info: Set the default recording visbility for new recordings
title: Recording Default Visibility
warning: This setting will only be applied to rooms that aren't running
maintenance_banner:
info: Displays a Banner to inform the user of a scheduled maintenance
title: Maintenance Banner
display: Set
clear: Clear
time: "Maintenance: On Friday, there may be disruptions in service starting at 6 p.m."
registration:
info: Change the way that users register to the website
title: Registration Method
Expand All @@ -106,7 +112,7 @@ en:
demoted: User has been successfully demoted
invite: Invite successfully sent to %{email}
invite_email_verification: Emails must be enabled in order to use this method. Please contact your system administrator.
merge_fail: There was an issue merging the user accounts. Please check the users selected and try again
merge_fail: There was an issue merging the user accounts. Please check the users selected and try again
merge_success: User accounts merged successfully
perm_deleted: User has been permanently deleted
promoted: User has been successfully promoted
Expand Down Expand Up @@ -136,7 +142,7 @@ en:
edit_site_settings: Allow users with this role to edit site settings
edit_roles: Allow users with this role to edit other roles
manage_users: Allow users with this role to manage users
invalid_assignment: There was a problem assigning the roles to the user. Please check the values and try again
invalid_assignment: There was a problem assigning the roles to the user. Please check the values and try again
colour:
title: Role Colour
info: Set the colour that will be associated with the role
Expand Down Expand Up @@ -474,7 +480,7 @@ en:
fail: Your account has not been approved yet. If multiples days have passed since you signed up, please contact your administrator.
signup: Your account was successfully created. It has been sent to an administrator for approval.
banned:
fail: You do not have access to this application. If you believe this is a mistake, please contact your administrator.
fail: You do not have access to this application. If you believe this is a mistake, please contact your administrator.
deprecated:
new_signin: Select a new login method for you account. All your rooms from your old account will be migrated to the new account
twitter_signin: Signing in via Twitter has been deprecated and will be removed in the next release. Click <a href="%{link}"> here </a> to move your account to a new authentication method
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/admins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@
end
end

context "POST #maintenance_banner" do
it "displays a banner with the maintenance string" do
allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(true)
allow_any_instance_of(User).to receive(:greenlight_account?).and_return(true)

@request.session[:user_id] = @admin.id
fake_banner_string = "Maintenance work at 2 pm"

post :update_settings, params: { setting: "Maintenance Banner", value: fake_banner_string }

feature = Setting.find_by(provider: "provider1").features.find_by(name: "Maintenance Banner")

expect(flash[:success]).to be_present
expect(feature[:value]).to eq(fake_banner_string)
expect(response).to redirect_to(admin_site_settings_path)
end
end

context "POST #shared_access" do
it "changes the shared access setting" do
allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(true)
Expand Down

0 comments on commit 9a96df6

Please sign in to comment.