1
0
Fork 0

Add action Staffs::People::RelationshipsController#index

This commit is contained in:
Alex Kotov 2019-08-15 02:26:43 +05:00
parent 7a0eec0b97
commit 41c6e149b6
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
12 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
class Staffs::People::RelationshipsController < ApplicationController
before_action :set_person
# GET /staff/people/:person_id/relationships
def index
authorize [:staff, @person, :relationship]
@relationships = policy_scope(
@person.all_relationships.reorder(from_date: :desc),
policy_scope_class: Staff::Person::RelationshipPolicy::Scope,
)
end
private
def set_person
@person = Person.find params[:person_id]
end
end

View file

@ -11,4 +11,6 @@ module RegionalOfficesHelper
regional_office.federal_subject.display_name
end
end
alias staff_regional_office_link_or_none regional_office_link_or_none
end

View file

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

View file

@ -4,6 +4,7 @@
tab,
overview: [:staff, person],
person_comments: staff_person_person_comments_path(person),
relationships: staff_person_relationships_path(person),
passports: staff_person_passports_path(person),
) %>
</div>

View file

@ -0,0 +1,51 @@
<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 Person.model_name.human(count: 0), staff_people_path %>
</li>
<li class="breadcrumb-item active" aria-current="page">
<%= @person.full_name %>
</li>
</ol>
</nav>
<%= render partial: 'staffs/people/nav_tabs',
locals: { person: @person, tab: :relationships } %>
<table class="table">
<thead>
<tr>
<th scope="col">
<%= Relationship.human_attribute_name :id %>
</th>
<th scope="col">
<%= Relationship.human_attribute_name :from_date %>
</th>
<th scope="col">
<%= Relationship.human_attribute_name :regional_office %>
</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<% @relationships.each do |relationship| %>
<tr>
<td scope="row"><%= relationship.id %></td>
<td><%= localize relationship.from_date, format: :long %></td>
<td>
<%= staff_regional_office_link_or_none \
relationship.regional_office %>
</td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View file

@ -19,6 +19,9 @@ en:
regional_office:
one: Regional office
many: Regional offices
relationship:
one: Party relation
one: Party relations
user:
one: User
many: Users
@ -70,6 +73,10 @@ en:
id: ID
current_supporters_count: Number of supporters
current_members_count: Number of members
relationship:
id: ID
regional_office: Regional department
from_date: From date
user:
id: ID
confirmation_sent_at: Confirmation sent at

View file

@ -19,6 +19,9 @@ ru:
regional_office:
one: Региональное отделение
many: Региональные отделения
relationship:
one: Отношение с партией
one: Отношения с партией
user:
one: Пользователь
many: Пользователи
@ -70,6 +73,10 @@ ru:
id: ID
current_supporters_count: Количество сторонников
current_members_count: Количество членов
relationship:
id: ID
regional_office: Региональное отделение
from_date: Дата начала
user:
id: ID
confirmation_sent_at: Дата отправки подтверждения

View file

@ -3,6 +3,7 @@ en:
person:
overview: Overview
person_comments: Comments
relationships: Party relations
passports: Passports
settings:
credentials: Credentials

View file

@ -3,6 +3,7 @@ ru:
person:
overview: Обзор
person_comments: Комментарии
relationships: Отношения с партией
passports: Паспорта
settings:
credentials: Данные для входа

View file

@ -56,6 +56,10 @@ Rails.application.routes.draw do
controller: 'people/person_comments',
only: %i[index create]
resources :relationships,
controller: 'people/relationships',
only: :index
resources :passports,
controller: 'people/passports',
only: :index

View file

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

View file

@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /staff/people/:person_id/relationships' do
let(:person) { create :initial_person }
before do
sign_in current_account.user if current_account&.user
create :supporter_relationship, person: person
create :member_relationship, person: person
create :excluded_relationship, person: person
get "/staff/people/#{person.to_param}/relationships"
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