Skip to content

Commit

Permalink
administrators can suppress an inactive calendar (HOURS-118)
Browse files Browse the repository at this point in the history
- add a missing error template for internal_server_error (HOURS-130)
- correct datatype of fk indexes to match id column types (bigint)
  • Loading branch information
barmintor committed Jul 10, 2024
1 parent f5cc307 commit 0a57dcd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 26 deletions.
13 changes: 10 additions & 3 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def index
path.blank? or path == '/'
end
if home_page
@locations = Location.where(front_page: true).where.not(code: 'all')
@locations = Location.where(front_page: true).where.not(code: 'all', suppress_display: true)
else
@locations = Location.where.not(code: 'all')
@locations = Location.where.not(code: 'all', suppress_display: true)
end
@locations = @locations.order(:name)
@now = Time.current
Expand Down Expand Up @@ -59,6 +59,13 @@ def destroy
end

def show
unless @location && (current_user || !@location.suppress_display)
respond_to do |format|
format.html { render "errors/not_found", status: 404, layout: "public" }
format.json { render json: {}, status: 404 }
end
return
end
@secondary_locations = Location.where(primary_location: @location).load
@date = params[:date] ? Date.parse(params[:date]) : Date.current
respond_to do |format|
Expand Down Expand Up @@ -129,7 +136,7 @@ def create_params

def update_params
if current_user.administrator?
params.require(:location).permit(:name, :code, :comment, :comment_two, :url, :summary, :primary, :primary_location_id, :front_page, :short_note, :short_note_url)
params.require(:location).permit(:name, :code, :comment, :comment_two, :url, :summary, :primary, :primary_location_id, :front_page, :short_note, :short_note_url, :suppress_display)
else
params.require(:location).permit(:comment, :comment_two, :url, :summary, :short_note, :short_note_url)
end
Expand Down
5 changes: 5 additions & 0 deletions app/views/errors/internal_server_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<h2>Internal Server Error</h2>

<p>Please contact a site administrator to report an error at this location.</p>
</div>
5 changes: 5 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<h2>Location not found</h2>

<p>Contact a site administrator if you think this is an error.</p>
</div>
9 changes: 9 additions & 0 deletions app/views/locations/_location_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<% end %>
</div>

<div class="form-group">
<%= f.label :suppress_display %>
<% if current_user.administrator? %>
<%= f.check_box :suppress_display %>
<% elsif @location.suppress_display %>
<p class="warn static-control-form"><%= t("location.suppressed") %></p>
<% end %>
</div>

<% if current_user.administrator? %>
<div class="form-group">
<%= f.label :front_page %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/locations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<div class="col-md-12">
<h2 class="location-name"><%= link_to @location.name, @location.url %></h2>
<div class="location-primary-comment">
<% if @location.suppress_display %>
<p class="warn">Public display of this location is suppressed.</p>
<% end %>
<% if @location.primary_location %>
<p>Check hours for: <strong class="text-center"><%= link_to @location.primary_location.name, location_path(@location.primary_location.code) %></strong></p>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
# available at https://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
location:
suppressed: "Public display of this location is suppressed."
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddLocationSuppressDisplaySwitch < ActiveRecord::Migration[6.0]
def up
add_column :locations, :suppress_display, :boolean, default: false
end

def down
remove_column :locations, :suppress_display
end
end
44 changes: 22 additions & 22 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_02_28_151512) do

create_table "locations", charset: "utf8", force: :cascade do |t|
ActiveRecord::Schema[7.0].define(version: 2024_07_10_150406) do
create_table "locations", force: :cascade do |t|
t.string "name", null: false
t.string "code", null: false
t.string "url"
t.text "comment"
t.text "comment_two"
t.string "summary"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.bigint "primary_location_id"
t.boolean "primary", default: false
t.boolean "front_page", default: false, null: false
t.string "short_note"
t.text "short_note_url"
t.boolean "suppress_display", default: false
t.index ["code"], name: "index_locations_on_code"
t.index ["front_page"], name: "index_locations_on_front_page"
t.index ["primary"], name: "index_locations_on_primary"
t.index ["primary_location_id"], name: "index_locations_on_primary_location_id"
end

create_table "permissions", charset: "utf8", force: :cascade do |t|
create_table "permissions", force: :cascade do |t|
t.bigint "user_id"
t.string "role", null: false
t.string "subject_class"
t.integer "subject_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["user_id"], name: "index_permissions_on_user_id"
end

create_table "timetables", charset: "utf8", force: :cascade do |t|
create_table "timetables", force: :cascade do |t|
t.date "date"
t.datetime "open"
t.datetime "close"
t.datetime "open", precision: nil
t.datetime "close", precision: nil
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.boolean "tbd", default: false, null: false
t.boolean "closed", default: false, null: false
t.string "note"
Expand All @@ -60,17 +60,17 @@
t.index ["open"], name: "index_timetables_on_open"
end

create_table "users", charset: "utf8", force: :cascade do |t|
create_table "users", force: :cascade do |t|
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "reset_password_sent_at", precision: nil
t.datetime "remember_created_at", precision: nil
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at", precision: nil
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.string "uid"
t.string "provider"
t.string "email", default: "", null: false
Expand Down
31 changes: 31 additions & 0 deletions spec/features/locations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
let(:lehman) { FactoryBot.create(:lehman) }
let(:underbutler) { FactoryBot.create(:underbutler) }
let(:butler) { underbutler.primary_location }
let(:duanereade) { FactoryBot.create(:duanereade, suppress_display: true) }

context 'when user without role logged in' do
# initialize at least one library
before { lehman }
Expand All @@ -28,6 +30,11 @@
expect(page).to have_css("h2", text: underbutler.name)
expect(page).to have_css("p", text: butler.name)
end

it "does not display suppressed locations", js: false do
visit("/locations/#{duanereade.code}")
expect(page.status_code).to eq(404)
end
end

context 'when administrator logged in' do
Expand Down Expand Up @@ -84,6 +91,20 @@
end

it "can update primary location"

it "displays suppressed locations", js: false do
visit("/locations/#{duanereade.code}")
expect(page).to have_content("Public display of this location is suppressed.")
end

it "can update suppress_display" do
expect(duanereade.suppress_display).to be true
visit edit_location_path(duanereade.code)
uncheck "Suppress"
click_on "Update Location"
expect(page).to have_content("Location successfully updated")
expect(duanereade.reload.suppress_display).to be false
end
end

context 'when manager logged in' do
Expand All @@ -103,6 +124,11 @@
visit new_location_path
expect(page).to have_content("Unauthorized")
end

it "displays suppressed locations", js: false do
visit("/locations/#{duanereade.code}")
expect(page).to have_content("Public display of this location is suppressed.")
end
end

context 'when editor logged in' do
Expand Down Expand Up @@ -131,5 +157,10 @@
end

it "cannot delete lehman"

it "displays suppressed locations", js: false do
visit("/locations/#{duanereade.code}")
expect(page).to have_content("Public display of this location is suppressed.")
end
end
end

0 comments on commit 0a57dcd

Please sign in to comment.