1
0
Fork 0

Add action Staffs::AccountsController#index

This commit is contained in:
Alex Kotov 2019-08-12 01:48:50 +05:00
parent ef89b1f381
commit 11da69af35
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
class Staffs::AccountsController < ApplicationController
# GET /staff/accounts
def index
authorize %i[staff account]
@accounts = policy_scope(
Account,
policy_scope_class: Staff::AccountPolicy::Scope,
)
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class Staff::AccountPolicy < ApplicationPolicy
def index?
account&.superuser?
end
class Scope < Scope
def resolve
return scope.all if account&.superuser?
scope.none
end
end
end

View file

@ -0,0 +1,49 @@
<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 active" aria-current="page">
<%= Account.model_name.human count: 0 %>
</li>
</ol>
</nav>
<table class="table">
<thead>
<tr>
<th scope="col">
<%= Account.human_attribute_name :id %>
</th>
<th scope="col">
<%= Account.human_attribute_name :nickname %>
</th>
<th scope="col">
<%= Account.human_attribute_name :public_name %>
</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<% @accounts.each do |account| %>
<tr>
<td scope="row"><%= account.id %></td>
<td><%= account.nickname %></td>
<td><%= account.public_name %></td>
<td>
<% if account.superuser? %>
<span class="badge badge-primary">
<%= translate :superuser %>
</span>
<% end %>
</td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View file

@ -8,6 +8,12 @@
</nav>
<ul>
<% if policy(%i[staff account]).index? %>
<li>
<%= link_to Account.model_name.human(count: 0), staff_accounts_path %>
</li>
<% end %>
<% if policy(%i[staff person]).index? %>
<li>
<%= link_to Person.model_name.human(count: 0), staff_people_path %>

View file

@ -48,6 +48,8 @@ Rails.application.routes.draw do
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
resources :accounts, only: :index
resources :people, only: %i[index show] do
resources :person_comments,
path: 'comments',

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Staff::AccountPolicy do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -0,0 +1,28 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /staff/accounts' do
before do
sign_in current_account.user if current_account&.user
create :guest_account
create :usual_account
create :personal_account
create :superuser_account
get '/staff/accounts'
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