-
Notifications
You must be signed in to change notification settings - Fork 56
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
Recipients controller & spec #67
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module RegionAdmin | ||
class RecipientsController < ApplicationController | ||
before_filter :authenticate_volunteer! | ||
before_filter :authorize_region_admin! | ||
|
||
def index | ||
@locations = regional_recipients | ||
@regions = available_regions | ||
end | ||
|
||
private | ||
|
||
def regional_recipients | ||
if current_volunteer.super_admin? | ||
Location.active.recipients | ||
else | ||
Location.active.recipients.regional(available_regions.map(&:id)) | ||
end | ||
end | ||
|
||
def available_regions | ||
if current_volunteer.super_admin? | ||
Region.all | ||
else | ||
current_volunteer.assignments.collect{ |a| a.admin ? a.region : nil }.compact | ||
end | ||
end | ||
|
||
def authorize_region_admin! | ||
return if region_admin? | ||
redirect_to root_url, alert: "Unauthorized" | ||
end | ||
|
||
def region_admin? | ||
current_volunteer.any_admin? | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<h2>Recipients</h2> | ||
|
||
<div style="text-align: right;"> | ||
<%= form_tag("/locations/new", :method => "get") do %> | ||
New Recipient Location For <%= select_tag(:region_id, options_for_select(@regions.collect{ |r| [r.name,r.id] })) %> | ||
<%= submit_tag("Go") %> | ||
<% end %> | ||
</div> | ||
|
||
<% if @locations.empty? %> | ||
<p>No locations.</p> | ||
<% else %> | ||
<table id="data_table" class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Address</th> | ||
<th>Link</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @locations.each do |location| %> | ||
<tr> | ||
<td> | ||
<%= link_to location.name.presence || "Unnamed location", location_url(location) %> <%= link_to "(website)", location.website if location.website.present? %> | ||
</td> | ||
<td> | ||
<%= location.address.gsub("\n","<br>").html_safe unless location.address.nil? %> | ||
</td> | ||
<td> | ||
<% if location.receipt_key.present? %> | ||
<%= link_to 'Hud', "/locations/hud?id=#{location.id}&key=#{location.receipt_key}" %><br> | ||
<% end %> | ||
<%= link_to "Edit", edit_location_url(location) %><br> | ||
<%= link_to "Delete", location_url(location), :confirm => "Are you sure?", :method => :delete %> | ||
</td> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this view is missing a few table columns that were originally shown when this list was rendered with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was intentional - there were too many fields in a row. All the data is visible on the #show page. |
||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
|
||
<% content_for :scripts do %> | ||
<script type="text/javascript"> | ||
$(function () { | ||
$('#data_table').dataTable({ | ||
'iDisplayLength' : 50, | ||
}); | ||
}); | ||
</script> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "Region Admin Recipients" do | ||
feature "Viewing the list of recipients" do | ||
let(:boulder) { create(:region) } | ||
let(:denver) { create(:region) } | ||
|
||
let!(:boulder_recipient) { create(:recipient, region: boulder, name: "Boulder recipient site") } | ||
let!(:denver_recipient) { create(:recipient, region: denver, name: "Denver recipient site") } | ||
|
||
context "as a region admin" do | ||
let(:volunteer) { create(:volunteer, regions: [], assigned: true) } | ||
|
||
before do | ||
create(:assignment, :admin, volunteer: volunteer, region: boulder) | ||
create(:assignment, volunteer: volunteer, region: denver) | ||
|
||
login volunteer | ||
end | ||
|
||
it "can see the list of recipients in my administrated regions" do | ||
visit "/region_admin/recipients" | ||
|
||
expect(page).to have_content("Boulder recipient site") | ||
end | ||
|
||
it "cannot see recipients from unadministered regions" do | ||
visit "/region_admin/recipients" | ||
|
||
expect(page).to_not have_content("Denver recipient site") | ||
end | ||
end | ||
|
||
context "as a super admin" do | ||
let(:volunteer) { create(:volunteer, regions: [], assigned: true, admin: true) } | ||
|
||
before do | ||
create(:assignment, volunteer: volunteer, region: boulder) | ||
|
||
login volunteer | ||
end | ||
|
||
it "can see the list of recipients in all regions" do | ||
visit "/region_admin/recipients" | ||
|
||
expect(page).to have_content("Boulder recipient site") | ||
expect(page).to have_content("Denver recipient site") | ||
end | ||
end | ||
|
||
context "as a visitor" do | ||
it "redirects to sign in" do | ||
visit "/region_admin/recipients" | ||
|
||
expect(page.current_path).to eq("/volunteers/sign_in") | ||
end | ||
end | ||
|
||
context "as a volunteer" do | ||
let(:volunteer) { create(:volunteer, regions: [boulder], assigned: true) } | ||
|
||
before do | ||
login volunteer | ||
end | ||
|
||
it "redirects to home" do | ||
visit "/region_admin/recipients" | ||
|
||
expect(page.current_path).to eq("/") | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from
_path
to_url
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real change is adding the
region_admin
prefix. I switched the_path
to_url
as a matter of preference