1
0
Fork 0

Add action Staffs::RelationStatusesController#show

This commit is contained in:
Alex Kotov 2019-09-21 20:56:53 +05:00
parent 17f8215d93
commit 434ba5b74e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 71 additions and 1 deletions

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Staffs::RelationStatusesController < ApplicationController
before_action :set_relation_status, only: :show
# GET /staff/relation_statuses
def index
authorize [:staff, RelationStatus]
@ -9,4 +11,15 @@ class Staffs::RelationStatusesController < ApplicationController
policy_scope_class: Staff::RelationStatusPolicy::Scope,
).page(params[:page])
end
# GET /staff/relation_statuses/:codename
def show
authorize [:staff, @relation_status]
end
private
def set_relation_status
@relation_status = RelationStatus.find_by! codename: params[:codename]
end
end

View file

@ -7,6 +7,12 @@ class Staff::RelationStatusPolicy < ApplicationPolicy
account&.superuser?
end
def show?
return false if restricted?
account&.superuser?
end
class Scope < Scope
def resolve
return scope.none if restricted?

View file

@ -7,6 +7,7 @@
<th scope="col">
<%= RelationStatus.human_attribute_name :name %>
</th>
<th scope="col"></th>
</tr>
</thead>
@ -15,6 +16,11 @@
<tr>
<td scope="row"><%= relation_status.codename %></td>
<td><%= relation_status.name %></td>
<td>
<% if policy([:staff, relation_status]).show? %>
<%= open_action [:staff, relation_status] %>
<% end %>
</td>
</tr>
<% end %>
</tbody>

View file

@ -0,0 +1,15 @@
<div class="container">
<%= nav_breadcrumb(
[translate(:staff_services), staff_root_path],
[RelationStatus.model_name.human(count: 0), staff_relation_statuses_path],
RelationStatus.model_name.human(count: 1),
) %>
<dl>
<dt><%= RelationStatus.human_attribute_name :codename %></dt>
<dd><%= @relation_status.codename %></dd>
<dt><%= RelationStatus.human_attribute_name :name %></dt>
<dd><%= @relation_status.name %></dd>
</dl>
</div>

View file

@ -59,7 +59,7 @@ Rails.application.routes.draw do
resources :contact_networks, only: :index
resources :relation_statuses, only: :index
resources :relation_statuses, param: :codename, only: %i[index show]
resources :accounts, param: :nickname, only: %i[index show]

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /staff/relation_statuses/:codename' do
let(:current_account) { create :usual_account }
let!(:some_relation_status) { create :some_relation_status }
def make_request
get "/staff/relation_statuses/#{some_relation_status.codename}"
end
before do
sign_in current_account.user if current_account&.user
make_request
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
end