-
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.
This commit adds a simple admin-only "pending" dashboard to make it easier and less error-prone to review albums that have been submitted for publication. I've decided to namespace the new controller under `admin` rather than reuse the existing album controller for this. Fixes #105
- Loading branch information
Showing
9 changed files
with
84 additions
and
0 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AlbumsController < ApplicationController | ||
def index | ||
authorize([:admin, Album]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AlbumPolicy < ApplicationPolicy | ||
def index? | ||
user.admin? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= render('shared/page_header', text: 'Albums') %> | ||
<%= render('shared/page_sub_header', text: 'Pending') %> | ||
|
||
<ul> | ||
<% Album.pending.each do |album| %> | ||
<li><%= text_link_to "#{album.title} by #{album.artist.name}", artist_album_path(album.artist, album) %></li> | ||
<% end %> | ||
</ul> |
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 @@ | ||
<h2 class="text-2xl tracking-tight leading-10 font-extrabold mb-3"><%= text %></h2> |
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Admin | ||
class AlbumsControllerTestSignedInAsAdmin < ActionDispatch::IntegrationTest | ||
def setup | ||
@album = create(:album, publication_status: :pending) | ||
@user = create(:user, admin: true) | ||
log_in_as(@user) | ||
end | ||
|
||
test '#index is authorized' do | ||
get admin_albums_path | ||
assert_response :success | ||
end | ||
|
||
test '#index lists pending albums' do | ||
get admin_albums_path | ||
assert_select 'li', text: "#{@album.title} by #{@album.artist.name}" | ||
end | ||
end | ||
|
||
class AlbumsControllerTestSignedOut < ActionDispatch::IntegrationTest | ||
test '#index is unauthorized' do | ||
get admin_albums_path | ||
assert_redirected_to log_in_url | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Admin | ||
class AlbumPolicyTest < ActiveSupport::TestCase | ||
test 'an admin' do | ||
user = build(:user, admin: true) | ||
album = build(:album) | ||
policy = Admin::AlbumPolicy.new(user, album) | ||
|
||
assert policy.index? | ||
end | ||
end | ||
end |