Skip to content

Commit

Permalink
Organizer can download CSV with applications
Browse files Browse the repository at this point in the history
  • Loading branch information
lisbethmarianne committed Dec 31, 2019
1 parent 1fb0b02 commit f592971
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/assets/images/icon-download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/icons.sass
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
background-size: 19px
background-position: 3px 4px

.icon-download
@extend %icon
background-image: image-url("icon-download.svg")
background-size: 28px
background-position: -2px -3px

.icon-delete
@extend %icon
background-image: image-url("icon-delete.svg")
Expand Down
23 changes: 19 additions & 4 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ def index_past
end

def show
if @event.unapproved && @event.organizer_id != current_user.id
flash[:alert] = t('.not_allowed')
redirect_back(fallback_location: root_path)
elsif @event.deleted
if @event.deleted
flash[:alert] = t('.event_deleted')
redirect_back(fallback_location: root_path)
end

respond_to do |format|
format.html do
if @event.unapproved && @event.organizer_id != current_user.id
flash[:alert] = t('.not_allowed')
redirect_back(fallback_location: root_path)
end
end

format.csv do
if @event.organizer_id != current_user.id
flash[:alert] = t('.not_allowed')
redirect_back(fallback_location: root_path)
else
send_data @event.to_csv, filename: "#{@event.name} #{DateTime.now.strftime("%F")}.csv"
end
end
end
end

def new
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin_events_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module AdminEventsHelper
def download_csv_link(event)
link_to t('.download_csv'), admin_event_path(id: event.id, format: :csv), class: "btn btn-save", title: t('.download_data')
link_to 'Download CSV', admin_event_path(id: event.id, format: :csv), class: "btn btn-save", title: 'Download Data'
end
end
9 changes: 8 additions & 1 deletion app/views/users/events.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide :title, t('.title') %>

<%= render partial: "shared/breadcrumbs", locals:{ title: t('.title') } %>
<%= render partial: "shared/breadcrumbs", locals: { title: t('.title') } %>

<h1><%= t(".title") %></h1>
<div class="two-columns">
Expand All @@ -24,6 +24,13 @@
<span class="icon-edit" aria-label="edit icon"></span>
<% end %>
</p>
<p>
<% if event.application_process == "selection_by_organizer" %>
<%= link_to event_path(id: event.id, format: :csv), class: "icon tooltip-large", title: t('.download_data') do %>
<span class="icon-download" aria-label="download icon"></span>
<% end %>
<% end %>
</p>
</li>
<% end %>
</ul>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ en:
past: "Past"
title: "Your events"
unapproved: "Not approved so far"
download_data: "Download Applications"
confirm_delete:
are_you_sure: "Are you sure you want to delete your user account?"
benefits_intro: "We would be sad to see you go and don't want you to miss out on the benefits of
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ es:
past: "Pasado"
title: "Tus eventos"
unapproved: "Aún sin aprobar"
download_data: "Descarga solicitudes"
confirm_delete:
are_you_sure: "¿Estás segura/o de que quieres eliminar tu cuenta de usuario?"
benefits_intro: "Nos entristecería que te marchases y no queremos que te pierdas los beneficios de un usuario registrado"
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ fr:
past: "Passés"
title: "Vos événements"
unapproved: "Non approuvé(s) jusqu'à présent"
download_data: "Téléchargez candidatures"
confirm_delete:
are_you_sure: "Êtes-vous sûr·e de vouloir supprimer votre compte utilisateur ?"
benefits_intro: "Nous serions tristes de vous voir partir et ne voulons pas que vous ne manquiez pas les avantages qu'une compte vous confère."
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,31 @@ class EventsControllerTest < ActionController::TestCase
assert_equal 'You are not allowed to access this event.', flash[:alert]
assert_redirected_to request.env["HTTP_REFERER"]
end

describe 'download event details as CSV' do
it 'shows the event details page in csv format to organizer' do
user = make_user(admin: false)
event = make_event(organizer_id: user.id)
sign_in_as(user)

get :show, params: { id: event.id }, format: :csv

assert_equal request.format, :csv
end

it 'does not show the event details page in csv format to other users' do
user = make_user(admin: false)
different_user = make_user(admin: false, email: "[email protected]")
event = make_event(organizer_id: user.id)
request.env["HTTP_REFERER"] = 'http://www.somewhere.net'
sign_in_as(different_user)

get :show, params: { id: event.id }, format: :csv

assert_equal 'You are not allowed to access this event.', flash[:alert]
assert_redirected_to request.env["HTTP_REFERER"]
end
end
end

describe '#preview' do
Expand Down
10 changes: 9 additions & 1 deletion test/integration/user_events_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
feature 'User Events Page' do
def setup
@user = make_user
@event = make_event(name: 'Applicants event', approved: true, organizer_id: @user.id)
@event = make_event(
name: 'Applicants event',
approved: true,
organizer_id: @user.id,
application_process: 'selection_by_organizer',
)
@application = make_application(@event, applicant_id: @user.id)
@draft = make_draft(@event, applicant_id: @user.id)
end
Expand All @@ -17,6 +22,9 @@ def setup

assert page.has_content?('Your events')
assert_equal event_path(@event.id), page.find_link(@event.name)[:href]
assert_equal edit_event_path(@event.id), page.find_link('Edit')[:href]
assert_equal event_path(id: @event.id, format: :csv),
page.find_link('Download Applications')[:href]
assert page.has_content?('1 application')
end
end

0 comments on commit f592971

Please sign in to comment.