-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable/enable self-deposit (#285)
* add site option to check if deposits are enabled * toggle deposit upload links in views * add deposit enable/disable button to admin * refactor deposits enable site option code * fix incorrect paginate variable name * add button styling * use local: true to disable ajax form submission Co-authored-by: Eric O <[email protected]> * create default value for site option on first access --------- Co-authored-by: Eric O <[email protected]>
- Loading branch information
1 parent
8aaec91
commit 8a4815d
Showing
27 changed files
with
1,274 additions
and
1,031 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class SiteOptionsController < AdminController | ||
load_and_authorize_resource class: SiteOption | ||
|
||
def update | ||
option_keys = params.keys.select { |key| SiteOption::OPTIONS.include?(key) } | ||
option_keys.each do |option_key| | ||
option = SiteOption.find_by(name: option_key) | ||
if option.nil? | ||
option = SiteOption.create!(name: option_key, | ||
value: SiteOption.default_value_for_option(option_key)) | ||
end | ||
option.update(value: params[option_key]) | ||
redirect_back fallback_location: { controller: '/admin', action: 'index' } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class SiteOption < ApplicationRecord | ||
DEPOSITS_ENABLED = 'deposits_enabled' | ||
OPTIONS = [DEPOSITS_ENABLED].freeze | ||
|
||
validates :name, presence: { inclusion: { in: OPTIONS } } | ||
validates :value, inclusion: { in: [true, false] } | ||
|
||
def self.deposits_enabled | ||
find_by(name: DEPOSITS_ENABLED)&.value | ||
end | ||
|
||
def self.default_value_for_option(option_key) | ||
unless OPTIONS.include?(option_key) | ||
raise ArgumentError, "Invalid option key: #{option_key}. Must be one of: #{OPTIONS.join(', ')}" | ||
end | ||
|
||
# options will default to false so that admins must turn the option on | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="col-4 text-right"> | ||
<%= form_with url: admin_site_options_path, method: :patch, local: true do |form| %> | ||
<% if deposits_enabled? %> | ||
<% action_label = "Disable Deposits" %> | ||
<% enable = false %> | ||
<% else %> | ||
<% action_label = "Enable Deposits" %> | ||
<% enable = true %> | ||
<% end %> | ||
<%= form.hidden_field SiteOption::DEPOSITS_ENABLED, value: enable %> | ||
<%= form.submit action_label, class: "btn btn-secondary"%> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateSiteOptions < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :site_options do |t| | ||
t.string :name | ||
t.boolean :value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :site_option do | ||
name { '' } | ||
value { false } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.