Skip to content

Commit

Permalink
Restrict lists to books available to the current library
Browse files Browse the repository at this point in the history
This is a quick fixes that only changes the template logic.
See also #18

Fixes #16
  • Loading branch information
MagnusEnger authored and Magnus Enger committed Nov 6, 2014
1 parent 5f9b9ea commit 1d13fc2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lib/Ebooksforlib/Route/Browse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ get '/lists' => sub {
get '/list/:id' => sub {
my $list_id = param 'id';
my $list = rset('List')->find( $list_id );
# FIXME List display should be limited the currently chosen library. At the
# moment we are doing this by looping over all items in the template. This
# is probably far from ideal, it would be better to do it in here, in the
# DBIC query. https://github.com/Libriotech/Ebooksforlib/issues/18
template 'list', {
list => $list,
pagetitle => $list->name,
Expand Down
13 changes: 12 additions & 1 deletion views/books_table.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@

<ul class="utlisting">
[% FOREACH book IN books %]
<li>
[%# Check that this book has at least one item that is not deleted and that is available to the chosen library %]
[%# FIXME This solutin is probably not ideal, it would probably be better to limit in the DBIC query in the route %]
[% SET available_items = 0 %]
[% FOREACH file IN book.files %]
[% FOREACH item IN file.items %]
[% IF item.deleted != 1 && item.is_available_to( session.chosen_library ) == 1 %]
[% available_items = available_items + 1 %]
[% END %]
[% END %]
[% END %]
[% NEXT IF available_items == 0 %]
<li>
<a href="/book/[% book.id %]" class="book-block">
<div class="utlisting-img">
[% IF book.coverimg %]
Expand Down
18 changes: 8 additions & 10 deletions views/list.tt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
</div>

[%# Display admin links if the user has the right role %]
[% FOREACH role IN session.logged_in_user_roles %]
[% IF role == 'admin' %]
<div class="adminactions">
<p>Admin actions</p>
<p>
<a href="/lists/edit/[% list.id %]" title="[% l('Edit this list') %]">[% l('Edit') %]</a> |
<a href="/lists/books/[% list.id %]" title="[% l('Delete books from this list') %]">[% l('Delete books') %]</a>
</p>
</div>
[% END %]
[% IF session.user_is_admin == 1 %]
<div class="adminactions">
<p>Admin actions</p>
<p>
<a href="/lists/edit/[% list.id %]" title="[% l('Edit this list') %]">[% l('Edit') %]</a> |
<a href="/lists/books/[% list.id %]" title="[% l('Delete books from this list') %]">[% l('Delete books') %]</a>
</p>
</div>
[% END %]
</div>

0 comments on commit 1d13fc2

Please sign in to comment.