Add action Staffs::RelationStatusesController#index
This commit is contained in:
parent
f6d5bd981b
commit
17f8215d93
10 changed files with 163 additions and 0 deletions
12
app/controllers/staffs/relation_statuses_controller.rb
Normal file
12
app/controllers/staffs/relation_statuses_controller.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staffs::RelationStatusesController < ApplicationController
|
||||
# GET /staff/relation_statuses
|
||||
def index
|
||||
authorize [:staff, RelationStatus]
|
||||
@relation_statuses = policy_scope(
|
||||
RelationStatus.order(codename: :asc),
|
||||
policy_scope_class: Staff::RelationStatusPolicy::Scope,
|
||||
).page(params[:page])
|
||||
end
|
||||
end
|
19
app/policies/staff/relation_status_policy.rb
Normal file
19
app/policies/staff/relation_status_policy.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staff::RelationStatusPolicy < ApplicationPolicy
|
||||
def index?
|
||||
return false if restricted?
|
||||
|
||||
account&.superuser?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.none if restricted?
|
||||
|
||||
return scope.all if account&.superuser?
|
||||
|
||||
scope.none
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,5 +26,12 @@
|
|||
staff_contact_networks_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if policy([:staff, RelationStatus]).index? %>
|
||||
<li>
|
||||
<%= link_to RelationStatus.model_name.human(count: 0),
|
||||
staff_relation_statuses_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
21
app/views/staffs/relation_statuses/_table.html.erb
Normal file
21
app/views/staffs/relation_statuses/_table.html.erb
Normal file
|
@ -0,0 +1,21 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= RelationStatus.human_attribute_name :codename %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= RelationStatus.human_attribute_name :name %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% relation_statuses.each do |relation_status| %>
|
||||
<tr>
|
||||
<td scope="row"><%= relation_status.codename %></td>
|
||||
<td><%= relation_status.name %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
10
app/views/staffs/relation_statuses/index.html.erb
Normal file
10
app/views/staffs/relation_statuses/index.html.erb
Normal file
|
@ -0,0 +1,10 @@
|
|||
<div class="container">
|
||||
<%= nav_breadcrumb(
|
||||
[translate(:staff_services), staff_root_path],
|
||||
RelationStatus.model_name.human(count: 0),
|
||||
) %>
|
||||
|
||||
<%= render partial: 'table',
|
||||
locals: { relation_statuses: @relation_statuses } %>
|
||||
<%= pagination @relation_statuses %>
|
||||
</div>
|
|
@ -26,6 +26,9 @@ en:
|
|||
regional_office:
|
||||
one: Regional office
|
||||
many: Regional offices
|
||||
relation_status:
|
||||
one: Relation status
|
||||
many: Relation statuses
|
||||
relationship:
|
||||
one: Party relation
|
||||
many: Party relations
|
||||
|
@ -93,6 +96,10 @@ en:
|
|||
text: Text
|
||||
regional_office:
|
||||
id: ID
|
||||
relation_status:
|
||||
id: ID
|
||||
codename: Codename
|
||||
name: Name
|
||||
relationship:
|
||||
id: ID
|
||||
regional_office: Regional department
|
||||
|
|
|
@ -26,6 +26,9 @@ ru:
|
|||
regional_office:
|
||||
one: Региональное отделение
|
||||
many: Региональные отделения
|
||||
relation_status:
|
||||
one: Статус отношения
|
||||
many: Статусы отношения
|
||||
relationship:
|
||||
one: Отношение с партией
|
||||
one: Отношения с партией
|
||||
|
@ -93,6 +96,10 @@ ru:
|
|||
text: Текст
|
||||
regional_office:
|
||||
id: ID
|
||||
relation_status:
|
||||
id: ID
|
||||
codename: Кодовое имя
|
||||
name: Название
|
||||
relationship:
|
||||
id: ID
|
||||
regional_office: Региональное отделение
|
||||
|
|
|
@ -59,6 +59,8 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :contact_networks, only: :index
|
||||
|
||||
resources :relation_statuses, only: :index
|
||||
|
||||
resources :accounts, param: :nickname, only: %i[index show]
|
||||
|
||||
resources :people, only: %i[index show new create] do
|
||||
|
|
7
spec/policies/staff/relation_status_policy_spec.rb
Normal file
7
spec/policies/staff/relation_status_policy_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Staff::RelationStatusPolicy do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
71
spec/requests/staff/relation_statuses/index_spec.rb
Normal file
71
spec/requests/staff/relation_statuses/index_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /staff/relation_statuses' do
|
||||
let(:current_account) { create :superuser_account }
|
||||
|
||||
let :relation_statuses_count do
|
||||
[0, 1, rand(2..4), rand(5..10), rand(20..40)].sample
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
create_list :some_relation_status, relation_statuses_count
|
||||
|
||||
get '/staff/relation_statuses'
|
||||
end
|
||||
|
||||
for_account_types nil, :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
|
||||
|
||||
context 'when there are no relation statuses' do
|
||||
let(:relation_statuses_count) { 0 }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is one relation status' do
|
||||
let(:relation_statuses_count) { 1 }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are few relation statuses' do
|
||||
let(:relation_statuses_count) { rand 2..4 }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are many relation statuses' do
|
||||
let(:relation_statuses_count) { rand 5..10 }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are lot of relation statuses' do
|
||||
let(:relation_statuses_count) { rand 20..40 }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue