Add action Staffs::AccountsController#show
This commit is contained in:
parent
11da69af35
commit
33b0bceea0
6 changed files with 91 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staffs::AccountsController < ApplicationController
|
||||
before_action :set_account, except: :index
|
||||
|
||||
# GET /staff/accounts
|
||||
def index
|
||||
authorize %i[staff account]
|
||||
|
@ -9,4 +11,15 @@ class Staffs::AccountsController < ApplicationController
|
|||
policy_scope_class: Staff::AccountPolicy::Scope,
|
||||
)
|
||||
end
|
||||
|
||||
# GET /staff/accounts/:nickname
|
||||
def show
|
||||
authorize [:staff, @account]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = Account.find_by! nickname: params[:nickname]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,10 @@ class Staff::AccountPolicy < ApplicationPolicy
|
|||
account&.superuser?
|
||||
end
|
||||
|
||||
def show?
|
||||
account&.superuser?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.all if account&.superuser?
|
||||
|
|
|
@ -41,7 +41,14 @@
|
|||
</span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<% if policy([:staff, account]).show? %>
|
||||
<%= link_to [:staff, account],
|
||||
role: :button, class: 'btn btn-light btn-sm' do %>
|
||||
<i class="far fa-eye"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
36
app/views/staffs/accounts/show.html.erb
Normal file
36
app/views/staffs/accounts/show.html.erb
Normal file
|
@ -0,0 +1,36 @@
|
|||
<div class="container">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item">
|
||||
<%= link_to translate(:staff_services), staff_root_path %>
|
||||
</li>
|
||||
|
||||
<li class="breadcrumb-item">
|
||||
<%= link_to Account.model_name.human(count: 0), staff_accounts_path %>
|
||||
</li>
|
||||
|
||||
<li class="breadcrumb-item active" aria-current="page">
|
||||
<%= @account.nickname %>
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<% if @account.superuser? %>
|
||||
<div class="mb-4">
|
||||
<span class="badge badge-primary">
|
||||
<%= translate :superuser %>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<dl>
|
||||
<dt><%= Account.human_attribute_name :id %></dt>
|
||||
<dd><%= @account.id %></dd>
|
||||
|
||||
<dt><%= Account.human_attribute_name :nickname %></dt>
|
||||
<dd><%= @account.nickname %></dd>
|
||||
|
||||
<dt><%= Account.human_attribute_name :public_name %></dt>
|
||||
<dd><%= @account.public_name %></dd>
|
||||
</dl>
|
||||
</div>
|
|
@ -48,7 +48,7 @@ Rails.application.routes.draw do
|
|||
|
||||
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
|
||||
|
||||
resources :accounts, only: :index
|
||||
resources :accounts, param: :nickname, only: %i[index show]
|
||||
|
||||
resources :people, only: %i[index show] do
|
||||
resources :person_comments,
|
||||
|
|
29
spec/requests/staff/accounts/show_spec.rb
Normal file
29
spec/requests/staff/accounts/show_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /staff/accounts/:nickname' do
|
||||
let!(:some_account) { create :usual_account }
|
||||
let(:current_account) { create :usual_account }
|
||||
|
||||
def make_request
|
||||
get "/staff/accounts/#{some_account.nickname}"
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
make_request
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual do
|
||||
specify do
|
||||
expect(response).to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
for_account_types :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue